Compute the hinge loss between two double-precision floating-point number.
var hinge = require( '@stdlib/ml/base/loss/float64/hinge' );Computes the hinge loss between two double-precision floating-point number.
var v = hinge( 1.0, 0.782 );
// returns ~0.218
v = hinge( 1.0, -0.9 );
// returns 1.9If either argument is NaN, the function returns NaN.
var g = hinge( NaN, 12.0 );
// returns NaN
g = hinge( 5.0, NaN );
// returns NaNIf y is not +1 or -1, the function returns NaN.
var g = hinge( 2.3, 1.0 );
// returns NaN
g = hinge( -1.3, 0.987 );
// returns NaNvar uniform = require( '@stdlib/random/array/uniform' );
var sample = require( '@stdlib/random/sample' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var hinge = require( '@stdlib/ml/base/loss/float64/hinge' );
var y = sample( [ -1.0, 1.0 ], {
'size': 100
});
var p = uniform( 100, -5.0, 5.0, {
'dtype': 'float64'
});
logEachMap( 'hinge(%0.4f, %0.4f) = %0.4f', y, p, hinge );#include "stdlib/ml/base/loss/float64/hinge.h"Computes the hinge loss between two double-precision floating-point number.
double out = stdlib_base_float64_hinge( 1.0, 0.782 );
// returns ~0.218The function accepts the following arguments:
- y:
[in] doubletrue target value. - p:
[in] doublepredicted value.
double stdlib_base_float64_hinge( const double y, const double p );#include "stdlib/ml/base/loss/float64/hinge.h"
#include <stdio.h>
int main( void ) {
const double y[] = { -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
const double p[] = { -5.0, -3.89, -2.78, -1.67, -0.56, 0.56, 1.67, 2.78, 3.89, 5.0 };
double v;
int i;
for ( i = 0; i < 10; i++ ) {
v = stdlib_base_float64_hinge( y[ i ], p[ i ] );
printf( "hinge(%lf, %lf) = %lf\n", y[ i ], p[ i ], v );
}
}