Exemple #1
0
        public void ScoreTest()
        {
            Console.WriteLine("ScoreTest");

            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 bp = new BlauPoint(s);

            bp.setCoordinate(0, 11.0);
            bp.setCoordinate(1, 22.0);
            bp.setCoordinate(2, 33.0);
            IScore score = new Score(bp, 5.0);

            Assert.AreEqual(score.Coordinates.CompareTo(bp), 0);
            Assert.AreEqual(score.Value, 5.0);
        }
Exemple #2
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);
        }
Exemple #3
0
        public override IBlauPoint getSample()
        {
            IBlauPoint answer = _current;
            BlauPoint  p      = new BlauPoint(this.SampleSpace);

            for (int i = 0; i < this.SampleSpace.Dimension; i++)
            {
                p.setCoordinate(i, _current.getCoordinate(i));
            }
            for (int i = 0; i < this.SampleSpace.Dimension; i++)
            {
                if (p.getCoordinate(i) + _step > this.SampleSpace.getAxis(i).MaximumValue)
                {
                    p.setCoordinate(i, this.SampleSpace.getAxis(i).MinimumValue);
                    if (i == this.SampleSpace.Dimension)
                    {
                        p = new BlauPoint(this.SampleSpace);
                        break;
                    }
                }
                else
                {
                    p.setCoordinate(i, _step + p.getCoordinate(i));
                    break;
                }
            }
            _current = p;

            return(answer);
        }
Exemple #4
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());
        }
Exemple #5
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 #6
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);
        }
Exemple #7
0
        public override IBlauPoint getSample()
        {
            BlauPoint p = new BlauPoint(this.SampleSpace);

            for (int i = 0; i < this.SampleSpace.Dimension; i++)
            {
                double val = Value;
                p.setCoordinate(i, val);
            }
            return(p);
        }
Exemple #8
0
        public override IBlauPoint getSample()
        {
            BlauPoint p = new BlauPoint(this.SampleSpace);

            for (int i = 0; i < this.SampleSpace.Dimension; i++)
            {
                double val;
                do
                {
                    val = SingletonRandomGenerator.Instance.NextGaussian(_mean, _std);
                }while ((val < SampleSpace.getAxis(i).MinimumValue) || (val > SampleSpace.getAxis(i).MaximumValue));
                p.setCoordinate(i, val);
            }
            return(p);
        }
Exemple #9
0
        public void BlauPointComparerTest()
        {
            Console.WriteLine("BlauPointComparerTest");


            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, 200.0, 300.0
            };
            IBlauSpace s = BlauSpace.create(dim, names, mins, maxs);

            IBlauPoint bp = new BlauPoint(s);

            bp.setCoordinate(0, 10.0);
            bp.setCoordinate(1, 20.0);
            bp.setCoordinate(2, 30.0);
            IBlauPoint bp2 = bp.clone();

            Dictionary <IBlauPoint, int> dic = new Dictionary <IBlauPoint, int>(new BlauPointComparer());

            dic.Add(bp, 1);
            Assert.AreEqual(dic.ContainsKey(bp), true);
            Assert.AreEqual(dic.ContainsKey(bp2), true);
            Assert.Throws <System.ArgumentException>(delegate { dic.Add(bp2, 2); });
            Assert.AreEqual(dic.Count, 1);
            Assert.AreEqual(dic[bp], 1);
            Assert.AreEqual(dic[bp2], 1);

            Dictionary <IBlauPoint, int> dic2 = new Dictionary <IBlauPoint, int>(new BlauPointComparer());

            dic2.Add(bp2, 2);
            Assert.AreEqual(dic2.ContainsKey(bp2), true);
            Assert.AreEqual(dic2.ContainsKey(bp), true);
            Assert.Throws <System.ArgumentException>(delegate { dic.Add(bp, 1); });
            Assert.AreEqual(dic2.Count, 1);
            Assert.AreEqual(dic2[bp], 2);
            Assert.AreEqual(dic2[bp2], 2);
        }
Exemple #10
0
        public void BlauPointSerializationTest()
        {
            Console.WriteLine("BlauSpaceSerializationTest");
            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, 200.0, 300.0
            };
            IBlauSpace bs = BlauSpace.create(dim, names, mins, maxs);

            SoapFormatter formatter = new SoapFormatter();
            // BinaryFormatter formatter = new BinaryFormatter();

            BlauPoint p1 = new BlauPoint(bs);
            BlauPoint p2 = new BlauPoint(bs);

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

            formatter.Serialize(fs, p1);
            fs.Close();
            fs = new FileStream("p2.xml", FileMode.Create);
            formatter.Serialize(fs, p2);
            fs.Close();

            fs = new FileStream("p1.xml", FileMode.Open);
            BlauPoint p1r = (BlauPoint)formatter.Deserialize(fs);

            fs.Close();
            fs = new FileStream("p2.xml", FileMode.Open);
            BlauPoint p2r = (BlauPoint)formatter.Deserialize(fs);

            fs.Close();

            Assert.AreEqual(p1r.Space == p1.Space, true);
            Assert.AreEqual(p2r.Space == p2.Space, true);
            Assert.AreEqual(p1r.Space == p2r.Space, true);
            Assert.AreEqual(p1.Space == p2.Space, true);
            SingletonLogger.Instance().DebugLog(typeof(blau_tests), "All spaces coincides as expected");
        }
