When Should `infer_is_positive` Be Set to False in TimesFM?
Set infer_is_positive=False in TimesFM whenever your target time series can legitimately take negative values, such as temperature readings, financial returns, or signed sensor measurements.
The infer_is_positive flag in the google-research/timesfm repository controls whether the model clamps forecast outputs to non-negative values. Understanding when to disable this safety mechanism is critical for accurate forecasting on signed data domains.
What infer_is_positive Controls
infer_is_positive is a boolean field defined in src/timesfm/configs.py within the ForecastConfig dataclass. When set to True (the default), TimesFM assumes every input series contains only non-negative numbers and applies a post-processing clamp that forces all forecasted points to be ≥ 0.
According to the source code in src/timesfm/timesfm_2p5/timesfm_2p5_torch.py, this flag triggers torch.clamp(output, min=0) during the final inference step. The JAX implementation applies an equivalent operation. This behavior is designed for domains like sales, demand counts, prices, and volumes where negative forecasts would be physically meaningless.
When to Set infer_is_positive to False
You must set infer_is_positive=False whenever the target series naturally spans both positive and negative values. Forcing non-negative constraints on signed data distorts prediction shapes and breaks downstream analytics like residual calculations or anomaly detection.
Temperature and Weather Data
Daily temperature anomalies, raw Celsius readings, or Fahrenheit values regularly cross zero. Clamping these forecasts to non-negative values would corrupt seasonal patterns and eliminate valid freezing-point predictions.
Financial Returns and Profit/Loss
Daily stock returns, profit-and-loss statements, and portfolio deltas are frequently negative to represent losses. The official timesfm-forecasting/SKILL.md documentation explicitly recommends setting the flag to False for financial return series.
Signed Sensor Measurements
Industrial sensors measuring pressure differential, voltage variance, or acoustic waves often report signed values. Negative readings in these contexts indicate directionality or decompression events, not errors.
Architectural Implementation
The flag directly controls a post-inference safety layer without affecting internal model weights or training dynamics. As implemented in src/timesfm/configs.py:
- When
True: The model executestorch.clamp(output, min=0)(PyTorch) or the JAX equivalent on the raw network output. - When
False: The clamp operation is skipped, returning the raw forecast tensor including negative values.
The timesfm-forecasting/references/api_reference.md notes: "Set False for temperature, returns, negatives."
Code Examples
Forecasting Temperature (Set to False)
import numpy as np
import timesfm
# Load model
model = timesfm.TimesFM_2p5_200M_torch.from_pretrained(
"google/timesfm-2.5-200m-pytorch"
)
# Configure for signed data
model.compile(
timesfm.ForecastConfig(
max_context=1024,
max_horizon=48,
normalize_inputs=True,
use_continuous_quantile_head=True,
infer_is_positive=False, # Critical for temperature
fix_quantile_crossing=True,
)
)
# Temperature data crossing zero
temp_series = np.sin(np.linspace(0, 6 * np.pi, 300)).astype(np.float32)
point, quantiles = model.forecast(horizon=48, inputs=[temp_series])
Forecasting Sales (Default True)
model.compile(
timesfm.ForecastConfig(
max_context=512,
max_horizon=24,
normalize_inputs=True,
use_continuous_quantile_head=True,
infer_is_positive=True, # Safe for non-negative data
fix_quantile_crossing=True,
)
)
sales = np.random.poisson(lam=20, size=200).astype(np.float32)
point, quantiles = model.forecast(horizon=24, inputs=[sales])
Verifying Configuration
cfg = timesfm.ForecastConfig(infer_is_positive=False)
print("Clamp to >=0?", cfg.infer_is_positive) # Output: False
Summary
- Set
infer_is_positive=Falsefor any time series that can legitimately take negative values (temperature, financial returns, signed sensors). - Keep the default
Truefor inherently non-negative domains (sales volume, demand counts, prices). - The flag resides in
src/timesfm/configs.pyand controls post-processing insrc/timesfm/timesfm_2p5/timesfm_2p5_torch.py. - Changing this setting only affects the final clamping operation, not model architecture or training.
Frequently Asked Questions
What happens if I leave infer_is_positive=True on negative data?
The model will forcibly clamp all forecast values to zero or above using torch.clamp(output, min=0). This distorts the prediction distribution, artificially inflates residuals near zero crossings, and renders the forecast unsuitable for applications like loss modeling or temperature anomaly detection.
Does setting infer_is_positive=False affect model training?
No. This parameter only influences the post-inference clamping layer. It does not modify internal model weights, attention mechanisms, or the training objective. It strictly controls how the raw network output tensor is prepared before returning to the user.
How do I check the current value of infer_is_positive in my config?
Access the attribute directly on your ForecastConfig instance after creation or inspect the configuration object passed to model.compile(). The boolean value is stored in the dataclass field defined in src/timesfm/configs.py.
Is infer_is_positive available in both PyTorch and JAX implementations?
Yes. The flag is framework-agnostic and defined in the shared configuration module. Both the PyTorch implementation (timesfm_2p5_torch.py) and the Flax/JAX counterpart check this field and apply the appropriate clamping operation (PyTorch's torch.clamp or JAX's jnp.clip) based on its value.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →