/// <summary> /// Validates that a gene is connected to an input node. /// </summary> /// <param name="gene">The gene being validated.</param> /// <param name="pathsChecked">A list of genes that have been traversed in the recursion.</param> /// <param name="excludeFrozen">Exclude frozen genes from validation (true network).</param> /// <returns>True if the gene is connected to an input node.</returns> private bool ValidateGeneBackward(Gene gene, List <Gene> pathsChecked, bool excludeFrozen) { NodeInformation origin = NodePool.FindById(gene.link.InNode); pathsChecked.Add(gene); if (origin.IsInput()) { return(true); } foreach (var path in Genes.Where(x => x.link.OutNode == gene.link.InNode && !pathsChecked.Contains(x))) { if (excludeFrozen && path.Frozen) { continue; } if (ValidateGeneBackward(path, pathsChecked, excludeFrozen)) { return(true); } } return(false); }
/// <summary> /// Creates node from NodeInformation. /// </summary> /// <param name="id">A unique ID in the network.</param> /// <param name="nodeInfo">Information of the node.</param> public Node(int id, NodeInformation nodeInfo) { Type = nodeInfo.Type; Id = id; ActivationFunction = ActivationFunctions.GetActivationFunction(nodeInfo.Style); if (Type == NodeType.BIAS) { InputValue = 1.0; OutputValue = 1.0; } }
/// <summary> /// Checks if the nodes are configured the same way. /// </summary> /// <param name="nodeInfo">The NodeInformation to compare to.</param> /// <returns>True if the configuration is the same.</returns> public bool IsSameAs(NodeInformation nodeInfo) { return(Type == nodeInfo.Type && Style == nodeInfo.Style); }
/// <summary> /// Adds a new node to the pool. /// </summary> /// <param name="nodeInfo">The information of the node added.</param> /// <returns>The unique identifier of the node.</returns> public static int Add(NodeInformation nodeInfo) { Pool.Add(nodeInfo); return(Size() - 1); }