ensemble module

Full Documentation for hippynn.graphs.ensemble module. Click here for a summary page.

collate_inputs(models: list[GraphModule], inputs: List[str]) Dict[str, List[_BaseNode]][source]

Internal function for ensembling.

Identify input classes for ensemble.

Parameters:
  • models

  • inputs

Returns:

collate_targets(models: List[GraphModule], targets: List[str]) Dict[str, List[_BaseNode]][source]

Internal function for ensembling.

Identify targets to ensemble.

Parameters:
  • models

  • targets

Returns:

construct_outputs(output_classes: Dict[str, List[_BaseNode]], prefix: str) Dict[str, EnsembleTarget][source]

Internal function for ensembling.

Build the EnsembleNodes for classes of outputs. Note that this function attempts to produce consistent index state versions for both a database-type index state and a reduced index state.

Parameters:
  • output_classes – Dictionary giving list of nodes to ensemble.

  • prefix – name to prepend to each ensembled variable.

Returns:

dictionary of ensembled node names to ndoes.

get_graphs(models: List[str | GraphModule | _BaseNode] | str) List[GraphModule][source]

Take a simple spec for modeled variables (glob for model directories, list of graphs, list of output nodes) and convert this into a list of graph modules.

Models can be a list with entries that are one of the following:

  • str: directory to use with load_model_from_cwd()

  • GraphModule: already built model

  • node: an output target, which will be converted to a GraphModule with automatically defined inputs.

or a string, which is used with glob to specify the list of strings.

Parameters:

models

Returns:

identify_inputs(models: list[GraphModule]) set[str][source]

Internal function for ensembling.

Find all required inputs for ensemble.

Parameters:

models

Returns:

identify_targets(models: List[GraphModule]) set[str][source]

Internal function for ensembling.

Identify targets types to ensemble.

Parameters:

models

Returns:

make_ensemble(models, *, targets: List[str] = 'auto', inputs: List[str] = 'auto', prefix: str = 'ensemble_', quiet=False) Tuple[GraphModule, Tuple[Dict[str, int], Dict[str, int]]][source]

Make an ensemble out of a set of models. The ensemble graph can then be used with a predictor, ase graph, or etc.

The selected nodes to ensemble are classed by the db_name associated with the nodes.

When using “auto” mode for inputs and outputs:

  • The input to the ensemble will be the combined inputs for all models in the ensemble.

  • The output of the ensemble will be the combined outputs for all models.

Otherwise, the set of ensemble inputs is explicitly specified, and errors may occur if the requested set of inputs and outputs is not available.

The result ensemble graph has several outputs, each of which has .mean, .std, and .all attributes which reflect the statistics of the models in the ensemble.

Note that it is not required that all models have the same sets of inputs and outputs.

If a desired node is automatically ensembled, it probably does not have a db_name. A remedy for this is to load the graphs with hippynn.graphs.ensemble.get_graphs, then find the requested nodes in the graphs and assign them the db_name. Then pass these graphs to make_ensemble.

For more information on the models parameter, see the get_graphs() function.

Parameters:
  • models – list containing str, node, or graphmodule, or str to glob for model directories.

  • targets – list of db_name strings or the string ‘auto’, which will attempt to infer.

  • inputs – list of db_name strings of the string ‘auto’, which will attempt to infer.

  • prefix – specifies the prefix for the db_name of created ensemble nodes.

  • quiet – whether to print information about the constructed ensemble.

Returns:

ensemble GraphModule, (intput_info, output_info)

make_ensemble_graph(ensemble_inputs: List[InputNode], ensemble_outputs: Dict[str, EnsembleTarget]) GraphModule[source]

Internal function for ensembling.

Put together the ensemble graph.

Parameters:
  • ensemble_inputs

  • ensemble_outputs

Returns:

make_ensemble_info(input_classes: Dict[str, List[_BaseNode]], output_classes: Dict[str, List[_BaseNode]], quiet=False)[source]

Internal function for ensembling.

Count up and print the ensemble variables identified.

Parameters:
  • input_classes

  • output_classes

  • quiet

Returns:

replace_inputs(input_classes: Dict[str, List[_BaseNode]]) List[InputNode][source]

Internal function for ensembling.

Replace all input nodes with the first representative from the class, thereby merging inputs.

Parameters:

input_classes

Returns:

list of new input nodes.