Esempio n. 1
0
 /// <summary>
 /// Hierarchical clustering successively finds the closest distance between pairs of centroids until k is reached
 /// </summary>
 /// <param name="data">The list of vectors to cluster</param>
 /// <param name="k">The number of clusters to find</param>
 /// <returns>A list of k clusters</returns>
 public static IReadOnlyList <IReadOnlyList <IVector> > HierachicalCluster(
     this IReadOnlyList <IVector> data, int k)
 {
     using var clusterer = new Hierarchical(k, data);
     clusterer.Cluster();
     return(clusterer.Clusters);
 }
Esempio n. 2
0
 private void GenerateStatusBarInfo()
 {
     if (Hierarchical == null)
     {
         StatusBarInfo = null;
         return;
     }
     StatusBarInfo = Hierarchical.GetInfo(Hierarchical == _allhierarchical || Hierarchical == _searchHierarchical);
 }
Esempio n. 3
0
                public HierarchicalMutable(Hierarchical ptype) : base((Ptype)ptype)

                {
                    childrenNames = new List <String>(ptype.children.Keys);
                    children      = new List <string>();
                    foreach (Ptype child in ptype.children.Values)
                    {
                        children.Add(child.Id);
                    }
                }
	public static void Main() {
		modshogun.init_shogun_with_defaults();
		int merges = 3;

		double[,] fm_train = Load.load_numbers("../data/fm_train_real.dat");

		RealFeatures feats_train = new RealFeatures(fm_train);
		EuclideanDistance distance = new EuclideanDistance(feats_train, feats_train);

		Hierarchical hierarchical = new Hierarchical(merges, distance);
		hierarchical.train();

		double[] out_distance = hierarchical.get_merge_distances();
		int[,] out_cluster = hierarchical.get_cluster_pairs();

	}
Esempio n. 5
0
        private void HierarchicalAdded(Hierarchical newComponent)
        {
            if (newComponent.Parent != EntityIdentifier.None)
            {
                _parentCache.Add(newComponent.EntityId, newComponent.Parent);

                if (!_hierarchyCache.ContainsKey(newComponent.Parent))
                {
                    _hierarchyCache.Add(newComponent.Parent, new List <long>());
                }

                var parentChildren = _hierarchyCache[newComponent.Parent];

                parentChildren.Add(newComponent.EntityId);
            }
        }
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        int merges = 3;

        double[,] fm_train = Load.load_numbers("../data/fm_train_real.dat");

        RealFeatures      feats_train = new RealFeatures(fm_train);
        EuclideanDistance distance    = new EuclideanDistance(feats_train, feats_train);

        Hierarchical hierarchical = new Hierarchical(merges, distance);

        hierarchical.train();

        double[] out_distance = hierarchical.get_merge_distances();
        int[,] out_cluster = hierarchical.get_cluster_pairs();
    }
Esempio n. 7
0
        private void HierarchicalUpdated(Hierarchical oldComponent, Hierarchical newComponent)
        {
            if (oldComponent.Parent != EntityIdentifier.None)
            {
                _parentCache.Remove(oldComponent.EntityId);

                var parentChildren = _hierarchyCache[oldComponent.Parent];

                parentChildren.Remove(oldComponent.EntityId);

                if (parentChildren.Count == 0)
                {
                    _hierarchyCache.Remove(oldComponent.Parent);
                }
            }

            HierarchicalAdded(newComponent);
        }
Esempio n. 8
0
        public void ShouldReturnAllInstancesInGraphWithoutDuplicates()
        {
            var root1 = new Hierarchical
            {
                Children = new[]
                {
                    new Hierarchical
                    {
                        Children = new[]
                        {
                            new Hierarchical(),
                            new Hierarchical()
                        }
                    },
                    new Hierarchical()
                }
            };
            var root2 = new Hierarchical
            {
                Children = new[]
                {
                    new Hierarchical
                    {
                        Children = new[]
                        {
                            new Hierarchical(),
                            new Hierarchical()
                        }
                    },
                    new Hierarchical()
                }
            };

            var flattened = Seq.Create(root1, root2).FlattenHierarchy(root => root.Children);

            Assert.That(flattened.Count(), Is.EqualTo(10));            //Ensures no duplicates
            Assert.That(flattened.Distinct().Count(), Is.EqualTo(10)); //Ensures all objects are there.
        }
    internal static ArrayList run(int para)
    {
        modshogun.init_shogun_with_defaults();
        int merges = para;

        DoubleMatrix fm_train = Load.load_numbers("../data/fm_train_real.dat");

        RealFeatures feats_train = new RealFeatures(fm_train);
        EuclidianDistance distance = new EuclidianDistance(feats_train, feats_train);

        Hierarchical hierarchical = new Hierarchical(merges, distance);
        hierarchical.train();

        DoubleMatrix out_distance = hierarchical.get_merge_distances();
        DoubleMatrix out_cluster = hierarchical.get_cluster_pairs();

        ArrayList result = new ArrayList();
        result.Add(hierarchical);
        result.Add(out_distance);
        result.Add(out_cluster);
        modshogun.exit_shogun();
        return result;
    }
Esempio n. 10
0
 public virtual bool Contains(Hierarchical hierarchical)
 {
     return(Content.Contains(hierarchical.Content));
 }
