Skip to main content

Overview

The Cortex class provides methods for predicting future states of twins and aggregates using the Cortex prediction engine. It can return predictions either mapped to human-readable embedding inputs or as raw state vectors.

Methods

predictions(data: NextStateRequest)

Predict the next n states for a twin and get responses mapped back to embedding inputs.
data
NextStateRequest
required
The prediction request parameters
response
tuple
Returns a tuple of (NextStateResponse | Error, status_code)
Example:
from avenieca.api.model import NextStateRequest

nsr = NextStateRequest(
    module_id="aggregate001",
    recall=20,
    range=20,
    n=1,
    status="e"
)

res, status = eca.cortex.predictions(data=nsr)
if status == 200:
    print("Current state:")
    for twin in res.current_state:
        print(f"  {twin.module_id}: {twin.state}")
    
    print("\nPredicted next state:")
    for twins in res.next_state:
        for twin in twins.list:
            print(f"  {twin.module_id}: {twin.state}")

predictions_raw(data: NextStateRequest)

Predict the next n states for a twin and get responses as raw aggregate state vectors.
data
NextStateRequest
required
The prediction request parameters (same as predictions method)
response
tuple
Returns a tuple of (NextStateResponseRaw | Error, status_code)
Example:
from avenieca.api.model import NextStateRequest

nsr = NextStateRequest(
    module_id="aggregate001",
    recall=20,
    range=20,
    n=3,  # Predict next 3 states
    status="e"
)

res, status = eca.cortex.predictions_raw(data=nsr)
if status == 200:
    print("Current state (raw):")
    for twin in res.current_state:
        print(f"  {twin.module_id}: {twin.state}")
    
    print(f"\nPredicted next {len(res.next_state)} states:")
    for i, twins in enumerate(res.next_state):
        print(f"\n  Step {i+1}:")
        for twin in twins.list:
            print(f"    {twin.module_id}: {twin.state}")

Understanding Predictions

The Cortex prediction engine uses historical sequences to predict future states:
  1. Range: Number of nearest neighbor sequences to consider
  2. Recall: How many historical states to look back
  3. N: Number of future states to predict
  4. Status: Filter sequences by their status value

Prediction Workflow

import os
from avenieca.api.eca import ECA
from avenieca.api.model import Config, NextStateRequest

# Initialize client
config = Config(
    uri="http://localhost:2580/v1",
    username=os.getenv("USERNAME"),
    password=os.getenv("PASSWORD")
)
eca = ECA(config)

# Make prediction request
request = NextStateRequest(
    module_id="air_conditioner",
    recall=10,      # Look back 10 states
    range=5,        # Consider 5 nearest sequences
    n=2,            # Predict next 2 states
    status="e",     # Only use 'existing' status sequences
    store_response=True,   # Save this prediction
    store_sequence=False   # Don't create new sequence
)

# Get human-readable predictions
res, status = eca.cortex.predictions(data=request)

if status == 200:
    # Display current state
    print("Current State:")
    for twin in res.current_state:
        print(f"  Module: {twin.module_id}")
        print(f"  ESS ID: {twin.ess_id}")
        print(f"  State: {twin.state}")
    
    # Display predictions
    print(f"\nPredicted States:")
    for step_num, twins_set in enumerate(res.next_state, 1):
        print(f"\n  Prediction {step_num}:")
        for twin in twins_set.list:
            print(f"    {twin.module_id}: {twin.state}")

When to Use Raw vs Mapped Predictions

Use predictions() when:
  • You need human-readable output
  • States are mapped to embedding inputs
  • Building user-facing features
Use predictions_raw() when:
  • You need numerical state vectors for computation
  • Performing further mathematical operations
  • States don’t have embedding mappings
  • Building analytics or ML pipelines

Build docs developers (and LLMs) love