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.function_monotone(outputs, method='exact', nsamples=100, random_seed=None)[source]
Determine if a given LUT is monotone.
Here we test every pair of inputs that are Hamming distance 1. (see Goldreich et al 2000)
- Parameters:
outputs (list) – The transition outputs of the function.
method (str) – ‘exact’ - test all pairs of inputs TODO: ‘random’ - sample pairs of inputs
nsamples (int) – when method==’random’, specifies the number of samples.
- Returns:
True if monotone.
- Return type:
(Bool)
Example
>>> is_monotone(outputs=[0,0,0,1])
- cana.utils.input_monotone(outputs, input_idx, activation=1)[source]
Determine if a given input is activating or inhibiting in a given function.
- Parameters:
outputs (list) – The transition outputs of the function.
input_idx (int) – The input to test.
activation (1 or -1) – Whether to test for activation or inhibition.
- Returns:
True if monotone with respect to activation or inhibition.
- Return type:
(Bool)
Example
>>> input_monotone([0,1,0,0], 0, activation=1) == False >>> input_monotone([0,1,0,0], 0, activation=-1) == True
- 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.negate_LUT_input(outputs, idx)[source]
For a LUT defined by the output list, it negates the input.
- Parameters:
outputs (list) – The output list defining the LUT.
idxs (int) – The indexes of the input to negate.
- Returns:
The new output with input idx negated
- Return type:
(list)
- cana.utils.output_transitions(eval_line, input_list)[source]
Returns an output list from combinatorically trying all input values.
Each input variable is assigned every possible binary combination (0/1) via a namespace dict, and the boolean expression is evaluated with
eval()(builtins disabled, but this is not a security boundary). Expressions must be trusted boolean rules usingand,or,not, and parentheses, as produced by CANA model files.- Parameters:
eval_line (string) – boolean expression to evaluate (e.g. “A and not B”)
input_list (list) – list of input variable names
- 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
Each input variable is assigned the corresponding value from each trial string via a namespace dict, and the expression is evaluated 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