public void AgentEvaluationTest() { Console.WriteLine("AgentEvaluationTest"); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 100.0, 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); string PROPERTY = "NetWorth"; IAgentEvaluation ae = new AgentEvaluation(PROPERTY, null); IBlauPoint mean = new BlauPoint(s); mean.setCoordinate(0, 10.0); mean.setCoordinate(1, 20.0); mean.setCoordinate(2, 30.0); IBlauPoint std = new BlauPoint(s); std.setCoordinate(0, 2.0); std.setCoordinate(1, 4.0); std.setCoordinate(2, 6.0); IDistribution d = new Distribution_Gaussian(s, mean, std); IAgentFactory afact = new AgentDummy_Factory(d); int NUMAGENTS = 100; IAgent[] agents = new IAgent[NUMAGENTS]; for (int i = 0; i < NUMAGENTS; i++) { agents[i] = afact.create(); SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "agent[" + i + "]: " + agents[i]); } double VAL = 1.0; for (int i = 0; i < NUMAGENTS; i++) { ae.set(agents[i], VAL); } for (int i = 0; i < NUMAGENTS; i++) { Assert.AreEqual(ae.eval(agents[i]), VAL); } SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "ae: " + ae.ToStringLong()); }
public void DummySimulation1() { Console.WriteLine("DummySimulation1"); LoggerInitialization.SetThreshold(typeof(sim_tests), LogLevel.Debug); LoggerInitialization.SetThreshold(typeof(AbstractAgent), LogLevel.Info); LoggerInitialization.SetThreshold(typeof(AgentDummy), LogLevel.Info); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 100.0, 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); IBlauPoint mean = new BlauPoint(s); mean.setCoordinate(0, 10.0); mean.setCoordinate(1, 20.0); mean.setCoordinate(2, 30.0); IBlauPoint std = new BlauPoint(s); std.setCoordinate(0, 2.0); std.setCoordinate(1, 4.0); std.setCoordinate(2, 6.0); IDistribution d = new Distribution_Gaussian(s, mean, std); IAgentFactory afact = new AgentDummy_Factory(d); int NUMAGENTS = 100; IPopulation pop = PopulationFactory.Instance().create(afact, NUMAGENTS); foreach (IAgent ag in pop) { SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "agent: " + ag); } IOrderbook_Observable ob = new Orderbook(); string PROPERTY = "NetWorth"; IAgentEvaluationBundle aeb = new AgentEvaluationBundle(PROPERTY); ISimulation sim = new Simulation(pop.clone(), ob.clone(), 0.0, 100.0); NamedMetricAgentEvaluationFactory metricEF = new NamedMetricAgentEvaluationFactory(PROPERTY); sim.add(metricEF); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Running Simulation"); ISimulationResults res = sim.run(); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Stopping Simulation"); IAgentEvaluation ae = metricEF.create(); aeb.addAgentEvaluation(ae); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "aeb: " + aeb.ToStringLong()); SingletonLogger.Instance().DebugLog(typeof(sim_tests), "res: " + res.ToStringLong()); Assert.AreEqual(res.Valid, true); }
public void PopulationFactoryTest() { Console.WriteLine("PopulationFactoryTest"); int dimP = 3; string [] namesP = new string [3] { "x0", "x1", "x2" }; double [] minsP = new double [3] { 0.0, 0.0, 0.0 }; double [] maxsP = new double [3] { 100.0, 100.0, 100.0 }; IBlauSpace sP = BlauSpace.create(dimP, namesP, minsP, maxsP); Product d = new Product(sP); for (int i = 0; i < 3; i++) { int dim = 1; string [] names = new string [1]; names[0] = "x" + i; double [] mins = new double [1] { 0.00 }; double [] maxs = new double [1] { 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); double mean = 10.0 * (i + 1.0); double std = i + 1.0; IDistribution di = new Distribution_Gaussian(s, mean, std); d.Add(di); } d.DistributionComplete(); IPopulationFactory pf = PopulationFactory.Instance(); int POPSIZE = 100; AgentDummy_Factory adf = new AgentDummy_Factory(d); IPopulation pop = pf.create(adf, POPSIZE); Assert.AreEqual(pop.Size, POPSIZE); SingletonLogger.Instance().DebugLog(typeof(agent_tests), "distribution: " + d); SingletonLogger.Instance().DebugLog(typeof(agent_tests), "pop: \n" + pop); int count = 0; foreach (IAgent ag in pop) { for (int x = 0; x < 3; x++) { double diff = Math.Abs(ag.Coordinates.getCoordinate(x) - (10.0 * (x + 1.0))); Assert.AreEqual((diff > 5.0 * (x + 1.0)), false); } count++; } Assert.AreEqual(count, POPSIZE); for (int j = 0; j < count; j++) { IAgent agj = pop.getAgent(j); Assert.Throws <Exception>(delegate { pop.addAgent(agj); }); } for (int j = 0; j < count; j++) { IAgent agj = pop.getAgent(0); pop.removeAgent(agj); Assert.AreEqual(pop.Size, POPSIZE - 1); Assert.Throws <Exception>(delegate { pop.removeAgent(agj); }); pop.addAgent(agj); } }
public void NamedMetricAgentEvaluationFactoryTest() { Console.WriteLine("NamedMetricAgentEvaluationFactoryTest"); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 100.0, 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); int STEPS = 10; int [] STEPSarray = new int[s.Dimension]; for (int j = 0; j < s.Dimension; j++) { STEPSarray[j] = STEPS; } IBlauSpaceLattice bsl = BlauSpaceLattice.create(s, STEPSarray); IBlauPoint mean = new BlauPoint(s); mean.setCoordinate(0, 10.0); mean.setCoordinate(1, 20.0); mean.setCoordinate(2, 30.0); IBlauPoint std = new BlauPoint(s); std.setCoordinate(0, 2.0); std.setCoordinate(1, 4.0); std.setCoordinate(2, 6.0); IDistribution d = new Distribution_Gaussian(s, mean, std); IAgentFactory afact = new AgentDummy_Factory(d); int NUMAGENTS = 100; IPopulation pop = PopulationFactory.Instance().create(afact, NUMAGENTS); IOrderbook_Observable ob = new Orderbook(); foreach (IAgent ag in pop) { SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "agent: " + ag); } string PROPERTY = "NetWorth"; IAgentEvaluationBundle aeb = new AgentEvaluationBundle(PROPERTY); int NUMTRIALS = 100; for (int trial = 0; trial < NUMTRIALS; trial++) { SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "*** Trial " + trial); ISimulation sim = new Simulation(pop.clone(), ob.clone(), 0.0, 100.0); NamedMetricAgentEvaluationFactory metricEF = new NamedMetricAgentEvaluationFactory(PROPERTY); sim.add(metricEF); sim.broadcast(new SimulationStart()); sim.broadcast(new SimulationEnd()); IAgentEvaluation ae = metricEF.create(); aeb.addAgentEvaluation(ae); } IBlauSpaceEvaluation meanEval = aeb.MeanEvaluation(bsl); IBlauSpaceEvaluation stdEval = aeb.StdEvaluation(bsl); foreach (IBlauPoint p in meanEval.AssignedLatticePoints) { double meanval = meanEval.eval(p); double stdval = stdEval.eval(p); SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "Scores binned to Blaupoint: " + p + " ===> mean:" + meanval + ", std:" + stdval); Assert.Less(Math.Abs(meanval - AgentDummy.MEANWORTH), 0.1); Assert.Less(stdval, 0.1); } SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "aeb: " + aeb.ToString()); SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "meanEval: " + meanEval.ToStringLong()); SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "stdEval: " + stdEval.ToStringLong()); }
public void AgentEvaluationBundleCollapsingTest() { Console.WriteLine("AgentEvaluationBundleCollapsingTest"); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 100.0, 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); int STEPS = 10; int [] STEPSarray = new int[s.Dimension]; for (int j = 0; j < s.Dimension; j++) { STEPSarray[j] = STEPS; } IBlauSpaceLattice bsl = BlauSpaceLattice.create(s, STEPSarray); IBlauPoint mean = new BlauPoint(s); mean.setCoordinate(0, 10.0); mean.setCoordinate(1, 20.0); mean.setCoordinate(2, 30.0); IBlauPoint std = new BlauPoint(s); std.setCoordinate(0, 2.0); std.setCoordinate(1, 4.0); std.setCoordinate(2, 6.0); IDistribution d = new Distribution_Gaussian(s, mean, std); IAgentFactory afact = new AgentDummy_Factory(d); int NUMAGENTS = 100; IAgent[] agents = new IAgent[NUMAGENTS]; for (int i = 0; i < NUMAGENTS; i++) { agents[i] = afact.create(); } string PROPERTY = "NetWorth"; IAgentEvaluationBundle aeb = new AgentEvaluationBundle(PROPERTY); int NUMTRIALS = 1000; double MEANVAL = 1.0; for (int trial = 0; trial < NUMTRIALS; trial++) { SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "*** Trial " + trial); IAgentEvaluation ae = new AgentEvaluation(PROPERTY, null); for (int i = 0; i < NUMAGENTS; i++) { ae.set(agents[i], SingletonRandomGenerator.Instance.NextGaussian(MEANVAL, 0.2)); } aeb.addAgentEvaluation(ae); } IBlauSpaceEvaluation meanEval = aeb.MeanEvaluation(bsl); IBlauSpaceEvaluation stdEval = aeb.StdEvaluation(bsl); foreach (IBlauPoint p in meanEval.AssignedLatticePoints) { double meanval = meanEval.eval(p); double stdval = stdEval.eval(p); SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "Scores binned to Blaupoint: " + p + " ===> mean:" + meanval + ", std:" + stdval); Assert.Less(Math.Abs(meanval - MEANVAL), 0.1); Assert.Less(stdval, 0.1); } SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "aeb: " + aeb.ToString()); SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "meanEval: " + meanEval.ToStringLong()); SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "stdEval: " + stdEval.ToStringLong()); }
public void BlauSpaceMultiEvaluationConstructionTest() { Console.WriteLine("BlauSpaceMultiEvaluationConstructionTest"); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 100.0, 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); int STEPS = 10; int [] STEPSarray = new int[s.Dimension]; for (int j = 0; j < s.Dimension; j++) { STEPSarray[j] = STEPS; } IBlauSpaceLattice bsl = BlauSpaceLattice.create(s, STEPSarray); IBlauPoint mean = new BlauPoint(s); mean.setCoordinate(0, 10.0); mean.setCoordinate(1, 20.0); mean.setCoordinate(2, 30.0); IBlauPoint std = new BlauPoint(s); std.setCoordinate(0, 2.0); std.setCoordinate(1, 4.0); std.setCoordinate(2, 6.0); IDistribution d = new Distribution_Gaussian(s, mean, std); IAgentFactory afact = new AgentDummy_Factory(d); int NUMAGENTS = 100; IAgent[] agents = new IAgent[NUMAGENTS]; for (int i = 0; i < NUMAGENTS; i++) { agents[i] = afact.create(); } string PROPERTY = "NetWorth"; BlauSpaceMultiEvaluation mev = new BlauSpaceMultiEvaluation(PROPERTY, bsl); int NUMTRIALS = 10; for (int trial = 0; trial < NUMTRIALS; trial++) { SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "*** Trial " + trial); IAgentEvaluation ae = new AgentEvaluation(PROPERTY, null); for (int i = 0; i < NUMAGENTS; i++) { ae.set(agents[i], SingletonRandomGenerator.Instance.NextGaussian(1.0, 0.2)); } ae.AddToBlauSpaceMultiEvaluation(mev); int count = 0; foreach (IBlauPoint p in mev.AssignedLatticePoints) { LinkedList <IScore> scores = mev.eval(p); SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "" + scores.Count + " Readings binned to Blaupoint: " + p); count += scores.Count; } Assert.AreEqual(count, NUMAGENTS * (trial + 1)); } SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "mev: " + mev.ToStringLong()); }