Metrics#
- tn4ml.metrics.NegLogLikelihood(model, data)[source][source]#
Negative Log-Likelihood loss.
- Parameters:
model (
quimb.tensor.MatrixProductState) – Matrix Product State modeldata (
quimb.tensor.MatrixProductState) – Input MPS
- Return type:
float
- tn4ml.metrics.TransformedSquaredNorm(model, data)[source][source]#
Squared norm of transformed input data.
- Parameters:
model (
tn4ml.models.smpo.SpacedMatrixProductOperator) – Spaced Matrix Product Operatordata (
quimb.tensor.MatrixProductState) – Input mps.
- Return type:
float
- tn4ml.metrics.LogFrobNorm(model)[source][source]#
Regularization cost - log(Frobenius-norm of model)
- Parameters:
model (
quimb.tensor.MatrixProductState) – Matrix Product State model- Return type:
float
- tn4ml.metrics.LogPowFrobNorm(model)[source][source]#
Regularization cost - log(squared(Frobenius-norm of model))
- Parameters:
model (
quimb.tensor.MatrixProductState) – Matrix Product State model- Return type:
float
- tn4ml.metrics.LogReLUFrobNorm(model)[source][source]#
Regularization cost using ReLU of the log of the Frobenius-norm of model.
- Parameters:
model (
tn4ml.models.smpo.SpacedMatrixProductOperator) – Spaced Matrix Product Operator- Return type:
float
- tn4ml.metrics.QuadFrobNorm(model)[source][source]#
Regularization cost using the quadratic formula centered in 1 of the Frobenius-norm of model.
- Parameters:
model (
tn4ml.models.smpo.SpacedMatrixProductOperator) – Spaced Matrix Product Operator- Return type:
float
- tn4ml.metrics.LogQuadNorm(model, data)[source][source]#
Example of error calculation when applying
tn4ml.models.smpo.SpacedMatrixProductOperatorP to data.- Parameters:
model (
tn4ml.models.smpo.SpacedMatrixProductOperator) – Spaced Matrix Product Operatordata (
quimb.tensor.MatrixProductState) – Input mps.
- Return type:
float
- tn4ml.metrics.QuadNorm(model, data)[source][source]#
Example of error calculation when applying
tn4ml.models.smpo.SpacedMatrixProductOperatorP to data.- Parameters:
model (
tn4ml.models.smpo.SpacedMatrixProductOperator) – Spaced Matrix Product Operatordata (
quimb.tensor.MatrixProductState) – Input mps.
- Return type:
float
- tn4ml.metrics.SemiSupervisedLoss(model, data, y_true, **kwargs)[source][source]#
Loss function for semi-supervised learning.
- Parameters:
model (
tn4ml.models.smpo.SpacedMatrixProductOperator) – Spaced Matrix Product Operatordata (
quimb.tensor.MatrixProductState) – Input Matrix Product Statey_true (
Number) – Target class percentage.
- Return type:
float
- tn4ml.metrics.SemiSupervisedNLL(model, data, y_true=None, **kwargs)[source][source]#
Loss function for semi-supervised learning.
- Parameters:
model (
tn4ml.models.smpo.SpacedMatrixProductOperator) – Spaced Matrix Product Operatordata (
quimb.tensor.MatrixProductState) – Input Matrix Product Statey_true (
Number) – Target class percentage.
- Return type:
float
- tn4ml.metrics.Softmax(z, position)[source][source]#
Softmax function.
- Parameters:
z (
jnp.array`) – Predicted probabilities.position (int) – Indicates for which class we are calculating softmax value.
- Return type:
float
- tn4ml.metrics.CrossEntropySoftmax(model, data, targets)[source][source]#
Cross-entropy loss function for supervised learning.
- Parameters:
model (
tn4ml.models.smpo.SpacedMatrixProductOperator) – Spaced Matrix Product Operatordata (
quimb.tensor.MatrixProductState) – Input Matrix Product Statetargets (
numpy.ndarray) – Target class vector. Example = [1 0 0 0] for n_classes = 4.
- Return type:
float
- tn4ml.metrics.MeanSquaredError(model, data, targets)[source][source]#
Mean Squared Error loss function for supervised learning.
- Parameters:
model (
tn4ml.models.smpo.SpacedMatrixProductOperator) – Spaced Matrix Product Operatordata (
quimb.tensor.MatrixProductState) – Input Matrix Product Statetargets (
numpy.ndarray) – Target class vector. Example = [1 0 0 0] for n_classes = 4.
- Return type:
float
- tn4ml.metrics.OptaxWrapper(optax_loss=None)[source][source]#
Wrapper around optax loss functions for supervised learning. Make sure you got all inputs to loss function correct. Refer to documentation for each loss to https://optax.readthedocs.io/en/latest/api/losses.html . Make sure SMPO has only one output with dimension = number of classes.
- Parameters:
model (
tn4ml.models.model.Model) – Tensor Network model.data (
quimb.tensor.MatrixProductState) – Input Matrix Product Statey_true (
numpy.ndarray) – Target class vector. Example = [1 0 0 0] for n_classes = 4.kwargs (dict) – Additional arguments for optax loss function.
- Return type:
float
- tn4ml.metrics.CrossEntropyWeighted(class_weights=None)[source][source]#
- Parameters:
class_weights (array)
- Return type:
Callable
- tn4ml.metrics.CombinedLoss(model, data, y_true=None, error=<function LogQuadNorm>, reg=<function NoReg>, embedding=None)[source][source]#
Unified Loss function combining error computation and regularization.
- Parameters:
model (
tn4ml.models.Model) – Tensor Network with parametrized tensors.data (Union[
qtn.MatrixProductState,numpy.ndarray]) – Data used for computing the loss value.y_true (Optional[
jnp.array]) – True labels for supervised learning tasks (only applicable for MatrixProductState data).error (function) – Function for error calculation.
reg (function) – Function for regularization value calculation.
embedding (
tn4ml.embeddings.Embedding, optional) – Data embedding function.
- Returns:
Computed loss value.
- Return type:
float