Ejemplo n.º 1
0
        public IBlauSpaceEvaluation MeanEvaluation(IBlauSpaceLattice lattice)
        {
            IAgentEvaluationBundleCollapser meanCalculator = AgentEvaluationBundleCollapser_Mean.Instance();
            IBlauSpaceEvaluation            mean           = meanCalculator.eval(this, lattice);

            return(mean);
        }
Ejemplo n.º 2
0
        public IBlauSpaceEvaluation AssignmentCounts(IBlauSpaceLattice lattice)
        {
            IAgentEvaluationBundleCollapser countsCalculator = AgentEvaluationBundleCollapser_Counts.Instance();
            IBlauSpaceEvaluation            counts           = countsCalculator.eval(this, lattice);

            return(counts);
        }
        public IBlauSpaceEvaluation eval(IAgentEvaluationBundle aeb, IBlauSpaceLattice lattice)
        {
            IBlauSpaceEvaluation meanEval = aeb.MeanEvaluation(lattice);

            IBlauSpaceMultiEvaluation bsme = new BlauSpaceMultiEvaluation(aeb.Name, lattice);
            IBlauSpaceEvaluation      bse  = new BlauSpaceEvaluation(aeb.Name + "-Std", lattice);

            foreach (IAgentEvaluation ae in aeb.Evaluations)
            {
                ae.AddToBlauSpaceMultiEvaluation(bsme);
            }
            foreach (IBlauPoint p in bsme.AssignedLatticePoints)
            {
                LinkedList <IScore> scores = bsme.eval(p);
                double meanValue           = meanEval.eval(p);

                double total = 0.0;
                int    count = 0;
                foreach (IScore s in scores)
                {
                    double delta = (s.Value - meanValue);
                    total += (delta * delta);
                    count++;
                }
                double mean = Math.Sqrt(total) / (double)count;
                bse.set(p, mean);
            }
            return(bse);
        }
Ejemplo n.º 4
0
        public IBlauSpaceEvaluation StdEvaluation(IBlauSpaceLattice lattice)
        {
            IAgentEvaluationBundleCollapser stdCalculator = AgentEvaluationBundleCollapser_Std.Instance();
            IBlauSpaceEvaluation            std           = stdCalculator.eval(this, lattice);

            return(std);
        }
Ejemplo n.º 5
0
        /*
         * protected override int RecalculateHashCode() {
         * int val = 0;
         *      int digit = 1;
         *      for (int i=0; i<this.Space.Dimension; i++) {
         *              val += getQuantizedCoordinate(i) * digit;
         *              val = val % Int16.MaxValue;
         *
         *              digit *= _quantizer.getSteps(i);
         *              digit = digit % Int16.MaxValue;
         *      }
         *      return val;
         * }
         */

        public QuantizedBlauPoint(IBlauSpace space, IBlauSpaceLattice quantizer) : base(space)
        {
            _quantizer       = quantizer;
            _quantizedCoords = new int [space.Dimension];
            for (int i = 0; i < space.Dimension; i++)
            {
                this.setQuantizedCoordinate(i, 0);
            }
        }
Ejemplo n.º 6
0
        public void BlauSpaceLatticeSerializationTest()
        {
            Console.WriteLine("BlauSpaceLatticeSerializationTest");
            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);

            int [] steps1 = new int [3] {
                10, 10, 10
            };
            IBlauSpaceLattice bsl1a = BlauSpaceLattice.create(bs, steps1);
            IBlauSpaceLattice bsl1b = BlauSpaceLattice.create(bs, steps1);

            Assert.AreEqual(bsl1a == bsl1b, true);

            int [] steps2 = new int [3] {
                20, 20, 20
            };
            IBlauSpaceLattice bsl2 = BlauSpaceLattice.create(bs, steps2);

            Assert.AreEqual(bsl1a == bsl2, false);

            FileStream    fs        = new FileStream("bsl1.xml", FileMode.Create);
            SoapFormatter formatter = new SoapFormatter();

            formatter.Serialize(fs, bsl1a);
            fs.Flush();
            fs.Close();

            SingletonLogger.Instance().DebugLog(typeof(blau_tests), "bsl1a => " + bsl1a.ToString());

            FileStream       fs2      = new FileStream("bsl1.xml", FileMode.Open);
            BlauSpaceLattice bsl1read = (BlauSpaceLattice)formatter.Deserialize(fs2);

            fs2.Close();

            SingletonLogger.Instance().DebugLog(typeof(blau_tests), "bs1read => " + bsl1read.ToString());

            IBlauSpaceLattice bsl3 = BlauSpaceLatticeRegistry.Instance().validate(bsl1read);

            Assert.AreEqual(bsl1a == bsl3, true);
            SingletonLogger.Instance().DebugLog(typeof(blau_tests), "bs1a agrees with validated bs1read");

            Assert.AreEqual(bsl1a == bsl1read, true);
            SingletonLogger.Instance().DebugLog(typeof(blau_tests), "bs1a agrees with bs1read");
        }
