예제 #1
0
 public Cluster(Node parent)
 {
     this.clusterPair = null;
     this.items = new List<Vector>();
     this.mean = null;
     this.parent = parent;
 }
예제 #2
0
 public ClusterX(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     child = (Node)info.GetValue("child", typeof(Node));
     covarianceMatrixMDF = (ILArray<double>)info.GetValue("covarianceMatrixMDF", typeof(ILArray<double>));
     label = (double)info.GetValue("label", typeof(double));
 }
예제 #3
0
 // The special constructor is used to deserialize values.
 public Cluster(SerializationInfo info, StreamingContext context)
 {
     clusterPair = (ClusterPair)info.GetValue("clusterPair", typeof(ClusterPair));
     items = (List<Vector>)info.GetValue("items", typeof(List<Vector>));
     mean = (Vector)info.GetValue("mean", typeof(Vector));
     meanMDF = (ILArray<double>)info.GetValue("meanMDF", typeof(ILArray<double>));
     parent = (Node)info.GetValue("parent", typeof(Node));
 }
예제 #4
0
        public ClusterY(Sample sample, Node parent)
            : base(sample, parent)
        {
            this.dimension = Params.outputDataDimension;

            this.items.Add(new Vector(sample.Y.Values.ToArray(), sample.Label, this.items.Count + 1));
            this.mean = new Vector(sample.Y.Values.ToArray());
        }
예제 #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);
        }
예제 #6
0
        public ClusterX(Sample sample, Node parent)
            : base(sample, parent)
        {
            this.child = null;
            this.dimension = Params.inputDataDimension;

            items.Add(new Vector(sample.X.Values.ToArray(), sample.Label, 1));
            this.mean = new Vector(sample.X.Values.ToArray());

            //#warning TODO count covariance matrix
            //this.covarianceMatrix = ILMath.zeros(Params.inputDataDimension, Params.inputDataDimension);
        }
예제 #7
0
 // The special constructor is used to deserialize values.
 public Node(SerializationInfo info, StreamingContext context)
 {
     id = (int)info.GetValue("id", typeof(int));
     parent = (Node)info.GetValue("parent", typeof(Node));
     //samples = (Samples)info.GetValue("samples", typeof(Samples));
     clustersX = (List<ClusterX>)info.GetValue("clustersX", typeof(List<ClusterX>));
     clustersY = (List<ClusterY>)info.GetValue("clustersY", typeof(List<ClusterY>));
     clusterPairs = (List<ClusterPair>)info.GetValue("clusterPairs", typeof(List<ClusterPair>));
     isLeafNode = (bool)info.GetValue("isLeafNode", typeof(bool));
     isPlastic = (bool)info.GetValue("isPlastic", typeof(bool));
     countOfSamples = (int)info.GetValue("countOfSamples", typeof(int));
     path = (string)info.GetValue("path", typeof(string));
     gSOManifold = (ILArray<double>)info.GetValue("gSOManifold", typeof(ILArray<double>));
     covarianceMatrixMeanMDF = (ILArray<double>)info.GetValue("covarianceMatrixMeanMDF", typeof(ILArray<double>));
     covarianceMatrixMean = (ILArray<double>)info.GetValue("covarianceMatrixMean", typeof(ILArray<double>));
     c = (ILArray<double>)info.GetValue("c", typeof(ILArray<double>));
     children = (List<Node>)info.GetValue("children", typeof(List<Node>));
 }
예제 #8
0
        public void CountGSOManifold_ProvideCorrectCounting()
        {
            Params.inputDataDimension = 4;

            Node node = new Node(0.0, 0.0, 0.0, 0.0, "");
            Sample s1 = new Sample(new double[] { 1, 0, 2, 1 }, 1, 0);
            Sample s2 = new Sample(new double[] { -1, 1, 0, -1 }, 1, 0);
            Sample s3 = new Sample(new double[] { 2, 1, 1, 1 }, 1, 0);

            node.ClustersX.Add(new ClusterX(s1, null));
            node.ClustersX.Add(new ClusterX(s2, null));
            node.ClustersX.Add(new ClusterX(s3, null));

            List<Vector> scatterVectors = new List<Vector>();
            scatterVectors.Add(new Vector(new double[] { 1, 0, 2, 1 }));
            scatterVectors.Add(new Vector(new double[] { -1, 1, 0, -1 }));
            scatterVectors.Add(new Vector(new double[] { 2, 1, 1, 1 }));

            ILArray<double> array = node.GetManifold(scatterVectors);
        }
