Exemplo n.º 1
0
        public char[] Classify(RecordSet data, bool parallel = true)
        {
            Score scores = this.Scorer.Score(data, parallel);

            double[] ratios = Yarr.Div(scores.SScores, scores.BScores);

            char[] result = new char[data.NRows];
            for (int i = 0; i < data.NRows; i++)
            {
                result[i] = (ratios[i] >= this.Cutoff) ? 's' : 'b';
            }
            return(result);
        }
Exemplo n.º 2
0
        private BlockingCollection <Score> ParallelScorer(RecordSet data)
        {
            int cores = Environment.ProcessorCount;


            var models = new BlockingCollection <T>(this.SubModels.Count);

            foreach (T model in this.SubModels)
            {
                models.Add(model);
            }
            models.CompleteAdding();

            var scores         = new BlockingCollection <RandomForest.Score>(cores * 10);
            int numScorerTasks = cores;

            Task[] scorerTasks = new Task[numScorerTasks];
            for (int i = 0; i < numScorerTasks; i++)
            {
                scorerTasks[i] = Task.Factory.StartNew(
                    () =>
                {
                    T model;
                    while (!models.IsCompleted)
                    {
                        try
                        {
                            model = models.Take();
                        }
                        catch (InvalidOperationException)
                        {
                            continue;
                        }
                        scores.Add(model.Score(data, parallel: false));
                    }
                }
                    );
            }

            //asynchronously wait for the scorer tasks to finish
            Task.Factory.StartNew(
                () =>
            {
                Task.WaitAll(scorerTasks);
                scores.CompleteAdding();
            }
                );

            return(scores);
        }
Exemplo n.º 3
0
 public Score Score(RecordSet data, bool parallel = true)
 {
     if (parallel)
     {
         return(ParallelGmeaner(
                    ParallelScorer(data),
                    data.NRows
                    ));
     }
     else
     {
         return(GMean(
                    this.SubModels.Select(model => model.Score(data, parallel: false)),
                    data.NRows
                    ));
     }
 }
Exemplo n.º 4
0
        protected RecordSet(RecordSet copyFrom, bool[] filter)
        {
            this.Index     = Yarr.Filter(copyFrom.Index, filter);
            this.NRows     = this.Index.Length;
            this.NFeatures = copyFrom.NFeatures;

            this._EventIds = copyFrom._EventIds;
            this.EventIds  = new Indexer <int>(this, this._EventIds);

            this._FeatureCols = copyFrom._FeatureCols;
            this.FeatureCols  = new Indexer <double> [this.NFeatures];
            for (int featureNum = 0; featureNum < this.NFeatures; featureNum++)
            {
                this.FeatureCols[featureNum] = new Indexer <double>(this, this._FeatureCols[featureNum]);
            }

            this._GlobalMins = copyFrom._GlobalMins;
            this._GlobalMaxs = copyFrom._GlobalMaxs;
        }
Exemplo n.º 5
0
        public Score Score(RecordSet data, bool parallel = true)
        {
            //NOTE: ignore parallel parameter

            double[] sScores = Yarr.Repeat(double.NaN, data.NRows);
            double[] bScores = Yarr.Repeat(double.NaN, data.NRows);

            bool[] filter       = Yarr.InlineNot(data.HasNaN(this.TargetFeatures));
            var    filteredData = data.Filter(filter);

            data = null;             // unlikely to let anything be GC'ed (lots of references to same obj) but it can't hurt

            this._Score(
                filteredData,
                Yarr.Range(filteredData.NRows).MakeSlice(),
                sScores,
                bScores
                );
            return(new Score(sScores, bScores));
        }
Exemplo n.º 6
0
 public Indexer(RecordSet parent, T[] target)
 {
     Parent = parent;
     Target = target;
 }