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); }
public NgramBufferBuilder(int ngramLength, int skipLength, int slotLim, NgramIdFinder finder) { Contracts.Assert(ngramLength > 0); Contracts.Assert(skipLength >= 0); Contracts.Assert(ngramLength <= MaxSkipNgramLength - skipLength); Contracts.Assert(slotLim >= 0); _ngramLength = ngramLength; _skipLength = skipLength; _slotLim = slotLim; _ngram = new uint[_ngramLength]; _queue = new FixedSizeQueue <uint>(_ngramLength + _skipLength); _bldr = BufferBuilder <Float> .CreateDefault(); _finder = finder; }
/// <summary> /// This is for the bagging case - vector input and outputs should be added. /// </summary> private ValueGetter <VBuffer <Float> > MakeGetterBag(IRow input, int iinfo) { Host.AssertValue(input); Host.Assert(Infos[iinfo].TypeSrc.IsVector); Host.Assert(Infos[iinfo].TypeSrc.ItemType.IsKey); Host.Assert(_bag[iinfo]); Host.Assert(Infos[iinfo].TypeSrc.ItemType.KeyCount == _types[iinfo].VectorSize); var info = Infos[iinfo]; int size = info.TypeSrc.ItemType.KeyCount; Host.Assert(size > 0); int cv = info.TypeSrc.VectorSize; Host.Assert(cv >= 0); var getSrc = RowCursorUtils.GetVecGetterAs <uint>(NumberType.U4, input, info.Source); var src = default(VBuffer <uint>); var bldr = BufferBuilder <float> .CreateDefault(); return ((ref VBuffer <Float> dst) => { bldr.Reset(size, false); getSrc(ref src); Host.Check(cv == 0 || src.Length == cv); // The indices are irrelevant in the bagging case. var values = src.Values; int count = src.Count; for (int slot = 0; slot < count; slot++) { uint key = values[slot] - 1; if (key < size) { bldr.AddFeature((int)key, 1); } } bldr.GetResult(ref dst); }); }