The Cortex API provides predictive capabilities for state transitions in AveniECA. Given a current state (or sequence of states), Cortex predicts the most likely next states based on historical patterns.
Predict multiple future states by requesting n > 1:
nsr = NextStateRequest( module_id="aggregate001", recall=30, range=30, n=5, # Get top 5 most likely next states status="e")res, status = eca.cortex.predictions(data=nsr)for i, twins in enumerate(res.next_state, 1): print(f"\nPrediction {i} (ranked by likelihood):") for twin in twins.list: print(f" {twin.module_id}: {twin.state}")
When predicting aggregates, each component module is predicted:
nsr = NextStateRequest( module_id="aggregate001", # Aggregate of multiple modules recall=25, range=25, n=2, status="e")res, status = eca.cortex.predictions(data=nsr)# Current aggregate stateprint("Current state components:")for twin in res.current_state: print(f" {twin.module_id} (ESS {twin.ess_id}): {twin.state}")# Predicted aggregate statesfor i, twins in enumerate(res.next_state, 1): print(f"\nPrediction {i}:") for twin in twins.list: # Each twin represents one component of the aggregate print(f" {twin.module_id}: {twin.state}") print(f" Aggregate ID: {twin.aggregate_id}") print(f" ESS ID: {twin.ess_id}")
from avenieca.api.model import Errorres, status = eca.cortex.predictions(data=nsr)if isinstance(res, Error): print("Prediction failed:") for error in res.errors: print(f" - {error}")elif status != 200: print(f"Request failed with status {status}")else: # Process successful predictions print(f"Got {len(res.next_state)} predictions")
Tuning recall and range: Higher values provide more context but increase computation time. Start with lower values (10-20) and increase if predictions aren’t accurate enough.
Sequence status filtering: Using status filters can significantly speed up predictions by limiting the search space to relevant sequences only.