HyperNEATCPPNGenotype extends TWEANNGenotype { void loopThroughLinks(HyperNEATTask hnt, ArrayList<LinkGene> linksSoFar, TWEANN cppn, int outputIndex, Substrate s1, Substrate s2, int s1Index, int s2Index, List<Substrate> subs, int layersWidth, int layersHeight) { for(Pair<Integer,Integer> src : s1.coordinateList()) { int fromXIndex = src.t1; int fromYIndex = src.t2; if(!s1.isNeuronDead(fromXIndex, fromYIndex)) { for(Pair<Integer,Integer> target: s2.coordinateList()) { int targetXindex = target.t1; int targetYIndex = target.t2; if(!s2.isNeuronDead(targetXindex, targetYIndex)) { ILocated2D scaledSourceCoordinates = MMNEAT.substrateMapping.transformCoordinates(new Tuple2D(fromXIndex, fromYIndex), s1.getSize().t1, s1.getSize().t2); ILocated2D scaledTargetCoordinates = MMNEAT.substrateMapping.transformCoordinates(new Tuple2D(targetXindex, targetYIndex), s2.getSize().t1, s2.getSize().t2); double[] inputs = hnt.filterCPPNInputs(new double[]{scaledSourceCoordinates.getX(), scaledSourceCoordinates.getY(), scaledTargetCoordinates.getX(), scaledTargetCoordinates.getY(), BIAS}); assert -1 <= inputs[0] && inputs[0] <= 1 : "CPPN input 0 out of range: " + inputs[0]; assert -1 <= inputs[1] && inputs[1] <= 1 : "CPPN input 1 out of range: " + inputs[1]; assert -1 <= inputs[2] && inputs[2] <= 1 : "CPPN input 2 out of range: " + inputs[2]; assert -1 <= inputs[3] && inputs[3] <= 1 : "CPPN input 3 out of range: " + inputs[3]; assert -1 <= inputs[4] && inputs[4] <= 1 : "CPPN input 4 out of range: " + inputs[4]; if(CommonConstants.substrateLocationInputs) { ILocated2D scaledSubstrate1Coordinates = MMNEAT.substrateMapping.transformCoordinates(new Tuple2D(s1.getSubLocation().t1, s1.getSubLocation().t2), layersWidth, layersHeight); ILocated2D scaledSubstrate2Coordinates = MMNEAT.substrateMapping.transformCoordinates(new Tuple2D(s2.getSubLocation().t1, s2.getSubLocation().t2), layersWidth, layersHeight); inputs = ArrayUtil.combineArrays(inputs, new double[]{scaledSubstrate1Coordinates.getX(), scaledSubstrate1Coordinates.getY(), scaledSubstrate2Coordinates.getX(), scaledSubstrate2Coordinates.getY()}); assert -1 <= inputs[5] && inputs[5] <= 1 : "CPPN input 5 out of range: " + inputs[5]; assert -1 <= inputs[6] && inputs[6] <= 1 : "CPPN input 6 out of range: " + inputs[6]; assert -1 <= inputs[7] && inputs[7] <= 1 : "CPPN input 7 out of range: " + inputs[7]; assert -1 <= inputs[8] && inputs[8] <= 1 : "CPPN input 8 out of range: " + inputs[8]; } conditionalLinkAdd(linksSoFar, cppn, inputs, outputIndex, fromXIndex, fromYIndex, s1Index, targetXindex, targetYIndex, s2Index, subs, innovationID++); } } } } } HyperNEATCPPNGenotype();  HyperNEATCPPNGenotype(ArrayList<NodeGene> nodes, ArrayList<LinkGene> links, int neuronsPerModule, int archetypeIndex);  HyperNEATCPPNGenotype(int archetypeIndex, ArrayList<LinkGene> links, ArrayList<NodeGene> genes, int outputNeurons);  HyperNEATCPPNGenotype(int networkInputs, int networkOutputs, int archetypeIndex); TWEANN getCPPN(); @Override TWEANN getPhenotype(); TWEANNGenotype getSubstrateGenotype(HyperNEATTask hnt); TWEANNGenotype getSubstrateGenotypeForEvolution(HyperNEATTask hnt); @Override Genotype<TWEANN> copy(); ArrayList<NodeGene> createSubstrateNodes(HyperNEATTask hnt, TWEANN cppn, List<Substrate> subs, int layersWidth, int layersHeight); long getInnovationID(int x, int y, int sIndex, List<Substrate> subs); @Override Genotype<TWEANN> newInstance(); static int numCPPNOutputsPerLayerPair; static int numBiasOutputs; static final int LINK_INDEX; static final int LEO_INDEX; static final double BIAS; transient static boolean constructingNetwork; transient int innovationID; }
@Test public void testLoopThroughLinks() { int indexOfTest = 0; ArrayList<LinkGene> newLinks = new ArrayList<LinkGene>(); hcppn.loopThroughLinks((HyperNEATTask) MMNEAT.task, newLinks, cppn, indexOfTest, subs.get(sub1Index), subs.get(sub2Index), sub1Index, sub2Index, subs, 2, 1); ILocated2D scaledSourceCoordinates = CartesianGeometricUtilities.centerAndScale(new Tuple2D(0, 0), subs.get(sub1Index).getSize().t1, subs.get(sub1Index).getSize().t2); Tuple2D size = new Tuple2D(subs.get(sub2Index).getSize().t1 - 1, subs.get(sub2Index).getSize().t2 - 1); ILocated2D scaledTargetCoordinates = CartesianGeometricUtilities.centerAndScale(size, subs.get(sub2Index).getSize().t1, subs.get(sub2Index).getSize().t2); assertEquals(scaledSourceCoordinates.getY(), -1, .001); assertEquals(scaledSourceCoordinates.getX(), -1, .001); assertEquals(scaledTargetCoordinates.getX(), 1, .01); assertEquals(scaledTargetCoordinates.getY(), 1, .01); int index = 0; for(long i = 0; i <= 24; i++) { for(long j = 25; j <= 49; j++) { assertEquals(newLinks.get(index).sourceInnovation, i); assertEquals(newLinks.get(index).targetInnovation, j); index++; } } }