示例#1
0
        private AgentOrderbookLoader MakeAgentOrderbookLoader(string PATH)
        {
            int dim = 0;

            string []  names = new string [0];
            double []  mins  = new double [0];
            double []  maxs  = new double [0];
            IBlauSpace s     = BlauSpace.create(dim, names, mins, maxs);

            IBlauPoint    mean = new BlauPoint(s);
            IBlauPoint    std  = new BlauPoint(s);
            IDistribution d    = new Distribution_Gaussian(s, mean, std);

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

            AgentOrderbookLoader loader = null;

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

            return(loader);
        }
示例#2
0
        private IDistribution createGaussianMixture(double mean, double std, double mean2, double std2)
        {
            IDistribution d1 = create1DGaussian(mean, std);
            IDistribution d2 = create1DGaussian(mean2, std2);

            int dim = 1;

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

            d.Add(d1, 0.75);
            d.Add(d2, 0.25);
            d.DistributionComplete();

            return(d);
        }
示例#3
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);
        }
示例#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());
        }
示例#5
0
        static public AgentOrderbookLoader MakeAgentOrderbookLoader(string path)
        {
            string [] names = new string [1] {
                "x"
            };
            double [] mins = new double [1] {
                0.00
            };
            double [] maxs = new double [1] {
                100.0
            };
            IBlauSpace    s = BlauSpace.create(1, names, mins, maxs);
            IDistribution d = new Distribution_Gaussian(s, 0.0, 0.0);

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

            AgentOrderbookLoader loader = null;

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

            return(loader);
        }
示例#6
0
        public void DistributionSpaceIterator_GaussianMixtureTest()
        {
            Console.WriteLine("DistributionSpaceIterator_GaussianMixtureTest");

            double        mean  = 70.0;
            double        std   = 1.0;
            IDistribution d1    = create1DGaussian(mean, std);
            double        mean2 = 20.0;
            double        std2  = 1.0;
            IDistribution d2    = create1DGaussian(mean2, std2);

            int dim = 1;

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

            d.Add(d1, 0.75);
            d.Add(d2, 0.25);
            d.DistributionComplete();


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

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

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

                IDistributionSpaceIterator it = ds.iterator(steps);

                int count   = 0;
                int validCt = 0;
                foreach (IDistribution diter in it)
                {
                    if (diter.IsValid())
                    {
                        validCt++;
                        SingletonLogger.Instance().DebugLog(typeof(dist_tests), "iterator distribution: " + diter);
                    }
                    count++;
                }
                Assert.AreEqual((N + 1) * (N + 1) * (N + 1) * (N + 1) * (N + 1) * (N + 1), count);
                SingletonLogger.Instance().InfoLog(typeof(dist_tests), "N=" + N + "  valid distributions: " + validCt + " / total: " + count);
            }
        }
示例#7
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);
        }
示例#8
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");
        }
示例#9
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);
        }
示例#10
0
 private bool IntersectsFactors(IBlauSpace s1)
 {
     foreach (IDistribution d in _factor)
     {
         if (BlauSpace.intersects(s1, d.SampleSpace))
         {
             return(true);
         }
     }
     return(false);
 }
示例#11
0
        public void BlauSpaceRegistryTest()
        {
            Console.WriteLine("BlauSpaceRegistryTest");
            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);
            IBlauSpace s2 = BlauSpace.create(dim, names, mins, maxs);
            IBlauSpace s3 = BlauSpace.create(dim, names, mins, maxs);

            Assert.AreSame(s, s2);
            Assert.AreSame(s2, s3);
            Assert.AreSame(s, s3);


            names = new string [3] {
                "x", "y", "z1"
            };
            IBlauSpace X1 = BlauSpace.create(dim, names, mins, maxs);

            Assert.AreNotSame(s, X1);

            names = new string [3] {
                "x", "y", "z"
            };
            mins = new double [3] {
                0.0, 0.0, 0.1
            };
            IBlauSpace X2 = BlauSpace.create(dim, names, mins, maxs);

            Assert.AreNotSame(s, X2);

            mins = new double [3] {
                0.0, 0.0, 0.0
            };
            maxs = new double [3] {
                100.0, 200.1, 300.0
            };
            IBlauSpace X3 = BlauSpace.create(dim, names, mins, maxs);

            Assert.AreNotSame(s, X3);

            Assert.AreNotSame(X1, X2);
            Assert.AreNotSame(X2, X3);
            Assert.AreNotSame(X1, X3);
        }
