Node
Boolean Node
Main class for Boolean node objects.
- class cana.boolean_node.BooleanNode(id=0, name='x', k=1, inputs=[1], state=False, outputs=[0, 1], constant=False, network=None, verbose=False, *args, **kwargs)[source]
- activities()[source]
compute the activities of each incoming edge of the node, directly from the LUT. See
cana.sensitivity.activities().- Returns:
(list of floats)
- bias()[source]
The node bias. The sum of the boolean output transitions divided by the number of entries (\(2^k\)) in the LUT.
\[bias(x) = \frac{ \sum_{f_{\alpha}\in F} s_{\alpha} }{ |F| }\]- Returns:
(float)
See also
- c_sensitivity(c, mode='default', max_k=0)[source]
Node c-sensitivity. c-sensitivity is defined as: the mean probability that changing exactly
cvariables in input variables would change output value. There is another mode “forceK”, which will be used to calculate Derrida value. In that mode, it would assume the number of input variables is specified as max_k this methods is equivalent to Derrida value in [KKL17], only move a normalization coefficient from expression of Derrida value to c-sensitivity to simplify it- Parameters:
c (int) – the
cin the definition of c-senstivity abovemode (string) – either “default” or “forceK”
max_k (int) – you must specify max_k when you set mode as ‘forceK’
- Returns:
(float)
See also
derrida_curve()
- canalizing_map(output=None)[source]
Computes the node Canalizing Map (CM).
- Parameters:
output (int) – The output CM to return. Default is
None, retuning both [0,1].- Returns:
a directed graph representation of the CM.
- Return type:
CM (networkx.DiGraph)
See also
boolean_network.dynamics_canalization_map()for the DCM anddrawing.draw_canalizing_map_graphviz()for plotting.
- constant_step(input_state)[source]
Treat the node as a constant variable, always returning its state.
- distinct_symmetry()[source]
Compute the distinct permutation symmetry of the node LUT.
For each LUT entry, this computes the fraction of distinct input permutations that preserve the same output, excluding the identity permutation from both numerator and denominator.
- Returns:
(float)
See also
cana.symmetry.distinct_symmetry()
- dynamic_step(input_state)[source]
Returns the output of the node based on a specific input.
- Parameters:
input (str) – an input to the node (e.g.: ‘0111’ -> 7).
- Returns:
the output value.
- Return type:
output (bool)
- edge_effectiveness(bound='mean')[source]
The Edge Effectiveness is the mean number of an input’s states needed to determine the transition of the node.
\[e_i(x_i) = 1 - r_i(x_i)\]- Parameters:
bound (string) – The bound for the \(k_r\) Input Redundancy
- Returns:
The list of \(e_r\) values.
- Return type:
(list)
See also
- edge_redundancy(bound='mean')[source]
The Edge Redundancy \(r_{i}\) is the mean number of unnecessary inputs (or
#) in the Prime Implicants Look Up Table (LUT) for that input. Since there may be more than one redescription schema for each input entry, the input redundancy is bounded by an upper and lower limit.\[r_i(x_i) = \frac{ \sum_{f_{\alpha} \in F} \Phi_{\theta:f_{\alpha} \in \Theta_{\theta}} (X^{\#}_{\theta_i} ) }{ |F| }\]where \(\Phi\) is a function (\(min\) or \(max\)) and \(F\) is the node LUT.
- Parameters:
bound (string) – The bound to which compute input redundancy. Mode “input” accepts: [“lower”, “mean”, “ave”, upper”, “tuple”]. Defaults to “mean”.
- Returns:
The list of \(r_i\) for inputs.
- Return type:
(list)
Note
The complete mathematical description can be found in :cite:Gates:2020`.
See also
- effective_connectivity(operator=<function mean>, norm=True)[source]
The Effective Connectiviy is the mean number of input nodes needed to determine the transition of the node.
\[k_e(x) = k(x) - k_r(x)\]- Parameters:
operator (function) – The operator to use while computing input redundancy for the node. Defaults to statistics.mean, but min or max can be also considered.
norm (bool) –
Normalized between [0,1]. Use this value when comparing nodes with different input sizes. (Defaults to “True”.)
\(k^{*}_e(x) = \frac{ k_e(x) }{ k(x) }\).
- Returns:
The \(k_e\) value.
- Return type:
(float)
See also
- classmethod from_output_list(outputs=[], *args, **kwargs)[source]
Instanciate a Boolean Node from a output transition list.
- Parameters:
outputs (list) – The transition outputs of the node. Its length must be a power of two, \(2^k\).
- Returns:
the instanciated object. Subclasses receive an instance of the subclass.
- Return type:
- Raises:
ValueError – if the length of
outputsis not a power of two.
Example
>>> BooleanNode.from_output_list(outputs=[0,0,0,1], name="AND")
- input_mask(binstate)[source]
Returns the mask applied to the binary state binstate
- Parameters:
binstate (str) – the binary state
- Returns:
the masked state
- Return type:
output (str)
- input_redundancy(operator=<function mean>, norm=True)[source]
The Input Redundancy \(k_{r}\) is the mean number of unnecessary inputs (or
#) in the Prime Implicants Look Up Table (LUT). Since there may be more than one redescription schema for each input entry, the input redundancy is bounded by an upper and lower limit.\[k_{r}(x) = \frac{ \sum_{f_{\alpha} \in F} \Phi_{\theta:f_{\alpha} \in \Theta_{\theta}} (n^{\#}_{\theta} ) }{ |F| }\]where \(\Phi\) is a function (\(min\) or \(max\)) and \(F\) is the node LUT.
- Parameters:
operator (function) – The operator to use while computing input redundancy for the node. Defaults to statistics.mean, but min or max can be also considered.
norm (bool) –
Normalized between [0,1]. Use this value when comparing nodes with different input sizes. (Defaults to “True”.)
\(k^{*}_r(x) = \frac{ k_r(x) }{ k(x) }\).
- Returns:
The \(k_r\) value.
- Return type:
(float)
Note
The complete mathematical description can be found in [MPR13].
- input_signs()[source]
Determine if a each input can be considered activation (1), inhibition (-1), or neither (0).
Here we test every pair of inputs that are Hamming distance 1. (see Goldreich et al 2000)
- Returns:
The list of input signs.
- Return type:
(list)
Example
>>> is_monotone(outputs=[0,0,0,1])
- input_symmetry(aggOp='mean', kernel='numDots', sameSymbol=False)[source]
compute the input symmetry (k_s) of the boolean node, with variations via the specified functions. Convenience wrapper for lower-level function.
- Parameters:
aggOp – the function aggregating over all two-symbol schemata that redescribe a LUT entry
kernel – the function to compute on a given two-symbol schema
- Returns:
the mean over all LUT entries of the aggOp applied to the kernel of all two-symbol schemata that redescribe the LUT entry
- Return type:
(float)
- input_symmetry_mean()[source]
- compute the input symmetry (k_s) of the boolean node.
Specifically, computes it using the avg operator for the summand. Refactoring of input_symmetry for speed.
- Returns:
(float)
- look_up_table()[source]
Returns the Look Up Table (LUT)
- Returns:
the LUT
- Return type:
(pandas.DataFrame)
Examples
>>> AND = BooleanNode.from_output_list([0,0,0,1]) >>> AND.look_up_table()
See also
- pi_coverage()[source]
Returns the \(F'\) (Prime Implicants) binary state coverage.
- Returns:
(list)
See also
- raw_symmetry()[source]
Compute the raw symmetry of the node LUT.
LUT rows are grouped by input Hamming weight. For each row, this computes the fraction of rows in the same weight group that have the same output, then averages across all LUT rows.
- Returns:
(float)
See also
cana.symmetry.raw_symmetry()
- schemata_look_up_table(type='pi', pi_symbol='#', ts_symbol_list=['̊', '̯', '̃', '̰', '̆', '̮'])[source]
Returns the simplified schemata Look Up Table (LUT)
- Parameters:
type (string) – The type of schemata to return, either Prime Implicants
pior Two-Symbolts. Defaults to ‘pi’.pi_symbol (str) – The Prime Implicant don’t care symbol. Default is
#.ts_symbol_list (list) – A list containing Two Symbol permutable symbols, one per permutation group of a schema (combining marks: ring above, inverted breve below, tilde, tilde below, breve, breve below). A
ValueErroris raised if a schema has more groups than symbols.
- Returns:
the schemata LUT
- Return type:
(pandas.DataFrame or Latex)
Examples
>>> AND = BooleanNode.from_output_list([0,0,0,1]) >>> AND.schemata_look_up_table(type='pi')
Note
See the full list of combining characters to use other symbols as the permutation symbol.
See also
- sensitivity(norm=False)[source]
compute the average sensitivity of the node: the mean, over all input states, of the number of single-input flips that change the output.
Delegates to
cana.sensitivity.sensitivity(), which computes it directly from the look-up table. Up to CANA 1.0.2 this wassum(self.activities()), kept ascana.sensitivity.sensitivity_old(); the two are bit-exactly equal, as asserted intests/test_boolean_node.py(test_sensitivity_matches_original_implementation).- Parameters:
norm (bool) – whether or not to normalize by the number of inputs (k)
- Returns:
(float)
See also
cana.sensitivity.sensitivity(),activities(),c_sensitivity().
- set_constant(constant=True, state=None)[source]
Sets whether the node is to be treated as a contant
- Parameters:
constant (Boolean) – Whether to set or unset the node as a constant.
state (str; optional) – The state value to which to set the node. Either ‘0’ or ‘1’; default to current state value.
- symKernel_numDots(ts, sameSymbol=False)[source]
compute the number of variables involved in a symmetry group.
- Parameters:
ts ([str, [[]], [[]]]) – two symbol schema
sameSymbol (bool) – whether or not to consider same-symbol symmetry
- Returns:
(int)