private List <NEATGene> geneList; //consultor gene list /// <summary> /// Creating consultor structure NEAT packet retrived from database and coefficient information from UI /// </summary> /// <param name="packet">NEATPacket retrieved from database</param> /// <param name="deltaThreshold">Delta threshold to set</param> /// <param name="disjointCoefficient">Disjoint coefficient to set</param> /// <param name="excessCoefficient">Excess coefficient to set</param> /// <param name="averageWeightDifferenceCoefficient">Averange weight difference coefficient to set</param> public NEATConsultor(NEATPacket packet, float deltaThreshold, float disjointCoefficient, float excessCoefficient, float averageWeightDifferenceCoefficient) { this.numberOfInputs = packet.node_inputs; //get number of inputs from packet this.numberOfOutputs = packet.node_outputs; //get number of outputs from packet //copy thresholdes and coefficients this.deltaThreshold = deltaThreshold; this.disjointCoefficient = disjointCoefficient; this.excessCoefficient = excessCoefficient; this.averageWeightDifferenceCoefficient = averageWeightDifferenceCoefficient; int informationSize = NEATGene.GENE_INFORMATION_SIZE; //get number of gene information size float[] geneInformation = packet.consultor_genome.Split('_').Select(x => float.Parse(x)).ToArray(); //using Linq libary and delimiters, parse and spilt string genome from neat packet into float array geneList = new List <NEATGene>(); for (int i = 0; i < geneInformation.Length; i += informationSize) { NEATGene gene = new NEATGene(innovationNumber, (int)geneInformation[i], (int)geneInformation[i + 1], 1f, true); geneList.Add(gene); innovationNumber++; } }
/// <summary> /// Retrieves all neural networks with the given name in JSON markup form /// </summary> /// <param name="name">Name of the neural network to retrieve</param> /// <returns>Returns web information on executed url</returns> public IEnumerator GetNet(string name) { done = false; //set to fasle to wait for web to return if (fileSaveMode == false) { string page = retrievePage; //retrieve page page += "&creature_name=" + name; //create retrieve page url web = new WWW(page); //run page yield return(web); //wait for web to execute url JsonParser(web.text); //parse given web text with JSON parser done = true; //retrieved is true } else { if (File.Exists(name + ".txt")) { try { StreamReader reader = new StreamReader(name + ".txt"); retrieveNet = new NEATPacket[1]; string[] lines = reader.ReadToEnd().Split('\n'); float fitness = float.Parse(lines[0]); int nodeTotal = int.Parse(lines[1]); int nodeInputs = int.Parse(lines[2]); int nodeOutputs = int.Parse(lines[3]); int geneTotal = int.Parse(lines[4]); int genomeTotal = int.Parse(lines[5]); string genome = lines[6]; string consultorGenome = lines[7]; NEATPacket packet = new NEATPacket(); packet.creature_fitness = fitness; packet.node_total = nodeTotal; packet.node_inputs = nodeInputs; packet.node_outputs = nodeOutputs; packet.gene_total = geneTotal; packet.genome_total = genomeTotal; packet.genome = genome; packet.consultor_genome = consultorGenome; retrieveNet[0] = packet; } catch (Exception error) { retrieveNet = null; } } else { retrieveNet = null; } done = true; yield return(true); } }