예제 #1
0
        public void Distribution_GaussianMixtureSerializationTest()
        {
            Console.WriteLine("Distribution_GaussianMixtureSerializationTest");

            double        mean  = 70.0;
            double        std   = 1.0;
            double        mean2 = 20.0;
            double        std2  = 1.0;
            IDistribution d     = createGaussianMixture(mean, std, mean2, std2);

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

            SoapFormatter formatter = new SoapFormatter();

            SingletonLogger.Instance().DebugLog(typeof(dist_tests), "SERIALIZING");

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

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

            SingletonLogger.Instance().DebugLog(typeof(dist_tests), "DESERIALIZING");

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

            fs.Close();

            SingletonLogger.Instance().DebugLog(typeof(dist_tests), "DONE");

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

            Assert.AreEqual(d is Mixture, true);
            Assert.AreEqual(d2 is Mixture, true);

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

            Assert.AreEqual(g1.Params.CompareTo(g2.Params), 0);
            g1.IsValid();
            g2.IsValid();

            Assert.AreEqual(g1.IsValid().CompareTo(g2.IsValid()), 0);

            for (int i = 0; i < g1.Params; i++)
            {
                Assert.AreEqual(g1.getParam(i).CompareTo(g2.getParam(i)), 0);
                Assert.AreEqual(g1.getParamMin(i).CompareTo(g2.getParamMin(i)), 0);
                Assert.AreEqual(g1.getParamMax(i).CompareTo(g2.getParamMax(i)), 0);
            }

            SingletonLogger.Instance().DebugLog(typeof(dist_tests), "All distributions coincide as expected");
        }