private static int PredictBagLabel(IClassifier<SparseBag> classifier, BagTestData[] bags, SparseBag bagToTest)
        {
            var sparseBags = BagTestData.ToSparseBags(bags);

            classifier.Train(sparseBags);

            return classifier.PredictWinner(bagToTest);
        }
コード例 #2
0
        static internal IEnumerable<SparseBag> ToSparseBags(BagTestData[] bags)
        {
            var sparseBags = new SparseBag[bags.Length];
            for (var bagId = 0; bagId < sparseBags.Length; bagId++)
            {
                var istances = new IDictionary<int, float>[bags[bagId].Points.Length];
                for (var pointId = 0; pointId < bags[bagId].Points.Length; pointId++)
                {
                    var j = 1;
                    var features = (from f in bags[bagId].Points[pointId] select f).ToDictionary(i => (j++), i => (float)i);
                    istances[pointId] = features;
                }

                sparseBags[bagId] = new SparseBag(bags[bagId].Label, bags[bagId].Name.ToString(), istances);
            }
            return sparseBags;
        }
コード例 #3
0
        private static int PredictBagLabel(BagTestData[] bags, SparseBag bagToTest, int M)
        {
            var sparseBags = BagTestData.ToSparseBags(bags);

            var citationNearestNeighbor = ClassifierFactory.GetMultiInstanceClassifier("rbfn:distance=hausdorff,M=" + M+",sigma=1");

            citationNearestNeighbor.Train(sparseBags);

            return citationNearestNeighbor.PredictWinner(bagToTest);
        }
        private static int PredictBagLabel(BagTestData[] bags, SparseBag bagToTest, int K)
        {
            var sparseBags = BagTestData.ToSparseBags(bags);

            // When
            var citationNearestNeighbor = ClassifierFactory.GetMultiInstanceClassifier("nn:distance=hausdorff,K=" + K);

            citationNearestNeighbor.Train(sparseBags);

            return citationNearestNeighbor.PredictWinner(bagToTest);
        }
        public void PredictWinner_NegativeWins_EmptyKnowledge()
        {
            // Given
            var bags = new BagTestData[0];
            var bagToTest = new SparseBag(1, "1", new[]
                                                      {
                                                          new Dictionary<int, float> {{1, 22.8529f}, {2, 22.6664f}},
                                                          new Dictionary<int, float> {{1, 59.1986f}, {2, 34.5393f}}
                                                      });

            int predictedLabelForOne = PredictBagLabel(bags, bagToTest, 2);


            // Then
            Assert.That(predictedLabelForOne, Is.EqualTo(-1));
        }