add repr for genome and gene;
add ipynb test for testing whether add node or add conn will not change the output for the network.
This commit is contained in:
@@ -39,3 +39,11 @@ class BaseNodeGene(BaseGene):
|
||||
),
|
||||
attrs,
|
||||
)
|
||||
|
||||
def repr(self, state, node, precision=2, idx_width=3, func_width=8):
|
||||
idx = node[0]
|
||||
|
||||
idx = int(idx)
|
||||
return "{}(idx={:<{idx_width}})".format(
|
||||
self.__class__.__name__, idx, idx_width=idx_width
|
||||
)
|
||||
|
||||
@@ -122,3 +122,28 @@ class DefaultNodeGene(BaseNodeGene):
|
||||
)
|
||||
|
||||
return z
|
||||
|
||||
def repr(self, state, node, precision=2, idx_width=3, func_width=8):
|
||||
idx, bias, res, agg, act = node
|
||||
|
||||
idx = int(idx)
|
||||
bias = round(float(bias), precision)
|
||||
res = round(float(res), precision)
|
||||
agg = int(agg)
|
||||
act = int(act)
|
||||
|
||||
if act == -1:
|
||||
act_func = Act.identity
|
||||
else:
|
||||
act_func = self.activation_options[act]
|
||||
return "{}(idx={:<{idx_width}}, bias={:<{float_width}}, response={:<{float_width}}, aggregation={:<{func_width}}, activation={:<{func_width}})".format(
|
||||
self.__class__.__name__,
|
||||
idx,
|
||||
bias,
|
||||
res,
|
||||
self.aggregation_options[agg].__name__,
|
||||
act_func.__name__,
|
||||
idx_width=idx_width,
|
||||
float_width=precision + 3,
|
||||
func_width=func_width
|
||||
)
|
||||
|
||||
@@ -98,3 +98,26 @@ class NodeGeneWithoutResponse(BaseNodeGene):
|
||||
)
|
||||
|
||||
return z
|
||||
|
||||
def repr(self, state, node, precision=2, idx_width=3, func_width=8):
|
||||
idx, bias, agg, act = node
|
||||
|
||||
idx = int(idx)
|
||||
bias = round(float(bias), precision)
|
||||
agg = int(agg)
|
||||
act = int(act)
|
||||
|
||||
if act == -1:
|
||||
act_func = Act.identity
|
||||
else:
|
||||
act_func = self.activation_options[act]
|
||||
return "{}(idx={:<{idx_width}}, bias={:<{float_width}}, aggregation={:<{func_width}}, activation={:<{func_width}})".format(
|
||||
self.__class__.__name__,
|
||||
idx,
|
||||
bias,
|
||||
self.aggregation_options[agg].__name__,
|
||||
act_func.__name__,
|
||||
idx_width=idx_width,
|
||||
float_width=precision + 3,
|
||||
func_width=func_width,
|
||||
)
|
||||
|
||||
@@ -25,3 +25,8 @@ class KANNode(BaseNodeGene):
|
||||
|
||||
def forward(self, state, attrs, inputs, is_output_node=False):
|
||||
return Agg.sum(inputs)
|
||||
|
||||
def repr(self, state, node, precision=2):
|
||||
idx = node[0]
|
||||
idx = int(idx)
|
||||
return "{}(idx: {})".format(self.__class__.__name__, idx)
|
||||
|
||||
Reference in New Issue
Block a user