예제 #9
0
        public Node(double deltaX, double deltaY, double blx, double bly, string savePath)
        {
            this.clustersX = new List<ClusterX>();
            this.clustersY = new List<ClusterY>();
            //this.samples = new Samples();
            this.clusterPairs = new List<ClusterPair>();
            this.isLeafNode = true;
            this.parent = null;
            this.countOfSamples = 0;
            this.samples = new List<Sample>();

            this.children = new List<Node>(Params.q);
            this.path = savePath + "root\\";

            this.deltaX = deltaX;
            this.deltaY = deltaY;

            this.blx = Math.Min(Math.Round(blx), Params.blxMax);
            this.bly = Math.Min(Math.Round(bly), Params.blyMax);

            this.IsPlastic = true;
        }
예제 #10
0
        public void GetScatterVectors_GetCorrectVectors()
        {
            Params.inputDataDimension = 3;
            Node node = new Node(0.0, 0.0, 0.0, 0.0, "");
            Sample s1 = new Sample(new double[] { 1, 2, 3 }, 1, 0);
            Sample s2 = new Sample(new double[] { 2, 3, 4 }, 1, 0);
            Sample s3 = new Sample(new double[] { 3, 4, 5 }, 1, 0);

            node.ClustersX.Add(new ClusterX(s1, null));
            node.ClustersX.Add(new ClusterX(s2, null));
            node.ClustersX.Add(new ClusterX(s3, null));

            List<Vector> scatterVectors = node.GetScatterVectors();

            Assert.AreEqual(scatterVectors[0].Values[0], 0);
            Assert.AreEqual(scatterVectors[0].Values[1], 0);
            Assert.AreEqual(scatterVectors[0].Values[2], 0);

            Assert.AreEqual(scatterVectors[1].Values[0], 1);
            Assert.AreEqual(scatterVectors[1].Values[1], 1);
            Assert.AreEqual(scatterVectors[1].Values[2], 1);
        }
예제 #11
0
 // The special constructor is used to deserialize values.
 public Tree(SerializationInfo info, StreamingContext context)
 {
     // Reset the property value using the GetValue method.
     root = (Node)info.GetValue("root", typeof(Node));
     isEmpty = (bool)info.GetValue("isEmpty", typeof(bool));
 }
예제 #12
0
 public Tree()
 {
     root = new Node(Params.deltaX, Params.deltaY, Params.blx, Params.bly, Params.savePath);
     isEmpty = true;
 }
예제 #13
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));
 }
예제 #14
0
 public void SetParentsToXCluster(Node parent)
 {
     this.clusterX.Parent = parent;
 }
예제 #15
0
 public Cluster(Sample sample, Node parent)
 {
     this.items = new List<Vector>();
     this.parent = parent;
 }
예제 #16
0
        private void Swap_Modified()
        {
            if (!Params.StoreSamples)
            {
                throw new InvalidOperationException("Unable to swap modified because samples are not stored in memory.");
            }

            this.IsLeafNode = false;

            for (int i = 0; i < Params.q; i++)
            {
                // create node + set save path
                Node node = new Node(this, this.path + "node" + (children.Count + 1).ToString() + @"\", this.deltaX * Params.deltaMultiplyReduction, this.deltaY * Params.deltaMultiplyReduction, this.blx * Params.blxMultiplyIncrease, this.bly * Params.blyMultiplyIncrease);
                List<ClusterPair> clPairs = this.clusterPairs.Where(cp => cp.CurrentCenter == i).ToList();

                // set id of node
                node.Id = this.children.Count + 1;

                List<Sample> sampleForNewNode = new List<Sample>();
                foreach (var item in clPairs)
                {
                    // set reference to ClusterPair, which node correspond to this ClusterPair
                    item.CorrespondChild = node;
                    sampleForNewNode.AddRange(item.Samples);
                }

                foreach (var item in sampleForNewNode)
                {
                    node.UpdateNode_ForSwapping(item);
                }

                // set parent to clusters X
                node.SetParentToXClusters();

                // count covariance patrix mean for probability counting
                // node.CountCovarianceMatrixMean();

                // set plastic/non plastic
                this.UpdatePlasticityOfParents(node);

                // add children
                this.children.Add(node);
            }
        }
예제 #17
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);
        }
예제 #18
0
        public void GetNearestClusterPairX_GetCorrectClusterPair()
        {
            Node node = new Node(0.0, 0.0, 0.0, 0.0, "");
            Sample s1 = new Sample(new double[] { 1, 2, 3 }, 1, 0);
            Sample s2 = new Sample(new double[] { 1, 2, 3 }, 1, 0);
            Sample s3 = new Sample(new double[] { 1, 2, 3 }, 1, 0);

            node.ClustersX.Add(new ClusterX(s1, null));
        }
예제 #19
0
 public ClusterY(Node parent)
     : base(parent)
 {
     this.dimension = Params.outputDataDimension;
 }
