kumulant

RandomForestClassifierStat

class RandomForestClassifierStat(val featureSize: Int, val numClasses: Int, val splitCandidates: List<SerializableSplit>, val nbrTrees: Int = StatDefaults.FOREST_SIZE, config: ClassificationTreeConfig = ClassificationTreeConfig(), val bagging: Boolean = StatDefaults.FOREST_BAGGING, val concurrency: Concurrency = Concurrency.None, leafArmFactory: (Concurrency) -> SeriesStat<ClassCountsResult>? = null, randomSeed: Int = StatDefaults.TREE_RANDOM_SEED) : RegressionStat<ForestClassificationResult> (source)

Online random-forest classifier; the classification counterpart of RandomForestRegressionStat. Same diversity tricks (Oza & Russell bagging, per-leaf mtry), but per-tree leaves are ClassCountsResult and ensemble predictions average per-class probabilities across trees.

Use cases: online classification wanting ensembled diversity and a per-class probability estimate averaged across trees. Reach for DecisionTreeClassifierStat alone when a single tree suffices.

Memory: O(nbrTrees · single-tree memory); see DecisionTreeClassifierStat. 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 DecisionTreeClassifierStat'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

RandomForestClassifierStat

constructor(featureSize: Int, numClasses: Int, splitCandidates: List<SerializableSplit>, nbrTrees: Int = StatDefaults.FOREST_SIZE, config: ClassificationTreeConfig = ClassificationTreeConfig(), bagging: Boolean = StatDefaults.FOREST_BAGGING, concurrency: Concurrency = Concurrency.None, leafArmFactory: (Concurrency) -> SeriesStat<ClassCountsResult>? = 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

featureSize

open override val featureSize: Int(source)

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

nbrTrees

Trees in the forest.

numClasses

Number of classes; y must round to [0, numClasses).

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): RandomForestClassifierStat(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.

merge

open override fun merge(values: ForestClassificationResult, 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.

read

open override fun read(timestampNanos: Long = currentTimeNanos()): ForestClassificationResult(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.

trees

Live underlying classification trees. Use for inspection.

validateMerge

open override fun validateMerge(values: ForestClassificationResult)(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.