public BehaviorType(BehaviorType copyFrom) { if (copyFrom.behaviorList != null) { behaviorList = new List <double>(copyFrom.behaviorList); } }
public static double Distance(BehaviorType x, BehaviorType y) { if (x.wraparoundRange) { return(DistanceWithWraparound(x, y)); } double dist = 0.0; for (int k = 0; k < x.behaviorList.Count; k++) { double delta = x.behaviorList[k] - y.behaviorList[k]; dist += delta * delta; } return(dist);//*/ // JUSTIN: Below is code for a cache of distance calculations.. it doesn't help for small BCs (~2 dimensions) but probably helps a lot for large BCs. // Note: also need to uncomment the uniqId variables and some other stuff at the top of this file. // Note: this cache is quick and dirty and is subject to a memory leak since it keeps around cache values for individuals long since deleted from the archive. /*double dist; * if (!x.cachedDistances.TryGetValue(y.uniqId, out dist)) // JUSTIN: Cache of distance calculations... hopefully this speeds things up and doesn't waste too much memory... * { * dist = 0.0; * for (int k = 0; k < x.behaviorList.Count; k++) * { * double delta = x.behaviorList[k] - y.behaviorList[k]; * dist += delta * delta; * } * x.cachedDistances[y.uniqId] = dist; * } * return dist;//*/ }
public static double Distance(BehaviorType x, BehaviorType y) { if (x.wraparoundRange) return DistanceWithWraparound(x, y); double dist = 0.0; for (int k = 0; k < x.behaviorList.Count; k++) { double delta = x.behaviorList[k] - y.behaviorList[k]; dist += delta * delta; } return dist;//*/ // JUSTIN: Below is code for a cache of distance calculations.. it doesn't help for small BCs (~2 dimensions) but probably helps a lot for large BCs. // Note: also need to uncomment the uniqId variables and some other stuff at the top of this file. // Note: this cache is quick and dirty and is subject to a memory leak since it keeps around cache values for individuals long since deleted from the archive. /*double dist; if (!x.cachedDistances.TryGetValue(y.uniqId, out dist)) // JUSTIN: Cache of distance calculations... hopefully this speeds things up and doesn't waste too much memory... { dist = 0.0; for (int k = 0; k < x.behaviorList.Count; k++) { double delta = x.behaviorList[k] - y.behaviorList[k]; dist += delta * delta; } x.cachedDistances[y.uniqId] = dist; } return dist;//*/ }
public static double Distance(BehaviorType x, BehaviorType y) { double dist = 0.0; for(int k=0;k<x.behaviorList.Count;k++) { double delta = x.behaviorList[k]-y.behaviorList[k]; dist += delta*delta; } return dist; }
public static double Distance(BehaviorType x, BehaviorType y) { double dist = 0.0; for (int k = 0; k < x.behaviorList.Count; k++) { double delta = x.behaviorList[k] - y.behaviorList[k]; dist += delta * delta; } return(dist); }
public BehaviorType(BehaviorType copyFrom) { if(copyFrom.behaviorList!=null) behaviorList = new List<double>(copyFrom.behaviorList); if (copyFrom.finalLocation != null) finalLocation = new List<double>(copyFrom.finalLocation); if (copyFrom.trajectory != null) trajectory = new List<int>(copyFrom.trajectory); }
// {Assumes the BC values are in the range 0-1} and calculates distance as if the range wrapped around. public static double DistanceWithWraparound(BehaviorType x, BehaviorType y) { double dist = 0.0; double delta; for (int k = 0; k < x.behaviorList.Count; k++) { // JUSTIN: I *think* this works.... delta = 0.5 - Math.Abs(Math.Abs(x.behaviorList[k] - y.behaviorList[k]) - 0.5); dist += delta * delta; } return(dist); }
// {Assumes the BC values are in the range 0-1} and calculates distance as if the range wrapped around. public static double DistanceWithWraparound(BehaviorType x, BehaviorType y) { double dist = 0.0; double delta; for (int k = 0; k < x.behaviorList.Count; k++) { // JUSTIN: I *think* this works.... delta = 0.5 - Math.Abs(Math.Abs(x.behaviorList[k] - y.behaviorList[k]) - 0.5); dist += delta * delta; } return dist; }
public BehaviorType(BehaviorType copyFrom) { if (copyFrom.behaviorList != null) { behaviorList = new List <double>(copyFrom.behaviorList); } if (copyFrom.finalLocation != null) { finalLocation = new List <double>(copyFrom.finalLocation); } if (copyFrom.trajectory != null) { trajectory = new List <int>(copyFrom.trajectory); } }
/// <summary> /// Threadsafe wrapper function for the experiment class's evaluteNetwork function. /// </summary> /// <param name="network">If using NEAT (with direct encoding), the network is the controller itself. Otherwise, if using HyperNEAT, the network is a CPPN that indirectly encodes the controller.</param> /// <param name="sem">Semaphore for managing parallel processes.</param> /// <param name="behavior">** Output parameter ** Returns a vector representation of the agent's behavior inside the experimental domain.</param> public double threadSafeEvaluateNetwork(SharpNeatLib.NeuralNetwork.INetwork network, System.Threading.Semaphore sem, out SharpNeatLib.BehaviorType behavior, int thread) { //TODO: deal with threading return(Experiment.evaluateNetwork(network, out behavior, sem)); }
/// <summary> /// Wrapper function for the experiment class's evaluteNetwork function. /// </summary> /// <param name="network">If using NEAT (with direct encoding), the network is the controller itself. Otherwise, if using HyperNEAT, the network is a CPPN that indirectly encodes the controller.</param> /// <param name="behavior">** Output parameter ** Returns a vector representation of the agent's behavior inside the experimental domain.</param> public double evaluateNetwork(SharpNeatLib.NeuralNetwork.INetwork network, out SharpNeatLib.BehaviorType behavior) { return(Experiment.evaluateNetwork(network, out behavior, null)); }
public BehaviorType(BehaviorType copyFrom) { if(copyFrom.behaviorList!=null) behaviorList = new List<double>(copyFrom.behaviorList); }
//TODO: deal with threading public double threadSafeEvaluateNetwork(SharpNeatLib.NeuralNetwork.INetwork network, System.Threading.Semaphore sem, out SharpNeatLib.BehaviorType behavior, int thread) { // try { return(exp.evaluateNetwork(network, out behavior, sem)); //} catch (Exception e) { // behavior=new BehaviorType(); // Console.WriteLine(e.Message); // Console.WriteLine(e.StackTrace); // throw e; // return 0.0001; //} }