public virtual void InitMC <F>(IProbabilisticClassifier <L, F> classifier, GeneralDataset <L, F> data)
        {
            //if (!(gData instanceof Dataset)) {
            //  throw new UnsupportedOperationException("Can only handle Datasets, not "+gData.getClass().getName());
            //}
            //
            //Dataset data = (Dataset)gData;
            IPriorityQueue <Pair <int, Pair <double, bool> > > q = new BinaryHeapPriorityQueue <Pair <int, Pair <double, bool> > >();

            total         = 0;
            correct       = 0;
            logLikelihood = 0.0;
            for (int i = 0; i < data.Size(); i++)
            {
                IDatum <L, F> d            = data.GetRVFDatum(i);
                ICounter <L>  scores       = classifier.LogProbabilityOf(d);
                L             guess        = Counters.Argmax(scores);
                L             correctLab   = d.Label();
                double        guessScore   = scores.GetCount(guess);
                double        correctScore = scores.GetCount(correctLab);
                int           guessInd     = data.LabelIndex().IndexOf(guess);
                int           correctInd   = data.LabelIndex().IndexOf(correctLab);
                total++;
                if (guessInd == correctInd)
                {
                    correct++;
                }
                logLikelihood += correctScore;
                q.Add(new Pair <int, Pair <double, bool> >(int.Parse(i), new Pair <double, bool>(guessScore, bool.ValueOf(guessInd == correctInd))), -guessScore);
            }
            accuracy = (double)correct / (double)total;
            IList <Pair <int, Pair <double, bool> > > sorted = q.ToSortedList();

            scores    = new double[sorted.Count];
            isCorrect = new bool[sorted.Count];
            for (int i_1 = 0; i_1 < sorted.Count; i_1++)
            {
                Pair <double, bool> next = sorted[i_1].Second();
                scores[i_1]    = next.First();
                isCorrect[i_1] = next.Second();
            }
        }
Exemplo n.º 2
0
        public virtual void Init(IList <Pair <double, int> > dataScores)
        {
            IPriorityQueue <Pair <int, Pair <double, int> > > q = new BinaryHeapPriorityQueue <Pair <int, Pair <double, int> > >();

            for (int i = 0; i < dataScores.Count; i++)
            {
                q.Add(new Pair <int, Pair <double, int> >(int.Parse(i), dataScores[i]), -dataScores[i].First());
            }
            IList <Pair <int, Pair <double, int> > > sorted = q.ToSortedList();

            scores  = new double[sorted.Count];
            classes = new int[sorted.Count];
            logger.Info("incoming size " + dataScores.Count + " resulting " + sorted.Count);
            for (int i_1 = 0; i_1 < sorted.Count; i_1++)
            {
                Pair <double, int> next = sorted[i_1].Second();
                scores[i_1]  = next.First();
                classes[i_1] = next.Second();
            }
            Init();
        }