public Particle(Position position, CostEvaluator evaluator, Attraction attraction) { _evaluator = evaluator; Velocity = GenerateRandomVelocity(position.Vector.Length); Position = position; Attraction = attraction; PersonalBest = Position; }
private static void RunAlgorithm(int runCount, CostEvaluator trainCostEvaluator, CostEvaluator testCostEvaluator, IParticleSwarm pso, int particleCount, ConsoleLogger logger, string outputFilePath) { Console.WriteLine($"Starting {runCount} runs..."); for (var i = 0; i < runCount; i++) { var simulator = new ParticleSwarmSimulator(trainCostEvaluator, pso); var weights = simulator.Simulate(particleCount); var cost = testCostEvaluator.Cost(weights); logger.LogRunResult(i, cost, weights); AppendToResultsFile(outputFilePath, cost, weights); } }
public ParticleSwarmSimulator(CostEvaluator evaluator, IParticleSwarm particleSwarm) { _evaluator = evaluator; _particleSwarm = particleSwarm; _random = new Random(); }
public void EvaluateWith(CostEvaluator evaluator) { Value = evaluator.Cost(Vector); }