Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# isClassificationLossFn

> Test if an input value is a supported classification loss function.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var isClassificationLossFn = require( '@stdlib/ml/base/sgd/assert/is-classification-loss-function' );
```

#### isClassificationLossFn( value )

Tests if an input `value` is a supported classification loss function.

```javascript
var bool = isClassificationLossFn( 'hinge' );
// returns true

bool = isClassificationLossFn( 'perceptron' );
// returns true
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var isClassificationLossFn = require( '@stdlib/ml/base/sgd/assert/is-classification-loss-function' );

var bool = isClassificationLossFn( 'epsilon-insensitive' );
// returns true

bool = isClassificationLossFn( 'hinge' );
// returns true

bool = isClassificationLossFn( 'huber' );
// returns true

bool = isClassificationLossFn( 'log' );
// returns true

bool = isClassificationLossFn( 'modified-huber' );
// returns true

bool = isClassificationLossFn( 'perceptron' );
// returns true

bool = isClassificationLossFn( 'squared-epsilon-insensitive' );
// returns true

bool = isClassificationLossFn( 'squared-error' );
// returns true

bool = isClassificationLossFn( 'squared-hinge' );
// returns true

bool = isClassificationLossFn( '' );
// returns false

bool = isClassificationLossFn( 'foo' );
// returns false
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isClassificationLossFn = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var out;
var v;
var i;

values = [
'epsilon-insensitive',
'hinge',
'huber',
'log',
'modified-huber',
'perceptron',
'squared-epsilon-insensitive',
'squared-error',
'squared-hinge'
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = values[ i%values.length ];
out = isClassificationLossFn( v );
if ( typeof out !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( out ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

{{alias}}( value )
Tests if an input value is a supported classification loss function.

Parameters
----------
value: any
Value to test.

Returns
-------
bool: boolean
Boolean indicating if an input value is a supported classification loss
function.

Examples
--------
> var bool = {{alias}}( 'epsilon-insensitive' )
true
> bool = {{alias}}( 'hinge' )
true
> bool = {{alias}}( 'huber' )
true
> bool = {{alias}}( 'log' )
true
> bool = {{alias}}( 'modified-huber' )
true
> bool = {{alias}}( 'perceptron' )
true
> bool = {{alias}}( 'squared-epsilon-insensitive' )
true
> bool = {{alias}}( 'squared-error' )
true
> bool = {{alias}}( 'squared-hinge' )
true
> bool = {{alias}}( '' )
false
> bool = {{alias}}( 'beep' )
false

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 4.1

/**
* Tests whether an input value is a supported classification loss function.
*
* @param v - value to test
* @returns boolean indicating whether an input value is a supported classification loss function
*
* @example
* var bool = isClassificationLossFn( 'epsilon-insensitive' );
* // returns true
*
* bool = isClassificationLossFn( 'hinge' );
* // returns true
*
* bool = isClassificationLossFn( 'huber' );
* // returns true
*
* bool = isClassificationLossFn( 'log' );
* // returns true
*
* bool = isClassificationLossFn( 'modified-huber' );
* // returns true
*
* bool = isClassificationLossFn( 'perceptron' );
* // returns true
*
* bool = isClassificationLossFn( 'squared-epsilon-insensitive' );
* // returns true
*
* bool = isClassificationLossFn( 'squared-error' );
* // returns true
*
* bool = isClassificationLossFn( 'squared-hinge' );
* // returns true
*
* bool = isClassificationLossFn( 'foo' );
* // returns false
*/
declare function isClassificationLossFn( v: any ): boolean;

Check warning on line 58 in lib/node_modules/@stdlib/ml/base/sgd/assert/is-classification-loss-function/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type


// EXPORTS //

export = isClassificationLossFn;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import isClassificationLossFn = require( './index' );


// TESTS //

// The function returns a boolean...
{
isClassificationLossFn( 'squared-epsilon-insensitive' ); // $ExpectType boolean
isClassificationLossFn( 'foo' ); // $ExpectType boolean
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isClassificationLossFn(); // $ExpectError
isClassificationLossFn( undefined, 123 ); // $ExpectError
}
Loading