Utilities¶
-
cana.utils.
entropy
(prob_vector, logbase=2.0)[source]¶ Calculates the entropy given a probability vector
-
cana.utils.
flip_binstate_bit_set
(binstate, idxs)[source]¶ Flips the binary value for a set of bits in a binary state.
- Parameters
binstate (string) – The binary state to flip.
idxs (int) – The indexes of the bits to flip.
- Returns
The flipped states
- Return type
(list)
-
cana.utils.
flip_bitset_in_strstates
(strstates, idxs)[source]¶ Flips the binary value for a set of bits in a binary state.
- Parameters
binstate (string) – The binary state to flip.
idxs (int) – The indexes of the bits to flip.
- Returns
The flipped states
- Return type
(list)
Example
>>> flip_bit_in_strstates('000',[0, 2]) ['100','001']
-
cana.utils.
isclose
(a, b, rel_tol=1e-09, abs_tol=0.0)[source]¶ Python 2 doesn’t have math.isclose() Here is an equivalent function Use this to tell whether two float numbers are close enough considering using == to compare floats is dangerous! 2.0*3.3 != 3.0*2.2 in python!
- Parameters
a (float) – the first float number
b (float) – the second float number
rel_tol (float) – the relative difference threshold between a and b
abs_tol (float) – absolute difference threshold. not recommended for float
- Returns
bool
-
cana.utils.
ncr
(n, r)[source]¶ Return the combination number. The combination of selecting r items from n iterms, order doesn’t matter.
- Parameters
n (int) – number of elements in collection
r (int) – length of combination
- Returns
int
-
cana.utils.
output_transitions
(eval_line, input_list)[source]¶ Returns an output list from combinatorically trying all input values
- Parameters
eval_line (string) – logic or arithmetic line to evaluate
input_list (list) – list of input variables
- Returns
list of all possible output transitions (list)
Example
RAS*=(GRB2 or PLCG1) and not GAP
>>> eval_line = "(GRB2 or PLCG1) and not GAP" >>> input_list = ['GRB2', 'PLCG1', 'GAP'] >>> output_transitions(eval_line, input_list) 000 001 010 011 100 101 110 111
A variable is dynamically created for each member of the input list and assigned the corresponding value from each trail string. The original eval_line is then evaluated with each assignment which results in the output list [0, 0, 1, 0, 1, 0, 1, 0]
-
cana.utils.
pathlength
(p, weights, rule='sum')[source]¶ Calculate the length of path p, with weighted edges, given the length rule of:
- Ars:
weights:
- rule (str):
‘sum’ - sum of edge weights along path ‘prod’ - product of edge weights along path ‘min’ - minimum of edge weights along path (weakest-link) ‘max’ - maximum of edge weights along path
TODO: update description