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 /graphof genius model loaded from a JSON or from the GeniusModel classGET /graphof genius model and print/view its contentsDELETE /graphto unload the model from the agentPOST /inferto perform inference given some evidence and a variable of interestPOST /learnto perform parameter learning given an input CSV or list of variables and their observationsPOST /actionselectionto perform action selection given a POMDP model structure and observation vectorPOST /importto perform structure learning given a CSV data filePOST /validate-csvto perform validation on a CSV data filePOST /simulateto perform simulation on a POMDP model structurePOST /auto-bin-one-offto 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
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.
Parameters
Class initialization parameters.
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.
The observation must be an integer corresponding to a possible observation category. If there are multiple observation modalities then the observation will be a list with an integer corresponding to each observation modality.
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:
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.
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:
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
variablesandobservationsarguments are required.If inputing a CSV file with data, then the
csv_pathvariable is required only.
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:
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.
model
GeniusModel
Required
A instance of the GeniusModel class.
Example:
load_model_from_json
Sends a JSON representation of a model to the agent.
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.
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.
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
-
-
-
-
validate_csv
Performs validation on a given CSV file.
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.
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:
dict
A dictionary containing the simulation result.
auto_bin_one_off
Automatically bins a given column by clustering.
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:
dict
A dictionary containing the binning result.
Last updated