pysatl_tsp.implementations.processor.fwma_handler

Module Contents

Classes

FWMAHandler

Fibonacci Weighted Moving Average (FWMA) handler.

API

class pysatl_tsp.implementations.processor.fwma_handler.FWMAHandler(length: int = 10, asc: bool = True, source: pysatl_tsp.core.Handler[Any, float | None] | None = None)[source]

Bases: pysatl_tsp.core.processor.inductive.weighted_moving_average_handler.WeightedMovingAverageHandler

Fibonacci Weighted Moving Average (FWMA) handler.

Calculates a moving average using Fibonacci sequence numbers as weights. The Fibonacci sequence (1, 1, 2, 3, 5, 8, 13, …) provides a natural weighting scheme where each number is the sum of the two preceding ones.

By default, higher weights are assigned to more recent values (when asc=False), making this moving average more responsive to recent changes in the data.

Inherits general behavior from WeightedMovingAverageHandler, only changing the weight calculation method.

Example:
# Create a data source with numeric values
data_source = SimpleDataProvider([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])

# Create a FWMA handler with length of 5
fwma_handler = FWMAHandler(length=5)
fwma_handler.set_source(data_source)

# Process the data
for value in fwma_handler:
    print(value)

# First 4 values will be None (not enough data points)
# Subsequent values will be weighted averages using Fibonacci weights
# For length=5, weights would be [0.01, 0.01, 0.02, 0.03, 0.05] (normalized)
# or [0.05, 0.03, 0.02, 0.01, 0.01] when asc=False (default)

Initialization

Initialize weighted moving average handler with specified parameters.

_calculate_weights(length: int, asc: bool) list[float][source]

Calculate Fibonacci weights for FWMA.

Generates weights based on the Fibonacci sequence and normalizes them to sum to 1.0. The sequence order can be reversed based on the asc parameter.

Parameters:
  • length – The number of weights to generate

  • asc – Whether weights should be in ascending order

Returns:

A list of normalized weights summing to 1.0

_fibonacci_sequence(n: int) list[float][source]

Generate the Fibonacci sequence of specified length.

Creates a list containing the first n numbers in the Fibonacci sequence. The sequence starts with 1, 1 and each subsequent number is the sum of the two preceding ones.

Parameters:

n – The length of the sequence to generate

Returns:

A list containing the Fibonacci sequence