示例#1
0
        private AgentOrderbookLoader MakeAgentOrderbookLoader(string PATH)
        {
            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 AgentOrderbookLoader_Factory(PATH, d);
            IPopulation   pop   = PopulationFactory.Instance().create(afact, 1);

            AgentOrderbookLoader loader = null;

            foreach (IAgent ag in pop)
            {
                loader = (AgentOrderbookLoader)ag;
                break;
            }

            return(loader);
        }
示例#2
0
        static public AgentOrderbookLoader MakeAgentOrderbookLoader(string path)
        {
            string [] names = new string [1] {
                "x"
            };
            double [] mins = new double [1] {
                0.00
            };
            double [] maxs = new double [1] {
                100.0
            };
            IBlauSpace    s = BlauSpace.create(1, names, mins, maxs);
            IDistribution d = new Distribution_Gaussian(s, 0.0, 0.0);

            IAgentFactory afact = new AgentOrderbookLoader_Factory(path, d);
            IPopulation   pop   = PopulationFactory.Instance().create(afact, 1);

            AgentOrderbookLoader loader = null;

            foreach (IAgent ag in pop)
            {
                loader = (AgentOrderbookLoader)ag;
                break;
            }

            return(loader);
        }
示例#3
0
        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());
        }
示例#4
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);
        }
示例#5
0
        public void Agent0x1Simulation_AgentTrajectories1()
        {
            Console.WriteLine("Agent0x1Simulation_AgentTrajectories1");
            LoggerInitialization.SetThreshold(typeof(sim_tests), LogLevel.Debug);
            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();

            // 1 hours
            ISimulation sim = new Simulation(pop, ob, 0.0, 3600.0);

            IAgent             agent = PopulationSelector.Select(pop);
            ITrajectoryFactory agTF  = new TrajectoryFactory_AgentOrders(agent, 10.0, 0.0);

            sim.add(agTF);
            ITrajectoryFactory agTF2 = new TrajectoryFactory_AgentNamedMetric(agent, "NetWorth", 10.0, 0.0);

            sim.add(agTF2);
            ITrajectoryFactory agTF3 = new TrajectoryFactory_AgentNamedMetric(agent, "NetWorth", 10.0, 0.99);

            sim.add(agTF3);

            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Running Simulation");
            ISimulationResults res = sim.run();

            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Stopping Simulation");

            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Results\n" + res.ToStringLong());
            Assert.AreEqual(res.Valid, true);
        }
示例#6
0
        private static IDistribution create2DGaussian(double mean, double std, double mean2, double std2)
        {
            int dim = 1;

            string [] names = new string [1] {
                "x"
            };
            double [] mins = new double [1] {
                0.00
            };
            double [] maxs = new double [1] {
                100.0
            };
            IBlauSpace    s = BlauSpace.create(dim, names, mins, maxs);
            IDistribution d = new Distribution_Gaussian(s, mean, std);

            int dim2 = 1;

            string [] names2 = new string [1] {
                "y"
            };
            double [] mins2 = new double [1] {
                0.00
            };
            double [] maxs2 = new double [1] {
                100.0
            };
            IBlauSpace    s2 = BlauSpace.create(dim2, names2, mins2, maxs2);
            IDistribution d2 = new Distribution_Gaussian(s2, mean2, std2);

            int dim3 = 2;

            string [] names3 = new string [2] {
                "x", "y"
            };
            double [] mins3 = new double [2] {
                0.00, 0.00
            };
            double [] maxs3 = new double [2] {
                100.0, 100.0
            };
            IBlauSpace s3 = BlauSpace.create(dim3, names3, mins3, maxs3);

            Product d3 = new Product(s3);

            d3.Add(d);
            d3.Add(d2);
            d3.DistributionComplete();

            return(d3);
        }
示例#7
0
        public void DistributionSpaceIteratorReverse_SingleGaussianTest()
        {
            Console.WriteLine("DistributionSpaceIteratorReverse_SingleGaussianTest");

            int dim = 1;

            string [] names = new string [1] {
                "x"
            };
            double [] mins = new double [1] {
                0.00
            };
            double [] maxs = new double [1] {
                100.0
            };
            IBlauSpace    s    = BlauSpace.create(dim, names, mins, maxs);
            double        mean = 70.0;
            double        std  = 1.0;
            IDistribution d    = new Distribution_Gaussian(s, mean, std);

            SingletonLogger.Instance().DebugLog(typeof(dist_tests), "original distribution: " + d);
            DistributionSpace ds = new DistributionSpace(d);

            int [] steps = new int[ds.ParamSpace.Dimension];

            for (int N = 3; N <= 5; N++)
            {
                for (int i = 0; i < ds.ParamSpace.Dimension; i++)
                {
                    steps[i] = N;
                }

                IDistributionSpaceIterator it = ds.iterator(steps);

                int count   = 0;
                int validCt = 0;
                foreach (IDistribution d2 in it)
                {
                    if (d2.IsValid())
                    {
                        validCt++;
                        SingletonLogger.Instance().DebugLog(typeof(dist_tests), "iterator distribution: " + d2);
                    }
                    count++;
                }
                Assert.AreEqual((N + 1) * (N + 1), count);
                SingletonLogger.Instance().InfoLog(typeof(dist_tests), "N=" + N + "  valid distributions: " + validCt + " / total: " + count);
            }
        }
