Utilities

Utility functions for interacting with GAIuS

exception ia.gaius.utils.GDFFormatError

Bases: BaseException

Error raised when GDF is of improper format

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.build_pipeline_layers(input_slot_data, pipelines_dict)
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 GDFFormatError will be raised

ia.gaius.utils.dict_to_plotly_string(node_data: Dict, hover_line_length=30)
ia.gaius.utils.find_output_slots_and_add_to_end(pipeline_layers, output_slots_dict)
ia.gaius.utils.load_sequence_from_file(directory_name: str, filename: str) list

Load a GDF sequence to a file

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

  • filename (str, required) – filename to load from

Example

from ia.gaius.utils import load_sequence_from_file, create_gdf
sequence = [create_gdf(strings=["hello"]),
            create_gdf(strings=["world"])]
filename = 'hello_world'
directory_name = '/example/dir'
load_sequence_from_file(directory_name, filename)
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.node_data_to_plotly_string(node_data: Dict, hover_line_length=30)
ia.gaius.utils.plot_directed_networkx_graph(graph: DiGraph, starting_functions: list, base_x_distance=10, base_y_distance=10, arrow_marker_size=15, node_marker_size=15, hover_line_length=30, title='Directed Graph')
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