public Cluster(Node parent) { this.clusterPair = null; this.items = new List <Vector>(); this.mean = null; this.parent = parent; }
public ClusterPair GetClone() { ClusterPair cp = new ClusterPair(); foreach (var x in this.X.Items) { cp.X.AddItemWithoutUpdatingStats(x); cp.X.ClusterPair = cp; } foreach (var y in this.Y.Items) { cp.Y.AddItemWithoutUpdatingStats(y); } try { //cp.X.CovMatrix = ILMath.array(this.X.CovMatrix.ToArray(), Params.inputDataDimension, Params.inputDataDimension); cp.X.Mean = new Vector(this.X.Mean.Values.ToArray()); cp.Y.Mean = new Vector(this.Y.Mean.Values.ToArray()); } catch (Exception ee) { throw new InvalidOperationException(""); } if (cp.X.Mean == null || cp.Y.Mean == null) { throw new InvalidCastException("Bad clone"); } return(cp); }
public Cluster(Node parent) { this.clusterPair = null; this.items = new List<Vector>(); this.mean = null; this.parent = parent; }
// 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)); }
// 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)); }
public TestResult GetTestResultByWidthSearch(Sample item) { ClusterPair resultClusterPair = root.GetTestResultByWidthSearch(item); return(new TestResult() { ClusterMeanX = resultClusterPair.X.Mean, ClusterMeanY = resultClusterPair.Y.Mean, Label = resultClusterPair.X.Label }); }
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 SetClusterPair(ClusterPair clusterPair) { this.clusterPair = clusterPair; }
public ClusterPair GetClone() { ClusterPair cp = new ClusterPair(); foreach (var x in this.X.Items) { cp.X.AddItemWithoutUpdatingStats(x); cp.X.ClusterPair = cp; } foreach (var y in this.Y.Items) { cp.Y.AddItemWithoutUpdatingStats(y); } try { //cp.X.CovMatrix = ILMath.array(this.X.CovMatrix.ToArray(), Params.inputDataDimension, Params.inputDataDimension); cp.X.Mean = new Vector(this.X.Mean.Values.ToArray()); cp.Y.Mean = new Vector(this.Y.Mean.Values.ToArray()); } catch (Exception ee) { throw new InvalidOperationException(""); } if (cp.X.Mean == null || cp.Y.Mean == null) { throw new InvalidCastException("Bad clone"); } return cp; }
/// <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); }
public void AddClusterPair(ClusterPair clusterPair) { this.clusterPairs.Add(clusterPair); this.clustersX.Add(clusterPair.X); this.clustersY.Add(clusterPair.Y); }
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); }