Exemple #1
0
        public void add(ISimulationResults res)
        {
            foreach (ITrajectory t in res.getTrajectories())
            {
                ITrajectoryBundle tb = null;

                if (!_tbundles.ContainsKey(t.Name))
                {
                    tb = new TrajectoryBundle(t.Name);
                    _tbundles.Add(t.Name, tb);
                }
                else
                {
                    tb = _tbundles[t.Name];
                }
                tb.addTrajectory(t);
            }

            foreach (IAgentEvaluation ae in res.getAgentEvaluations())
            {
                IAgentEvaluationBundle aeb = null;
                if (!_aebundles.ContainsKey(ae.Name))
                {
                    aeb = new AgentEvaluationBundle(ae.Name);
                    _aebundles.Add(ae.Name, aeb);
                }
                else
                {
                    aeb = _aebundles[ae.Name];
                }
                aeb.addAgentEvaluation(ae);
            }
        }
Exemple #2
0
        public void Agent0x1Simulation_ZeroDimensional()
        {
            Console.WriteLine("Agent0x1Simulation_ZeroDimensional");
            LoggerInitialization.SetThreshold(typeof(sim_tests), LogLevel.Debug);
            LoggerInitialization.SetThreshold(typeof(AbstractAgent), LogLevel.Info);
            LoggerInitialization.SetThreshold(typeof(AgentOrderbookLoader), LogLevel.Info);
            LoggerInitialization.SetThreshold(typeof(Agent0x0), LogLevel.Info);

            int dim = 0;

            string []     names = new string [0];
            double []     mins  = new double [0];
            double []     maxs  = new double [0];
            IBlauSpace    s     = BlauSpace.create(dim, names, mins, maxs);
            IBlauPoint    mean  = new BlauPoint(s);
            IBlauPoint    std   = new BlauPoint(s);
            IDistribution d     = new Distribution_Gaussian(s, mean, std);

            IAgentFactory afact     = new Agent0x0_Factory(d);
            int           NUMAGENTS = 10;
            IPopulation   pop       = PopulationFactory.Instance().create(afact, NUMAGENTS);

            foreach (IAgent ag in pop)
            {
                SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "agent: " + ag);
            }

            string PATH = "" + ApplicationConfig.EXECDIR + "orderbooks/orderbook.csv";
            AgentOrderbookLoader loader = MakeAgentOrderbookLoader(PATH);

            pop.addAgent(loader);

            IOrderbook_Observable ob = new Orderbook();

            string PROPERTY            = "NetWorth";
            IAgentEvaluationBundle aeb = new AgentEvaluationBundle(PROPERTY);

            // 1 hours
            ISimulation sim = new Simulation(pop, ob, 0.0, 3600.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), "ob: " + ob.ToStringLong());
            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "aeb: " + aeb.ToStringLong());
            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "res: " + res.ToStringLong());

            Assert.AreEqual(res.Valid, true);
        }
Exemple #3
0
        public void add(ISimulationResultsBundle resb)
        {
            foreach (ITrajectoryBundle tb in resb.getTrajectoryBundles())
            {
                foreach (ITrajectory t in tb.Trajectories)
                {
                    ITrajectoryBundle newtb = null;
                    if (!_tbundles.ContainsKey(t.Name))
                    {
                        newtb = new TrajectoryBundle(t.Name);
                        _tbundles.Add(t.Name, newtb);
                    }
                    else
                    {
                        newtb = _tbundles[t.Name];
                    }
                    newtb.addTrajectory(t);
                }
            }

            foreach (IAgentEvaluationBundle aeb in resb.getAgentEvaluationBundles())
            {
                foreach (IAgentEvaluation ae in aeb.Evaluations)
                {
                    IAgentEvaluationBundle newaeb = null;
                    if (!_aebundles.ContainsKey(ae.Name))
                    {
                        newaeb = new AgentEvaluationBundle(ae.Name);
                        _aebundles.Add(ae.Name, newaeb);
                    }
                    else
                    {
                        newaeb = _aebundles[ae.Name];
                    }
                    aeb.addAgentEvaluation(ae);
                }
            }
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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());
        }
Exemple #6
0
        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());
        }