Beispiel #1
0
        public void CountMeanOfNode_CountCorrectMean()
        {
            Params.inputDataDimension = 3;
            Node node = new Node(1, 1, 0.0, 0.0, "");
            // cluster 1
            ClusterX newClusterX1 = new ClusterX(node);

            newClusterX1.Items.Add(new Vector(new double[] { 1, 2, 3 }, new double[] { 1, -2, 3 }));
            newClusterX1.Items.Add(new Vector(new double[] { 2, 3, 4 }, new double[] { 2, 3, 4 }));
            newClusterX1.Items.Add(new Vector(new double[] { 3, 4, 5 }, new double[] { 3, 4, 5 }));
            newClusterX1.Mean = new Vector(new double[] { 1, 2, 3 });
            node.ClustersX.Add(newClusterX1);

            ClusterPair clusterPair1 = new ClusterPair();

            clusterPair1.X = newClusterX1;

            newClusterX1.SetClusterPair(clusterPair1);

            node.ClusterPairs.Add(clusterPair1);

            node.CountMeanAndVarianceMDF();
            node.CountOfSamples = 4;

            node.UpdateMeanAndVarianceMdf(new Vector(new double[] { 4, 5, 6 }, new double[] { 4, 5, 6 }));

            node.CountOfSamples = 5;

            node.UpdateMeanAndVarianceMdf(new Vector(new double[] { 5, 6, -7 }, new double[] { 5, 6, -7 }));
            Assert.AreEqual(node.VarianceMDF[0], 2.5);
            Assert.AreEqual(node.VarianceMDF[1], 9.7);
            Assert.AreEqual(node.VarianceMDF[2], 27.7);
        }
        public void ClusterXCreate_CreateCorrectClusterX()
        {
            // set params
            Params.inputDataDimension = 3;
            Sample   sample   = new Sample(new double[] { 1.0, 2.0, 3.0 }, 1.0, 0);
            ClusterX clusterX = new ClusterX(sample, null);

            Assert.IsTrue(clusterX.Mean.EqualsToVector(new Vector(new double[] { 1.0, 2.0, 3.0 })));
        }
        public void UpdateMatrix_CovarianceMatrixIsCorrect()
        {
            Params.inputDataDimension  = 3;
            Params.outputDataDimension = 3;

            ClusterX clusterX = new ClusterX(new Sample(new double[] { 4.0, 2.0, 0.6 }, 1.0, 0), null);

            clusterX.AddItem(new Vector(new double[] { 4.2, 2.1, 0.59 }), 0);
            clusterX.AddItem(new Vector(new double[] { 3.9, 2.0, 0.58 }), 0);
            clusterX.AddItem(new Vector(new double[] { 4.3, 2.1, 0.62 }), 0);
            clusterX.AddItem(new Vector(new double[] { 4.1, 2.2, 0.63 }), 0);
        }
        public void CountLabelOfCluster_LabelIsCorrect()
        {
            Params.inputDataDimension  = 3;
            Params.outputDataDimension = 3;

            ClusterX clusterX = new ClusterX(new Sample(new double[] { 1, 2, 3 }, 1.0, 0), null);

            clusterX.AddItem(new Vector(new double[] { 2, 3, 4 }), 2.0);
            clusterX.AddItem(new Vector(new double[] { 2, 3, 4 }), 3.0);
            clusterX.AddItem(new Vector(new double[] { 2, 3, 4 }), 2.0);
            clusterX.AddItem(new Vector(new double[] { 2, 3, 4 }), 1.0);
            clusterX.AddItem(new Vector(new double[] { 2, 3, 4 }), 2.0);

            clusterX.CountLabelOfCluter();

            Assert.AreEqual(clusterX.Label, 2.0);
        }
        public void UpdateMean_UpdatingIsCorrect()
        {
            Params.inputDataDimension = 3;
            Params.t1 = 10;

            ClusterX clusterX = new ClusterX(new Sample(new double[] { 1.0, 2.0, 3.0 }, 1.0, 0), null);

            clusterX.AddItem(new Vector(new double[] { 2.0, 3.0, 4.0 }), 0);

            Assert.AreEqual(clusterX.Mean.Values[0], 1.5);
            Assert.AreEqual(clusterX.Mean.Values[1], 2.5);
            Assert.AreEqual(clusterX.Mean.Values[2], 3.5);

            clusterX.AddItem(new Vector(new double[] { 3.0, 4.0, 5.0 }), 0);

            Assert.AreEqual(clusterX.Mean.Values[0], 2.0);
            Assert.AreEqual(clusterX.Mean.Values[1], 3.0);
        }
        public void CountMDFMean_CountCorrectMean()
        {
            Params.inputDataDimension  = 3;
            Params.outputDataDimension = 3;

            ClusterX clusterX = new ClusterX(new Sample(new double[] { 1, 2, 3 }, 1.0, 0), null);

            clusterX.AddItem(new Vector(new double[] { 2, 3, 4 }), 0);
            clusterX.AddItem(new Vector(new double[] { 3, 4, 5 }), 0);

            clusterX.Items[0].ValuesMDF = new double[] { 1, 2, 3 };
            clusterX.Items[1].ValuesMDF = new double[] { 2, 3, 4 };
            clusterX.Items[2].ValuesMDF = new double[] { 3, 4, 5 };

            clusterX.CountMDFMean();

            Assert.AreEqual(clusterX.MeanMDF[0], 2.0);
            Assert.AreEqual(clusterX.MeanMDF[1], 3.0);
            Assert.AreEqual(clusterX.MeanMDF[2], 4.0);
        }
        public void CountCovarianceMatrixMDF_CountCorrectCM()
        {
            Params.inputDataDimension  = 3;
            Params.outputDataDimension = 3;

            ClusterX clusterX = new ClusterX(new Sample(new double[] { 4.0, 2.0, 0.6 }, 1.0, 0), null);

            clusterX.AddItem(new Vector(new double[] { 4.2, 2.1, 0.59 }), 0);
            clusterX.AddItem(new Vector(new double[] { 3.9, 2.0, 0.58 }), 0);
            clusterX.AddItem(new Vector(new double[] { 4.3, 2.1, 0.62 }), 0);
            clusterX.AddItem(new Vector(new double[] { 4.1, 2.2, 0.63 }), 0);


            clusterX.Items[0].ValuesMDF = new double[] { 4.0, 2.0, 0.6 };
            clusterX.Items[1].ValuesMDF = new double[] { 4.2, 2.1, 0.59 };
            clusterX.Items[2].ValuesMDF = new double[] { 3.9, 2.0, 0.58 };
            clusterX.Items[3].ValuesMDF = new double[] { 4.3, 2.1, 0.62 };
            clusterX.Items[4].ValuesMDF = new double[] { 4.1, 2.2, 0.63 };

            clusterX.CountCovarianceMatrixMDF();
        }
        public void CountCovarianceMatrix_CovarianceMatrixIsCorrect()
        {
#warning not complet test, update of covariance matrix must be reimplemented

            Params.inputDataDimension  = 3;
            Params.outputDataDimension = 3;

            ClusterX clusterX = new ClusterX(new Sample(new double[] { 4.0, 2.0, 0.6 }, 1.0, 0), null);
            clusterX.AddItem(new Vector(new double[] { 4.2, 2.1, 0.59 }), 0);

            //clusterX.CountCovariacneMatrix();

            clusterX.AddItem(new Vector(new double[] { 3.9, 2.0, 0.58 }), 0);
            clusterX.AddItem(new Vector(new double[] { 4.3, 2.1, 0.62 }), 0);

            //clusterX.CountCovariacneMatrix();

            clusterX.AddItem(new Vector(new double[] { 4.1, 2.2, 0.63 }), 0);

            //clusterX.CountCovariacneMatrix();
        }
        public void GetGaussianNLL_GetCorrectGausianNLL()
        {
            Params.inputDataDimension  = 3;
            Params.outputDataDimension = 3;

            ClusterX clusterX = new ClusterX(new Sample(new double[] { 1, 2, 3 }, 1.0, 0), null);

            clusterX.AddItem(new Vector(new double[] { 2, 3, 4 }), 0);
            clusterX.AddItem(new Vector(new double[] { 3, 4, 5 }), 0);

            clusterX.Items[0].ValuesMDF = new double[] { 1, 2, 3 };
            clusterX.Items[1].ValuesMDF = new double[] { 2, 3, 4 };
            clusterX.Items[2].ValuesMDF = new double[] { 3, 4, 5 };

            clusterX.CountMDFMean();

            clusterX.CovMatrixMDF = new double[3, 3] {
                { 1, 2, 3 }, { 2, 1, 2 }, { 3, 3, 1 }
            };

            // clusterX.GetGaussianNLL(new double[] { 1, 2, 3 });
        }
Beispiel #10
0
        public void CountC_CountCCorrect()
        {
            Node node = new Node(0, 0, 0.0, 0.0, "");

            Params.inputDataDimension = 3;
            node.CountOfSamples       = 6;

            // cluster 1
            ClusterX newClusterX1 = new ClusterX(node);

            newClusterX1.Items.Add(new Vector(0, 0));
            newClusterX1.Items.Add(new Vector(0, 0));
            newClusterX1.Items.Add(new Vector(0, 0));
            newClusterX1.Mean = new Vector(new double[] { 1, 2, 3 });
            node.ClustersX.Add(newClusterX1);

            ClusterPair clusterPair1 = new ClusterPair();

            clusterPair1.X = newClusterX1;

            newClusterX1.SetClusterPair(clusterPair1);

            node.ClusterPairs.Add(clusterPair1);

            // cluster 2
            ClusterX newClusterX2 = new ClusterX(node);

            newClusterX2.Items.Add(new Vector(0, 0));
            newClusterX2.Items.Add(new Vector(0, 0));
            newClusterX2.Mean = new Vector(new double[] { 3, 3, 4 });
            node.ClustersX.Add(newClusterX2);

            ClusterPair clusterPair2 = new ClusterPair();

            clusterPair2.X = newClusterX2;

            newClusterX2.SetClusterPair(clusterPair2);

            node.ClusterPairs.Add(clusterPair2);

            // cluster 3
            ClusterX newClusterX3 = new ClusterX(node);

            newClusterX3.Items.Add(new Vector(0, 0));
            newClusterX3.Mean = new Vector(new double[] { 9, 6, 7 });
            node.ClustersX.Add(newClusterX3);

            ClusterPair clusterPair3 = new ClusterPair();

            clusterPair3.X = newClusterX3;

            newClusterX3.SetClusterPair(clusterPair3);

            node.ClusterPairs.Add(clusterPair3);

            Vector mean = node.GetCFromClustersX();

            Assert.AreEqual(mean.Values[0], 3);
            Assert.AreEqual(mean.Values[1], 3);
            Assert.AreEqual(mean.Values[2], 1);
        }