Skip to main content

Overview

The Signal class is a dataclass that represents a signal in the AveniECA system. It extends the Base class and provides a structure for storing state vectors along with optional metadata like valence, score, and embedding input.

Class Definition

from avenieca.data import Signal

Fields

state
List[float]
required
The state vector representing the signal. This is a list of floating-point values that encode the signal’s representation.
valence
float
default:"None"
Optional valence value associated with the signal. Represents the emotional or evaluative tone of the signal.
score
int
default:"None"
Optional score associated with the signal. Can be used for ranking or importance metrics.
emb_inp
int
default:"None"
Optional embedding input identifier. References the ID of the embedding input used to generate this signal.

Inherited Methods

The Signal class inherits from Base, which provides the following methods:

__dict__

Returns a dictionary representation of the signal.
signal_dict = signal.__dict__

json

Returns a JSON string representation of the signal with indentation.
signal_json = signal.json
print(signal_json)

to_json_file(file)

Writes the signal to a JSON file. Parameters:
  • file (str): The file path where the JSON will be written
signal.to_json_file('signal_output.json')

Usage Examples

Creating a Signal

from avenieca.data import Signal

# Create a basic signal with just a state vector
signal = Signal(
    state=[0.1, 0.2, 0.3, 0.4, 0.5]
)

# Create a signal with all fields
signal = Signal(
    state=[0.1, 0.2, 0.3, 0.4, 0.5],
    valence=0.75,
    score=95,
    emb_inp=123
)

Serializing to JSON

# Get JSON string
json_output = signal.json
print(json_output)

# Save to file
signal.to_json_file('my_signal.json')

Converting to Dictionary

# Convert to dictionary for further processing
signal_data = signal.__dict__
print(signal_data)
# Output: {'state': [0.1, 0.2, 0.3, 0.4, 0.5], 'valence': 0.75, 'score': 95, 'emb_inp': 123}

Deserializing from JSON

import json
from avenieca.data import Signal

# Load from JSON string
json_data = '{"state": [0.1, 0.2, 0.3], "valence": 0.8, "score": 90}'
signal = Signal.from_json(json_data)

# Load from dictionary
data = {"state": [0.1, 0.2, 0.3], "valence": 0.8}
signal = Signal.from_dict(data)

Build docs developers (and LLMs) love