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); }