Exemple #11
0
        public override IBlauPoint getSample()
        {
            if (!_completed)
            {
                throw new Exception("Attempt to sample from Product distribution that has not been completed");
            }
            IBlauPoint p = new BlauPoint(this.SampleSpace);

            foreach (IDistribution d in _factor)
            {
                IBlauPoint q = d.getSample();
                for (int i = 0; i < q.Space.Dimension; i++)
                {
                    p.setCoordinate(p.Space.getAxisIndex(q.Space.getAxis(i).Name), q.getCoordinate(i));
                }
            }
            return(p);
        }
Exemple #12
0
        public void BlauSpaceLatticeTest()
        {
            Console.WriteLine("BlauSpaceLatticeTest");

            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);

            Assert.AreEqual(bsl.getStepSize(0), 100.0 / (double)STEPS);
            Assert.AreEqual(bsl.getStepSize(1), 100.0 / (double)STEPS);
            Assert.AreEqual(bsl.getStepSize(2), 100.0 / (double)STEPS);

            Assert.AreEqual(bsl.getSteps(0), STEPS);
            Assert.AreEqual(bsl.getSteps(1), STEPS);
            Assert.AreEqual(bsl.getSteps(2), STEPS);

            IBlauPoint bp = new BlauPoint(s);

            bp.setCoordinate(0, 11.0);
            bp.setCoordinate(1, 22.0);
            bp.setCoordinate(2, 33.0);

            IBlauPoint bpq = bsl.quantize(bp);

            Assert.AreNotEqual(bp.CompareTo(bpq), 0);

            IBlauPoint bp2 = new BlauPoint(s);

            bp2.setCoordinate(0, 10.0);
            bp2.setCoordinate(1, 20.0);
            bp2.setCoordinate(2, 30.0);

            IBlauPoint bpq2 = bsl.quantize(bp2);

            Assert.AreEqual(bp2.CompareTo(bpq2), 0);

            Assert.AreEqual(bpq.CompareTo(bp2), 0);
            Assert.AreEqual(bpq.CompareTo(bpq2), 0);

            IBlauPoint bp3 = new BlauPoint(s);

            bp3.setCoordinate(0, 9.0);
            bp3.setCoordinate(1, 19.0);
            bp3.setCoordinate(2, 29.0);
            IBlauPoint bpq3 = bsl.quantize(bp3);

            Assert.AreEqual(bpq3.CompareTo(bpq), 0);
            Assert.AreEqual(bpq3.CompareTo(bp2), 0);
            Assert.AreEqual(bpq3.CompareTo(bpq2), 0);
        }
Exemple #13
0
        public void QuantizedBlauPointSerializationTest()
        {
            Console.WriteLine("QuantizedBlauPointSerializationTest");
            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, 200.0, 300.0
            };
            IBlauSpace bs = BlauSpace.create(dim, names, mins, maxs);

            SoapFormatter formatter = new SoapFormatter();
            // BinaryFormatter formatter = new BinaryFormatter();

            BlauPoint p1 = new BlauPoint(bs);

            p1.setCoordinate(0, 11.0);
            p1.setCoordinate(1, 21.0);
            p1.setCoordinate(2, 31.0);

            BlauPoint p2 = new BlauPoint(bs);

            p2.setCoordinate(0, 21.0);
            p2.setCoordinate(1, 31.0);
            p2.setCoordinate(2, 41.0);

            int []            steps = new int[3]; steps[0] = 10; steps[1] = 20; steps[2] = 30;
            IBlauSpaceLattice bsl   = BlauSpaceLattice.create(bs, steps);

            IBlauPoint qp1 = bsl.quantize(p1);
            IBlauPoint qp2 = bsl.quantize(p2);

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

            formatter.Serialize(fs, p1);
            fs.Close();
            fs = new FileStream("p2.xml", FileMode.Create);
            formatter.Serialize(fs, p2);
            fs.Close();

            fs = new FileStream("qp1.xml", FileMode.Create);
            formatter.Serialize(fs, qp1);
            fs.Close();
            fs = new FileStream("qp2.xml", FileMode.Create);
            formatter.Serialize(fs, qp2);
            fs.Close();

            fs = new FileStream("qp1.xml", FileMode.Open);
            IBlauPoint p1r = (IBlauPoint)formatter.Deserialize(fs);

            fs.Close();
            fs = new FileStream("qp2.xml", FileMode.Open);
            IBlauPoint p2r = (IBlauPoint)formatter.Deserialize(fs);

            fs.Close();

            Assert.AreEqual(p1r.Space == p1.Space, true);
            Assert.AreEqual(p2r.Space == p2.Space, true);
            Assert.AreEqual(p1r.Space == p2r.Space, true);
            Assert.AreEqual(p1.Space == p2.Space, true);

            Assert.AreEqual(qp1 is QuantizedBlauPoint, true);
            Assert.AreEqual(qp2 is QuantizedBlauPoint, true);

            Assert.AreEqual(qp2.Space == p2.Space, true);
            Assert.AreEqual(qp1.Space == p1.Space, true);

            Assert.AreEqual(qp1.CompareTo(p1r), 0);
            Assert.AreEqual(qp2.CompareTo(p2r), 0);

            Assert.AreNotEqual(qp1.CompareTo(p1), 0);
            Assert.AreNotEqual(qp2.CompareTo(p2), 0);

            SingletonLogger.Instance().DebugLog(typeof(blau_tests), "Quantized points are as expected");
        }
