From 21beeb829e783ae3d846d0db54f83e8c0a0f7789 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Wed, 8 Jul 2026 20:33:58 +0530 Subject: [PATCH 1/2] feat: add `ml/base/sgd-classification/learning-rates` --- 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 --- --- .../learning-rates/README.md | 190 ++++++++++++++++++ .../learning-rates/benchmark/benchmark.js | 48 +++++ .../learning-rates/docs/repl.txt | 31 +++ .../learning-rates/docs/types/index.d.ts | 35 ++++ .../learning-rates/docs/types/test.ts | 32 +++ .../learning-rates/examples/index.js | 36 ++++ .../base/sgd-classification/learning_rates.h | 39 ++++ .../learning-rates/lib/data.json | 6 + .../learning-rates/lib/enum.js | 57 ++++++ .../learning-rates/lib/index.js | 47 +++++ .../learning-rates/lib/main.js | 44 ++++ .../learning-rates/manifest.json | 36 ++++ .../learning-rates/package.json | 67 ++++++ .../learning-rates/test/test.js | 77 +++++++ 14 files changed, 745 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/include/stdlib/ml/base/sgd-classification/learning_rates.h create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/data.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/enum.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/manifest.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/README.md b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/README.md new file mode 100644 index 000000000000..3bc7b9220a57 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/README.md @@ -0,0 +1,190 @@ + + +# Learning rates + +> SGD classification learning rate schedulers. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var learningRates = require( '@stdlib/ml/base/sgd-classification/learning-rates' ); +``` + +#### learningRates() + +Returns a list of SGD classification learning rate schedulers. + +```javascript +var out = learningRates(); +// e.g., returns [ 'basic', 'constant', 'invscaling', 'pegasos' ] +``` + +The output array contains the following learning rate schedulers: + +- `basic`: basic learning rate function according to the formula `10/(10+t)` where `t` is the current iteration. +- `constant`: constant learning rate function. By default, when the learning rate function is 'constant', the learning rate is set to `0.02`. +- `invscaling`: inverse scaling learning rate function according to the formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and `power_t` is the exponent controlling how quickly the learning rate decreases. +- `pegasos`: pegasos learning rate function according to the formula `1/(lambda*t)` where `t` is the current iteration and `lambda` is the regularization parameter. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var learningRates = require( '@stdlib/ml/base/sgd-classification/learning-rates' ); + +var isLearningRate = contains( learningRates() ); + +var bool = isLearningRate( 'constant' ); +// returns true + +bool = isLearningRate( 'pegasos' ); +// returns true + +bool = isLearningRate( 'beep' ); +// returns false +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ml/base/sgd-classification/learning_rates.h" +``` + +#### STDLIB_ML_SGD_CLASSIFICATION_LEARNING_RATES + +An enumeration of SGD classification learning rate schedulers with the following fields: + +- **STDLIB_ML_SGD_CLASSIFICATION_BASIC**: Basic learning rate function according to the formula `10/(10+t)` where `t` is the current iteration. +- **STDLIB_ML_SGD_CLASSIFICATION_CONSTANT**: Constant learning rate function. By default, when the learning rate function is 'constant', the learning rate is set to `0.02`. +- **STDLIB_ML_SGD_CLASSIFICATION_INVSCALING**: Inverse scaling learning rate function according to the formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and `power_t` is the exponent controlling how quickly the learning rate decreases. +- **STDLIB_ML_SGD_CLASSIFICATION_PEGASOS**: Pegasos learning rate function according to the formula `1/(lambda*t)` where `t` is the current iteration and `lambda` is the regularization parameter. + +```c +#include "stdlib/ml/base/sgd-classification/learning_rates.h" + +const enum STDLIB_ML_SGD_CLASSIFICATION_LEARNING_RATES v = STDLIB_ML_SGD_CLASSIFICATION_BASIC; +``` + +
+ + + + + +
+ +### 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/learning-rates/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/benchmark/benchmark.js new file mode 100644 index 000000000000..95c330ebd9fb --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/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 learningRates = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = learningRates(); + 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/learning-rates/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/repl.txt new file mode 100644 index 000000000000..23fb76ca1bbb --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/repl.txt @@ -0,0 +1,31 @@ + +{{alias}}() + Returns a list of SGD classification learning rate schedulers. + + The output array contains the following learning rate schedulers: + + - basic: basic learning rate function according to the formula `10/(10+t)` + where `t` is the current iteration. + - constant: constant learning rate function. By default, when the learning + rate function is 'constant', the learning rate is set to `0.02`. + - invscaling: inverse scaling learning rate function according to the + formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and + `power_t` is the exponent controlling how quickly the learning rate + decreases. + - pegasos: pegasos learning rate function according to the formula + `1/(lambda*t)` where `t` is the current iteration and `lambda` is the + regularization parameter. + + Returns + ------- + out: Array + List of learning rate schedulers. + + Examples + -------- + > var out = {{alias}}() + [...] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/types/index.d.ts new file mode 100644 index 000000000000..dcffa578ea70 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/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 learning rate schedulers. +* +* @returns list of learning rate schedulers +* +* @example +* var list = learningRates(); +* // e.g., returns [ 'basic', 'constant', 'invscaling', 'pegasos' ] +*/ +declare function learningRates(): Array; + + +// EXPORTS // + +export = learningRates; diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/types/test.ts new file mode 100644 index 000000000000..c8605c6f84de --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/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 learningRates = require( './index' ); + + +// TESTS // + +// The function returns an array of strings... +{ + learningRates(); // $ExpectType string[] +} + +// The compiler throws an error if the function is provided any arguments... +{ + learningRates( 9 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/examples/index.js new file mode 100644 index 000000000000..c7427e0fe2fd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/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 learningRates = require( './../lib' ); + +var isLearningRate = contains( learningRates() ); + +var bool = isLearningRate( 'basic' ); +console.log( bool ); +// => true + +bool = isLearningRate( 'constant' ); +console.log( bool ); +// => true + +bool = isLearningRate( 'beep' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/include/stdlib/ml/base/sgd-classification/learning_rates.h b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/include/stdlib/ml/base/sgd-classification/learning_rates.h new file mode 100644 index 000000000000..313d67f11921 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/include/stdlib/ml/base/sgd-classification/learning_rates.h @@ -0,0 +1,39 @@ +/** +* @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_LEARNING_RATES_H +#define STDLIB_ML_BASE_SGD_CLASSIFICATION_LEARNING_RATES_H + +/** +* Enumeration of SGD classification learning rate schedulers. +*/ +enum STDLIB_ML_SGD_CLASSIFICATION_LEARNING_RATES { + // Basic learning rate function according to the formula `10/(10+t)` where `t` is the current iteration: + STDLIB_ML_SGD_CLASSIFICATION_BASIC = 0, + + // Constant learning rate function. By default, when the learning rate function is 'constant', the learning rate is set to `0.02`: + STDLIB_ML_SGD_CLASSIFICATION_CONSTANT, + + // Inverse scaling learning rate function according to the formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and `power_t` is the exponent controlling how quickly the learning rate decreases: + STDLIB_ML_SGD_CLASSIFICATION_INVSCALING, + + // Pegasos learning rate function according to the formula `1/(lambda*t)` where `t` is the current iteration and `lambda` is the regularization parameter: + STDLIB_ML_SGD_CLASSIFICATION_PEGASOS +}; + +#endif // !STDLIB_ML_BASE_SGD_CLASSIFICATION_LEARNING_RATES_H diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/data.json b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/data.json new file mode 100644 index 000000000000..9f4424ed10e9 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/data.json @@ -0,0 +1,6 @@ +[ + "basic", + "constant", + "invscaling", + "pegasos" +] diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/enum.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/enum.js new file mode 100644 index 000000000000..8d13912d289c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/enum.js @@ -0,0 +1,57 @@ +/** +* @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 learning rate schedulers to integer values for purposes of C inter-operation. +* +* ## Notes +* +* - Downstream consumers of this mapping should **not** rely on specific integer values (e.g., `BASIC == 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 learning rate schedulers to integer values +* +* @example +* var table = enumerated(); +* // returns +*/ +function enumerated() { + // NOTE: the following should match the C `learning rates.h` enumeration!!!! + return { + // Basic learning rate function according to the formula `10/(10+t)` where `t` is the current iteration: + 'basic': 0, + + // Constant learning rate function. By default, when the learning rate function is 'constant', the learning rate is set to `0.02`: + 'constant': 1, + + // Inverse scaling learning rate function according to the formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and `power_t` is the exponent controlling how quickly the learning rate decreases: + 'invscaling': 2, + + // Pegasos learning rate function according to the formula `1/(lambda*t)` where `t` is the current iteration and `lambda` is the regularization parameter: + 'pegasos': 3 + }; +} + + +// EXPORTS // + +module.exports = enumerated; diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/index.js new file mode 100644 index 000000000000..9af59ae848b9 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/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 learning rate schedulers. +* +* @module @stdlib/ml/base/sgd-classification/learning-rates +* +* @example +* var learningRates = require( '@stdlib/ml/base/sgd-classification/learning-rates' ); +* +* var list = learningRates(); +* // e.g., returns [ 'basic', 'constant', 'invscaling', 'pegasos' ] +*/ + +// 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/learning-rates/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/main.js new file mode 100644 index 000000000000..fc7d1e0cee31 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/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 learning rate schedulers. +* +* @returns {Array} list of learning rate schedulers +* +* @example +* var list = learningRates(); +* // e.g., returns [ 'basic', 'constant', 'invscaling', 'pegasos' ] +*/ +function learningRates() { + return DATA.slice(); +} + + +// EXPORTS // + +module.exports = learningRates; diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/manifest.json b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/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/learning-rates/package.json b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/package.json new file mode 100644 index 000000000000..80efce55d631 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/ml/base/sgd-classification/learning-rates", + "version": "0.0.0", + "description": "SGD classification learning rate schedulers.", + "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", + "learning rates", + "learning rate schedulers", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/test/test.js new file mode 100644 index 000000000000..8b83fc23cfa5 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/test/test.js @@ -0,0 +1,77 @@ +/** +* @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 learningRates = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof learningRates, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a list of SGD classification learning rate schedulers', function test( t ) { + var expected; + var actual; + + expected = [ + 'basic', + 'constant', + 'invscaling', + 'pegasos' + ]; + actual = learningRates(); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main function is an `enum` method to return an object mapping learning rate schedulers to integer values for C inter-operation', function test( t ) { + var obj; + var o; + var i; + + t.strictEqual( hasOwnProp( learningRates, 'enum' ), true, 'has property' ); + t.strictEqual( typeof learningRates.enum, 'function', 'has method' ); + + obj = learningRates.enum(); + t.strictEqual( typeof obj, 'object', 'returns expected value' ); + + // List of values which should be supported... + o = [ + 'basic', + 'constant', + 'invscaling', + 'pegasos' + ]; + 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 d921b9f989f0e945d20c9272cd7c130776b1ca43 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 8 Jul 2026 16:16:46 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../sgd-classification/learning-rates/README.md | 14 +++++++------- .../learning-rates/docs/repl.txt | 5 ++--- .../ml/base/sgd-classification/learning_rates.h | 4 ++-- .../sgd-classification/learning-rates/lib/enum.js | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/README.md b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/README.md index 3bc7b9220a57..b010fea72323 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/README.md @@ -52,9 +52,9 @@ var out = learningRates(); The output array contains the following learning rate schedulers: - `basic`: basic learning rate function according to the formula `10/(10+t)` where `t` is the current iteration. -- `constant`: constant learning rate function. By default, when the learning rate function is 'constant', the learning rate is set to `0.02`. +- `constant`: constant learning rate function. - `invscaling`: inverse scaling learning rate function according to the formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and `power_t` is the exponent controlling how quickly the learning rate decreases. -- `pegasos`: pegasos learning rate function according to the formula `1/(lambda*t)` where `t` is the current iteration and `lambda` is the regularization parameter. +- `pegasos`: Pegasos learning rate function according to the formula `1/(lambda*t)` where `t` is the current iteration and `lambda` is the regularization parameter. @@ -122,19 +122,19 @@ bool = isLearningRate( 'beep' ); #include "stdlib/ml/base/sgd-classification/learning_rates.h" ``` -#### STDLIB_ML_SGD_CLASSIFICATION_LEARNING_RATES +#### STDLIB_ML_SGD_CLASSIFICATION_LEARNING_RATE An enumeration of SGD classification learning rate schedulers with the following fields: -- **STDLIB_ML_SGD_CLASSIFICATION_BASIC**: Basic learning rate function according to the formula `10/(10+t)` where `t` is the current iteration. -- **STDLIB_ML_SGD_CLASSIFICATION_CONSTANT**: Constant learning rate function. By default, when the learning rate function is 'constant', the learning rate is set to `0.02`. -- **STDLIB_ML_SGD_CLASSIFICATION_INVSCALING**: Inverse scaling learning rate function according to the formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and `power_t` is the exponent controlling how quickly the learning rate decreases. +- **STDLIB_ML_SGD_CLASSIFICATION_BASIC**: basic learning rate function according to the formula `10/(10+t)` where `t` is the current iteration. +- **STDLIB_ML_SGD_CLASSIFICATION_CONSTANT**: constant learning rate function. +- **STDLIB_ML_SGD_CLASSIFICATION_INVSCALING**: inverse scaling learning rate function according to the formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and `power_t` is the exponent controlling how quickly the learning rate decreases. - **STDLIB_ML_SGD_CLASSIFICATION_PEGASOS**: Pegasos learning rate function according to the formula `1/(lambda*t)` where `t` is the current iteration and `lambda` is the regularization parameter. ```c #include "stdlib/ml/base/sgd-classification/learning_rates.h" -const enum STDLIB_ML_SGD_CLASSIFICATION_LEARNING_RATES v = STDLIB_ML_SGD_CLASSIFICATION_BASIC; +const enum STDLIB_ML_SGD_CLASSIFICATION_LEARNING_RATE v = STDLIB_ML_SGD_CLASSIFICATION_BASIC; ``` diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/repl.txt index 23fb76ca1bbb..6128e38d404a 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/repl.txt +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/docs/repl.txt @@ -6,13 +6,12 @@ - basic: basic learning rate function according to the formula `10/(10+t)` where `t` is the current iteration. - - constant: constant learning rate function. By default, when the learning - rate function is 'constant', the learning rate is set to `0.02`. + - constant: constant learning rate function. - invscaling: inverse scaling learning rate function according to the formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and `power_t` is the exponent controlling how quickly the learning rate decreases. - - pegasos: pegasos learning rate function according to the formula + - pegasos: Pegasos learning rate function according to the formula `1/(lambda*t)` where `t` is the current iteration and `lambda` is the regularization parameter. diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/include/stdlib/ml/base/sgd-classification/learning_rates.h b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/include/stdlib/ml/base/sgd-classification/learning_rates.h index 313d67f11921..4c6f37b1bc21 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/include/stdlib/ml/base/sgd-classification/learning_rates.h +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/include/stdlib/ml/base/sgd-classification/learning_rates.h @@ -22,11 +22,11 @@ /** * Enumeration of SGD classification learning rate schedulers. */ -enum STDLIB_ML_SGD_CLASSIFICATION_LEARNING_RATES { +enum STDLIB_ML_SGD_CLASSIFICATION_LEARNING_RATE { // Basic learning rate function according to the formula `10/(10+t)` where `t` is the current iteration: STDLIB_ML_SGD_CLASSIFICATION_BASIC = 0, - // Constant learning rate function. By default, when the learning rate function is 'constant', the learning rate is set to `0.02`: + // Constant learning rate function: STDLIB_ML_SGD_CLASSIFICATION_CONSTANT, // Inverse scaling learning rate function according to the formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and `power_t` is the exponent controlling how quickly the learning rate decreases: diff --git a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/enum.js b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/enum.js index 8d13912d289c..27c8b2643a09 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/enum.js +++ b/lib/node_modules/@stdlib/ml/base/sgd-classification/learning-rates/lib/enum.js @@ -40,7 +40,7 @@ function enumerated() { // Basic learning rate function according to the formula `10/(10+t)` where `t` is the current iteration: 'basic': 0, - // Constant learning rate function. By default, when the learning rate function is 'constant', the learning rate is set to `0.02`: + // Constant learning rate function: 'constant': 1, // Inverse scaling learning rate function according to the formula `eta0/pow(t, power_t)` where `eta0` is the initial learning rate and `power_t` is the exponent controlling how quickly the learning rate decreases: