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 })));
 }
Beispiel #2
0
 /// <summary>
 /// create cluster pair with clusterX and clusterY, not set Clusters parents
 /// </summary>
 public ClusterPair()
 {
     this.clusterX = new ClusterX(null);
     this.clusterX.SetClusterPair(this);
     this.clusterY = new ClusterY(null);
     this.clusterY.SetClusterPair(this);
     this.samples = new List<Sample>();
 }
Beispiel #3
0
 /// <summary>
 /// create cluster pair with clusterX and clusterY, not set Clusters parents
 /// </summary>
 public ClusterPair()
 {
     this.clusterX = new ClusterX(null);
     this.clusterX.SetClusterPair(this);
     this.clusterY = new ClusterY(null);
     this.clusterY.SetClusterPair(this);
     this.samples = new List <Sample>();
 }
Beispiel #4
0
        public ClusterPair(ClusterX cX, ClusterY cY, Sample sample)
        {
            clusterX = cX;
            clusterY = cY;

            this.PreviousCenter = 0;
            this.CurrentCenter = 0;

            this.samples = new List<Sample>() { sample };
        }
Beispiel #5
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);
        }
        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);
        }
Beispiel #7
0
        public ClusterPair(ClusterX cX, ClusterY cY, Sample sample)
        {
            clusterX = cX;
            clusterY = cY;

            this.PreviousCenter = 0;
            this.CurrentCenter  = 0;

            this.samples = new List <Sample>()
            {
                sample
            };
        }
        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 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();
        }
Beispiel #10
0
        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();
        }
Beispiel #11
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);
        }
Beispiel #12
0
 // The special constructor is used to deserialize values.
 public ClusterPair(SerializationInfo info, StreamingContext context)
 {
     clusterX        = (ClusterX)info.GetValue("clusterX", typeof(ClusterX));
     clusterY        = (ClusterY)info.GetValue("clusterY", typeof(ClusterY));
     correspondChild = (Node)info.GetValue("correspondChild", typeof(Node));
 }
Beispiel #13
0
        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 #14
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);
        }
Beispiel #15
0
 // The special constructor is used to deserialize values.
 public ClusterPair(SerializationInfo info, StreamingContext context)
 {
     clusterX = (ClusterX)info.GetValue("clusterX", typeof(ClusterX));
     clusterY = (ClusterY)info.GetValue("clusterY", typeof(ClusterY));
     correspondChild = (Node)info.GetValue("correspondChild", typeof(Node));
 }
Beispiel #16
0
        /// <summary>
        /// Create new clusers X and Y and their cluster pair
        /// </summary>
        /// <param name="sample">new sample</param>
        private void CreateNewClusters(Sample sample, Node parent)
        {
            ClusterX newClusterX = new ClusterX(sample, parent);
            this.clustersX.Add(newClusterX);
            ClusterY newClusterY = new ClusterY(sample, parent);
            this.clustersY.Add(newClusterY);

            ClusterPair clusterPair = new ClusterPair(newClusterX, newClusterY, sample);
            newClusterX.SetClusterPair(clusterPair);
            newClusterY.SetClusterPair(clusterPair);

            clusterPair.Id = clusterPairs.Count;
            clusterPair.Samples.Add(sample);

            this.clusterPairs.Add(clusterPair);
        }
Beispiel #17
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);
        }