general
import "github.com/umbralcalc/stochadex/pkg/general"
Package general provides general-purpose iteration functions and utilities for stochadex simulations. It includes data transformation functions, aggregation utilities, and flexible iteration patterns that can be composed to create complex simulation behaviors.
Key Features:
- Data transformation and reduction functions
- Flexible function-based iterations
- Parameter value management and copying
- Constant value generation and propagation
- Cumulative computation utilities
- Embedded simulation run support
Usage Patterns:
- Create reusable iteration functions for common simulation patterns
- Transform and aggregate simulation data
- Manage parameter values across simulation runs
- Implement custom computation logic with flexible interfaces
Index
- func AppendFloatToKey(key string, value float64, precision int) string
- func CountAggregation(defaultValues []float64, outputIndexByGroup map[string]int, groupings map[string][]float64, weightings map[string][]float64) []float64
- func DataValuesFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
- func DataValuesVarianceFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
- func FloatTupleToKey(tuple []float64, precision int) string
- func MaxAggregation(defaultValues []float64, outputIndexByGroup map[string]int, groupings map[string][]float64, weightings map[string][]float64) []float64
- func MeanAggregation(defaultValues []float64, outputIndexByGroup map[string]int, groupings map[string][]float64, weightings map[string][]float64) []float64
- func MinAggregation(defaultValues []float64, outputIndexByGroup map[string]int, groupings map[string][]float64, weightings map[string][]float64) []float64
- func NewTransformReduceFunction(transform func(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) map[string][]float64, reduce func(values map[string][]float64) []float64) func(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
- func NextNonEmptyPopIndexFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) (int, bool)
- func OtherPartitionPushFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) ([]float64, bool)
- func OtherValuesFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
- func ParamValuesPushFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) ([]float64, bool)
- func ParamsEventFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
- func ParamsTransform(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) map[string][]float64
- func PartitionEventFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
- func PastDiscountedDataValuesFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
- func PastDiscountedOtherValuesFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
- func PopFromOtherCollectionPushFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) ([]float64, bool)
- func SumAggregation(defaultValues []float64, outputIndexByGroup map[string]int, groupings map[string][]float64, weightings map[string][]float64) []float64
- func SumReduce(values map[string][]float64) []float64
- func UnitValueFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
- type ConstantValuesIteration
- type CopyValuesIteration
- type CumulativeIteration
- type
EmbeddedSimulationRunIteration
- func NewEmbeddedSimulationRunIteration(settings *simulator.Settings, implementations *simulator.Implementations) *EmbeddedSimulationRunIteration
- func (e *EmbeddedSimulationRunIteration) Configure(partitionIndex int, settings *simulator.Settings)
- func (e *EmbeddedSimulationRunIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
- type FromHistoryIteration
- func (f *FromHistoryIteration) Configure(partitionIndex int, settings *simulator.Settings)
- func (f *FromHistoryIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
- func (f *FromHistoryIteration) UpdateMemory(params *simulator.Params, update StateMemoryUpdate)
- type FromHistoryTimestepFunction
- type FromStorageIteration
- type FromStorageTimestepFunction
- type NamedIndexedState
- type ParamValuesIteration
- type SortingValues
- func OtherPartitionsPushAndSortFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) (SortingValues, bool)
- func ParamValuesPushAndSortFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) (SortingValues, bool)
- type StateMemoryIteration
- type StateMemoryUpdate
- type
ValuesChangingEventsIteration
- func (v *ValuesChangingEventsIteration) Configure(partitionIndex int, settings *simulator.Settings)
- func (v *ValuesChangingEventsIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
- type ValuesCollectionIteration
- type ValuesFunctionIteration
- type
ValuesFunctionVectorCovarianceIteration
- func (v *ValuesFunctionVectorCovarianceIteration) Configure(partitionIndex int, settings *simulator.Settings)
- func (v *ValuesFunctionVectorCovarianceIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
- type
ValuesFunctionVectorMeanIteration
- func (v *ValuesFunctionVectorMeanIteration) Configure(partitionIndex int, settings *simulator.Settings)
- func (v *ValuesFunctionVectorMeanIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
- type
ValuesGroupedAggregationIteration
- func (v *ValuesGroupedAggregationIteration) Configure(partitionIndex int, settings *simulator.Settings)
- func (v *ValuesGroupedAggregationIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
- type
ValuesSortingCollectionIteration
- func (v *ValuesSortingCollectionIteration) Configure(partitionIndex int, settings *simulator.Settings)
- func (v *ValuesSortingCollectionIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
- type
ValuesWeightedResamplingIteration
- func (v *ValuesWeightedResamplingIteration) Configure(partitionIndex int, settings *simulator.Settings)
- func (v *ValuesWeightedResamplingIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
func AppendFloatToKey
func AppendFloatToKey(key string, value float64, precision int) string
AppendFloatToKey appends a formatted float to a composite grouping key at a fixed precision.
func CountAggregation
func CountAggregation(defaultValues []float64, outputIndexByGroup map[string]int, groupings map[string][]float64, weightings map[string][]float64) []float64
CountAggregation outputs, per group, the sum of weights (i.e., a count when weights are all 1).
func DataValuesFunction
func DataValuesFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
DataValuesFunction returns values from “data_values_partition”, optionally subselecting indices.
func DataValuesVarianceFunction
func DataValuesVarianceFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
DataValuesVarianceFunction returns per-index squared deviations from the provided “mean” for “data_values_partition”.
func FloatTupleToKey
func FloatTupleToKey(tuple []float64, precision int) string
FloatTupleToKey converts a vector to a composite key string at fixed precision, suitable for use as a map key.
func MaxAggregation
func MaxAggregation(defaultValues []float64, outputIndexByGroup map[string]int, groupings map[string][]float64, weightings map[string][]float64) []float64
MaxAggregation computes the maximum of weighted values per group.
func MeanAggregation
func MeanAggregation(defaultValues []float64, outputIndexByGroup map[string]int, groupings map[string][]float64, weightings map[string][]float64) []float64
MeanAggregation computes the weighted mean of values per group.
func MinAggregation
func MinAggregation(defaultValues []float64, outputIndexByGroup map[string]int, groupings map[string][]float64, weightings map[string][]float64) []float64
MinAggregation computes the minimum of weighted values per group.
func NewTransformReduceFunction
func NewTransformReduceFunction(transform func(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) map[string][]float64, reduce func(values map[string][]float64) []float64) func(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
NewTransformReduceFunction returns a function that first transforms the provided simulation context into a map of vectors, then reduces those vectors into a single vector.
Usage hints:
- Compose transform/reduce pipelines to feed ValuesFunctionIteration.
func NextNonEmptyPopIndexFunction
func NextNonEmptyPopIndexFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) (int, bool)
NextNonEmptyPopIndexFunction scans the rolling collection for the next occupied slot (index > 0) and returns its index for popping.
Usage hints:
- Index 0 is reserved for the most recently popped values.
- Configure “values_state_width” and “empty_value” to mark empty slots.
func OtherPartitionPushFunction
func OtherPartitionPushFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) ([]float64, bool)
OtherPartitionPushFunction collects the latest values from another partition to push into the collection, subject to empty_value.
Usage hints:
- Provide: “other_partition” and “value_indices”.
- If the first element equals “empty_value”, the push is skipped.
func OtherValuesFunction
func OtherValuesFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
OtherValuesFunction returns values from “other_values_partition”, optionally subselecting indices.
func ParamValuesPushFunction
func ParamValuesPushFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) ([]float64, bool)
ParamValuesPushFunction reads the next values directly from params under “next_values_push”, subject to empty_value.
Usage hints:
- Provide: “next_values_push” and “empty_value”.
func ParamsEventFunction
func ParamsEventFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
ParamsEventFunction emits an event value from the “event” params.
func ParamsTransform
func ParamsTransform(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) map[string][]float64
ParamsTransform is a convenience transform that returns the current params map. Useful as a building block for transform/reduce pipelines.
func PartitionEventFunction
func PartitionEventFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
PartitionEventFunction emits an event value from the latest state of another partition.
Usage hints:
- Provide: “event_partition_index” and “event_state_value_index”.
func PastDiscountedDataValuesFunction
func PastDiscountedDataValuesFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
PastDiscountedDataValuesFunction reads from “data_values_partition” and applies an exponential discount factor raised to the history depth index. Useful with a kernel for a past-discounted rolling mean.
func PastDiscountedOtherValuesFunction
func PastDiscountedOtherValuesFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
PastDiscountedOtherValuesFunction mirrors PastDiscountedDataValuesFunction for “other_values_partition”, optionally subselecting indices.
func PopFromOtherCollectionPushFunction
func PopFromOtherCollectionPushFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) ([]float64, bool)
PopFromOtherCollectionPushFunction pulls the current popped values from another collection-like partition and uses them as the next values to push.
Usage hints:
- Provide: “other_partition” and “values_state_width”.
- If the first element equals “empty_value”, the push is skipped.
func SumAggregation
func SumAggregation(defaultValues []float64, outputIndexByGroup map[string]int, groupings map[string][]float64, weightings map[string][]float64) []float64
SumAggregation computes the weighted sum of values per group.
func SumReduce
func SumReduce(values map[string][]float64) []float64
SumReduce reduces a map of equally sized vectors by summing them element-wise into a single output vector.
Usage hints:
- Combine with NewTransformReduceFunction to compose dataflow operations.
func UnitValueFunction
func UnitValueFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, stateHistoryDepthIndex int) []float64
UnitValueFunction returns [1]. Combine with “without_normalisation” to compute a kernel density (sum of weights) directly.
type ConstantValuesIteration
ConstantValuesIteration leaves initial state values unchanged over time.
Usage hints:
- Useful for fixed baselines or as a placeholder partition.
type ConstantValuesIteration struct {
}
func (*ConstantValuesIteration) Configure
func (c *ConstantValuesIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*ConstantValuesIteration) Iterate
func (c *ConstantValuesIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type CopyValuesIteration
CopyValuesIteration copies selected values from other partitions’ latest states into its own state.
Usage hints:
- Provide params: “partitions” (indices) and “partition_state_values”.
type CopyValuesIteration struct {
}
func (*CopyValuesIteration) Configure
func (c *CopyValuesIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*CopyValuesIteration) Iterate
func (c *CopyValuesIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type CumulativeIteration
CumulativeIteration accumulates a provided iteration’s outputs over time.
Usage hints:
- Wrap another iteration to compute cumulative sums step-by-step.
type CumulativeIteration struct {
.Iteration
Iteration simulator}
func (*CumulativeIteration) Configure
func (c *CumulativeIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*CumulativeIteration) Iterate
func (c *CumulativeIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type EmbeddedSimulationRunIteration
EmbeddedSimulationRunIteration runs a nested simulation to termination at each outer step.
Usage hints:
- Configure params on the outer iteration with keys of the form “<innerPartitionName>/<param_name>” to forward into the inner simulation.
- Use “<innerPartitionName>/initial_state_from_partition_history” to seed inner initial states from an outer partition’s history.
- Use “<innerPartitionName>/update_from_partition_history” to stream outer histories into inner iterations that implement StateMemoryIteration.
- Optional “burn_in_steps” skips initial outer steps before running inner sim.
type EmbeddedSimulationRunIteration struct {
// contains filtered or unexported fields
}
func NewEmbeddedSimulationRunIteration
func NewEmbeddedSimulationRunIteration(settings *simulator.Settings, implementations *simulator.Implementations) *EmbeddedSimulationRunIteration
NewEmbeddedSimulationRunIteration constructs an embedded run iteration from prepared settings and implementations.
func (*EmbeddedSimulationRunIteration) Configure
func (e *EmbeddedSimulationRunIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*EmbeddedSimulationRunIteration) Iterate
func (e *EmbeddedSimulationRunIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type FromHistoryIteration
FromHistoryIteration streams data from an in-memory StateHistory.
Usage hints:
- Use with EmbeddedSimulationRun or analysis windows to replay data.
- Set Data to the source history; supports initial offset via InitStepsTaken.
type FromHistoryIteration struct {
*simulator.StateHistory
Data int
InitStepsTaken }
func (*FromHistoryIteration) Configure
func (f *FromHistoryIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*FromHistoryIteration) Iterate
func (f *FromHistoryIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
func (*FromHistoryIteration) UpdateMemory
func (f *FromHistoryIteration) UpdateMemory(params *simulator.Params, update StateMemoryUpdate)
type FromHistoryTimestepFunction
FromHistoryTimestepFunction streams timesteps from an in-memory CumulativeTimestepsHistory.
Usage hints:
- Set Data to the source timestep series; supports initial offset via InitStepsTaken.
type FromHistoryTimestepFunction struct {
*simulator.CumulativeTimestepsHistory
Data int
InitStepsTaken }
func (*FromHistoryTimestepFunction) NextIncrement
func (f *FromHistoryTimestepFunction) NextIncrement(timestepsHistory *simulator.CumulativeTimestepsHistory) float64
type FromStorageIteration
FromStorageIteration streams data from an in-memory [][]float64.
Usage hints:
- Provide Data (rows over time); supports initial offset via InitStepsTaken.
type FromStorageIteration struct {
[][]float64
Data int
InitStepsTaken }
func (*FromStorageIteration) Configure
func (f *FromStorageIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*FromStorageIteration) Iterate
func (f *FromStorageIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type FromStorageTimestepFunction
FromStorageTimestepFunction streams timesteps from an in-memory []float64.
Usage hints:
- Provide Data; supports initial offset via InitStepsTaken.
type FromStorageTimestepFunction struct {
[]float64
Data int
InitStepsTaken }
func (*FromStorageTimestepFunction) NextIncrement
func (f *FromStorageTimestepFunction) NextIncrement(timestepsHistory *simulator.CumulativeTimestepsHistory) float64
type NamedIndexedState
NamedIndexedState pairs a partition’s name/index with its state history. Useful for initialising inner histories from a chosen outer partition.
type NamedIndexedState struct {
.NamedPartitionIndex
NamedIndex simulator*simulator.StateHistory
History }
type ParamValuesIteration
ParamValuesIteration writes the float param values under “param_values” directly to the state.
Usage hints:
- Useful for injecting immediate parameter-driven values.
type ParamValuesIteration struct {
}
func (*ParamValuesIteration) Configure
func (p *ParamValuesIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*ParamValuesIteration) Iterate
func (p *ParamValuesIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type SortingValues
SortingValues encapsulates a new entry to add to the sorting collection.
type SortingValues struct {
float64
SortBy []float64
Values }
func OtherPartitionsPushAndSortFunction
func OtherPartitionsPushAndSortFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) (SortingValues, bool)
OtherPartitionsPushAndSortFunction retrieves values from one partition and sorts by another partition’s value.
Usage hints:
- Provide: “other_partition”, “value_indices”, “other_partition_sort_by”, and “value_index_sort_by”. Skip push if first value equals “empty_value”.
func ParamValuesPushAndSortFunction
func ParamValuesPushAndSortFunction(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) (SortingValues, bool)
ParamValuesPushAndSortFunction uses params for both values and sort key.
Usage hints:
- Provide: “next_values_push”, “empty_value”, and “next_values_sort_by”.
type StateMemoryIteration
StateMemoryIteration marks iterations that can receive state/time from a parent simulation and store it for later use.
type StateMemoryIteration interface {
(params *simulator.Params, update StateMemoryUpdate)
UpdateMemory}
type StateMemoryUpdate
StateMemoryUpdate carries a named partition’s state and timestep history from an outer simulation into an inner (embedded) simulation.
Usage hints:
- Used by iterations implementing StateMemoryIteration to receive context.
- Set Name to the outer partition name for disambiguation.
type StateMemoryUpdate struct {
string
Name *simulator.StateHistory
StateHistory *simulator.CumulativeTimestepsHistory
TimestepsHistory }
type ValuesChangingEventsIteration
ValuesChangingEventsIteration calls and outputs from an iteration in the map keyed by an event. If no event key matches, it returns previous values or optional “default_values”.
Usage hints:
- Set EventIteration to produce the event key; provide IterationByEvent map.
- Optional: set “default_values” to override fallback behaviour.
type ValuesChangingEventsIteration struct {
.Iteration
EventIteration simulatormap[float64]simulator.Iteration
IterationByEvent }
func (*ValuesChangingEventsIteration) Configure
func (v *ValuesChangingEventsIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*ValuesChangingEventsIteration) Iterate
func (v *ValuesChangingEventsIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type ValuesCollectionIteration
ValuesCollectionIteration maintains a fixed-width rolling collection of value vectors.
Usage hints:
- Provide: “values_state_width” and “empty_value” for sentinel handling.
- Set Push to define how new values are appended; set PopIndex to surface an existing entry into index 0 and clear that slot.
type ValuesCollectionIteration struct {
func(
PopIndex *simulator.Params,
params int,
partitionIndex []*simulator.StateHistory,
stateHistories *simulator.CumulativeTimestepsHistory,
timestepsHistory ) (int, bool)
func(
Push *simulator.Params,
params int,
partitionIndex []*simulator.StateHistory,
stateHistories *simulator.CumulativeTimestepsHistory,
timestepsHistory ) ([]float64, bool)
}
func (*ValuesCollectionIteration) Configure
func (v *ValuesCollectionIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*ValuesCollectionIteration) Iterate
func (v *ValuesCollectionIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type ValuesFunctionIteration
ValuesFunctionIteration provides a flexible way to compute derived values from simulation state and parameters using user-defined functions.
This iteration type allows for custom computation logic within simulations, enabling feature engineering, data transformation, and complex derived value calculations. It’s particularly useful for creating custom aggregation functions, feature extraction, and data preprocessing.
Design Philosophy: The function-based approach emphasizes composition and reusability. By providing a pure function interface, this iteration enables:
- Stateless computation (no side effects)
- Easy testing and validation
- Composition with other iteration types
- Reusable computation logic across simulations
Function Signature: The Function field must implement a pure mapping from simulation context to output values. It receives:
- params: Current simulation parameters
- partitionIndex: Index of the current partition
- stateHistories: All partition state histories
- timestepsHistory: Time and timestep information
And returns a slice of float64 values representing the computed output.
Applications:
- Feature engineering: Compute derived features from raw simulation data
- Data transformation: Apply mathematical transformations to state values
- Custom aggregations: Implement specialized aggregation logic
- Parameter synthesis: Combine multiple parameters into derived values
- Event detection: Compute indicators for significant events
Example:
:= &ValuesFunctionIteration{
iteration : func(params *simulator.Params, partitionIndex int,
Function[]*simulator.StateHistory,
stateHistories *simulator.CumulativeTimestepsHistory) []float64 {
timestepsHistory // Extract current state from first partition
:= stateHistories[0].Values.RawRowView(0)
currentState
// Compute derived feature: moving average
if len(currentState) >= 2 {
return []float64{(currentState[0] + currentState[1]) / 2.0}
}
return []float64{0.0}
},
}
Performance Considerations:
- Function is called once per simulation step
- Avoid expensive computations in the function body
- Consider caching for repeated calculations
- Memory allocations should be minimized
API Stability:
- This interface is stable and will not change in future versions
- Function signature is compatible across all stochadex versions
Related Types:
- See NewTransformReduceFunction for composed transform-reduce operations
- See ParamsTransform for parameter extraction utilities
- See SumReduce for simple reduction operations
type ValuesFunctionIteration struct {
func(
Function *simulator.Params,
params int,
partitionIndex []*simulator.StateHistory,
stateHistories *simulator.CumulativeTimestepsHistory,
timestepsHistory ) []float64
}
func (*ValuesFunctionIteration) Configure
func (v *ValuesFunctionIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*ValuesFunctionIteration) Iterate
func (v *ValuesFunctionIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type ValuesFunctionVectorCovarianceIteration
ValuesFunctionVectorCovarianceIteration computes a kernel-weighted rolling covariance of a function over historical values and times.
Usage hints:
- Provide Function that accepts a history index (-1 for latest) and returns a vector matching the partition state width.
- Set Kernel and related params (e.g., bandwidth, discounting).
- Requires a “mean” param vector for centring.
- The upper-triangular covariance is returned flattened.
type ValuesFunctionVectorCovarianceIteration struct {
func(
Function *simulator.Params,
params int,
partitionIndex []*simulator.StateHistory,
stateHistories int,
stateHistoryDepthIndex ) []float64
.IntegrationKernel
Kernel kernels}
func (*ValuesFunctionVectorCovarianceIteration) Configure
func (v *ValuesFunctionVectorCovarianceIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*ValuesFunctionVectorCovarianceIteration) Iterate
func (v *ValuesFunctionVectorCovarianceIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type ValuesFunctionVectorMeanIteration
ValuesFunctionVectorMeanIteration computes a kernel-weighted rolling mean of a function over historical values and times.
Usage hints:
- Provide Function that accepts a history index (-1 for latest) and returns a vector matching the partition state width.
- Set Kernel and related params (e.g., discount factors, bandwidth, etc.).
- Use “without_normalisation” to return the weighted sum rather than mean; “subtract_from_normalisation” adjusts the normaliser if needed.
type ValuesFunctionVectorMeanIteration struct {
func(
Function *simulator.Params,
params int,
partitionIndex []*simulator.StateHistory,
stateHistories int,
stateHistoryDepthIndex ) []float64
.IntegrationKernel
Kernel kernels}
func (*ValuesFunctionVectorMeanIteration) Configure
func (v *ValuesFunctionVectorMeanIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*ValuesFunctionVectorMeanIteration) Iterate
func (v *ValuesFunctionVectorMeanIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type ValuesGroupedAggregationIteration
ValuesGroupedAggregationIteration collects historical values and weights into grouping buckets (defined by tupled grouping series) and applies a caller-provided aggregation per bucket.
Usage hints:
- Configure accepted group tuples via params: “accepted_value_group_tupindex_k”.
- Provide grouping source partitions/indices via “grouping_partition_tupindex_k” and “grouping_value_indices_tupindex_k”.
- Provide the state series via “state_partition” and “state_value_indices”.
- Set Kernel and precision (“float_precision”); optionally set “default_values”.
type ValuesGroupedAggregationIteration struct {
func(
Aggregation []float64,
defaultValues map[string]int,
outputIndexByGroup map[string][]float64,
groupings map[string][]float64,
weightings ) []float64
.IntegrationKernel
Kernel kernels// contains filtered or unexported fields
}
func (*ValuesGroupedAggregationIteration) Configure
func (v *ValuesGroupedAggregationIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*ValuesGroupedAggregationIteration) Iterate
func (v *ValuesGroupedAggregationIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type ValuesSortingCollectionIteration
ValuesSortingCollectionIteration maintains a sorted collection of entries.
Usage hints:
- Provide: “values_state_width” (entry width minus 1 for sort key) and “empty_value” sentinel. Set PushAndSort to define insertion behaviour.
type ValuesSortingCollectionIteration struct {
func(
PushAndSort *simulator.Params,
params int,
partitionIndex []*simulator.StateHistory,
stateHistories *simulator.CumulativeTimestepsHistory,
timestepsHistory ) (SortingValues, bool)
}
func (*ValuesSortingCollectionIteration) Configure
func (v *ValuesSortingCollectionIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*ValuesSortingCollectionIteration) Iterate
func (v *ValuesSortingCollectionIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
type ValuesWeightedResamplingIteration
ValuesWeightedResamplingIteration resamples historical values from other partitions according to provided (optionally discounted) weights.
Usage hints:
- Provide: “log_weight_partitions” (and optional “log_weight_indices”).
- Provide: “data_values_partitions” to choose which values to resample.
- Use “past_discounting_factor” to downweight older history (exponential).
type ValuesWeightedResamplingIteration struct {
.Source
Src rand// contains filtered or unexported fields
}
func (*ValuesWeightedResamplingIteration) Configure
func (v *ValuesWeightedResamplingIteration) Configure(partitionIndex int, settings *simulator.Settings)
func (*ValuesWeightedResamplingIteration) Iterate
func (v *ValuesWeightedResamplingIteration) Iterate(params *simulator.Params, partitionIndex int, stateHistories []*simulator.StateHistory, timestepsHistory *simulator.CumulativeTimestepsHistory) []float64
Generated by gomarkdoc