OffsetHybrIDGenotype extends HyperNEATCPPNGenotype { @Override public TWEANN getPhenotype() { TWEANNGenotype genotype = (TWEANNGenotype) super.getSubstrateGenotype(HyperNEATUtil.getHyperNEATTask()).copy(); ArrayList<Double> offsets = rvg.getPhenotype(); List<Triple<String, String, Boolean>> connections = HyperNEATUtil.getHyperNEATTask().getSubstrateConnectivity(); List<Substrate> subs = HyperNEATUtil.getHyperNEATTask().getSubstrateInformation(); HashMap<String, Integer> substrateIndexMapping = new HashMap<String, Integer>(); for (int i = 0; i < subs.size(); i++) { substrateIndexMapping.put(subs.get(i).getName(), i); } int offsetIndex = 0; for (int j = 0; j < connections.size(); j++) { int sourceSubstrateIndex = substrateIndexMapping.get(connections.get(j).t1); int targetSubstrateIndex = substrateIndexMapping.get(connections.get(j).t2); Substrate sourceSubstrate = subs.get(sourceSubstrateIndex); Substrate targetSubstrate = subs.get(targetSubstrateIndex); for(Pair<Integer,Integer> src : sourceSubstrate.coordinateList()) { int fromXIndex = src.t1; int fromYIndex = src.t2; if(!sourceSubstrate.isNeuronDead(fromXIndex, fromYIndex)) { for(Pair<Integer,Integer> target: targetSubstrate.coordinateList()) { int targetXindex = target.t1; int targetYIndex = target.t2; if(!targetSubstrate.isNeuronDead(targetXindex, targetYIndex)) { long sourceID = getInnovationID(fromXIndex, fromYIndex, sourceSubstrateIndex, subs); long targetID = getInnovationID(targetXindex, targetYIndex, targetSubstrateIndex, subs); LinkGene link = getLinkBetween(sourceID, targetID); if(link != null) { double offset = offsets.get(offsetIndex); link.weight += offset; } offsetIndex++; } } } } } return genotype.getPhenotype(); } OffsetHybrIDGenotype();  OffsetHybrIDGenotype(HyperNEATCPPNGenotype hngt);  OffsetHybrIDGenotype(int archetypeIndex, ArrayList<LinkGene> links, ArrayList<NodeGene> genes, int outputNeurons); static RealValuedGenotype newZeroOffsets(int length); @Override TWEANN getPhenotype(); @Override Genotype<TWEANN> copy(); @Override Genotype<TWEANN> newInstance(); @Override void mutate(); @Override Genotype<TWEANN> crossover(Genotype<TWEANN> other); @SuppressWarnings("unchecked") static ArrayList<Genotype<T>> getSubstrateGenotypesFromCPPNs(HyperNEATTask hnt, ArrayList<Genotype<T>> population);  }
@Test public void testAllOffsetsZero() { for(int i = 0; i < HyperNEATUtil.totalPossibleLinks(HyperNEATUtil.getHyperNEATTask()); i++) { ohg.rvg.setValue(i, 0.0); } for(int i = 0; i < 100; i++) { double[] randomArray = RandomNumbers.randomArray(hncg.getPhenotype().numInputs()); double[] hncgOutput = hncg.getPhenotype().process(randomArray); double[] ohgOutput = ohg.getPhenotype().process(randomArray); assertTrue(Arrays.equals(hncgOutput, ohgOutput)); } }
@Test public void testLinkSize() { assertEquals(ohg.links.size(), hncg.links.size()); assertEquals(ohg.rvg.getPhenotype().size(), ((TWEANNGenotype) hncg.getSubstrateGenotype(HyperNEATUtil.getHyperNEATTask())).links.size()); }