Esempio n. 11
0
        public void Run()
        {
            DateTime expSt = DateTime.Now;

            Console.WriteLine("========================================================================");
            Console.WriteLine(" Metoda porównania: " + comparators[comparatorId].GetType());
            Console.WriteLine("========================================================================");
            WordsStats stats = new WordsStats(Words.ComputeWords(DataStore.Instance.GetAllNews()));

            stats.Compute();

            List <string> experimentTopics;

            if (topics != null)
            {
                experimentTopics = new List <string>();
                experimentTopics.AddRange(topics);
            }
            else
            {
                experimentTopics = GetRandomTopics(topicCount);
            }


            Group initialGroup = GroupFactory.CreateGroupWithNewsFromTopics(experimentTopics);


            Console.WriteLine("========================================================================");
            Console.WriteLine("Topiki w grupie początkowej:");
            foreach (string topic in experimentTopics)
            {
                Console.WriteLine(topic + " [" + Util.topicCountInGroup(topic, initialGroup) + "]");
            }

            Console.WriteLine("Rozmiar grupy: " + initialGroup.Count);
            ;

            DateTime start;
            TimeSpan t1, t2;


            Hierarchical hr = new Hierarchical(comparators[comparatorId], stats, maxLen);
            Kmeans       km = new Kmeans(comparators[comparatorId], stats, maxLen);

            Console.WriteLine("========================================================================");

            if (!onlyKMeans)
            {
                start = DateTime.Now;
                List <Group> hierarchicalResult = hr.Compute(initialGroup, topicCount != 0 ? topicCount : (uint)topics.Length,
                                                             Hierarchical.Distance.AVG);
                t1 = (DateTime.Now - start);
                PrintStats("Hierachical", t1, hierarchicalResult, 0);
            }

            start = DateTime.Now;
            List <Group> kMeansResult = km.Compute(initialGroup, topicCount != 0 ? topicCount : (uint)topics.Length, kMeansIterations);

            t2 = (DateTime.Now - start);
            PrintStats("KMeans", t2, kMeansResult, kMeansIterations);


            Console.WriteLine("========================================================================");
            Console.WriteLine("Czas działania: " + (DateTime.Now - expSt));
        }
Esempio n. 12
0
 protected bool Equals(Hierarchical other)
 {
     return(string.Equals(Content, other.Content));
 }
Esempio n. 13
0
 public virtual bool IsParentOf(Hierarchical hierarchical)
 {
     return(hierarchical.IsChildOf(this));
 }
Esempio n. 14
0
 public virtual bool IsChildOf(Hierarchical hierarchical)
 {
     return(Content.StartsWith(hierarchical.Content));
 }
Esempio n. 15
0
				public HierarchicalMutable(Hierarchical ptype) : base((Ptype)ptype)

				{
					childrenNames = new List<String>(ptype.children.Keys);
					children = new List<string>();
					foreach (Ptype child in ptype.children.Values)
						children.Add(child.Id);
				}
Esempio n. 16
0
 internal static HandleRef getCPtr(Hierarchical obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
Esempio n. 17
0
 internal static HandleRef getCPtr(Hierarchical obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Esempio n. 18
0
        public void ComputeTest()
        {
            List <Pointer> pointers = new List <Pointer>()
            {
                new  Pointer()
                {
                    X = 1, Y = 21, Z = 0
                },
                new  Pointer()
                {
                    X = 12, Y = 23, Z = 0
                },
                new  Pointer()
                {
                    X = 10, Y = 2, Z = 0
                },
                new  Pointer()
                {
                    X = 3, Y = 10, Z = 0
                },
                new  Pointer()
                {
                    X = 13, Y = 12, Z = 0
                },
                new  Pointer()
                {
                    X = 4, Y = 15, Z = 0
                },
                new  Pointer()
                {
                    X = 9, Y = 6, Z = 0
                },
                new  Pointer()
                {
                    X = 21, Y = 8, Z = 0
                },
                new  Pointer()
                {
                    X = 11, Y = 6, Z = 0
                },
                new  Pointer()
                {
                    X = 21, Y = 9, Z = 0
                },
                new  Pointer()
                {
                    X = 13, Y = 6, Z = 0
                },
                new  Pointer()
                {
                    X = 20, Y = 19, Z = 0
                },
                new  Pointer()
                {
                    X = 20, Y = 19, Z = 0
                },
                new  Pointer()
                {
                    X = 1, Y = 21, Z = 0
                },
                new  Pointer()
                {
                    X = 12, Y = 23, Z = 0
                },
                new  Pointer()
                {
                    X = 10, Y = 2, Z = 0
                },
                new  Pointer()
                {
                    X = 3, Y = 10, Z = 0
                },
                new  Pointer()
                {
                    X = 13, Y = 12, Z = 0
                },
                new  Pointer()
                {
                    X = 4, Y = 15, Z = 0
                },
                new  Pointer()
                {
                    X = 9, Y = 6, Z = 0
                },
                new  Pointer()
                {
                    X = 21, Y = 8, Z = 0
                },
                new  Pointer()
                {
                    X = 11, Y = 6, Z = 0
                },
                new  Pointer()
                {
                    X = 21, Y = 9, Z = 0
                },
                new  Pointer()
                {
                    X = 13, Y = 6, Z = 0
                },
                new  Pointer()
                {
                    X = 20, Y = 19, Z = 0
                },
                new  Pointer()
                {
                    X = 20, Y = 19, Z = 0
                },
            };
            Hierarchical kmeans = new Hierarchical(pointers);

            kmeans.Compute(3);
        }