mlreco.models.layers.gnn.losses.node_kinematics module

class mlreco.models.layers.gnn.losses.node_kinematics.LogRMSE(reduction='none', eps=1e-07)[source]

Bases: torch.nn.modules.loss._Loss

__init__(reduction='none', eps=1e-07)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

reduction: str
forward(inputs, targets)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

__module__ = 'mlreco.models.layers.gnn.losses.node_kinematics'
class mlreco.models.layers.gnn.losses.node_kinematics.BerHuLoss(reduction='none')[source]

Bases: torch.nn.modules.loss._Loss

__init__(reduction='none')[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(inputs, targets)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

__module__ = 'mlreco.models.layers.gnn.losses.node_kinematics'
reduction: str
class mlreco.models.layers.gnn.losses.node_kinematics.NodeKinematicsLoss(loss_config, batch_col=0, coords_col=(1, 4))[source]

Bases: torch.nn.modules.module.Module

Takes the n-features node output of the GNN and optimizes node-wise scores such that the score corresponding to the correct class is maximized. For use in config: model:

name: cluster_gnn modules:

grappa_loss:
node_loss:

name: : type batch_col : <column in the label data that specifies the batch ids of each voxel (default 3)> type_col : <column in the label data that specifies the target node class (default 7)> momentum_col : <column in the label data that specifies the target node momentum (default 8)> loss : <loss function: ‘CE’ or ‘MM’ (default ‘CE’)> reduction : <loss reduction method: ‘mean’ or ‘sum’ (default ‘sum’)> balance_classes : <balance loss per class: True or False (default False)>

__init__(loss_config, batch_col=0, coords_col=(1, 4))[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(out, types)[source]

Applies the requested loss on the node prediction. :param out: ‘node_pred’ (torch.tensor): (C,2) Two-channel node predictions

‘clusts’ ([np.ndarray]) : [(N_0), (N_1), …, (N_C)] Cluster ids

Parameters

types ([torch.tensor]) – (N,9) [x, y, z, batchid, value, id, groupid, pdg, p]

Returns

loss, accuracy, clustering metrics

Return type

double

__module__ = 'mlreco.models.layers.gnn.losses.node_kinematics'
training: bool
class mlreco.models.layers.gnn.losses.node_kinematics.NodeEvidentialKinematicsLoss(loss_config, **kwargs)[source]

Bases: mlreco.models.layers.gnn.losses.node_kinematics.NodeKinematicsLoss

__init__(loss_config, **kwargs)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

__module__ = 'mlreco.models.layers.gnn.losses.node_kinematics'
compute_type(node_pred_type, labels, clusts, iteration)[source]
training: bool
compute_momentum(node_pred_p, labels, clusts, iteration=None)[source]
compute_vertex(node_pred_vtx, labels, clusts)[source]
forward(out, types, iteration=None)[source]

Applies the requested loss on the node prediction.

Parameters
  • out (dict) – ‘node_pred’ (torch.tensor): (C,2) Two-channel node predictions ‘clusts’ ([np.ndarray]) : [(N_0), (N_1), …, (N_C)] Cluster ids

  • types ([torch.tensor]) – (N,9) [x, y, z, batchid, value, id, groupid, pdg, p]

Returns

loss, accuracy, clustering metrics

Return type

double

class mlreco.models.layers.gnn.losses.node_kinematics.NodeTransformerLoss(loss_config, **kwargs)[source]

Bases: mlreco.models.layers.gnn.losses.node_kinematics.NodeEvidentialKinematicsLoss

Vertex Loss Override for Transformer-like vertex net.

__module__ = 'mlreco.models.layers.gnn.losses.node_kinematics'
training: bool
__init__(loss_config, **kwargs)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

compute_type(node_pred_type, labels, clusts, iteration=None)[source]

Compute particle classification type loss.

compute_vertex(node_pred_vtx, labels, clusts)[source]