Utilities

Utility functions for interacting with GAIuS

ia.gaius.utils.abstract_names(ensemble: list) list

Get a set of model names from a prediction ensemble

Parameters:

ensemble (list) – a prediction ensemble

Returns:

list of models from predictions in the prediction ensemble

Return type:

list

Example

from ia.gaius.agent_client import AgentClient
from ia.gaius.utils import abstract_names
...
agent = AgentClient(agent_info)
agent.connect()
...
ensemble = agent.get_predictions(nodes=['P1'])
models = abstract_names(ensemble)
ia.gaius.utils.create_gdf(strings=None, vectors=None, emotives=None, metadata=None) dict

Create GDF using supplied list of strings, vectors, emotives, and/or metadata

Parameters:
  • strings (list, optional) – Used to provide symbols as string data to GAIuS. Defaults to None.

  • vectors (list, optional) – Used to input vector data to GAIuS. Defaults to None.

  • emotives (dict, optional) – Used to provide emotional data to GAIuS. Defaults to None.

  • metadata (dict, optional) – Used to provide miscellaneous data to GAIuS. Defaults to None.

Returns:

A dictionary representing the GDF

Return type:

dict

Example

from ia.gaius.utils import create_gdf
gdf = create_gdf(strings=["hello"], emotives={"happy": 10.0})

Warning

If fields provided are not of the type expected, a warning will be raised, but the GDF will still be made with the improper format

ia.gaius.utils.log_progress(sequence, every=None, size=None, name='Items')

A nice little Jupyter progress bar widget from: https://github.com/alexanderkuk/log-progress

ia.gaius.utils.merge_gdfs(gdf1: dict, gdf2: dict) dict

Merge two GDFs into a single gdf, accumulating the values in each field

Parameters:
  • gdf1 (dict) – First GDF

  • gdf2 (dict) – Second GDF

Raises:

Exception – When vectors are of differing lengths

Returns:

Merged GDF

Return type:

dict

ia.gaius.utils.retrieve_bottom_level_records(traceback: dict) list

Retrieve all records from a traceback (ia.gaius.agent_client.AgentClient.investigate_record()) call that have bottomLevel=True

Parameters:

traceback (dict) – the dictionary pertaining to the output of an investigate call

Returns:

list of records from the traceback

Return type:

list

Example

from ia.gaius.agent_client import AgentClient
from ia.gaius.utils import retrieve_bottom_level_records
...
agent = AgentClient(agent_info)
...
traceback_output = agent.investigate_record(record=record,
                                            node=['P1'])
bottom_level = retrieve_bottom_level_records(traceback_output)
ia.gaius.utils.write_gdf_to_file(directory_name: str, filename: str, sequence: list) str

Write a GDF sequence to a file

Parameters:
  • directory_name (str, required) – directory to save GDFs to

  • filename (str, required) – filename to save to

  • sequence (list, required) – list of individual GDF events making up a sequence

Example

from ia.gaius.utils import write_gdf_to_file, create_gdf
sequence = [create_gdf(strings=["hello"]),
            create_gdf(strings=["world"])]
filename = 'hello_world'
directory_name = '/example/dir'
write_gdf_to_file(directory_name, filename, sequence)

Warning

Will overwrite the file at <directory_name>/<filename>. Please ensure it is acceptable to do so. No safety checks are performed in this function