예제 #1
0
        public override ObjectClassificationResult PredictProba(double[] sarr)
        {
            var result = new ObjectClassificationResult();

            // modifying data
            for (int i = 0; i < sarr.Length; i++)
            {
                sarr[i] -= _avgs[i];
                sarr[i] /= _vars[i] > 0 ? Math.Sqrt(_vars[i]) : 1;
            }

            var source = _trainLoader.Rows;
            var tlist  = new ConcurrentBag <Tuple <double, double> >();
            List <Tuple <double, double> > taskList;

            if (IsParallel)
            {
                taskList = (from row in source.AsParallel()
                            select ProceedRow(sarr, row)
                            ).ToList();
            }
            else
            {
                taskList = (from row in source
                            select ProceedRow(sarr, row)
                            ).ToList();
            }

            taskList.ForEach(t => tlist.Add(t));

            var slist   = tlist.OrderBy(t => t.Item1).ToArray();
            var pcounts = new SortedDictionary <double, double>();

            var sb = new StringBuilder();

            for (int i = NeighborsOffset, ilen = 0; i < KNeighbors + NeighborsOffset; i++, ilen++)
            {
                var targ = slist[i].Item2;
                if (!pcounts.ContainsKey(targ))
                {
                    pcounts.Add(targ, 0);
                }
                pcounts[targ]++;

                if (ilen < InfoLength)
                {
                    sb.Append(slist[i].Item1.ToString("F08") + ';');
                }
            }

            result.ObjectInfo = sb.ToString();
            result.Probs      = new double[_nclasses];
            for (int i = 0; i < _nclasses; i++)
            {
                result.Probs[i] = pcounts.ContainsKey(i) ? pcounts[i] / KNeighbors : 0;
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Predict probability for object
        /// </summary>
        /// <param name="sarr">array of double params</param>
        /// <returns></returns>
        public override ObjectClassificationResult PredictProba(double[] sarr)
        {
            var result = new ObjectClassificationResult();

            var y   = PredictCounts(sarr);
            int cnt = _classifiers.Keys.Sum(id => _classifiers[id].CountTreesInBatch);

            for (int i = 0; i < y.Length; i++)
            {
                y[i] /= cnt;
            }

            result.Probs = y;
            return(result);
        }
예제 #3
0
        public override ObjectClassificationResult PredictProba(double[] sarr)
        {
            var result = new ObjectClassificationResult();

            Node[] x = new Node[sarr.Length];
            for (int j = 0; j < sarr.Length; j++)
            {
                x[j]       = new Node();
                x[j].Index = j + 1;
                x[j].Value = sarr[j];
            }
            var ret = Prediction.PredictProbability(_model, x);

            result.Probs = ret;
            return(result);
        }
예제 #4
0
        /// <summary>
        /// Predict probability for object
        /// </summary>
        /// <param name="sarr">array of double params</param>
        /// <returns></returns>
        public override ObjectClassificationResult PredictProba(double[] sarr)
        {
            var result = new ObjectClassificationResult();

            var y = PredictCounts(sarr);
            int cnt = _classifiers.Keys.Sum(id => _classifiers[id].CountTreesInBatch);

            for (int i = 0; i < y.Length; i++)
                y[i] /= cnt;

            result.Probs = y;
            return result;
        }
예제 #5
0
        public override ObjectClassificationResult PredictProba(double[] sarr)
        {
            var result = new ObjectClassificationResult();
            // modifying data
            for (int i = 0; i < sarr.Length; i++)
            {
                sarr[i] -= _avgs[i];
                sarr[i] /= _vars[i] > 0 ? Math.Sqrt(_vars[i]) : 1;
            }

            var source = _trainLoader.Rows;
            var tlist = new ConcurrentBag<Tuple<double, double>>();
            List<Tuple<double, double>> taskList;

            if (IsParallel)
                taskList = (from row in source.AsParallel()
                            select ProceedRow(sarr, row)
                        ).ToList();
            else
                taskList = (from row in source
                         select ProceedRow(sarr, row)
                        ).ToList();

            taskList.ForEach(t => tlist.Add(t));

            var slist = tlist.OrderBy(t => t.Item1).ToArray();
            var pcounts = new SortedDictionary<double, double>();

            var sb = new StringBuilder();

            for (int i= NeighborsOffset,ilen=0; i<KNeighbors + NeighborsOffset; i++,ilen++)
            {
                var targ = slist[i].Item2;
                if (!pcounts.ContainsKey(targ))
                    pcounts.Add(targ, 0);
                pcounts[targ]++;

                if (ilen<InfoLength)
                    sb.Append(slist[i].Item1.ToString("F08")+';');
            }

            result.ObjectInfo = sb.ToString();
            result.Probs = new double[_nclasses];
            for (int i=0;i<_nclasses;i++)
            {
                result.Probs[i] = pcounts.ContainsKey(i) ? pcounts[i] / KNeighbors : 0;
            }

            return result;
        }
예제 #6
0
 public override ObjectClassificationResult PredictProba(double[] sarr)
 {
     var result = new ObjectClassificationResult();
     Node[] x = new Node[sarr.Length];
     for (int j = 0; j < sarr.Length; j++)
     {
         x[j] = new Node();
         x[j].Index = j + 1;
         x[j].Value = sarr[j];
     }
     var ret = Prediction.PredictProbability(_model, x);
     result.Probs = ret;
     return result;
 }