Ejemplo n.º 7
0
        public void QuantizedBlauPointTest()
        {
            Console.WriteLine("QuantizedBlauPointTest");

            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);
            IBlauSpaceLattice bsl2 = BlauSpaceLattice.create(s, STEPSarray);

            IBlauPoint bp  = new QuantizedBlauPoint(s, bsl);
            IBlauPoint bp2 = new QuantizedBlauPoint(s, bsl2);
            IBlauPoint bp3 = new QuantizedBlauPoint(s, bsl);

            bp.setCoordinate(0, 10.0);
            bp.setCoordinate(1, 20.0);
            bp.setCoordinate(2, 30.0);
            bp2.setCoordinate(0, 9.99);
            bp2.setCoordinate(1, 19.99);
            bp2.setCoordinate(2, 29.99);
            bp3.setCoordinate(0, 10.01);
            bp3.setCoordinate(1, 20.01);
            bp3.setCoordinate(2, 30.01);
            Assert.AreEqual(bp.CompareTo(bp2), 0);
            Assert.AreEqual(bp.CompareTo(bp3), 0);
            Assert.AreEqual(bp2.CompareTo(bp), 0);
            Assert.AreEqual(bp.CompareTo(bp), 0);
            Assert.AreEqual(bp3.CompareTo(bp), 0);
            Assert.AreEqual(bp3.CompareTo(bp2), 0);
        }
Ejemplo n.º 8
0
        public IBlauSpaceEvaluation eval(IAgentEvaluationBundle aeb, IBlauSpaceLattice lattice)
        {
            IBlauSpaceMultiEvaluation bsme = new BlauSpaceMultiEvaluation(aeb.Name, lattice);
            IBlauSpaceEvaluation      bse  = new BlauSpaceEvaluation(aeb.Name + "-Mean", lattice);

            foreach (IAgentEvaluation ae in aeb.Evaluations)
            {
                ae.AddToBlauSpaceMultiEvaluation(bsme);
            }
            foreach (IBlauPoint p in bsme.AssignedLatticePoints)
            {
                LinkedList <IScore> scores = bsme.eval(p);
                double count = (double)scores.Count;
                bse.set(p, (double)count);
            }
            return(bse);
        }
Ejemplo n.º 9
0
        public IBlauSpaceLattice getLattice(IDistribution d, IAgentEvaluationBundle aeb)
        {
            IAgentEvaluationFactory aef = null;;

            foreach (IAgentEvaluation iae in aeb.Evaluations)
            {
                aef = iae.Creator;
                break;
            }

            int[] steps = new int[d.SampleSpace.Dimension];
            for (int j = 0; j < d.SampleSpace.Dimension; j++)
            {
                steps[j] = getAgentEvaluationConfig(aef).BlauSpaceGridding;
            }
            IBlauSpaceLattice bsl = BlauSpaceLattice.create(d.SampleSpace, steps);

            return(bsl);
        }
        public IBlauSpaceEvaluation eval(IAgentEvaluationBundle aeb, IBlauSpaceLattice lattice)
        {
            IBlauSpaceMultiEvaluation bsme = new BlauSpaceMultiEvaluation(aeb.Name, lattice);
            IBlauSpaceEvaluation      bse  = new BlauSpaceEvaluation(aeb.Name + "-Mean", lattice);

            foreach (IAgentEvaluation ae in aeb.Evaluations)
            {
                ae.AddToBlauSpaceMultiEvaluation(bsme);
            }
            foreach (IBlauPoint p in bsme.AssignedLatticePoints)
            {
                LinkedList <IScore> scores = bsme.eval(p);
                double total = 0.0;
                int    count = 0;
                foreach (IScore s in scores)
                {
                    total += s.Value;
                    count++;
                }
                double mean = total / (double)count;
                bse.set(p, mean);
            }
            return(bse);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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");
        }