示例#12
0
        public void BlauSpaceZEROTest()
        {
            Console.WriteLine("BlauSpaceTest");
            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);

            Assert.AreEqual(s.Dimension, 0);
            SingletonLogger.Instance().DebugLog(typeof(blau_tests), "Zero dimensional BS => " + s);
        }
示例#13
0
        private static IDistribution create2DGaussian(double mean, double std, double mean2, double std2)
        {
            int dim = 1;

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

            int dim2 = 1;

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

            int dim3 = 2;

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

            Product d3 = new Product(s3);

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

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

            int dim = 1;

            string [] names = new string [1] {
                "x"
            };
            double [] mins = new double [1] {
                0.00
            };
            double [] maxs = new double [1] {
                100.0
            };
            IBlauSpace    s   = BlauSpace.create(dim, names, mins, maxs);
            double        min = 20.0;
            double        max = 80.0;
            IDistribution d   = new Distribution_Interval(s, min, max);

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

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

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

                IDistributionSpaceIterator it = ds.iterator(steps);

                int count   = 0;
                int validCt = 0;
                foreach (IDistribution d2 in it)
                {
                    if (d2.IsValid())
                    {
                        validCt++;
                        SingletonLogger.Instance().DebugLog(typeof(dist_tests), "iterator distribution: " + d2);
                    }

                    count++;
                }
                Assert.AreEqual((N + 1) * (N + 1), count);
                SingletonLogger.Instance().InfoLog(typeof(dist_tests), "N=" + N + "  valid distributions: " + validCt + " / total: " + count);
            }
        }
示例#15
0
        private static IDistribution createPointed(double[] p)
        {
            int dim = p.Length;

            IDistribution [] d     = new IDistribution[dim];
            IDistribution    prodd = null;

            string [] names_all = new string [dim];
            double [] mins_all  = new double [dim];
            double [] maxs_all  = new double [dim];

            IBlauSpace [] s     = new IBlauSpace[dim];
            IBlauSpace    prods = null;

            for (int i = 0; i < dim; i++)
            {
                string [] names = new string [1] {
                    "x" + i
                };
                double [] mins = new double [1] {
                    0.00
                };
                double [] maxs = new double [1] {
                    100.0
                };
                IBlauSpace s1 = BlauSpace.create(1, names, mins, maxs);
                d[i] = new Distribution_Pointed(s1, p [i]);

                names_all[i] = names[0];
                mins_all[i]  = mins[0];
                maxs_all[i]  = maxs[0];

                s[i] = BlauSpace.create(i + 1, names_all, mins_all, maxs_all);
                if (i == 0)
                {
                    prods = s[i];
                    prodd = d[i];
                }
                else
                {
                    prods = s[i];
                    Product prodd2 = new Product(prods);
                    prodd2.Add(prodd);
                    prodd2.Add(d[i]);
                    prodd2.DistributionComplete();
                    prodd = prodd2;
                }
            }
            return(prodd);
        }
示例#16
0
        public void Distribution_IntervalSerializationTest()
        {
            Console.WriteLine("Distribution_IntervalSerializationTest");

            int dim = 1;

            string [] names = new string [1] {
                "x"
            };
            double [] mins = new double [1] {
                0.00
            };
            double [] maxs = new double [1] {
                100.0
            };
            IBlauSpace    s   = BlauSpace.create(dim, names, mins, maxs);
            double        min = 10.0;
            double        max = 30.0;
            IDistribution d   = new Distribution_Interval(s, min, max);

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

            SoapFormatter formatter = new SoapFormatter();

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

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

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

            fs.Close();

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

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

            Assert.AreEqual(g1.Max, g2.Max);
            Assert.AreEqual(g1.Min, g2.Min);
            Assert.AreEqual(g1.Params, g2.Params);
            Assert.AreEqual(g1.SampleSpace, g2.SampleSpace);

            SingletonLogger.Instance().DebugLog(typeof(dist_tests), "All distributions coincide as expected");
        }
