diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/README.md b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/README.md new file mode 100644 index 000000000000..9e016060d1c8 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/README.md @@ -0,0 +1,201 @@ + + +# Loss functions + +> SGD classification loss functions. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var lossFunctions = require( '@stdlib/ml/base/sgd-classification/loss-functions' ); +``` + +#### lossFunctions() + +Returns a list of SGD classification loss functions. + +```javascript +var out = lossFunctions(); +// e.g., returns [ 'epsilonInsensitive', 'hinge', 'huber', 'log', 'modifiedHuber', 'perceptron', 'squaredEpsilonInsensitive', 'squaredError', 'squaredHinge' ] +``` + +The output array contains the following loss functions: + +- `epsilonInsensitive`: Penalty is the absolute value of the error whenever the absolute error exceeds epsilon and zero otherwise. +- `hinge`: Hinge loss function. Corresponds to a soft-margin linear Support Vector Machine (SVM), which can handle non-linearly separable data. +- `huber`: Squared-error loss for observations with error smaller than epsilon in magnitude, linear loss otherwise. Should be used in order to decrease the influence of outliers on the model fit. +- `log`: Logistic loss function. Corresponds to Logistic Regression. +- `modifiedHuber`: Huber loss function variant for classification. +- `perceptron`: Hinge loss function without a margin. Corresponds to the original perceptron by Rosenblatt (1957). +- `squaredEpsilonInsensitive`: Squared epsilon insensitive loss function. +- `squaredError`: Squared error loss, i.e. the squared difference of the observed and fitted values. +- `squaredHinge`: Squared hinge loss function SVM (L2-SVM). + + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var lossFunction = require( '@stdlib/ml/base/sgd-classification/loss-functions' ); + +var isLossFunction = contains( lossFunction() ); + +var bool = isLossFunction( 'hinge' ); +// returns true + +bool = isLossFunction( 'log' ); +// returns true + +bool = isLossFunction( 'beep' ); +// returns false +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ml/base/sgd-classification/loss_functions.h" +``` + +#### STDLIB_ML_SGD_CLASSIFICATION + +An enumeration of SGD classification loss functions with the following fields: + +- **STDLIB_ML_BASE_SGD_CLASSIFICATION_EPSILON_INSENSITIVE**: Penalty is the absolute value of the error whenever the absolute error exceeds epsilon and zero otherwise. +- **STDLIB_ML_BASE_SGD_CLASSIFICATION_HINGE**: Corresponds to a soft-margin linear Support Vector Machine (SVM), which can handle non-linearly separable data. +- **STDLIB_ML_BASE_SGD_CLASSIFICATION_HUBER**: Squared-error loss for observations with error smaller than epsilon in magnitude, linear loss otherwise. +- **STDLIB_ML_BASE_SGD_CLASSIFICATION_LOG**: Corresponds to Logistic Regression. +- **STDLIB_ML_BASE_SGD_CLASSIFICATION_MODIFIED_HUBER**: Huber loss function variant for classification. +- **STDLIB_ML_BASE_SGD_CLASSIFICATION_PERCEPTRON**: Corresponds to the original perceptron by Rosenblatt (1957). +- **STDLIB_ML_BASE_SGD_CLASSIFICATION_SQUARED_EPSILON_INSENSITIVE**: Squared epsilon insensitive loss function. +- **STDLIB_ML_BASE_SGD_CLASSIFICATION_SQUARED_ERROR**: Squared difference of the observed and fitted values. +- **STDLIB_ML_BASE_SGD_CLASSIFICATION_SQUARED_HINGE**: Squared hinge loss function SVM (L2-SVM). + +```c +#include "stdlib/ml/base/sgd-classification/loss_functions.h" + +const enum STDLIB_ML_SGD_CLASSIFICATION_LOSS_FUNCTIONS v = STDLIB_ML_SGD_CLASSIFICATION_HINGE; +``` + +
+ + + + + +
+ +### Notes + +- Enumeration constants should be considered opaque values, and one should **not** rely on specific integer values. + +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/benchmark/benchmark.js new file mode 100644 index 000000000000..fc9b818bd1cd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/benchmark/benchmark.js @@ -0,0 +1,48 @@ +/** +* @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 isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var pkg = require( './../package.json' ).name; +var lossFunctions = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = lossFunctions(); + if ( out.length < 2 ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isStringArray( out ) ) { + b.fail( 'should return an array of strings' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/docs/repl.txt new file mode 100644 index 000000000000..292ae56bc590 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}() + Returns a list of SGD classification loss functions. + + The output array contains the following loss functions: + + - epsilonInsensitive: Penalty is the absolute value of the error whenever + the absolute error exceeds epsilon and zero otherwise. + - hinge: Hinge loss function. Corresponds to a soft-margin linear Support + Vector Machine (SVM), which can handle non-linearly separable data. + - huber: Squared-error loss for observations with error smaller than epsilon + in magnitude, linear loss otherwise. Should be used in order to decrease the + influence of outliers on the model fit. + - log: Logistic loss function. Corresponds to Logistic Regression. + - modifiedHuber: Huber loss function variant for classification. + - perceptron: Hinge loss function without a margin. Corresponds to the + original perceptron by Rosenblatt (1957). + - squaredEpsilonInsensitive: Squared epsilon insensitive loss function. + - squaredError: Squared error loss, i.e. the squared difference of the + observed and fitted values. + - squaredHinge: Squared hinge loss function SVM (L2-SVM). + + + Returns + ------- + out: Array + List of loss functions. + + Examples + -------- + > var out = {{alias}}() + [...] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/docs/types/index.d.ts new file mode 100644 index 000000000000..c107c17522ef --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/docs/types/index.d.ts @@ -0,0 +1,35 @@ +/* +* @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 + +/** +* Returns a list of SGD classification loss functions. +* +* @returns list of loss functions +* +* @example +* var list = lossFunctions(); +* // e.g., returns [ 'epsilonInsensitive', 'hinge', 'huber', 'log', 'modifiedHuber', 'perceptron', 'squaredEpsilonInsensitive', 'squaredError', 'squaredHinge' ] +*/ +declare function lossFunctions(): Array; + + +// EXPORTS // + +export = lossFunctions; diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/docs/types/test.ts new file mode 100644 index 000000000000..6c51642dacaa --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/docs/types/test.ts @@ -0,0 +1,32 @@ +/* +* @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 lossFunctions = require( './index' ); + + +// TESTS // + +// The function returns an array of strings... +{ + lossFunctions(); // $ExpectType string[] +} + +// The compiler throws an error if the function is provided any arguments... +{ + lossFunctions( 9 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/examples/index.js new file mode 100644 index 000000000000..1fa9e2f61bbf --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/examples/index.js @@ -0,0 +1,36 @@ +/** +* @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'; + +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var lossFunctions = require( './../lib' ); + +var isLossFunction = contains( lossFunctions() ); + +var bool = isLossFunction( 'hinge' ); +console.log( bool ); +// => true + +bool = isLossFunction( 'log' ); +console.log( bool ); +// => true + +bool = isLossFunction( 'beep' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/include/stdlib/ml/base/sgd-classification/loss_functions.h b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/include/stdlib/ml/base/sgd-classification/loss_functions.h new file mode 100644 index 000000000000..2fb7b3fc33ef --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/include/stdlib/ml/base/sgd-classification/loss_functions.h @@ -0,0 +1,54 @@ +/** +* @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. +*/ + +#ifndef STDLIB_ML_BASE_SGD_CLASSIFICATION_LOSS_FUNCTIONS_H +#define STDLIB_ML_BASE_SGD_CLASSIFICATION_LOSS_FUNCTIONS_H + +/** +* Enumeration of SGD classification loss functions. +*/ +enum STDLIB_ML_BASE_SGD_CLASSIFICATION_LOSS_FUNCTIONS { + // Penalty is the absolute value of the error whenever the absolute error exceeds epsilon and zero otherwise: + STDLIB_ML_BASE_SGD_CLASSIFICATION_EPSILON_INSENSITIVE = 0, + + // Corresponds to a soft-margin linear Support Vector Machine (SVM), which can handle non-linearly separable data: + STDLIB_ML_BASE_SGD_CLASSIFICATION_HINGE, + + // Squared-error loss for observations with error smaller than epsilon in magnitude, linear loss otherwise: + STDLIB_ML_BASE_SGD_CLASSIFICATION_HUBER, + + // Corresponds to Logistic Regression: + STDLIB_ML_BASE_SGD_CLASSIFICATION_LOG, + + // Huber loss function variant for classification: + STDLIB_ML_BASE_SGD_CLASSIFICATION_MODIFIED_HUBER, + + // Corresponds to the original perceptron by Rosenblatt (1957): + STDLIB_ML_BASE_SGD_CLASSIFICATION_PERCEPTRON, + + // Squared epsilon insensitive loss function: + STDLIB_ML_BASE_SGD_CLASSIFICATION_SQUARED_EPSILON_INSENSITIVE, + + // Squared difference of the observed and fitted values: + STDLIB_ML_BASE_SGD_CLASSIFICATION_SQUARED_ERROR, + + // Squared hinge loss function SVM (L2-SVM): + STDLIB_ML_BASE_SGD_CLASSIFICATION_SQUARED_HINGE +}; + +#endif // !STDLIB_ML_BASE_SGD_CLASSIFICATION_LOSS_FUNCTIONS_H diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/data.json b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/data.json new file mode 100644 index 000000000000..98f5d1b4148b --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/data.json @@ -0,0 +1,11 @@ +[ + "epsilonInsensitive", + "hinge", + "huber", + "log", + "modifiedHuber", + "perceptron", + "squaredEpsilonInsensitive", + "squaredError", + "squaredHinge" +] diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/enum.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/enum.js new file mode 100644 index 000000000000..c9931875a64f --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/enum.js @@ -0,0 +1,72 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns an object mapping supported loss functions to integer values for purposes of C inter-operation. +* +* ## Notes +* +* - Downstream consumers of this mapping should **not** rely on specific integer values (e.g., `HINGE == 0`). Instead, the object should be used in an opaque manner. +* - The main purpose of this function is JavaScript and C inter-operation. +* +* @returns {Object} object mapping supported loss functions to integer values +* +* @example +* var table = enumerated(); +* // returns +*/ +function enumerated() { + // NOTE: the following should match the C `loss functions.h` enumeration!!!! + return { + // Penalty is the absolute value of the error whenever the absolute error exceeds epsilon and zero otherwise: + 'epsilonInsensitive': 0, + + // Corresponds to a soft-margin linear Support Vector Machine (SVM), which can handle non-linearly separable data: + 'hinge': 1, + + // Squared-error loss for observations with error smaller than epsilon in magnitude, linear loss otherwise: + 'huber': 2, + + // Corresponds to Logistic Regression: + 'log': 3, + + // Huber loss function variant for classification: + 'modifiedHuber': 4, + + // Corresponds to the original perceptron by Rosenblatt (1957): + 'perceptron': 5, + + // Squared epsilon insensitive loss function: + 'squaredEpsilonInsensitive': 6, + + // Squared difference of the observed and fitted values: + 'squaredError': 7, + + // Squared hinge loss function SVM (L2-SVM): + 'squaredHinge': 8 + }; +} + + +// EXPORTS // + +module.exports = enumerated; diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/index.js new file mode 100644 index 000000000000..9445ed9b1243 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/index.js @@ -0,0 +1,47 @@ +/** +* @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'; + +/** +* Return a list of SGD classification loss functions. +* +* @module @stdlib/ml/base/sgd-classification/loss-functions +* +* @example +* var lossFunctions = require( '@stdlib/ml/base/sgd-classification/loss-functions' ); +* +* var list = lossFunctions(); +* // e.g., returns [ 'epsilonInsensitive', 'hinge', 'huber', 'log', 'modifiedHuber', 'perceptron', 'squaredEpsilonInsensitive', 'squaredError', 'squaredHinge' ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var enumeration = require( './enum.js' ); + + +// MAIN // + +setReadOnly( main, 'enum', enumeration ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/main.js new file mode 100644 index 000000000000..225b36bdae0d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/lib/main.js @@ -0,0 +1,44 @@ +/** +* @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 DATA = require( './data.json' ); + + +// MAIN // + +/** +* Returns a list of SGD classification loss functions. +* +* @returns {Array} list of loss functions +* +* @example +* var list = lossFunctions(); +* // e.g., returns [ 'epsilonInsensitive', 'hinge', 'huber', 'log', 'modifiedHuber', 'perceptron', 'squaredEpsilonInsensitive', 'squaredError', 'squaredHinge' ] +*/ +function lossFunctions() { + return DATA.slice(); +} + + +// EXPORTS // + +module.exports = lossFunctions; diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/manifest.json b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/package.json b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/package.json new file mode 100644 index 000000000000..8fb42101d6a1 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ml/base/sgd-classification/loss-functions", + "version": "0.0.0", + "description": "SGD classification loss functions.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "ml", + "machine", + "learning", + "sgd classification", + "loss functions", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/test/test.js new file mode 100644 index 000000000000..217485fd546b --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/loss-functions/test/test.js @@ -0,0 +1,87 @@ +/** +* @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 tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var lossFunctions = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof lossFunctions, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a list of SGD classification loss functions', function test( t ) { + var expected; + var actual; + + expected = [ + 'epsilonInsensitive', + 'hinge', + 'huber', + 'log', + 'modifiedHuber', + 'perceptron', + 'squaredEpsilonInsensitive', + 'squaredError', + 'squaredHinge' + ]; + actual = lossFunctions(); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main function is an `enum` method to return an object mapping loss functions to integer values for C inter-operation', function test( t ) { + var obj; + var o; + var i; + + t.strictEqual( hasOwnProp( lossFunctions, 'enum' ), true, 'has property' ); + t.strictEqual( typeof lossFunctions.enum, 'function', 'has method' ); + + obj = lossFunctions.enum(); + t.strictEqual( typeof obj, 'object', 'returns expected value' ); + + // List of values which should be supported... + o = [ + 'epsilonInsensitive', + 'hinge', + 'huber', + 'log', + 'modifiedHuber', + 'perceptron', + 'squaredEpsilonInsensitive', + 'squaredError', + 'squaredHinge' + ]; + for ( i = 0; i < o.length; i++ ) { + t.strictEqual( hasOwnProp( obj, o[ i ] ), true, 'has property `' + o[ i ] + '`' ); + t.strictEqual( isNonNegativeInteger( obj[ o[i] ] ), true, 'returns expected value' ); + } + + t.end(); +});