Exemple #14
0
        public void BlauPointTest()
        {
            Console.WriteLine("BlauPointTest");
            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, 200.0, 300.0
            };
            IBlauSpace s = BlauSpace.create(dim, names, mins, maxs);

            IBlauPoint bp = new BlauPoint(s);

            bp.setCoordinate(0, 10.0);
            bp.setCoordinate(1, 20.0);
            bp.setCoordinate(2, 30.0);
            Assert.AreEqual(bp.getCoordinate(0), 10.0);
            Assert.AreEqual(bp.getCoordinate(1), 20.0);
            Assert.AreEqual(bp.getCoordinate(2), 30.0);

            Assert.Throws <Exception>(delegate { bp.setCoordinate(0, -10.0); });
            Assert.Throws <Exception>(delegate { bp.setCoordinate(0, 110.0); });
            Assert.Throws <Exception>(delegate { bp.setCoordinate(1, -10.0); });
            Assert.Throws <Exception>(delegate { bp.setCoordinate(1, 210.0); });
            Assert.Throws <Exception>(delegate { bp.setCoordinate(2, -10.0); });
            Assert.Throws <Exception>(delegate { bp.setCoordinate(2, 310.0); });

            IBlauPoint bp2 = bp.clone();

            Assert.AreEqual(bp.CompareTo(bp2), 0);
            Assert.AreEqual(bp2.CompareTo(bp), 0);

            int h, h2;

            h  = bp.GetHashCode();
            h2 = bp2.GetHashCode();
            Assert.AreEqual(h, h2);
            bp.setCoordinate(0, 11.0);
            h  = bp.GetHashCode();
            h2 = bp2.GetHashCode();
            Assert.AreNotEqual(h, h2);
            bp2.setCoordinate(0, 11.0);
            h  = bp.GetHashCode();
            h2 = bp2.GetHashCode();
            Assert.AreEqual(h, h2);

            bp.setCoordinate(1, 22.0);
            h  = bp.GetHashCode();
            h2 = bp2.GetHashCode();
            Assert.AreNotEqual(h, h2);
            bp2.setCoordinate(1, 22.0);
            h  = bp.GetHashCode();
            h2 = bp2.GetHashCode();
            Assert.AreEqual(h, h2);

            bp.setCoordinate(2, 33.0);
            h  = bp.GetHashCode();
            h2 = bp2.GetHashCode();
            Assert.AreNotEqual(h, h2);
            bp2.setCoordinate(2, 33.0);
            h  = bp.GetHashCode();
            h2 = bp2.GetHashCode();
            Assert.AreEqual(h, h2);

            Dictionary <IBlauPoint, int> dic = new Dictionary <IBlauPoint, int>();

            dic.Add(bp, 1);
            Assert.AreEqual(dic.ContainsKey(bp), true);
            Assert.AreEqual(dic.ContainsKey(bp2), false);

            SortedDictionary <IBlauPoint, int> dic2 = new SortedDictionary <IBlauPoint, int>();

            dic2.Add(bp, 1);
            Assert.AreEqual(dic2.ContainsKey(bp), true);
            Assert.AreEqual(dic2.ContainsKey(bp2), true);
        }
