Exemple #1
0
        public virtual HashBag <int> getVotesBag(Neighbor[] kNN, int k, int[] unknown, IList <int> Y)
        {
            HashBag <int> votes = new HashBag <int>();

            for (int i = 0; i < k && i < kNN.Length; i++)
            {
                votes.add(Y[kNN[i].corpusVectorIndex]);
            }
            if (dumpVotes && kNN.Length > 0)
            {
                Console.Write(Trainer.featureNameHeader(FEATURES));
                InputDocument firstDoc = corpus.documentsPerExemplar[kNN[0].corpusVectorIndex];                 // pick any neighbor to get parser
                Console.WriteLine(Trainer._toString(FEATURES, firstDoc, unknown) + "->" + votes);
                int size = Math.Min(k, kNN.Length);
                kNN = kNN.Take(Math.Min(k, kNN.Length)).ToArray();
                StringBuilder buf = new StringBuilder();
                foreach (Neighbor n in kNN)
                {
                    buf.Append(n.ToString(FEATURES, Y));
                    buf.Append("\n");
                }
                Console.WriteLine(buf);
            }
            return(votes);
        }
Exemple #2
0
        public static HashBag <int> getCategoriesBag(ICollection <int> categories)
        {
            HashBag <int> votes = new HashBag <int>();

            foreach (int category in categories)
            {
                votes.add(category);
            }
            return(votes);
        }