Example #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);
        }
Example #2
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);
            }
        }
Example #3
0
        public static void Main1DMixture(string[] args)
        {
            Console.WriteLine("console_tests");

            LoggerInitialization.SetThreshold(typeof(console_tests.MainClass), LogLevel.Debug);

            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(console_tests.MainClass), "original distribution: " + d);
            Console.WriteLine("original distribution: " + d);

            DistributionSpace ds = new DistributionSpace(d);

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

            // N = subdivisions of each of the parameter values
            for (int N = 3; N <= 6; 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(console_tests.MainClass), "iterator distribution: " + diter);
                        Console.WriteLine("valid distribution: " + diter);
                    }
                    else
                    {
                        Console.WriteLine("invalid distribution: " + diter);
                    }
                    count++;
                }

                Console.WriteLine("# of valid distributions: " + validCt);
                Console.WriteLine("# of total distributions: " + count);

                Assert.AreEqual((N + 1) * (N + 1) * (N + 1) * (N + 1) * (N + 1) * (N + 1), count);
                SingletonLogger.Instance().InfoLog(typeof(console_tests.MainClass), "N=" + N + "  valid distributions: " + validCt + " / total: " + count);
            }
        }
Example #4
0
        public static void MakeMixture_Main(string[] args)
        {
            Console.WriteLine("MakeMixture");

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

            bool   err       = false;
            string errString = "";

            string file1   = "unassigned";
            string file2   = "unassigned";
            string outfile = "unassigned";

            // Look for specific arguments values and display
            // them if they exist (return null if they don't)
            if (CommandLine["file1"] != null)
            {
                file1 = CommandLine["file1"];
                if (!File.Exists(file1))
                {
                    errString += ("The specified 'file1' was not found: " + file1 + "  ");
                    err        = true;
                }
            }
            else
            {
                errString += ("The 'file1' was not specified.  ");
                err        = true;
            }

            double weight1 = -1.0;

            // Look for specific arguments values and display
            // them if they exist (return null if they don't)
            if (CommandLine["weight1"] != null)
            {
                try {
                    weight1 = Double.Parse(CommandLine["weight1"]);
                    if ((weight1 < 0.0) || (weight1 > 1.0))
                    {
                        errString += ("The specified 'weight1' was not in the range [0,1].  ");
                        err        = true;
                    }
                }
                catch (Exception) {
                    errString += ("The specified 'weight1' was not valid.  ");
                    err        = true;
                }
            }
            else
            {
                errString += ("The 'weight1' was not specified.  ");
                err        = true;
            }

            if (CommandLine["file2"] != null)
            {
                file2 = CommandLine["file2"];
                if (!File.Exists(file2))
                {
                    errString += ("The specified 'file2' was not found: " + file2 + "  ");
                    err        = true;
                }
            }
            else
            {
                errString += ("The 'file2' 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("  file1 = " + file1);
                Console.Out.WriteLine("  weight1 = " + weight1);
                Console.Out.WriteLine("  file2 = " + file2);
                Console.Out.WriteLine("  weight2 = " + (1 - weight1));
                Console.Out.WriteLine("  outfile = " + outfile);

                SoapFormatter formatter = new SoapFormatter();

                FileStream    fs = new FileStream(file1, FileMode.Open);
                IDistribution d1 = (IDistribution)formatter.Deserialize(fs);
                fs.Close();

                fs = new FileStream(file2, FileMode.Open);
                IDistribution d2 = (IDistribution)formatter.Deserialize(fs);
                fs.Close();

                if (!BlauSpace.contains(d1.SampleSpace, d2.SampleSpace) || !BlauSpace.contains(d2.SampleSpace, d1.SampleSpace))
                {
                    Console.Out.WriteLine("The sample spaces of the two distributions are not identical intersection.");
                    Console.Out.WriteLine("  d1: " + d1);
                    Console.Out.WriteLine("  d2: " + d2);
                    Console.Out.WriteLine("The mixture must be constructed over identical sample spaces.");
                    Console.Out.WriteLine("This is a fatal error, preventing the construction of the mixture distribution.");
                }
                else
                {
                    int       dim3   = d1.SampleSpace.Dimension;
                    string [] names3 = new string [dim3];
                    double [] mins3  = new double [dim3];
                    double [] maxs3  = new double [dim3];
                    for (int i = 0; i < d1.SampleSpace.Dimension; i++)
                    {
                        names3[i] = d1.SampleSpace.getAxis(i).Name;
                        mins3[i]  = d1.SampleSpace.getAxis(i).MinimumValue;
                        maxs3[i]  = d1.SampleSpace.getAxis(i).MaximumValue;
                    }
                    IBlauSpace s3 = BlauSpace.create(dim3, names3, mins3, maxs3);

                    Mixture d3 = new Mixture(s3);
                    d3.Add(d1, weight1);
                    d3.Add(d2, 1.0 - weight1);
                    d3.DistributionComplete();

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


                    fs = new FileStream(outfile, FileMode.Create);
                    formatter.Serialize(fs, d3);
                    fs.Close();
                }
            }
        }