Exemple #15
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 #16
0
        public void BlauSpaceMultiEvaluationTest()
        {
            Console.WriteLine("BlauSpaceMultiEvaluationTest");
            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);
            IBlauSpaceMultiEvaluation mev = new BlauSpaceMultiEvaluation("net worth", bsl);

            IBlauPoint bp = new BlauPoint(s);

            bp.setCoordinate(0, 11.0);
            bp.setCoordinate(1, 22.0);
            bp.setCoordinate(2, 33.0);

            mev.set(bp, 10.0);
            Assert.AreEqual(mev.eval(bp).Count, 1);
            mev.set(bp, 20.0);
            Assert.AreEqual(mev.eval(bp).Count, 2);

            IBlauPoint bp2 = bp.clone();

            mev.set(bp2, 30.0);
            Assert.AreEqual(mev.eval(bp).Count, 3);
            Assert.AreEqual(mev.eval(bp2).Count, 3);
            mev.set(bp2, 40.0);
            Assert.AreEqual(mev.eval(bp).Count, 4);
            Assert.AreEqual(mev.eval(bp2).Count, 4);

            Assert.AreEqual(mev.AssignedLatticePoints.Count, 1);

            IBlauPoint bp3 = new BlauPoint(s);

            bp3.setCoordinate(0, 12.0);
            bp3.setCoordinate(1, 23.0);
            bp3.setCoordinate(2, 34.0);
            mev.set(bp3, 50.0);
            Assert.AreEqual(mev.eval(bp).Count, 5);
            Assert.AreEqual(mev.eval(bp2).Count, 5);
            Assert.AreEqual(mev.eval(bp3).Count, 5);
            Assert.AreEqual(mev.AssignedLatticePoints.Count, 1);

            IBlauPoint bpX = new BlauPoint(s);

            bpX.setCoordinate(0, 22.0);
            bpX.setCoordinate(1, 33.0);
            bpX.setCoordinate(2, 44.0);
            mev.set(bpX, 100.0);
            Assert.AreEqual(mev.eval(bp).Count, 5);
            Assert.AreEqual(mev.eval(bp2).Count, 5);
            Assert.AreEqual(mev.eval(bp3).Count, 5);
            Assert.AreEqual(mev.eval(bpX).Count, 1);
            Assert.AreEqual(mev.AssignedLatticePoints.Count, 2);

            SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "mev: " + mev.ToStringLong());
        }
Exemple #17
0
        public void BlauSpaceEvaluationTest()
        {
            Console.WriteLine("BlauSpaceEvaluationTest");
            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);
            IBlauSpaceMultiEvaluation mev = new BlauSpaceMultiEvaluation("net worth", bsl);

            IBlauPoint bp = new BlauPoint(s);

            bp.setCoordinate(0, 11.0);
            bp.setCoordinate(1, 22.0);
            bp.setCoordinate(2, 33.0);

            mev.set(bp, 10.0);
            mev.set(bp, 20.0);
            IBlauPoint bp2 = bp.clone();

            mev.set(bp2, 30.0);
            mev.set(bp2, 40.0);
            IBlauPoint bp3 = new BlauPoint(s);

            bp3.setCoordinate(0, 12.0);
            bp3.setCoordinate(1, 23.0);
            bp3.setCoordinate(2, 34.0);
            mev.set(bp3, 50.0);
            IBlauPoint bpX = new BlauPoint(s);

            bpX.setCoordinate(0, 22.0);
            bpX.setCoordinate(1, 33.0);
            bpX.setCoordinate(2, 44.0);
            mev.set(bpX, 100.0);

            IBlauSpaceEvaluation bse = new BlauSpaceEvaluation("net worth", bsl);

            foreach (IBlauPoint p in mev.AssignedLatticePoints)
            {
                LinkedList <IScore> scores = mev.eval(p);
                double total = 0.0;
                double count = 0.0;
                foreach (IScore sc in scores)
                {
                    total += sc.Value;
                    count += 1.0;
                }
                if (p.CompareTo(bp) == 0)
                {
                    Assert.AreEqual(total, 150.0);
                    Assert.AreEqual(count, 5.0);
                }
                if (p.CompareTo(bpX) == 0)
                {
                    Assert.AreEqual(total, 100.0);
                    Assert.AreEqual(count, 1.0);
                }
                double ave = total / count;
                bse.set(p, ave);
                Assert.Throws <Exception>(delegate { bse.set(p, ave); });
                Assert.Throws <Exception>(delegate { bse.set(p.clone(), ave); });

                Assert.AreEqual(bse.eval(p), ave);
                Assert.AreEqual(bse.eval(p.clone()), ave);
            }

            SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "bse: " + bse.ToStringLong());
        }
Exemple #18
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);
        }
Exemple #19
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());
        }
Exemple #20
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());
        }
Exemple #21
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());
        }