Averaging predictions per atom¶
- metatrain.utils.per_atom.average_by_num_atoms(tensor_map_dict: Dict[str, TensorMap], systems: List[System], per_structure_keys: List[str]) Dict[str, TensorMap][source]¶
Averages a dictionary of
TensorMapobjects by the number of atoms in each system.This function averages by the number of atoms in each system. Targets that are present in
per_structure_keyswill not be averaged.- Parameters:
- Returns:
The dictionary of averaged
TensorMapobjects.- Return type:
- metatrain.utils.per_atom.divide_by_num_atoms(tensor_map: TensorMap, num_atoms: Tensor) TensorMap[source]¶
Takes the average values per atom of a
TensorMap.Since some quantities might already be per atom (e.g., atomic energies or position gradients), this function only divides a block (or gradient block) by the number of atoms if the block’s samples do not contain the “atom” key. In practice, this guarantees the desired behavior for the majority of the cases, including energies, forces, and virials, where the energies and virials should be divided by the number of atoms, while the forces should not.