public Configuration(Configuration template) { model = template.model; SIAs = new List<Tuple<double, double>>(); SIAs.AddRange(template.SIAs); Weights = new List<double>(); Weights.AddRange(template.Weights); }
public List<Configuration> Run(List<Configuration> elements) { //Runs ONE iteration // copy default configuration List<Configuration> population = new List<Configuration>(); population.AddRange(elements); Configuration leader = population[0]; Configuration worst = population[0]; foreach (Configuration c in population) { if (c.GE < leader.GE) leader = c; if (c.GE > worst.GE) worst = c; } if (worst.GE - leader.GE < ps["MinDiv"]) //everyone too close return population; List<Configuration> ng = new List<Configuration>(); for (int k = 0; k < population.Count; k++) { Configuration c = population[k]; // Dealing with leader, put him in the candidate list if (c == leader) { ng.Add(c); continue; } List<Configuration> jumps = new List<Configuration>(); for (int i = 0; i < ps["PathLength"] / ps["Step"]; i++) { int prtsize = leader.SIAs.Count * 3 + leader.Weights.Count; List<int> prtv = GetPRTVector(prtsize); Configuration leaderdiff = leader.GetDifference(c); Configuration onejump = new Configuration(c); c.AddVector(leaderdiff, i, ps["Step"], prtv); jumps.Add(onejump); } int bestindex = -1; for (int j = 0; j < jumps.Count; j++) { if (jumps[j].GE < c.GE) bestindex = j; } ng.Add((bestindex == -1) ? population[k] : jumps[bestindex]); } return population; }
public void UpdateConfiguration(Configuration c) { // only weights and slopes will be altered //assemble list of all neurons and then all synapses List<Neuron> allneurons = new List<Neuron>(); List<Synapse> allsynapses = new List<Synapse>(); foreach (List<Neuron> nlist in Neurons.Values) allneurons.AddRange(nlist); foreach (List<Synapse> slist in Synapses.Values) allsynapses.AddRange(slist); // update data if (c.SIAs.Count != allneurons.Count || c.Weights.Count != allsynapses.Count) return; for (int i = 0; i < allneurons.Count; i++) { allneurons[i].Slope = c.SIAs[i].Item1; allneurons[i].Augment = c.SIAs[i].Item2; } for (int i = 0; i < allsynapses.Count; i++) { allsynapses[i].Weight = c.Weights[i]; } }
public void AddVector(Configuration leaderdiff, int step, double stepsize, List<int> prt) { int prtcount = 0; for (int i = 0; i < SIAs.Count; i++) { SIAs[i] = new Tuple<double, double> ( SIAs[i].Item1 + leaderdiff.SIAs[i].Item1 * step * stepsize * prt[prtcount], SIAs[i].Item2 + leaderdiff.SIAs[i].Item2 * step * stepsize * prt[prtcount + 1] ); prtcount += 2; // must match tuple size!!! } for (int i = 0; i < Weights.Count; i++) { Weights[i] += leaderdiff.Weights[i] * step * stepsize * prt[prtcount]; prtcount++; } }
public Configuration GetDifference(Configuration c) { Configuration result = new Configuration(this); for (int i = 0; i < this.SIAs.Count; i++) result.SIAs[i] = new Tuple<double, double> (result.SIAs[i].Item1 - c.SIAs[i].Item1, result.SIAs[i].Item2 - c.SIAs[i].Item2); for (int i = 0; i < this.Weights.Count; i++) result.Weights[i] -= c.Weights[i]; return result; }