public double[] GetChampOutput(int nodeDepth, int nodeSiblingNum, int maxDepth, int maxBranching) { IGenomeDecoder <NeatGenome, IBlackBox> decoder = experiment.CreateGenomeDecoder(); IBlackBox box = decoder.Decode(contentEA.CurrentChampGenome); // Normalize nodeDepth and nodeSiblingNum to range of 0-1. This may affect outputs? double normDepth = (double)nodeDepth / (double)maxDepth; double normSib; if (nodeDepth == 0) { normSib = 0; // Only one node at depth 0, prevent a divide by 0 error } else { normSib = (double)nodeSiblingNum / (double)(Mathf.Pow(maxBranching, nodeDepth) - 1); } box.InputSignalArray[0] = normDepth; box.InputSignalArray[1] = normSib; box.ResetState(); box.Activate(); //Debug.Log("(" + normDepth + "," + normSib + ") -> (" + box.OutputSignalArray[0] + "," + box.OutputSignalArray[1] + "," + box.OutputSignalArray[2] + "," //+ box.OutputSignalArray[3] + "," + box.OutputSignalArray[4] + "," + box.OutputSignalArray[5] + ")"); double[] outputs = new double[box.OutputCount]; for (int i = 0; i < box.OutputCount; i++) { outputs[i] = box.OutputSignalArray[i]; } return(outputs); }
public static IBlackBox LoadBrain(string filePath, INeatExperiment experiment) { NeatGenome genome = null; // Try to load the genome from the XML document. try { using (XmlReader xr = XmlReader.Create(filePath)) genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, (NeatGenomeFactory)experiment.CreateGenomeFactory())[0]; } catch (Exception e1) { print(filePath + " Error loading genome from file!\nLoading aborted.\n" + e1.Message + "\nJoe: " + filePath); return(null); } // Get a genome decoder that can convert genomes to phenomes. var genomeDecoder = experiment.CreateGenomeDecoder(); // Decode the genome into a phenome (neural network). var phenome = genomeDecoder.Decode(genome); return(phenome); }
//public static IBlackBox LoadBrain(string filePath) //{ // OptimizationExperiment experiment = new OptimizationExperiment(); // XmlDocument xmlConfig = new XmlDocument(); // TextAsset textAsset = (TextAsset)Resources.Load("phototaxis.config"); // // xmlConfig.Load(OptimizerParameters.ConfigFile); // xmlConfig.LoadXml(textAsset.text); // // experiment.SetOptimizer(this); // experiment.Initialize(OptimizerParameters.Name, xmlConfig.DocumentElement, OptimizerParameters.NumInputs, OptimizerParameters.NumOutputs); // return LoadBrain(filePath, experiment); //} public static IBlackBox LoadBrain(string filePath, INeatExperiment experiment) { NeatGenome genome = null; // Try to load the genome from the XML document. try { using (XmlReader xr = XmlReader.Create(filePath)) genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, (NeatGenomeFactory)experiment.CreateGenomeFactory())[0]; } catch (Exception e1) { print(filePath + " Error loading genome from file!\nLoading aborted.\n" + e1.Message + "\nJoe: " + filePath); return null; } // Get a genome decoder that can convert genomes to phenomes. var genomeDecoder = experiment.CreateGenomeDecoder(); // Decode the genome into a phenome (neural network). var phenome = genomeDecoder.Decode(genome); return phenome; }