From 73e7e4ed220a88e2c928880c24b9531b0bcdb563 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 23 Jul 2026 15:43:11 +0530 Subject: [PATCH 1/2] feat: add `ml/base/sgd-classification/penalties` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../sgd-classification/penalties/README.md | 188 ++++++++++++++++++ .../penalties/benchmark/benchmark.js | 48 +++++ .../penalties/docs/repl.txt | 27 +++ .../penalties/docs/types/index.d.ts | 35 ++++ .../penalties/docs/types/test.ts | 32 +++ .../penalties/examples/index.js | 36 ++++ .../ml/base/sgd-classification/penalties.h | 36 ++++ .../penalties/lib/data.json | 5 + .../sgd-classification/penalties/lib/enum.js | 54 +++++ .../sgd-classification/penalties/lib/index.js | 47 +++++ .../sgd-classification/penalties/lib/main.js | 44 ++++ .../penalties/manifest.json | 36 ++++ .../sgd-classification/penalties/package.json | 66 ++++++ .../sgd-classification/penalties/test/test.js | 75 +++++++ 14 files changed, 729 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/include/stdlib/ml/base/sgd-classification/penalties.h create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/data.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/enum.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/manifest.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/README.md b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/README.md new file mode 100644 index 000000000000..42470c781c0c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/README.md @@ -0,0 +1,188 @@ + + +# Penalties + +> SGD classification penalties. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var penalties = require( '@stdlib/ml/base/sgd-classification/penalties' ); +``` + +#### penalties() + +Returns a list of SGD classification penalties. + +```javascript +var out = penalties(); +// e.g., returns [ 'elasticnet', 'l1', 'l2' ] +``` + +The output array contains the following penalties: + +- `elasticnet`: regularization method that linearly combines the `L1` and `L2` penalties of the lasso and ridge methods. +- `l1`: L1 regularization (also called LASSO) leads to sparse models by adding a penalty based on the absolute value of coefficients. +- `l2`: L2 regularization (also called ridge regression) encourages smaller, more evenly distributed weights by adding a penalty based on the square of the coefficients. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var penalties = require( '@stdlib/ml/base/sgd-classification/penalties' ); + +var isPenalty = contains( penalties() ); + +var bool = isPenalty( 'l1' ); +// returns true + +bool = isPenalty( 'l2' ); +// returns true + +bool = isPenalty( 'beep' ); +// returns false +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ml/base/sgd-classification/penalties.h" +``` + +#### STDLIB_ML_SGD_CLASSIFICATION_PENALTY + +An enumeration of SGD classification penalties with the following fields: + +- **STDLIB_ML_SGD_CLASSIFICATION_ELASTICNET**: regularization method that linearly combines the `L1` and `L2` penalties of the lasso and ridge methods. +- **STDLIB_ML_SGD_CLASSIFICATION_L1**: L1 regularization (also called LASSO) leads to sparse models by adding a penalty based on the absolute value of coefficients. +- **STDLIB_ML_SGD_CLASSIFICATION_L2**: L2 regularization (also called ridge regression) encourages smaller, more evenly distributed weights by adding a penalty based on the square of the coefficients. + +```c +#include "stdlib/ml/base/sgd-classification/penalties.h" + +const enum STDLIB_ML_SGD_CLASSIFICATION_PENALTY v = STDLIB_ML_SGD_CLASSIFICATION_ELASTICNET; +``` + +
+ + + + + +
+ +### 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/penalties/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/benchmark/benchmark.js new file mode 100644 index 000000000000..a279d0987452 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/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 penalties = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = penalties(); + 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/penalties/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/repl.txt new file mode 100644 index 000000000000..d63e45751a0b --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/repl.txt @@ -0,0 +1,27 @@ + +{{alias}}() + Returns a list of SGD classification penalties. + + The output array contains the following penalties: + + - elasticnet: regularization method that linearly combines the `L1` and `L2` + penalties of the lasso and ridge methods. + - l1: L1 regularization (also called LASSO) leads to sparse models by adding + a penalty based on the absolute value of coefficients. + - l2: L2 regularization (also called ridge regression) encourages smaller, + more evenly distributed weights by adding a penalty based on the square of + the coefficients. + + Returns + ------- + out: Array + List of penalties. + + Examples + -------- + > var out = {{alias}}() + [...] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/types/index.d.ts new file mode 100644 index 000000000000..91661323d389 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/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 penalties. +* +* @returns list of penalties +* +* @example +* var list = penalties(); +* // e.g., returns [ 'elasticnet', 'l1', 'l2' ] +*/ +declare function penalties(): Array; + + +// EXPORTS // + +export = penalties; diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/types/test.ts new file mode 100644 index 000000000000..c536e7fc758d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/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 penalties = require( './index' ); + + +// TESTS // + +// The function returns an array of strings... +{ + penalties(); // $ExpectType string[] +} + +// The compiler throws an error if the function is provided any arguments... +{ + penalties( 9 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/examples/index.js new file mode 100644 index 000000000000..5d65a24f81e0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/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 penalties = require( './../lib' ); + +var isPenalty = contains( penalties() ); + +var bool = isPenalty( 'elasticnet' ); +console.log( bool ); +// => true + +bool = isPenalty( 'l1' ); +console.log( bool ); +// => true + +bool = isPenalty( 'beep' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/include/stdlib/ml/base/sgd-classification/penalties.h b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/include/stdlib/ml/base/sgd-classification/penalties.h new file mode 100644 index 000000000000..75b2eae39abd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/include/stdlib/ml/base/sgd-classification/penalties.h @@ -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. +*/ + +#ifndef STDLIB_ML_BASE_SGD_CLASSIFICATION_PENALTIES_H +#define STDLIB_ML_BASE_SGD_CLASSIFICATION_PENALTIES_H + +/** +* Enumeration of SGD classification penalties. +*/ +enum STDLIB_ML_SGD_CLASSIFICATION_PENALTY { + // Regularization method that linearly combines the `L1` and `L2` penalties of the lasso and ridge methods: + STDLIB_ML_SGD_CLASSIFICATION_ELASTICNET = 0, + + // L1 regularization (also called LASSO) leads to sparse models by adding a penalty based on the absolute value of coefficients: + STDLIB_ML_SGD_CLASSIFICATION_L1, + + // L2 regularization (also called ridge regression) encourages smaller, more evenly distributed weights by adding a penalty based on the square of the coefficients: + STDLIB_ML_SGD_CLASSIFICATION_L2 +}; + +#endif // !STDLIB_ML_BASE_SGD_CLASSIFICATION_PENALTIES_H diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/data.json b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/data.json new file mode 100644 index 000000000000..fc80f4120168 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/data.json @@ -0,0 +1,5 @@ +[ + "elasticnet", + "l1", + "l2" +] diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/enum.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/enum.js new file mode 100644 index 000000000000..4b6cfa26e85c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/enum.js @@ -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. +*/ + +'use strict'; + +// MAIN // + +/** +* Returns an object mapping supported penalties to integer values for purposes of C inter-operation. +* +* ## Notes +* +* - Downstream consumers of this mapping should **not** rely on specific integer values (e.g., `ELASTICNET == 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 penalties to integer values +* +* @example +* var table = enumerated(); +* // returns +*/ +function enumerated() { + // NOTE: the following should match the C `penalties.h` enumeration!!!! + return { + // Regularization method that linearly combines the `L1` and `L2` penalties of the lasso and ridge methods: + 'elasticnet': 0, + + // L1 regularization (also called LASSO) leads to sparse models by adding a penalty based on the absolute value of coefficients: + 'l1': 1, + + // L2 regularization (also called ridge regression) encourages smaller, more evenly distributed weights by adding a penalty based on the square of the coefficients: + 'l2': 2 + }; +} + + +// EXPORTS // + +module.exports = enumerated; diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/index.js new file mode 100644 index 000000000000..df720b00907b --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/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 penalties. +* +* @module @stdlib/ml/base/sgd-classification/penalties +* +* @example +* var penalties = require( '@stdlib/ml/base/sgd-classification/penalties' ); +* +* var list = penalties(); +* // e.g., returns [ 'elasticnet', 'l1', 'l2' ] +*/ + +// 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/penalties/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/main.js new file mode 100644 index 000000000000..8792f4913113 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/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 penalties. +* +* @returns {Array} list of penalties +* +* @example +* var list = penalties(); +* // e.g., returns [ 'elasticnet', 'l1', 'l2' ] +*/ +function penalties() { + return DATA.slice(); +} + + +// EXPORTS // + +module.exports = penalties; diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/manifest.json b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/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/penalties/package.json b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/package.json new file mode 100644 index 000000000000..3d3ec63623f8 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ml/base/sgd-classification/penalties", + "version": "0.0.0", + "description": "SGD classification penalties.", + "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", + "penalties", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/test/test.js new file mode 100644 index 000000000000..bbec477342e0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/test/test.js @@ -0,0 +1,75 @@ +/** +* @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 penalties = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof penalties, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a list of SGD classification penalties', function test( t ) { + var expected; + var actual; + + expected = [ + 'elasticnet', + 'l1', + 'l2' + ]; + actual = penalties(); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main function is an `enum` method to return an object mapping penalties to integer values for C inter-operation', function test( t ) { + var obj; + var o; + var i; + + t.strictEqual( hasOwnProp( penalties, 'enum' ), true, 'has property' ); + t.strictEqual( typeof penalties.enum, 'function', 'has method' ); + + obj = penalties.enum(); + t.strictEqual( typeof obj, 'object', 'returns expected value' ); + + // List of values which should be supported... + o = [ + 'elasticnet', + 'l1', + 'l2' + ]; + 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(); +}); From 74b9c3509e1e918aaf527608b8f8a4bf0802d85c Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 23 Jul 2026 21:07:08 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/ml/base/sgd-classification/penalties/README.md | 4 ++-- .../ml/base/sgd-classification/penalties/docs/repl.txt | 2 +- .../include/stdlib/ml/base/sgd-classification/penalties.h | 2 +- .../@stdlib/ml/base/sgd-classification/penalties/lib/enum.js | 2 +- .../@stdlib/ml/base/sgd-classification/penalties/package.json | 3 ++- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/README.md b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/README.md index 42470c781c0c..1a5ff6f38301 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/README.md @@ -51,7 +51,7 @@ var out = penalties(); The output array contains the following penalties: -- `elasticnet`: regularization method that linearly combines the `L1` and `L2` penalties of the lasso and ridge methods. +- `elasticnet`: regularization method that linearly combines the L1 and L2 penalties of the lasso and ridge methods. - `l1`: L1 regularization (also called LASSO) leads to sparse models by adding a penalty based on the absolute value of coefficients. - `l2`: L2 regularization (also called ridge regression) encourages smaller, more evenly distributed weights by adding a penalty based on the square of the coefficients. @@ -125,7 +125,7 @@ bool = isPenalty( 'beep' ); An enumeration of SGD classification penalties with the following fields: -- **STDLIB_ML_SGD_CLASSIFICATION_ELASTICNET**: regularization method that linearly combines the `L1` and `L2` penalties of the lasso and ridge methods. +- **STDLIB_ML_SGD_CLASSIFICATION_ELASTICNET**: regularization method that linearly combines the L1 and L2 penalties of the lasso and ridge methods. - **STDLIB_ML_SGD_CLASSIFICATION_L1**: L1 regularization (also called LASSO) leads to sparse models by adding a penalty based on the absolute value of coefficients. - **STDLIB_ML_SGD_CLASSIFICATION_L2**: L2 regularization (also called ridge regression) encourages smaller, more evenly distributed weights by adding a penalty based on the square of the coefficients. diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/repl.txt index d63e45751a0b..e10bf6c27f1f 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/repl.txt +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/docs/repl.txt @@ -4,7 +4,7 @@ The output array contains the following penalties: - - elasticnet: regularization method that linearly combines the `L1` and `L2` + - elasticnet: regularization method that linearly combines the L1 and L2 penalties of the lasso and ridge methods. - l1: L1 regularization (also called LASSO) leads to sparse models by adding a penalty based on the absolute value of coefficients. diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/include/stdlib/ml/base/sgd-classification/penalties.h b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/include/stdlib/ml/base/sgd-classification/penalties.h index 75b2eae39abd..bcc858d31951 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/include/stdlib/ml/base/sgd-classification/penalties.h +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/include/stdlib/ml/base/sgd-classification/penalties.h @@ -23,7 +23,7 @@ * Enumeration of SGD classification penalties. */ enum STDLIB_ML_SGD_CLASSIFICATION_PENALTY { - // Regularization method that linearly combines the `L1` and `L2` penalties of the lasso and ridge methods: + // Regularization method that linearly combines the L1 and L2 penalties of the lasso and ridge methods: STDLIB_ML_SGD_CLASSIFICATION_ELASTICNET = 0, // L1 regularization (also called LASSO) leads to sparse models by adding a penalty based on the absolute value of coefficients: diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/enum.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/enum.js index 4b6cfa26e85c..09b73316ab5c 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/enum.js +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/lib/enum.js @@ -37,7 +37,7 @@ function enumerated() { // NOTE: the following should match the C `penalties.h` enumeration!!!! return { - // Regularization method that linearly combines the `L1` and `L2` penalties of the lasso and ridge methods: + // Regularization method that linearly combines the L1 and L2 penalties of the lasso and ridge methods: 'elasticnet': 0, // L1 regularization (also called LASSO) leads to sparse models by adding a penalty based on the absolute value of coefficients: diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/package.json b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/package.json index 3d3ec63623f8..057f5c45e57b 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/package.json +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/penalties/package.json @@ -54,7 +54,8 @@ "ml", "machine", "learning", - "sgd classification", + "sgd", + "classification", "penalties", "utilities", "utility",