示例#17
0
        public void Distribution_GaussianSerializationTest()
        {
            Console.WriteLine("Distribution_Gaussian1DSerializationTest");

            int dim = 1;

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

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

            SoapFormatter formatter = new SoapFormatter();

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

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

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

            fs.Close();

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

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

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

            SingletonLogger.Instance().DebugLog(typeof(dist_tests), "All distributions coincide as expected");
        }
示例#18
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);
        }
示例#19
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");
        }
示例#20
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);
        }
示例#21
0
        private static IDistribution create1DGaussian(double mean, double std)
        {
            int dim = 1;

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

            return(d);
        }
示例#22
0
        public DistributionSpace(IDistribution d)
        {
            _d = d;

            int parms = d.Params;

            string [] names = new string[parms];
            double [] min   = new double[parms];
            double [] max   = new double[parms];

            for (int i = 0; i < parms; i++)
            {
                names[i] = d.getParamName(i);
                min[i]   = d.getParamMin(i);
                max[i]   = d.getParamMax(i);
            }

            _parmSpace = BlauSpace.create(parms, names, min, max);
        }
示例#23
0
        public void BlauSpaceIteratorManualTest()
        {
            Console.WriteLine("BlauSpaceIteratorManualTest");

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

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


            int STEPS = 10;

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

            IBlauSpaceIterator bsi = new BlauSpaceIterator(s, STEPSarray);
            int count    = 0;
            int expected = (STEPS + 1) * (STEPS + 1) * (STEPS + 1);

            while (bsi.hasNext())
            {
                IBlauPoint bp = (IBlauPoint)bsi.next();

                Assert.IsInstanceOf(typeof(QuantizedBlauPoint), bp);
                SingletonLogger.Instance().DebugLog(typeof(blau_tests), "=> " + bp);
                count++;
            }
            Assert.AreEqual(count, expected);
        }
示例#24
0
        public void BlauSpaceSerializationTest()
        {
            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);

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

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

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

            FileStream fs2 = new FileStream("bs.xml", FileMode.Open);
            BlauSpace  bs2 = (BlauSpace)formatter.Deserialize(fs2);

            fs2.Close();

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

            IBlauSpace bs3 = BlauSpaceRegistry.Instance().validate(bs2);

            Assert.AreEqual(bs == bs3, true);
            SingletonLogger.Instance().DebugLog(typeof(blau_tests), "bs agrees with validated bs2");

            Assert.AreEqual(bs == bs2, true);
            SingletonLogger.Instance().DebugLog(typeof(blau_tests), "bs agrees with bs2");
        }
示例#25
0
        public void BlauSpaceTest()
        {
            Console.WriteLine("BlauSpaceTest");
            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);

            Assert.AreEqual(s.Dimension, 3);

            Assert.AreEqual(s.getAxis(0).Name, "x");
            Assert.AreEqual(s.getAxis(1).Name, "y");
            Assert.AreEqual(s.getAxis(2).Name, "z");

            Assert.AreEqual(s.getAxisIndex("x") >= 0, true);
            Assert.AreEqual(s.getAxisIndex("y") >= 0, true);
            Assert.AreEqual(s.getAxisIndex("z") >= 0, true);

            Assert.AreEqual(s.getAxis(0).MinimumValue, 0.0);
            Assert.AreEqual(s.getAxis(0).MaximumValue, 100.0);

            Assert.AreEqual(s.getAxis(1).MinimumValue, 0.0);
            Assert.AreEqual(s.getAxis(1).MaximumValue, 200.0);

            Assert.AreEqual(s.getAxis(2).MinimumValue, 0.0);
            Assert.AreEqual(s.getAxis(2).MaximumValue, 300.0);

            Assert.AreEqual("" + s, "BlauSpace[Dim:3]: x(0,100), y(0,200), z(0,300)");
        }