示例#8
0
        public void Distribution_GaussianSerializationTest()
        {
            Console.WriteLine("Distribution_Gaussian1DSerializationTest");

            int dim = 1;

            string [] names = new string [1] {
                "x"
            };
            double [] mins = new double [1] {
                0.00
            };
            double [] maxs = new double [1] {
                100.0
            };
            IBlauSpace    s    = BlauSpace.create(dim, names, mins, maxs);
            double        mean = 70.0;
            double        std  = 1.0;
            IDistribution d    = new Distribution_Gaussian(s, mean, std);

            SingletonLogger.Instance().DebugLog(typeof(dist_tests), "distribution: " + d);

            SoapFormatter formatter = new SoapFormatter();

            FileStream fs = new FileStream("gaussian.xml", FileMode.Create);

            formatter.Serialize(fs, d);
            fs.Close();

            fs = new FileStream("gaussian.xml", FileMode.Open);
            IDistribution d2 = (IDistribution)formatter.Deserialize(fs);

            fs.Close();

            Assert.AreEqual(d.SampleSpace == d2.SampleSpace, true);
            Assert.AreEqual(d is Distribution_Gaussian, true);
            Assert.AreEqual(d2 is Distribution_Gaussian, true);

            Distribution_Gaussian g1 = (Distribution_Gaussian)d;
            Distribution_Gaussian g2 = (Distribution_Gaussian)d2;

            Assert.AreEqual(g1.Mean.CompareTo(g2.Mean), 0);
            Assert.AreEqual(g1.Std.CompareTo(g2.Std), 0);
            Assert.AreEqual(g1.Params, g2.Params);
            Assert.AreEqual(g1.SampleSpace, g2.SampleSpace);

            SingletonLogger.Instance().DebugLog(typeof(dist_tests), "All distributions coincide as expected");
        }
示例#9
0
        private static IDistribution create1DGaussian(double mean, double std)
        {
            int dim = 1;

            string [] names = new string [1] {
                "x"
            };
            double [] mins = new double [1] {
                0.00
            };
            double [] maxs = new double [1] {
                100.0
            };
            IBlauSpace    s = BlauSpace.create(dim, names, mins, maxs);
            IDistribution d = new Distribution_Gaussian(s, mean, std);

            return(d);
        }
示例#10
0
        public static void MakeGaussian_Main(string[] args)
        {
            Console.WriteLine("MakeGaussian");

            // Command line parsing
            Arguments CommandLine = new Arguments(args);

            bool   err       = false;
            string errString = "";

            double mean, std, min, max;
            string variable = "unassigned";
            string outfile  = "unassigned";

            mean = std = min = max = -1.0;

            // Look for specific arguments values and display
            // them if they exist (return null if they don't)
            if (CommandLine["mean"] != null)
            {
                try {
                    mean = Double.Parse(CommandLine["mean"]);
                }
                catch (Exception) {
                    errString += ("The specified 'mean' was not valid.  ");
                    err        = true;
                }
            }
            else
            {
                errString += ("The 'mean' was not specified.  ");
                err        = true;
            }

            if (CommandLine["std"] != null)
            {
                try {
                    std = Double.Parse(CommandLine["std"]);
                }
                catch (Exception) {
                    errString += ("The specified 'std' was not valid.  ");
                    err        = true;
                }
            }
            else
            {
                errString += ("The 'std' was not specified.  ");
                err        = true;
            }

            if (CommandLine["variable"] != null)
            {
                variable = CommandLine["variable"];
            }
            else
            {
                errString += ("The 'variable' was not specified.  ");
                err        = true;
            }

            if (CommandLine["min"] != null)
            {
                try {
                    min = Double.Parse(CommandLine["min"]);
                }
                catch (Exception) {
                    errString += ("The specified 'min' was not valid.  ");
                    err        = true;
                }
            }
            else
            {
                errString += ("The 'min' was not specified.  ");
                err        = true;
            }

            if (CommandLine["max"] != null)
            {
                try {
                    max = Double.Parse(CommandLine["max"]);
                }
                catch (Exception) {
                    errString += ("The specified 'max' was not valid.  ");
                    err        = true;
                }
            }
            else
            {
                errString += ("The 'max' was not specified.  ");
                err        = true;
            }

            if (CommandLine["outfile"] != null)
            {
                outfile = CommandLine["outfile"];
            }
            else
            {
                errString += ("The 'outfile' was not specified.  ");
                err        = true;
            }

            if (err)
            {
                Console.Out.WriteLine("Arguments parsing failed.");
                Console.Out.WriteLine("  " + errString);
            }
            else
            {
                Console.Out.WriteLine("Arguments parsing successful.");
                Console.Out.WriteLine("  mean = " + mean);
                Console.Out.WriteLine("  std = " + std);
                Console.Out.WriteLine("  variable = " + variable);
                Console.Out.WriteLine("  min = " + min);
                Console.Out.WriteLine("  max = " + max);
                Console.Out.WriteLine("  outfile = " + outfile);

                int       dim   = 1;
                string [] names = new string [1] {
                    ""
                };
                double [] mins = new double [1] {
                    0.00
                };
                double [] maxs = new double [1] {
                    0.0
                };
                names[0] = variable;
                mins[0]  = min;
                maxs[0]  = max;
                IBlauSpace    s = BlauSpace.create(dim, names, mins, maxs);
                IDistribution d = new Distribution_Gaussian(s, mean, std);

                Console.Out.WriteLine("Distribution: " + d);

                SoapFormatter formatter = new SoapFormatter();

                FileStream fs = new FileStream(outfile, FileMode.Create);
                formatter.Serialize(fs, d);
                fs.Close();
            }
        }