Ejemplo n.º 13
0
        public override void run()
        {
            LoggerInitialization.SetThreshold(typeof(SingleDistributionExperiment), LogLevel.Debug);

            SingletonLogger.Instance().DebugLog(typeof(SingleDistributionExperiment), "run()");
            SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "distribution => " + theActualDistribution);

            IAgentFactory af = CreateAgentFactory(theActualDistribution, theTableConfig.AgentFactoryClassName);

            SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "agent factory => " + theTableConfig.AgentFactoryClassName);

            af.Initialize(theTableConfig);

            SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "creating initial orderbook");
            IOrderbook_Observable ob = new Orderbook();

            /* No Burnin at this point
             *
             * SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "Executing burnin...");
             * IPopulation popburn = CreatePopulation(af, theTableConfig.NumAgents, Path.Combine(ApplicationConfig.ROOTDIR, theTableConfig.InitialOrderbook));
             * ISimulation simburn = new Simulation(popburn, ob, 0.0, COMMON_BURNIN_TIME_SECONDS, false, "burnin") ;
             * ISimulationResults resultsburn = simburn.run();
             * ob = (IOrderbook_Observable)simburn.Orderbook;
             * SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "Done with burnin.");
             */

            ISimulationBundle        accumulated_simb = null;
            ISimulationResultsBundle accumulated_resb = null;

            for (int popi = 0; popi < theTableConfig.Populations; popi++)
            {
                SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "creating population... " + theTableConfig.NumAgents);
                // Populations all contain an OrderBookLoader agent
                IPopulation pop = CreatePopulation(af, theTableConfig.NumAgents, Path.Combine(ApplicationConfig.ROOTDIR, theTableConfig.InitialOrderbook));
                // SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "done.");

                string popname = POP_FILE_PREFIX + "." + popi + ".Validation";
                string poppath = Path.Combine(_popdir, popname);
                SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "population " + popi + " => " + poppath);
                savePopulation(poppath, pop);

                _simb = new SimulationBundle(pop, ob, 0.0, theTableConfig.DurationHours * 3600.0, LOG_FRAMES, "pop-" + popi);

                if (accumulated_simb == null)
                {
                    accumulated_simb = _simb;
                }

                foreach (TrajectoryFactoryConfig tfc in theTrajConfig.getTrajectories())
                {
                    IPassiveTrajectoryFactory tf = CreatePassiveTrajectoryFactory(tfc);
                    tf.Initialize(theTableConfig);
                    _simb.add(tf);
                }

                /*
                 * foreach (IAgent ag in pop) {
                 *      if (ag is IAgent_NonParticipant) continue;
                 *
                 *      _simb.add (new TrajectoryFactory_AgentNamedMetric(ag, Agent1x0.NetWorth_METRICNAME, 1.0, 0.0));
                 * }
                 */

                double MAX_ALPHA = 0.10;
                double TEMPORAL_GRANULARITY_FOR_ALPHA_SLICES = 1.0;

                for (double alpha = 0.0; alpha <= MAX_ALPHA; alpha += MAX_ALPHA / (double)theTableConfig.NumCombs)
                {
                    TrajectoryFactory_AlphaSlice tf = new TrajectoryFactory_AlphaSlice(TEMPORAL_GRANULARITY_FOR_ALPHA_SLICES, 0.0, alpha, true);
                    tf.Initialize(theTableConfig);
                    _simb.add(tf);
                    TrajectoryFactory_AlphaSlice tf2 = new TrajectoryFactory_AlphaSlice(TEMPORAL_GRANULARITY_FOR_ALPHA_SLICES, 0.0, alpha, false);
                    tf2.Initialize(theTableConfig);
                    _simb.add(tf2);
                }

                foreach (AgentEvaluationConfig aefc in theAgentEvaluationFactorySetConfig.getAgentEvaluations())
                {
                    IAgentEvaluationFactory aef = CreateAgentEvaluationFactory(aefc);
                    _simb.add(aef, aefc);
                }

                _resb = _simb.run(theTableConfig.Trials);

                //popname = POP_FILE_PREFIX+"."+popi+".Validation-Post";
                //poppath = Path.Combine(_popdir, popname);
                //SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "population post "+popi+" => "+poppath);
                //savePopulation(poppath, pop);

                if (accumulated_resb == null)
                {
                    accumulated_resb = _resb;
                }
                else
                {
                    accumulated_resb.add(_resb);
                }

                //WriteTrajectories(popi, _simb, _resb);
            }

            //WriteTrajectories(-1, accumulated_simb, accumulated_resb);

            PresentationConfig.Directory = Path.Combine(OutputDirectory, "results");
            if (!Directory.Exists(PresentationConfig.Directory))
            {
                Directory.CreateDirectory(PresentationConfig.Directory);
            }

            Latex.ClearImages();

            SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "Writing BlauSpaceEvaluations.");

            foreach (IAgentEvaluationBundle aeb in accumulated_resb.getAgentEvaluationBundles())
            {
                IBlauSpaceLattice    bsl      = accumulated_simb.getLattice(theActualDistribution, aeb);
                IBlauSpaceEvaluation meanEval = aeb.MeanEvaluation(bsl);
                IBlauSpaceEvaluation stdEval  = aeb.StdEvaluation(bsl);

                BlauSpaceEvaluationGnuplotPresenter pres = new BlauSpaceEvaluationGnuplotPresenter(_bsedir, PresentationConfig.Directory);
                pres.Present(this, meanEval, stdEval);
            }

            SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "Writing TrajectoryBundles.");
            foreach (ITrajectoryBundle tb in accumulated_resb.getTrajectoryBundles())
            {
                TrajectoryBundleGnuplotPresenter pres = new TrajectoryBundleGnuplotPresenter(_trajdir, PresentationConfig.Directory);
                pres.Present(this, tb);
            }

            SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "Writing Latex.");
            Latex.Instance().Present(this);

            CreateReport(this);

            SingletonLogger.Instance().InfoLog(typeof(SingleDistributionExperiment), "Done.");
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 16
0
        private void WriteTrajectories(int popi, ISimulationBundle simb, ISimulationResultsBundle resb)
        {
            string     trajname   = TRAJ_FILE_PREFIX + "." + popi + ".Validation";
            string     trajpath   = Path.Combine(_trajdir, trajname);
            TextWriter trajWriter = File.CreateText(trajpath);

            foreach (IAgentEvaluationBundle aeb in resb.getAgentEvaluationBundles())
            {
                trajWriter.WriteLine("# AgentEvaluation: " + aeb.Name);
                trajWriter.Write("# BlauPoint-Coordinates \t ");
                trajWriter.Write("mean \t std \t count");
                trajWriter.WriteLine("");

                IBlauSpaceLattice bsl = simb.getLattice(theActualDistribution, aeb);

                IBlauSpaceEvaluation meanEval = aeb.MeanEvaluation(bsl);
                IBlauSpaceEvaluation stdEval  = aeb.StdEvaluation(bsl);
                IBlauSpaceEvaluation ctEval   = aeb.AssignmentCounts(bsl);

                foreach (IBlauPoint bp in meanEval.AssignedLatticePoints)
                {
                    for (int c = 0; c < bp.Space.Dimension; c++)
                    {
                        trajWriter.Write("" + bp.Space.getAxis(c).Name + "=" + bp.getCoordinate(c).ToString("#0.000") + "\t");
                    }
                    trajWriter.Write("" + meanEval.eval(bp).ToString("#0.000") + "\t");
                    trajWriter.Write("" + stdEval.eval(bp).ToString("#0.000") + "\t");
                    trajWriter.Write("" + ctEval.eval(bp).ToString("#0.000") + "\t");
                    trajWriter.WriteLine("");
                }
            }

            double NUMTICKS = 100.0;

            foreach (ITrajectoryBundle tb in resb.getTrajectoryBundles())
            {
                trajWriter.WriteLine("# TrajectoryBundle: " + tb.Name);
                trajWriter.WriteLine("# time \t mean \t std \t center \t dev");

                ITrajectory meanTraj   = tb.MeanTrajectory;
                ITrajectory stdTraj    = tb.StdTrajectory;
                ITrajectory centerTraj = tb.CentralTrajectory;
                ITrajectory devTraj    = tb.CentralDevTrajectory;

                double mint  = tb.MinimumTime;
                double maxt  = tb.MaximumTime;
                double stept = (maxt - mint) / NUMTICKS;

                for (double t = mint; t < maxt; t += stept)
                {
                    trajWriter.Write("" + t.ToString("#0.000") + "\t");
                    trajWriter.Write("" + meanTraj.eval(t).ToString("#0.000") + "\t");
                    trajWriter.Write("" + stdTraj.eval(t).ToString("#0.000") + "\t");
                    trajWriter.Write("" + centerTraj.eval(t).ToString("#0.000") + "\t");
                    trajWriter.Write("" + devTraj.eval(t).ToString("#0.000") + "\t");
                    trajWriter.WriteLine("");
                }
            }

            trajWriter.Flush();
            trajWriter.Close();
        }
Ejemplo n.º 17
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());
        }
Ejemplo n.º 18
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());
        }
Ejemplo n.º 19
0
 public BlauSpaceEvaluation(string name, IBlauSpaceLattice lattice)
 {
     _name           = name;
     _lattice        = lattice;
     _evaluationData = new SortedDictionary <IBlauPoint, double>(new BlauPointComparer());
 }
Ejemplo n.º 20
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());
        }
Ejemplo n.º 21
0
 public BlauSpaceMultiEvaluation(string name, IBlauSpaceLattice lattice)
 {
     _name           = name;
     _lattice        = lattice;
     _evaluationData = new SortedDictionary <IBlauPoint, LinkedList <IScore> >(new BlauPointComparer());
 }
Ejemplo n.º 22
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());
        }