-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BooleanNode.from_partial_lut with bias and effective connectivity criteria #46
Conversation
… partial LUT using fill_out_lut() and from_output_list()
cana/boolean_network.py
Outdated
@@ -174,7 +175,10 @@ def from_file(self, file, type="cnet", keep_constants=True, **kwargs): | |||
@classmethod | |||
def from_string_cnet(self, string, keep_constants=True, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add option to retain old behavior in which prime implicant input is assumed
@@ -110,7 +111,12 @@ def __str__(self): | |||
|
|||
@classmethod | |||
def from_output_list(self, outputs=list(), *args, **kwargs): | |||
"""Instanciate a Boolean Node from a output transition list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's revert this for now. We don't have a way to know which inputs are missing yet
cana/boolean_node.py
Outdated
@@ -449,6 +580,11 @@ def schemata_look_up_table( | |||
See also: | |||
:func:`look_up_table` | |||
""" | |||
# Check if the outputs contain '?' and generate an error message if it does. | |||
if '?' in self.outputs: | |||
print("Error (schemata_look_up_table): The outputs contain missing values. Please fill the missing values before generating the schemata look-up table.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise exception instead or warning
cana/datasets/bio.py
Outdated
@@ -22,6 +22,19 @@ | |||
""" Make sure we know what the current directory is """ | |||
|
|||
|
|||
def PARTIAL_LUTS_DEMO(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move somewhere else (not bio)
cana/drawing/schema_vis.py
Outdated
@@ -11,6 +11,10 @@ def plot_schemata(n, plotTS=True): | |||
# Init values from BooleanNode | |||
k = n.k if n.k >= 1 else 1 | |||
outputs = np.array(n.outputs) | |||
|
|||
if "?" in outputs: # check if there are any '?' in the output. | |||
print("Error (plot_schemata()): The output contains '?'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise error
cana/utils.py
Outdated
|
||
k = len(partial_lut[0][0]) | ||
|
||
all_states = {entry[0]: entry[1] for entry in partial_lut} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just fyi, this works:
all_states = dict(partial_lut)
cana/boolean_node.py
Outdated
# Calculating max achievable bias | ||
max_achievable_output = ['1' if output == '?' else output for output in generated_node.outputs] | ||
max_achievable_bias = sum(map(int, max_achievable_output))/2**generated_node.k | ||
min_achievable_bias = generated_node.bias(verbose=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this relies on the bias function treating unknowns like zeros, which is weird. We might want to change that in the future, so it's probably a good idea to just calculate min_achievable_bias
directly, as you've done for its max counterpart
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you already have current_ones
below, so this would just be
min_achievable_bias = current_ones / 2**generated_node.k
right?
cana/boolean_node.py
Outdated
@@ -139,6 +156,120 @@ def from_output_list(self, outputs=list(), *args, **kwargs): | |||
*args, | |||
**kwargs | |||
) | |||
|
|||
def from_partial_lut(partial_lut, fill_missing_output_randomly = False, required_node_bias = None, required_effective_connectivity= None,verbose= True, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need more tests to make sure it works
cana/boolean_node.py
Outdated
required_effective_connectivity (float) : The required effective connectivity to fill the missing output values with. It will generate a node with the closest possible effective connectivity to the required effective connectivity. | ||
verbose (bool) : If True, print additional information. Default is True. | ||
|
||
Returns: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this return a list of all the ones that are "best"
cana/boolean_node.py
Outdated
for count, permutation in enumerate(permutations): | ||
for i, index in enumerate(missing_output_indices): | ||
generated_outputs[index] = permutation[i] | ||
generated_node_permutations[count] = BooleanNode.from_output_list(generated_outputs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor generated_node_permutations
into its own function. It will be useful all on its own (probably)
…l_lut = false keyword. split Boolean_node.from_partial_lut into three functions added a few tests. need to add more.
Refactor BooleanNode.generate_with_required_bias and effective connectiity for improved readability and performance reorganized partial_lut demo file
created a function under BooleanNode to generate a node from partial LUT. a
added fill missing values randomly option
added required bias option
added required effective connectivity option
also, did some code clean up on some old code using ruff linter.
NOTE: Need to add some tests. Will do this in next iteration.