示例#11
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);
        }
示例#12
0
        public void Agent0x1Simulation_TrajectoryBundles()
        {
            Console.WriteLine("Agent0x1Simulation_TrajectoryBundles");
            LoggerInitialization.SetThreshold(typeof(sim_tests), LogLevel.Debug);
            //LoggerInitialization.SetThreshold(typeof(Agent0x1), LogLevel.Info);
            //LoggerInitialization.SetThreshold(typeof(AbstractAgent), LogLevel.Info);
            //LoggerInitialization.SetThreshold(typeof(SimulationBundle), LogLevel.Debug);
            //LoggerInitialization.SetThreshold(typeof(Scheduler), LogLevel.Debug);
            //LoggerInitialization.SetThreshold(typeof(Trajectory), LogLevel.Debug);

            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 = 25;
            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";

            // 1 hours
            ISimulationBundle simb = new SimulationBundle(pop, ob, 0.0, 3600.0);

            IAgentEvaluationFactory metricEF = new NamedMetricAgentEvaluationFactory(PROPERTY);

            simb.add(metricEF);

            ITrajectoryFactory priceTF = new TrajectoryFactory_Price(10.0, 0.8);

            simb.add(priceTF);

            ITrajectoryFactory spreadTF = new TrajectoryFactory_Spread(10.0, 0.0);

            simb.add(spreadTF);

            int NUMTRIALS = 25;

            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Running Simulation");
            ISimulationResultsBundle resb = simb.run(NUMTRIALS);

            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Stopping Simulation");

            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "resb: " + resb.ToString());

            int STEPS = 1;

            int [] STEPSarray = new int[s.Dimension]; for (int j = 0; j < s.Dimension; j++)
            {
                STEPSarray[j] = STEPS;
            }
            IBlauSpaceLattice bsl = BlauSpaceLattice.create(s, STEPSarray);

            foreach (IAgentEvaluationBundle aeb in resb.getAgentEvaluationBundles())
            {
                IBlauSpaceEvaluation meanEval = aeb.MeanEvaluation(bsl);
                IBlauSpaceEvaluation stdEval  = aeb.StdEvaluation(bsl);
                SingletonLogger.Instance().DebugLog(typeof(sim_tests), "meanEval: " + meanEval.ToStringLong());
                SingletonLogger.Instance().DebugLog(typeof(sim_tests), "stdEval: " + stdEval.ToStringLong());
            }

            foreach (ITrajectoryBundle tb in resb.getTrajectoryBundles())
            {
                SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Computing meanTraj");
                ITrajectory meanTraj = tb.MeanTrajectory;
                SingletonLogger.Instance().DebugLog(typeof(sim_tests), "Computing stdTraj");
                ITrajectory stdTraj = tb.StdTrajectory;

                SingletonLogger.Instance().DebugLog(typeof(sim_tests), "meanTraj: " + meanTraj.ToStringLong());
                SingletonLogger.Instance().DebugLog(typeof(sim_tests), "stdTraj: " + stdTraj.ToStringLong());
            }

            Assert.AreEqual(resb.Valid, true);
        }
示例#13
0
        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);
            }
        }
示例#14
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());
        }
示例#15
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());
        }
示例#16
0
        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());
        }