kumulant

RandomForestRegressionStat

class RandomForestRegressionStat(val featureSize: Int, val splitCandidates: List<SerializableSplit>, val nbrTrees: Int = StatDefaults.FOREST_SIZE, config: RegressionTreeConfig = RegressionTreeConfig(), val bagging: Boolean = StatDefaults.FOREST_BAGGING, val concurrency: Concurrency = Concurrency.None, leafArmFactory: (Concurrency) -> SeriesStat<WeightedVarianceResult>? = null, randomSeed: Int = StatDefaults.TREE_RANDOM_SEED) : RegressionStat<ForestRegressionResult> (source)

Online random-forest regressor; a population of RegressionTrees sharing the candidate-split pool. Diversity comes from:

  • Oza & Russell online bagging: per-tree Poisson(1) reweighting at every update.

  • Per-leaf mtry: each tree's audit leaves consider a random subset of the candidate splits, drawn at leaf birth from the tree's own RNG.

Snapshot is a ForestRegressionResult carrying every per-tree TreeRegressionResult; tree-aware posteriors merge per-tree leaf aggregates at score time.

Use cases: non-linear contextual regression with built-in variance estimation across trees; the natural backbone for Thompson-sampling contextual bandits. Reach for DecisionTreeRegressionStat alone when a single tree's predictions suffice and ensembled diversity isn't needed.

Memory: O(nbrTrees · single-tree memory); see DecisionTreeRegressionStat. Heavier but parallelisable.

Update: O(nbrTrees · depth) per observation; each tree's update is independent. Under bagging = true, each tree applies a fresh Poisson(1)-reweighted version of the update.

Concurrency: Inherits DecisionTreeRegressionStat's per-tree concurrency model. Trees are updated sequentially within a single update() call (no inner parallelism); concurrent callers each contend for each tree's split lock independently.

Constructors

RandomForestRegressionStat

constructor(featureSize: Int, splitCandidates: List<SerializableSplit>, nbrTrees: Int = StatDefaults.FOREST_SIZE, config: RegressionTreeConfig = RegressionTreeConfig(), bagging: Boolean = StatDefaults.FOREST_BAGGING, concurrency: Concurrency = Concurrency.None, leafArmFactory: (Concurrency) -> SeriesStat<WeightedVarianceResult>? = null, randomSeed: Int = StatDefaults.TREE_RANDOM_SEED)(source)

Properties

bagging

Oza & Russell online bagging: per-tree Poisson(1) reweighting at update time.

concurrency

open override val concurrency: Concurrency(source)

Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.

config

RegressionTreeConfig with RegressionTreeConfig.mtry defaulted to ceil(sqrt(p)) when null.

featureSize

open override val featureSize: Int(source)

Number of features expected in x on each update. Mismatched lengths throw.

nbrTrees

Trees in the forest.

splitCandidates

Candidate split pool. Used by every tree; the per-leaf mtry filter draws from here.

Functions

create

open override fun create(concurrency: Concurrency? = null): RandomForestRegressionStat(source)

Create an independent accumulator at the configured baseline. A null concurrency preserves this accumulator's mode; a non-null value overrides it. Modality subtypes narrow the return type to preserve the input shape.

findLeaves

fun findLeaves(x: Vector): List<RegressionLeafNode<Vector>>(source)

Live leaves reached by x, in tree order; validates the feature dimension.

merge

open override fun merge(values: ForestRegressionResult, timestampNanos: Long = currentTimeNanos())(source)

Fold a compatible snapshot values into this accumulator at timestampNanos. Implementations document whether the combine is exact or approximate and which state the snapshot omits. The source accumulator is unaffected.

Time-dependent statistics, such as windows, place the snapshot at timestampNanos, which must share the clock the caller uses for updates and reads. Time-independent statistics ignore it.

predict

fun predict(x: Vector): Double(source)

Predict from live leaf statistics without snapshotting the forest's structure.

read

open override fun read(timestampNanos: Long = currentTimeNanos()): ForestRegressionResult(source)

Return the current result evaluated at timestampNanos. Time-independent statistics ignore the timestamp. Reading does not add an observation.

Snapshot consistency depends on the implementation's synchronisation. Locks protect coupled state under Concurrency.Strict and Concurrency.HighWrite; independently updated cells and JVM striped adders can still yield a best-effort snapshot. Concurrency.Relaxed permits drift across coupled cells.

reset

open override fun reset()(source)

Restores empty state and restarts the seed streams for reproducible growth.

tree

fun tree(index: Int): RegressionTree<Vector>(source)

Live tree at index, including any replacement installed by reset.

trees

fun trees(): List<RegressionTree<Vector>>(source)

Live underlying trees. Use for inspection.

validateMerge

open override fun validateMerge(values: ForestRegressionResult)(source)

Validate values for merge without changing accumulator state. Containers validate every child before merging any of them. Successful validation checks compatibility; it does not make a concurrent merge transactional.

Link copied to clipboard
open fun update(x: Vector, y: Double, weight: Double = 1.0)

Record the pair (x, y) with weight at the current monotonic time.

open fun update(x: DoubleArray, y: Double, weight: Double = 1.0)

Convenience overload that wraps x as a DenseVector.

open fun update(x: DoubleArray, y: Double, timestampNanos: Long, weight: Double = 1.0)

Timestamped convenience overload that wraps x as a DenseVector.

open override fun update(x: Vector, y: Double, timestampNanos: Long, weight: Double = 1.0)

Record the pair (x, y) with weight at timestampNanos.

update

open override fun update(x: Vector, y: Double, timestampNanos: Long, weight: Double = 1.0)(source)

Record the pair (x, y) with weight at timestampNanos.