예제 #1
0
            private void ProcessRowSecondPass()
            {
                AssertValid(assertGetters: true);

                _featGetter(ref _features);
                _scoreGetter(ref _scores);
                Host.Check(_scores.Length == _scoresArr.Length);

                if (VBufferUtils.HasNaNs(ref _scores) || VBufferUtils.HasNonFinite(ref _scores))
                {
                    return;
                }
                _scores.CopyTo(_scoresArr);
                int j = 0;

                foreach (var index in Enumerable.Range(0, _scoresArr.Length).OrderBy(i => _scoresArr[i]))
                {
                    _indicesArr[j++] = index;
                }

                UnweightedCounters.UpdateSecondPass(ref _features, _indicesArr);
                if (WeightedCounters != null)
                {
                    WeightedCounters.UpdateSecondPass(ref _features, _indicesArr);
                }
            }
예제 #2
0
            private void ProcessRowFirstPass()
            {
                AssertValid(assertGetters: true);

                Single label = 0;

                _labelGetter(ref label);
                if (Single.IsNaN(label))
                {
                    NumUnlabeledInstances++;
                    label = 0;
                }
                var intLabel = (int)label;

                if (intLabel != label || intLabel < 0)
                {
                    throw Host.Except("Invalid label: {0}", label);
                }

                _scoreGetter(ref _scores);
                Host.Check(_scores.Length == _scoresArr.Length);

                if (VBufferUtils.HasNaNs(ref _scores) || VBufferUtils.HasNonFinite(ref _scores))
                {
                    NumBadScores++;
                    return;
                }
                _scores.CopyTo(_scoresArr);
                Single weight = 1;

                if (_weightGetter != null)
                {
                    _weightGetter(ref weight);
                    if (!FloatUtils.IsFinite(weight))
                    {
                        NumBadWeights++;
                        weight = 1;
                    }
                }

                int j = 0;

                foreach (var index in Enumerable.Range(0, _scoresArr.Length).OrderBy(i => _scoresArr[i]))
                {
                    _indicesArr[j++] = index;
                }

                UnweightedCounters.UpdateFirstPass(intLabel, _scoresArr, 1, _indicesArr);
                if (WeightedCounters != null)
                {
                    WeightedCounters.UpdateFirstPass(intLabel, _scoresArr, weight, _indicesArr);
                }

                if (_clusterCentroids != null)
                {
                    _featGetter(ref _features);
                    VectorUtils.Add(ref _features, ref _clusterCentroids[_indicesArr[0]]);
                }
            }
            public override void ProcessRow()
            {
                _labelGetter(ref _label);
                Contracts.Check(_label.Length == _size);
                _scoreGetter(ref _score);
                Contracts.Check(_score.Length == _size);

                if (VBufferUtils.HasNaNs(ref _score))
                {
                    NumBadScores++;
                    return;
                }

                Float weight = 1;

                if (_weightGetter != null)
                {
                    _weightGetter(ref weight);
                    if (!FloatUtils.IsFinite(weight))
                    {
                        NumBadWeights++;
                        weight = 1;
                    }
                }

                Float[] label;
                if (!_label.IsDense)
                {
                    _label.CopyTo(_labelArr);
                    label = _labelArr;
                }
                else
                {
                    label = _label.Values;
                }
                Float[] score;
                if (!_score.IsDense)
                {
                    _score.CopyTo(_scoreArr);
                    score = _scoreArr;
                }
                else
                {
                    score = _score.Values;
                }
                UnweightedCounters.Update(score, label, _size, 1);
                if (WeightedCounters != null)
                {
                    WeightedCounters.Update(score, label, _size, weight);
                }
            }
 public static bool HasMissingNumericVector(IDataView data, DataViewSchema.Column column)
 {
     using (var cursor = data.GetRowCursor(new[] { column }))
     {
         var getter = cursor.GetGetter <VBuffer <Single> >(column);
         var value  = default(VBuffer <Single>);
         while (cursor.MoveNext())
         {
             getter(ref value);
             if (VBufferUtils.HasNaNs(value))
             {
                 return(true);
             }
         }
         return(false);
     }
 }
 protected override bool IsNaN(ref VBuffer <Float> score)
 {
     return(VBufferUtils.HasNaNs(ref score));
 }