예제 #20
0
        public Node(Node parent, string path, double deltaX, double deltaY, double blx, double bly)
        {
            this.parent = parent;

            clustersX = new List<ClusterX>();
            clustersY = new List<ClusterY>();
            this.samples = new List<Sample>();
            clusterPairs = new List<ClusterPair>();
            isLeafNode = true;
            countOfSamples = 0;

            this.children = new List<Node>(Params.q);
            this.path = path;

            this.deltaX = Math.Max(deltaX, Params.deltaXMin);
            this.deltaY = Math.Max(deltaY, Params.deltaYMin);

            this.blx = Math.Min(Math.Round(blx), Params.blxMax);
            this.bly = Math.Min(Math.Round(bly), Params.blyMax);

            this.IsPlastic = true;
        }
예제 #21
0
 private void UpdatePlasticityOfParents(Node node)
 {
     //Node n = node;
     //for (int i = 0; i <= Params.l; i++)
     //{
     //    if (n.parent != null)
     //    {
     //        n = n.parent;
     //        if (i == Params.l)
     //        {
     //            n.IsPlastic = false;
     //        }
     //    }
     //    else
     //    {
     //        return;
     //    }
     //}
     Node n = node;
     int distanceFromLeaf = 0;
     while (node != null)
     {
         if (node.Parent != null)
         {
             node = node.Parent;
         }
         else
         {
             node = null;
         }
         distanceFromLeaf++;
         if (node != null && distanceFromLeaf > Params.l)
         {
             node.IsPlastic = false;
         }
     }
 }
예제 #22
0
 public ClusterX(Node parent)
     : base(parent)
 {
     this.child = null;
 }
예제 #23
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);
        }
예제 #24
0
        private void Swap()
        {
            this.IsLeafNode = false;

            for (int i = 0; i < Params.q; i++)
            {
                // create node + set save path
                Node node = new Node(this, this.path + "node" + (children.Count + 1).ToString() + @"\", this.deltaX * Params.deltaMultiplyReduction, this.deltaY * Params.deltaMultiplyReduction, this.blx * Params.blxMultiplyIncrease, this.bly * Params.blyMultiplyIncrease);
                List<ClusterPair> clPairs = this.clusterPairs.Where(cp => cp.CurrentCenter == i).ToList();

                // set id of node
                node.Id = this.children.Count + 1;

                foreach (var item in clPairs)
                {
                    ClusterPair clusterPair = item.GetClone();
                    node.AddClusterPair(clusterPair);

                    // set reference to ClusterPair, which node correspond to this ClusterPair
                    item.CorrespondChild = node;

                    if (node == null)
                    {
                        throw new InvalidOperationException("Node cant be null");
                    }
                }

                // set parent to clusters X
                node.SetParentToXClusters();

                // count covariance patrix mean for probability counting
                // node.CountCovarianceMatrixMean();

                // set plastic/non plastic
                this.UpdatePlasticityOfParents(node);

                // add children
                this.children.Add(node);
            }
        }
예제 #25
0
        public void GetVarianceOfVectors()
        {
            Node node = new Node(0.0, 0.0, 0.0, 0.0, string.Empty);

            List<Vector> vectors = new List<Vector>();
            vectors.Add(new Vector(new double[] { 9, 2, 7 }, new double[] { 9, 2, 7 }));
            vectors.Add(new Vector(new double[] { 3, 3, 10 }, new double[] { 3, 3, 10 }));
            vectors.Add(new Vector(new double[] { 6, 4, 25 }, new double[] { 6, 4, 25 }));

            node.CountMeanMDF(vectors);
            node.CountVarianceMDF(vectors);

            Assert.AreEqual(node.VarianceMDF.ToArray()[0], 9);
            Assert.AreEqual(node.VarianceMDF.ToArray()[1], 1);
            Assert.AreEqual(node.VarianceMDF.ToArray()[2], 93);
        }
예제 #26
0
        public void GetCFromClustersX_GetCorrectC()
        {
            Params.inputDataDimension = 3;
            Node node = new Node(0.0, 0.0, 0.0, 0.0, "");
            Sample s1 = new Sample(new double[] { 1, 2, 3 }, 1, 0);
            Sample s2 = new Sample(new double[] { 2, 3, 4 }, 1, 0);
            Sample s3 = new Sample(new double[] { 3, 4, 5 }, 1, 0);

            node.ClustersX.Add(new ClusterX(s1, null));
            node.ClustersX.Add(new ClusterX(s2, null));
            node.ClustersX.Add(new ClusterX(s3, null));

            Vector C = node.GetCFromClustersX();

            Assert.AreEqual(C.Values[0], 2.0);
            Assert.AreEqual(C.Values[1], 3.0);
            Assert.AreEqual(C.Values[2], 4.0);
        }