示例#1
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);
        }
示例#2
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());
        }
示例#3
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);
            }
        }
示例#4
0
        public Mixture_Immutable(IBlauSpace space) : base(space, 0)
        {
            // _component = new Dictionary<IDistribution, double>();
            // _component = new C5.HashDictionary<IDistribution, double>();
            _component = new List <MixtureComponent>();

            _completed = false;
        }
示例#5
0
        public void Agent0x1Simulation_ZeroDimensional()
        {
            Console.WriteLine("Agent0x1Simulation_ZeroDimensional");
            LoggerInitialization.SetThreshold(typeof(sim_tests), LogLevel.Debug);
            LoggerInitialization.SetThreshold(typeof(AbstractAgent), LogLevel.Info);
            LoggerInitialization.SetThreshold(typeof(AgentOrderbookLoader), LogLevel.Info);
            LoggerInitialization.SetThreshold(typeof(Agent0x0), LogLevel.Info);

            int dim = 0;

            string []     names = new string [0];
            double []     mins  = new double [0];
            double []     maxs  = new double [0];
            IBlauSpace    s     = BlauSpace.create(dim, names, mins, maxs);
            IBlauPoint    mean  = new BlauPoint(s);
            IBlauPoint    std   = new BlauPoint(s);
            IDistribution d     = new Distribution_Gaussian(s, mean, std);

            IAgentFactory afact     = new Agent0x0_Factory(d);
            int           NUMAGENTS = 10;
            IPopulation   pop       = PopulationFactory.Instance().create(afact, NUMAGENTS);

            foreach (IAgent ag in pop)
            {
                SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "agent: " + ag);
            }

            string PATH = "" + ApplicationConfig.EXECDIR + "orderbooks/orderbook.csv";
            AgentOrderbookLoader loader = MakeAgentOrderbookLoader(PATH);

            pop.addAgent(loader);

            IOrderbook_Observable ob = new Orderbook();

            string PROPERTY            = "NetWorth";
            IAgentEvaluationBundle aeb = new AgentEvaluationBundle(PROPERTY);

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

            sim.add(metricEF);

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

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

            IAgentEvaluation ae = metricEF.create();

            aeb.addAgentEvaluation(ae);

            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "ob: " + ob.ToStringLong());
            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "aeb: " + aeb.ToStringLong());
            SingletonLogger.Instance().DebugLog(typeof(sim_tests), "res: " + res.ToStringLong());

            Assert.AreEqual(res.Valid, true);
        }
示例#6
0
        // public static factory method
        public static IBlauSpaceLattice create(IBlauSpace space, int[] steps)
        {
            BlauSpaceLattice s = new BlauSpaceLattice(space, steps);

            BlauSpaceLatticeRegistry.Instance().add(s);
            BlauSpaceLattice s_validated = BlauSpaceLatticeRegistry.Instance().validate(s);

            return(s_validated);
        }
        public AbstractAtomicDistribution(IBlauSpace space, int par) : base(space, par)
        {
            if (space.Dimension != 1)
            {
                throw new Exception("AbstractAtomicDistribution must be one-dimensional");
            }

            initParamRange(par);
        }
示例#8
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);
            }
        }
示例#9
0
 // copy constructor
 public BlauPoint(IBlauPoint orig)
 {
     _space  = orig.Space;
     _coords = new double [orig.Space.Dimension];
     for (int i = 0; i < orig.Space.Dimension; i++)
     {
         _coords[i] = orig.getCoordinate(i);
     }
     _dirty = true;
 }
示例#10
0
        // deserializer consults the blauspace registry to avoid duplicate instantiations
        public Object GetRealObject(StreamingContext context)
        {
            IBlauSpace s_validated = BlauSpaceRegistry.Instance().validate(this);

            if (LoggerDiags.Enabled)
            {
                SingletonLogger.Instance().InfoLog(typeof(BlauSpace), "VALIDATING BLAUSPACE");
            }
            return(s_validated);
        }
示例#11
0
 // constructor
 public BlauPoint(IBlauSpace space)
 {
     _space  = space;
     _coords = new double [space.Dimension];
     for (int i = 0; i < space.Dimension; i++)
     {
         _coords[i] = space.getAxis(i).MinimumValue;
     }
     _dirty = true;
 }
示例#12
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");
        }
示例#13
0
 private bool IntersectsFactors(IBlauSpace s1)
 {
     foreach (IDistribution d in _factor)
     {
         if (BlauSpace.intersects(s1, d.SampleSpace))
         {
             return(true);
         }
     }
     return(false);
 }
示例#14
0
        // static factory method, which consults registry to avoid multiple instantiations
        public static IBlauSpace create(int dimension, string [] names, double [] min, double [] max)
        {
            BlauSpace s = new BlauSpace(dimension, names, min, max);

            // register new instances with the registry
            BlauSpaceRegistry.Instance().add(s);
            // query the registry for canonical representative
            IBlauSpace s_validated = BlauSpaceRegistry.Instance().validate(s);

            return(s_validated);
        }
示例#15
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);
        }
示例#16
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);
        }
示例#17
0
 // getter which swaps in pre-existing identical blauspace, if one exists
 public IBlauSpace validate(IBlauSpace s)
 {
     if (!_spaces.ContainsKey(s.HashedName))
     {
         add(s);
         return(s);
     }
     else
     {
         return(_spaces[s.HashedName]);
     }
 }
示例#18
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);
        }
示例#19
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);
        }
示例#20
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);
            }
        }
示例#21
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);
        }
示例#22
0
 // add a blauspace lattice to the registry
 public void add(IBlauSpace s)
 {
     if (!_spaces.ContainsKey(s.HashedName))
     {
         if (LoggerDiags.Enabled)
         {
             SingletonLogger.Instance().DebugLog(typeof(BlauSpace), "BlauSpaceRegistry is adding " + s.HashedName);
         }
         _spaces.Add(s.HashedName, s);
         if (LoggerDiags.Enabled)
         {
             SingletonLogger.Instance().InfoLog(typeof(BlauSpaceLatticeRegistry), "BlauSpaceRegistry size is now " + _spaces.Count);
         }
     }
 }
示例#23
0
 // check if two BlauSpaces have a nontrivial intersection
 public static bool intersects(IBlauSpace s1, IBlauSpace s2)
 {
     for (int i = 0; i < s1.Dimension; i++)
     {
         if (s2.hasAxis(s1.getAxis(i).Name))
         {
             return(true);
         }
         else
         {
             continue;
         }
     }
     return(false);
 }
示例#24
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");
        }
示例#25
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");
        }
示例#26
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);
        }
示例#27
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);
        }
示例#28
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");
        }
示例#29
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);
        }
示例#30
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);
        }