public void GetPathIds(ref VBuffer <float> dst) { EnsureCachedPosition(); _ectx.Assert(_input.Position >= 0); _ectx.Assert(_cachedPosition == _input.Position); if (_cachedPathBuilderPosition != _input.Position) { if (_pathIdBuilder == null) { _pathIdBuilder = BufferBuilder <float> .CreateDefault(); } var trees = ((ITreeEnsemble)_ensemble).GetTrees(); _pathIdBuilder.Reset(_numLeaves - _numTrees, dense: false); var offset = 0; for (int i = 0; i < _numTrees; i++) { var numNodes = trees[i].NumLeaves - 1; var nodes = _pathIds[i]; _ectx.AssertValue(nodes); for (int j = 0; j < nodes.Count; j++) { var node = nodes[j]; _ectx.Assert(0 <= node && node < numNodes); _pathIdBuilder.AddFeature(offset + node, 1); } offset += numNodes; } _cachedPathBuilderPosition = _input.Position; } _ectx.AssertValue(_pathIdBuilder); _pathIdBuilder.GetResult(ref dst); }
public void GetLeafIds(ref VBuffer <float> dst) { EnsureCachedPosition(); _ectx.Assert(_input.Position >= 0); _ectx.Assert(_cachedPosition == _input.Position); if (_cachedLeafBuilderPosition != _input.Position) { if (_leafIdBuilder == null) { _leafIdBuilder = BufferBuilder <float> .CreateDefault(); } _leafIdBuilder.Reset(_numLeaves, false); var offset = 0; var trees = ((ITreeEnsemble)_ensemble).GetTrees(); for (int i = 0; i < trees.Length; i++) { _leafIdBuilder.AddFeature(offset + _leafIds[i], 1); offset += trees[i].NumLeaves; } _cachedLeafBuilderPosition = _input.Position; } _ectx.AssertValue(_leafIdBuilder); _leafIdBuilder.GetResult(ref dst); }
// Returns false if there is no need to process more ngrams. private bool ProcessNgrams(int icol) { Contracts.Assert(_queue.Count > 0); _ngram[0] = _queue[0]; int slot; bool more = true; if ((slot = _finder(_ngram, 1, icol, ref more)) >= 0) { Contracts.Assert(0 <= slot && slot < _slotLim); _bldr.AddFeature(slot, 1); } if (_queue.Count == 1 || !more) { return(more); } if (_skipLength > 0) { return(ProcessSkipNgrams(icol, 1, 0)); } for (int i = 1; i < _queue.Count; i++) { _ngram[i] = _queue[i]; Contracts.Assert(more); if ((slot = _finder(_ngram, i + 1, icol, ref more)) >= 0) { Contracts.Assert(0 <= slot && slot < _slotLim); _bldr.AddFeature(slot, 1); } if (!more) { return(false); } } return(true); }
protected override void CopyOut(ref T[] src, ref VBuffer <T> dst) { var length = Utils.Size(src); _bldr.Reset(length, false); for (int i = 0; i < length; i++) { _bldr.AddFeature(i, src[i]); } _bldr.GetResult(ref dst); }
private void EncodeValueToBinary(BufferBuilder <float> bldr, uint value, int bitsToConsider, int startIndex) { Contracts.Assert(0 < bitsToConsider && bitsToConsider <= sizeof(uint) * 8); Contracts.Assert(startIndex >= 0); //Treat missing values, zero, as a special value of all 1s. value--; while (bitsToConsider > 0) { bldr.AddFeature(startIndex++, (value >> --bitsToConsider) & 1U); } }
private void GenerateBitSlotName(int iinfo, ref VBuffer <DvText> dst) { const string slotNamePrefix = "Bit"; var bldr = new BufferBuilder <DvText>(TextCombiner.Instance); bldr.Reset(_bitsPerKey[iinfo], true); for (int i = 0; i < _bitsPerKey[iinfo]; i++) { bldr.AddFeature(i, new DvText(slotNamePrefix + (_bitsPerKey[iinfo] - i - 1))); } bldr.GetResult(ref dst); }