Loss functions and gradients
Loss function
MSE
MSE (x:numpy.ndarray, y:numpy.ndarray, fun:<built-infunctioncallable>, params=None)
Given the data \(x\) and \(y\), this function computes the mean square error between \(y\) and \(y'=f(x)\)
Type | Default | Details | |
---|---|---|---|
x | ndarray | x data of N elements | |
y | ndarray | y data of N elements | |
fun | callable | function \(y=f(x)\) | |
params | NoneType | None | Parameters of the function in the form of a dictionary |
Returns | float |
The mean square error is defined as \[ MSE(y,y')=\frac{1}{N}\sum_{i=1}^{N}(y'_i-y_i)^2.\]
grad_MSE_lr
grad_MSE_lr (x:numpy.ndarray, y:numpy.ndarray, params:dict)
Computes the gradient of the mean square error loss function with respect to \(a\) and \(b\) and returns np.array([\(\partial_a\) MSE,\(\partial_b\) MSE])
Type | Details | |
---|---|---|
x | ndarray | x data of N elements |
y | ndarray | y data of N elements |
params | dict | Parameters of the function |
Returns | ndarray | gradients |
grad_MSE_pr
grad_MSE_pr (x:numpy.ndarray, y:numpy.ndarray, params:dict)
Computes the gradient of the mean square error loss function with respect to \(a\) and \(b\) and returns np.array([\(\partial_a\) MSE,\(\partial_b\) MSE])
Type | Details | |
---|---|---|
x | ndarray | x data of N elements |
y | ndarray | y data of N elements |
params | dict | parameters of the function |
Returns | ndarray | gradients |
BCE
BCE (x:numpy.ndarray, y:numpy.ndarray, fun:<built-infunctioncallable>, params:dict)
Given the data \(x\) and \(y\), this function computes the mean binary cross entropy \(y\) and \(y'=f(x)\)
Type | Details | |
---|---|---|
x | ndarray | x data of N elements |
y | ndarray | y data of N elements |
fun | callable | function \(y=f(x)\) |
params | dict | Parameters of the function |
Returns | float |
grad_BCE
grad_BCE (x:numpy.ndarray, y:numpy.ndarray, params:dict)
Computes the gradient of the binary cross entropy loss function with respect to \(a\) and \(b\) and returns np.array([\(\partial_a\) BCE,\(\partial_b\) BCE])
Type | Details | |
---|---|---|
x | ndarray | x data of N elements |
y | ndarray | y data of N elements |
params | dict | Parameters of the function |
Returns | ndarray | gradients |
L_per
L_per (x:numpy.ndarray, y:numpy.ndarray, fun:<built-infunctioncallable>, params:dict)
Given the data \(x\) and \(y\), this function computes the Loss of the perceptron algorithm
Type | Details | |
---|---|---|
x | ndarray | x data of N elements |
y | ndarray | y data of N elements |
fun | callable | function \(y=f(x)\) |
params | dict | Parameters of the function |
Returns | float |
grad_per
grad_per (x:numpy.ndarray, y:numpy.ndarray, params:dict)
Computes the gradient of the perceptron loss function and returns np.array(grad_w)
Type | Details | |
---|---|---|
x | ndarray | x data of N elements |
y | ndarray | y data of N elements |
params | dict | Parameters of the function |
Returns | ndarray | gradients |