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);
        }
        private void Present(IBlauSpaceEvaluation bse, IBlauSpaceEvaluation std, int c)
        {
            this.BeginPresentation(_datadir, bse.Name + "" + c + ".bse");

            string header = "# BlauSpaceEvaluation " + bse.Name + "";

            this.AppendToPresentation(header);
            header = "# " + bse.Lattice.BlauSpace + " mean std";
            this.AppendToPresentation(header);

            foreach (IBlauPoint p in bse.AssignedLatticePoints)
            {
                string val = "" + bse.eval(p);
                string bar = "" + std.eval(p);
                string str = "" + p.getCoordinate(c) + "\t" + val + "\t" + bar;
                this.AppendToPresentation(str);
            }

            this.EndPresentation();

            this.BeginPresentation(_gpdir, bse.Name + "" + c + ".bse.gp");
            CreateGnuplotScript(bse, std, c);
            this.EndPresentation();
        }
Esempio n. 3
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());
        }
Esempio n. 4
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());
        }
Esempio n. 5
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();
        }