示例#26
0
        public void Distribution_Interval1DTest()
        {
            Console.WriteLine("Distribution_Interval1DTest");

            int dim = 1;

            string [] names = new string [1] {
                "x"
            };
            double [] mins = new double [1] {
                0.00
            };
            double [] maxs = new double [1] {
                100.0
            };
            IBlauSpace    s   = BlauSpace.create(dim, names, mins, maxs);
            double        min = 10.0;
            double        max = 30.0;
            IDistribution d   = new Distribution_Interval(s, min, max);

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

            for (int i = 0; i < 1000; i++)
            {
                IBlauPoint p = d.getSample();
                SingletonLogger.Instance().DebugLog(typeof(dist_tests), "=> " + p);

                for (int x = 0; x < dim; x++)
                {
                    double diff = p.getCoordinate(x) - min;
                    Assert.AreEqual(diff < 0.0, false);

                    diff = max - p.getCoordinate(x);
                    Assert.AreEqual(diff < 0.0, false);
                }
            }
        }
示例#27
0
        public static void MakeGaussian_Main(string[] args)
        {
            Console.WriteLine("MakeGaussian");

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

            bool   err       = false;
            string errString = "";

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

            mean = std = min = max = -1.0;

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

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

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

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

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

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

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

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

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

                SoapFormatter formatter = new SoapFormatter();

                FileStream fs = new FileStream(outfile, FileMode.Create);
                formatter.Serialize(fs, d);
                fs.Close();
            }
        }
示例#28
0
        public void BlauSpaceAxisTest()
        {
            Console.WriteLine("BlauSpaceAxisTest");

            {
                int       dim   = 3;
                string [] names = new string [3] {
                    "x", "y", "z"
                };
                double [] mins = new double [3] {
                    10.0, 0.0, 0.0
                };
                double [] maxs = new double [3] {
                    1.0, 1.0, 1.0
                };
                IBlauSpace s = null;
                Assert.Throws <Exception>(delegate { s = BlauSpace.create(dim, names, mins, maxs); });
                Console.WriteLine("BlauSpace could not be instantiated: " + (s == null));
            }

            {
                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] {
                    -10.0, 1.0, 1.0
                };
                IBlauSpace s = null;
                Assert.Throws <Exception>(delegate { s = BlauSpace.create(dim, names, mins, maxs); });
                Console.WriteLine("BlauSpace could not be instantiated: " + (s == null));
            }

            {
                int       dim   = 3;
                string [] names = new string [3] {
                    "x", "y", "z"
                };
                double [] mins = new double [3] {
                    0.0, 20.0, 0.0
                };
                double [] maxs = new double [3] {
                    1.0, 1.0, 1.0
                };
                IBlauSpace s = null;
                Assert.Throws <Exception>(delegate { s = BlauSpace.create(dim, names, mins, maxs); });
                Console.WriteLine("BlauSpace could not be instantiated: " + (s == null));
            }

            {
                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] {
                    1.0, -20.0, 1.0
                };
                IBlauSpace s = null;
                Assert.Throws <Exception>(delegate { s = BlauSpace.create(dim, names, mins, maxs); });
                Console.WriteLine("BlauSpace could not be instantiated: " + (s == null));
            }

            {
                int       dim   = 3;
                string [] names = new string [3] {
                    "x", "y", "z"
                };
                double [] mins = new double [3] {
                    0.0, 0.0, 30.0
                };
                double [] maxs = new double [3] {
                    1.0, 1.0, 1.0
                };
                IBlauSpace s = null;
                Assert.Throws <Exception>(delegate { s = BlauSpace.create(dim, names, mins, maxs); });
                Console.WriteLine("BlauSpace could not be instantiated: " + (s == null));
            }

            {
                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] {
                    1.0, 1.0, -30.0
                };
                IBlauSpace s = null;
                Assert.Throws <Exception>(delegate { s = BlauSpace.create(dim, names, mins, maxs); });
                Console.WriteLine("BlauSpace could not be instantiated: " + (s == null));
            }
        }
示例#29
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);
        }
示例#30
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);
        }