//phillip static List <NodeGene> NodeGeneration() { List <NodeGene> list = new List <NodeGene>(); SubstrateNodes temp; int nodeId = 0; temp = new SubstrateNodes(); temp.Function = "Identity"; temp.Id = nodeId; nodeId++; temp.Layer = 0; temp.Coordinate.Add(0); temp.Coordinate.Add(0); temp.Type = NodeType.Bias; list.Add(temp); double xIncrement = Math.Abs(config.SubstrateEndX - config.SubstrateStartX) / config.SubstrateX; double yIncrement = Math.Abs(config.SubstrateEndY - config.SubstrateStartY) / config.SubstrateY; for (double y = config.SubstrateStartY + yIncrement / 2; y <= config.SubstrateEndY - yIncrement / 2; y += yIncrement) { for (double x = config.SubstrateStartX + xIncrement / 2; x <= config.SubstrateEndX - xIncrement / 2; x += xIncrement) { temp = new SubstrateNodes(); temp.Type = NodeType.Input; temp.Layer = 0; temp.Id = nodeId; nodeId++; temp.Function = "Identity"; temp.Coordinate.Add(x); temp.Coordinate.Add(y); list.Add(temp); } } for (double y = config.SubstrateStartY + yIncrement / 2; y <= config.SubstrateEndY - yIncrement / 2; y += yIncrement) { for (double x = config.SubstrateStartX + xIncrement / 2; x <= config.SubstrateEndX - xIncrement / 2; x += xIncrement) { temp = new SubstrateNodes(); temp.Type = NodeType.Output; temp.Layer = 1; temp.Id = nodeId; nodeId++; temp.Function = "BipolarSigmoid"; temp.Coordinate.Add(x); temp.Coordinate.Add(y); list.Add(temp); } } return(list); }
public static List <NodeGene> XorNode() { List <NodeGene> list = new List <NodeGene>(); SubstrateNodes substrateNode1 = new SubstrateNodes(); substrateNode1.Function = "Identity"; substrateNode1.Id = 1; substrateNode1.Layer = 0; substrateNode1.Type = NodeType.Input; substrateNode1.SetCoordinate(-1.0, -1.0); list.Add((NodeGene)substrateNode1); SubstrateNodes substrateNode2 = new SubstrateNodes(); substrateNode2.Function = "Identity"; substrateNode2.Id = 2; substrateNode2.Layer = 0; substrateNode2.Type = NodeType.Input; substrateNode2.SetCoordinate(1.0, -1.0); list.Add((NodeGene)substrateNode2); SubstrateNodes substrateNode3 = new SubstrateNodes(); substrateNode3.Function = "Identity"; substrateNode3.Id = 3; substrateNode3.Layer = 0; substrateNode3.Type = NodeType.Input; substrateNode3.SetCoordinate(-1.0, 1.0); list.Add((NodeGene)substrateNode3); SubstrateNodes substrateNode4 = new SubstrateNodes(); substrateNode4.Function = "Identity"; substrateNode4.Id = 4; substrateNode4.Layer = 0; substrateNode4.Type = NodeType.Input; substrateNode4.SetCoordinate(1.0, 1.0); list.Add((NodeGene)substrateNode4); SubstrateNodes substrateNode5 = new SubstrateNodes(); substrateNode5.Function = "BipolarSigmoid"; substrateNode5.Id = 5; substrateNode5.Layer = 1; substrateNode5.Type = NodeType.Output; substrateNode5.SetCoordinate(new double[2]); list.Add((NodeGene)substrateNode5); return(list); }
public static void XorCreate(NetworkGenome sub, DecodedNetworks cppn) { SubstrateNodes substrateNode1 = sub.Nodes.Find((Predicate <NodeGene>)(n => n.Type == NodeType.Output)) as SubstrateNodes; double[] inputs = new double[4]; int id = 0; for (int index = 0; index < sub.Nodes.Count - 1; ++index) { SubstrateNodes substrateNode2 = sub.Nodes[index] as SubstrateNodes; cppn.Flush(); inputs[0] = substrateNode2.Coordinate[0]; inputs[1] = substrateNode2.Coordinate[1]; inputs[2] = substrateNode1.Coordinate[0]; inputs[3] = substrateNode1.Coordinate[1]; cppn.SetInputs(inputs); cppn.ActivateNetwork(5); double[] outputs = cppn.GetOutputs(); sub.Links.Add(new LinkGene(id, substrateNode2.Id, substrateNode1.Id, outputs[0])); } }
public DecodedNetworks GenerateNetwork(MapWeights create, DecodedNetworks cppn) { for (int index = 0; index < this.net.ActivatingNodes.Count; ++index) { this.net.ActivatingNodes[index].links.Clear(); } create(this.sub, cppn); double val1 = 0.0; foreach (LinkGene linkGene in this.sub.Links) { val1 = Math.Max(val1, Math.Abs(linkGene.Weight)); } List <LinkGene> list = new List <LinkGene>(); double staticThreshold1 = Substrates.param.StaticThreshold; DecodedNetworks.Link link1; using (List <LinkGene> .Enumerator enumerator = this.sub.Links.GetEnumerator()) { while (enumerator.MoveNext()) { LinkGene link = enumerator.Current; link.Weight *= Substrates.param.WeightRange / (2.0 * val1); double staticThreshold2 = Substrates.param.StaticThreshold; if (Substrates.param.ThresholdByDistance) { SubstrateNodes substrateNode1 = this.sub.Nodes.Find((Predicate <NodeGene>)(n => n.Id == link.Source)) as SubstrateNodes; SubstrateNodes substrateNode2 = this.sub.Nodes.Find((Predicate <NodeGene>)(n => n.Id == link.Target)) as SubstrateNodes; double d = 0.0; for (int index = 0; index < substrateNode1.Coordinate.Count; ++index) { double num = substrateNode1.Coordinate[index] - substrateNode2.Coordinate[index]; d += num * num; } double num1 = Math.Sqrt(d); staticThreshold2 += num1 * Substrates.param.StaticThreshold; } if (Math.Abs(link.Weight) >= staticThreshold2) { link1.sourceNode = link.Source; link1.weight = link.Weight; this.net.Neurons[link.Target].links.Add(link1); } } } for (int index = 0; index < this.net.ActivatingNodes.Count; ++index) { link1.sourceNode = -1; link1.weight = 0.0; this.net.ActivatingNodes[index].links.Add(link1); } if (Substrates.param.Normalize) { double num1 = 1.0; for (int index1 = 0; index1 < this.net.ActivatingNodes.Count; ++index1) { double d = 0.0; for (int index2 = 0; index2 < this.net.ActivatingNodes[index1].links.Count - 1; ++index2) { d += this.net.ActivatingNodes[index1].links[index2].weight * this.net.ActivatingNodes[index1].links[index2].weight; } num1 = Math.Max(num1, Math.Sqrt(d)); } double num2 = Math.Sqrt(num1); for (int index1 = 0; index1 < this.net.ActivatingNodes.Count; ++index1) { for (int index2 = 0; index2 < this.net.ActivatingNodes[index1].links.Count - 1; ++index2) { DecodedNetworks.Link link2; link2.sourceNode = this.net.ActivatingNodes[index1].links[index2].sourceNode; link2.weight = this.net.ActivatingNodes[index1].links[index2].weight / num2; this.net.ActivatingNodes[index1].links[index2] = link2; } } } return(this.net); }