GeniusAgent

The GeniusAgent class us a wrapper around the fastAPI calls used to communicate to and from the Genius agent. This class has the following capabilities enables by the API calls:

  • POST /graph of genius model loaded from a JSON or from the GeniusModel class

  • GET /graph of genius model and print/view its contents

  • DELETE /graph to unload the model from the agent

  • POST /infer to perform inference given some evidence and a variable of interest

  • POST /learn to perform parameter learning given an input CSV or list of variables and their observations

  • POST /actionselection to perform action selection given a POMDP model structure and observation vector

  • POST /import to perform structure learning given a CSV data file

  • POST /validate-csv to perform validation on a CSV data file

  • POST /simulate to perform simulation on a POMDP model structure

  • POST /auto-bin-one-off to perform automatic binning of a given column by clustering

To import the GeniusAgent class use: from genius_client_sdk.agent import GeniusAgent

Usage patterns

GeniusAgent(agent_http_protocol, agent_hostname, agent_port, auth_config)

Attributes

Variable
Type
Description

agent_http_protocol

str

The HTTP protocol of the agent to connect to.

agent_hostname

str

The hostname of the agent to connect to.

agent_port

str

The port of the agent to connect to.

agent_url

str

The URL of the agent to connect to. Concatenation of the http protocol, hostname, and port.

auth_config

AuthConfig

The auth configuration for the agent.

model

Local storage of the model to be sent to the agent.

Parameters

Class initialization parameters.

Variable
Type
Default
Description

agent_http_protocol

str

http

The HTTP protocol of the agent to connect to.

agent_hostname

str

localhost

The hostname of the agent to connect to.

agent_port

str

3000

The port of the agent to connect to.

auth_config

AuthConfig

NoAuthConfig

The auth configuration for the agent.

Methods

act

Performs action selection using active inference given an observation and policy length.

circle-exclamation
Parameter
Type
Default
Description

observation

Union[int, str, Dict[str, Union[int, str]]]

Required

The observation to send to the agent.

policy_len

int

2

The length of the policy.

verbose

bool

True

If true, prints out the action, inferred state, and policy distribution.

polling_timeout_sec

float

120

he maximum time to wait in seconds for interference to complete.

polling_frequency_sec

float

0.1

The time to wait in seconds in between checking if the task has completed.

learn_likelihoods

bool

False

learn_transitions

bool

False

learn_initial_state_priors

bool

False

Returns:

Type
Description

dict

A dictionary containing the results of action selection. See the action data reference for a comprehensive overview of the components of this data.

Example (single modality):

Assumes a JSON model file already exists.

Example (multiple modalities):

Assumes a JSON model file already exists.

infer

Run inference based on target variable and evidence of other variables.

Parameter
Type
Default
Description

variables

Union[str, list]

Required

The name of the target variable to infer.

evidence

dict

2

A dictionary containing observed data.

verbose

bool

True

If true, prints the probabilities associated with the inference result.

polling_timeout_sec

float

120

The maximum time to wait in seconds for interference to complete.

polling_frequency_sec

float

0.1

The time to wait in seconds in between checking if the task has completed.

Returns:

Type
Description

dict

A dictionary containing the results of inference. This includes the input evidence as well as the inferred probability distribution over the target variable.

Example:

Assumes a JSON model file already exists.

learn

Run learning based on observations of variables. Accepts either a list of variables and nested list of observations or a path to a CSV file.

  • If inputing a list of variables and observations then the variables and observations arguments are required.

  • If inputing a CSV file with data, then the csv_path variable is required only.

Parameter
Type
Default
Description

variables

list

None

A list of variables to learn.

observations

list

None

A nested list of observations for the variables.

csv_path

str

None

The path to a CSV file containing the observations.

verbose

bool

False

If True, prints out the JSON model file.

polling_timeout_sec

float

120

The maximum time to wait in seconds for interference to complete.

polling_frequency_sec

float

0.1

The time to wait in seconds in between checking if the task has completed.

Returns:

Type
Description

dict

A dictionary containing the results of learning. This includes a dict representation of the newly learned model file.

Example (from CSV):

Example (from Python):

load_genius_model

Sends an instance of the GeniusModel class to the agent.

Parameter
Type
Default
Description

model

GeniusModel

Required

A instance of the GeniusModel class.

Example:

load_model_from_json

Sends a JSON representation of a model to the agent.

Parameter
Type
Default
Description

json_path

str

Required

A path to a JSON file containing the model.

Example:

get_model_from_server

Gets the JSON model from the remote agent and updates the local model.

Parameter
Type
Default
Description

verbose

bool

False

If True, prints out the JSON model.

log_model

Prints the JSON model to logs. Optionally, summarizes the model in a slightly more readable format.

Parameter
Type
Default
Description

summary

bool

False

If true, prints a summarized view of the model.

logging_level

int

20

The logging level to use.

unload_model

Unloads the model locally and from the server

Parameter
Type
Default
Description

-

-

-

-

validate_csv

Performs validation on a given CSV file.

Parameter
Type
Default
Description

csv_path

str

Required

The path to the CSV file.

polling_timeout_sec

float

120

The maximum time to wait in seconds for interference to complete.

polling_frequency_sec

float

0.1

The time to wait in seconds in between checking if the task has completed.

simulate

Performs a simulation on the model given a library, number of steps, policy length, and initial state.

Parameter
Type
Default
Description

num_steps

int

Required

The number of steps to simulate.

policy_len

int

Required

The length of the policy.

init_state

dict

Required

The initial state for the simulation.

env

dict

Optional

The environment for the simulation.

polling_timeout_sec

float

120

The maximum time to wait in seconds for interference to complete.

polling_frequency_sec

float

0.1

he time to wait in seconds in between checking if the task has completed. Defaults to 0.1 seconds.

Returns:

Type
Description

dict

A dictionary containing the simulation result.

auto_bin_one_off

Automatically bins a given column by clustering.

Parameter
Type
Default
Description

csv_path

str

Required

The path to the CSV file.

variables

dict[str, AutoBinVariable]

Required

A dictionary of variables to bin. The keys are the variable names and the values are AutoBinVariable instances.

polling_timeout_sec

float

120

The maximum time to wait in seconds for interference to complete.

polling_frequency_sec

float

0.1

The time to wait in seconds in between checking if the task has completed.

Returns:

Type
Description

dict

A dictionary containing the binning result.

Last updated