ComponentFitCache

Memoizes group fits by index range, so that a group range fitted once is never fitted again for the same sample.

This is the single largest saving available to the search. Refinement moves one cut at a time, so consecutive partitions share most of their groups, and a search over the number of components revisits ranges repeatedly. Fitting a group means running the whole estimator catalog over it, which dominates the cost of everything else in the pipeline.

Failures are cached alongside successes. A group range for which no family fits is expensive to discover and just as expensive to rediscover; caching only successes would leave the worst case uncached.

The cache is bound to one sample. It holds no reference to the data and does not verify that successive calls pass the same array, because an index range is only meaningful relative to a fixed sample; create a new cache for a new sample.

This class is not safe for use from multiple threads. Each worker in a parallel experiment constructs its own fitter and cache, which is also required because KSL's scoring models and metrics are mutable.

Parameters

fitter

the fitter to delegate to on a miss

Constructors

Link copied to clipboard
constructor(fitter: ComponentFitterIfc)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The fraction of requests answered from the cache, or zero when there have been none.

Link copied to clipboard
val hits: Int

The number of requests answered from the cache.

Link copied to clipboard
val misses: Int

The number of requests that required a fit.

Link copied to clipboard
val size: Int

The number of distinct group ranges currently held.

Functions

Link copied to clipboard
fun clear()

Discards all cached fits and resets the hit and miss counts.

Link copied to clipboard
open override fun fitGroup(sortedData: DoubleArray, startIndex: Int, endIndex: Int): GroupFitResult

Fits every candidate family to the observations in the index range from startIndex until endIndex, returning those that succeeded and those that did not.

Link copied to clipboard
open override fun toString(): String