OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
error_utilities.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// E R R O R U T I L I T I E S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#pragma once
10
11#include "tensor_utilities.h"
12
13namespace opennn
14{
15
21void mean_squared_error(const TensorView& input, const TensorView& target, float& error, float* workspace_device);
26void mean_squared_error_gradient(const TensorView& input, const TensorView& target, const TensorView& input_delta);
27
34void normalized_squared_error(const TensorView& input, const TensorView& target, float coefficient, float& error, float* workspace_device);
36void normalized_squared_error_gradient(const TensorView& input, const TensorView& target, float coefficient, const TensorView& input_delta);
37
45void weighted_squared_error(const TensorView& input, const TensorView& target, float pos_w, float neg_w, float& error, float* workspace_device);
47void weighted_squared_error_gradient(const TensorView& input, const TensorView& target, float pos_w, float neg_w, float coefficient, const TensorView& input_delta);
48
50void binary_cross_entropy(const TensorView& input, const TensorView& target, float& error, float* workspace_device);
52void categorical_cross_entropy(const TensorView& input, const TensorView& target, float& error, float* workspace_device);
54void cross_entropy_gradient(const TensorView& input, const TensorView& target, const TensorView& input_delta);
55
57void minkowski_error(const TensorView& input, const TensorView& target, float power, float& error, float* workspace_device);
59void minkowski_error_gradient(const TensorView& input, const TensorView& target, float power, const TensorView& input_delta);
60
68void cross_entropy_3d(const TensorView& input, const TensorView& target, float& error, Index& active_tokens_out, Index& correct_tokens_out, float* errors_device = nullptr);
70void cross_entropy_3d_gradient(const TensorView& input, const TensorView& target, const TensorView& input_delta, Index active_tokens_count);
72void cross_entropy_3d_gradient_device_count(const TensorView& input, const TensorView& target, const TensorView& input_delta, const float* active_tokens_count_device);
73
75void l1_regularization(const TensorView& parameters, float lambda, float& penalty);
77void l1_regularization_gradient(const TensorView& parameters, float lambda, const TensorView& gradient);
78
80void l2_regularization(const TensorView& parameters, float lambda, float& penalty);
82void l2_regularization_gradient(const TensorView& parameters, float lambda, const TensorView& gradient);
83
84}
85
86// OpenNN: Open Neural Networks Library.
87// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
88// Licensed under the GNU Lesser General Public License v2.1 or later.
Definition adaptive_moment_estimation.h:14
void categorical_cross_entropy(const TensorView &input, const TensorView &target, float &error, float *workspace_device)
Computes the multi-class (categorical) cross-entropy between softmax probabilities and one-hot target...
void minkowski_error(const TensorView &input, const TensorView &target, float power, float &error, float *workspace_device)
Computes the Minkowski error sum(|input - target|^power) for the given power exponent.
void minkowski_error_gradient(const TensorView &input, const TensorView &target, float power, const TensorView &input_delta)
Writes the Minkowski-error gradient with respect to the predictions into input_delta.
void mean_squared_error_gradient(const TensorView &input, const TensorView &target, const TensorView &input_delta)
Writes the MSE gradient with respect to the predictions into input_delta.
void mean_squared_error(const TensorView &input, const TensorView &target, float &error, float *workspace_device)
Computes the mean squared error between predictions and targets.
void normalized_squared_error_gradient(const TensorView &input, const TensorView &target, float coefficient, const TensorView &input_delta)
Writes the normalized-squared-error gradient with respect to the predictions into input_delta.
void cross_entropy_3d(const TensorView &input, const TensorView &target, float &error, Index &active_tokens_out, Index &correct_tokens_out, float *errors_device=nullptr)
Computes 3-D (sequence) cross-entropy used by transformer-style targets, ignoring padded positions.
void l2_regularization_gradient(const TensorView &parameters, float lambda, const TensorView &gradient)
Adds the L2 regularization gradient 2 * lambda * parameters into the gradient tensor.
void weighted_squared_error_gradient(const TensorView &input, const TensorView &target, float pos_w, float neg_w, float coefficient, const TensorView &input_delta)
Writes the gradient of the weighted squared error scaled by coefficient into input_delta.
void weighted_squared_error(const TensorView &input, const TensorView &target, float pos_w, float neg_w, float &error, float *workspace_device)
Computes the binary squared error weighted asymmetrically for positive and negative classes.
void cross_entropy_gradient(const TensorView &input, const TensorView &target, const TensorView &input_delta)
Writes the cross-entropy gradient with respect to the (pre-softmax/logit) predictions into input_delt...
void binary_cross_entropy(const TensorView &input, const TensorView &target, float &error, float *workspace_device)
Computes the binary cross-entropy between predicted probabilities and binary targets.
void cross_entropy_3d_gradient_device_count(const TensorView &input, const TensorView &target, const TensorView &input_delta, const float *active_tokens_count_device)
Variant of cross_entropy_3d_gradient that reads the active-token count from device memory.
void l2_regularization(const TensorView &parameters, float lambda, float &penalty)
Computes the L2 regularization penalty lambda * sum(parameters^2).
void l1_regularization_gradient(const TensorView &parameters, float lambda, const TensorView &gradient)
Adds the L1 regularization gradient lambda * sign(parameters) into the gradient tensor.
void normalized_squared_error(const TensorView &input, const TensorView &target, float coefficient, float &error, float *workspace_device)
Computes the squared error normalized by a dataset-level coefficient.
void cross_entropy_3d_gradient(const TensorView &input, const TensorView &target, const TensorView &input_delta, Index active_tokens_count)
Writes the 3-D cross-entropy gradient into input_delta, normalizing by the host-side active-token cou...
void l1_regularization(const TensorView &parameters, float lambda, float &penalty)
Computes the L1 regularization penalty lambda * sum(|parameters|).
Non-owning view over a tensor: pointer, shape, and data type with rich reshape helpers.
Definition tensor_utilities.h:293