Skip to content

Commit

Permalink
fix bug related to linker
Browse files Browse the repository at this point in the history
  • Loading branch information
ShuhuaGao committed Oct 17, 2020
1 parent 9d6940d commit f8ca74f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
12 changes: 8 additions & 4 deletions geppy/core/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ def __init__(self, gene_gen, n_genes, linker=None):
.. note:
If a linker is specified, then it must accept *n_genes* arguments, each produced by one gene. If the
*linker* parameter is the default value ``None``, then for a monogenic chromosome, no linking is applied,
while for a multigenic chromosome, the ``tuple`` function is used.
while for a multigenic chromosome, the ``tuple`` function is used, i.e., a tuple of values of all genes
is returned.
"""
list.__init__(self, (gene_gen() for _ in range(n_genes)))
self._linker = linker
Expand Down Expand Up @@ -522,10 +523,13 @@ def kexpressions(self):
@property
def linker(self):
"""
Get the linking function.
Get the linking function.
.. note:
If linker is `None`, then the actual linking function during evaluation of an individual
returns the value of the single gene for a single-gene (monogenic) chromosome or a tuple of values of all
genes for a multi-gene chromosome.
"""
if self._linker is None and len(self) > 1:
return tuple
return self._linker

def __repr__(self):
Expand Down
7 changes: 4 additions & 3 deletions geppy/support/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def graph(genome, label_renaming_map=None):
for gene in genome:
expr = gene.kexpression
sub_roots.append(starting_index)
sub_nodes, sub_edges, sub_labels = _graph_kexpression(expr, starting_index)
sub_nodes, sub_edges, sub_labels = _graph_kexpression(
expr, starting_index)
nodes.extend(sub_nodes)
edges.extend(sub_edges)
labels.update(sub_labels)
Expand Down Expand Up @@ -114,7 +115,7 @@ def export_expression_tree(genome, label_renaming_map=None, file='tree.png'):
import graphviz as gv
import os.path

nodes, edges, labels = graph(genome, label_renaming_map)
_, edges, labels = graph(genome, label_renaming_map)
file_name, ext = os.path.splitext(file)
ext = ext.lstrip('.')
g = gv.Graph(format=ext)
Expand All @@ -125,4 +126,4 @@ def export_expression_tree(genome, label_renaming_map=None, file='tree.png'):
g.render(file_name)


__all__ = ['graph', 'export_expression_tree']
__all__ = ['graph', 'export_expression_tree']
4 changes: 2 additions & 2 deletions geppy/tools/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def compile_(individual, pset):
"""
fs = [_compile_gene(gene, pset) for gene in individual]
linker = individual.linker
if linker is None:
if linker is None: # return the gene itself for a monogenic one or tuple of all genes
if len(fs) == 1:
return fs[0]
else:
return lambda *x: tuple((f(*x) for f in fs))
return lambda *x: linker(*(f(*x) for f in fs))


__all__ = ['compile_']
__all__ = ['compile_']

0 comments on commit f8ca74f

Please sign in to comment.