From ede98fd2a9616cb386d5c64bac4025d6699bdfad Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Mon, 3 Aug 2026 11:12:05 +0530 Subject: [PATCH 01/24] feat: add `ml/base/sgd/params/struct-factory` --- 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 --- --- .../base/sgd/params/struct-factory/README.md | 168 ++++++++++++++ .../struct-factory/benchmark/benchmark.js | 54 +++++ .../sgd/params/struct-factory/docs/repl.txt | 24 ++ .../struct-factory/docs/types/index.d.ts | 189 ++++++++++++++++ .../params/struct-factory/docs/types/test.ts | 54 +++++ .../params/struct-factory/examples/index.js | 61 +++++ .../sgd/params/struct-factory/lib/index.js | 43 ++++ .../sgd/params/struct-factory/lib/main.js | 118 ++++++++++ .../sgd/params/struct-factory/package.json | 68 ++++++ .../sgd/params/struct-factory/test/test.js | 209 ++++++++++++++++++ 10 files changed, 988 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md new file mode 100644 index 000000000000..e47068d50640 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -0,0 +1,168 @@ + + +# structFactory + +> Create a new [`struct`][@stdlib/dstructs/struct] constructor tailored to a specified floating-point data type. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var structFactory = require( '@stdlib/ml/base/sgd/params/struct-factory' ); +``` + +#### structFactory( dtype ) + +Returns a new [`struct`][@stdlib/dstructs/struct] constructor tailored to a specified floating-point data type. + +```javascript +var Struct = structFactory( 'float64' ); +// returns + +var s = new Struct(); +// returns +``` + +The function supports the following parameters: + +- **dtype**: floating-point data type for storing floating-point parameters. Must be either `'float64'` or `'float32'`. + +A returned [`struct`][@stdlib/dstructs/struct] constructor supports the following fields: + +- **penalty**: regularization function to be used. +- **penaltyParams**: parameters specific to the regularization function being used. +- **learningRate**: learning rate scheduler to be used. +- **learningRateParams**: parameters specific to the learning rate scheduler being used. +- **lossFunction**: loss function to be used. +- **lossFunctionParams**: parameters specific to the loss function being used. +- **fitIntercept**: boolean indicating whether to include an intercept. +- **intercept**: initial intercept value. +- **maxIter**: maximum number of iterations to run. + +
+ + + + + +
+ +## Notes + +- A [`struct`][@stdlib/dstructs/struct] provides a fixed-width composite data structure for storing SGD trainer parameters and provides an ABI-stable data layout for JavaScript-C interoperation. +- Each parameter list is a fixed-length array which is large enough to accommodate the option requiring the most parameters (`penaltyParams`: `3`, `learningRateParams`: `2`, `lossFunctionParams`: `1`). Accordingly, one must provide a list having the expected length, with any unused elements set to zero. As struct instances are zero-filled upon initialization, one may omit a list when the corresponding option requires no parameters. + +
+ + + + + +
+ +## Examples + + + +```javascript +var resolveLREnum = require( '@stdlib/ml/base/sgd-classification/learning-rate-resolve-enum' ); +var resolveLossFunctionEnum = require( '@stdlib/ml/base/sgd-classification/loss-function-resolve-enum' ); +var resolvePenaltyEnum = require( '@stdlib/ml/base/sgd-classification/penalty-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var structFactory = require( '@stdlib/ml/base/sgd/params/struct-factory' ); + +// Note: hinge loss requires no parameters, and thus we may omit the respective parameter list. +var Struct = structFactory( 'float64' ); +var params = new Struct({ + 'penalty': resolvePenaltyEnum( 'l2' ), + 'penaltyParams': new Float64Array( [ 2.5, 0.0, 0.0 ] ), + 'learningRate': resolveLREnum( 'constant' ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunction': resolveLossFunctionEnum( 'hinge' ), + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500 +}); + +var str = params.toString({ + 'format': 'linear' +}); +console.log( str ); + +Struct = structFactory( 'float32' ); +params = new Struct({ + 'penalty': resolvePenaltyEnum( 'l2' ), + 'penaltyParams': new Float32Array( [ 2.5, 0.0, 0.0 ] ), + 'learningRate': resolveLREnum( 'constant' ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'lossFunction': resolveLossFunctionEnum( 'hinge' ), + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500 +}); + +str = params.toString({ + 'format': 'linear' +}); +console.log( str ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/benchmark/benchmark.js new file mode 100644 index 000000000000..f4c4a1b9ec96 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isFunction = require( '@stdlib/assert/is-function' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 'float64', + 'float32' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = factory( values[ i%values.length ] ); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( !isFunction( v ) ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/repl.txt new file mode 100644 index 000000000000..44d00f06a186 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/repl.txt @@ -0,0 +1,24 @@ + +{{alias}}( dtype ) + Returns a new struct constructor tailored to a specified floating-point data + type. + + Parameters + ---------- + dtype: string + Floating-point data type for storing floating-point parameters. + + Returns + ------- + fcn: Function + Struct constructor. + + Examples + -------- + > var S = {{alias}}( 'float64' ); + > var r = new S(); + > r.toString() + + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts new file mode 100644 index 000000000000..ca37ce059007 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -0,0 +1,189 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 + +/** +* Interface describing SGD trainer function parameters. +*/ +interface Params { + /** + * Regularization function to be used. + */ + penalty?: number; + + /** + * Parameters specific to the regularization function being used. + */ + penaltyParams?: T; + + /** + * Learning rate scheduler to be used. + */ + learningRate?: number; + + /** + * Parameters specific to the learning rate scheduler being used. + */ + learningRateParams?: T; + + /** + * Loss function to be used. + */ + lossFunction?: number; + + /** + * Parameters specific to the loss function being used. + */ + lossFunctionParams?: T; + + /** + * Boolean indicating whether to include intercept. + */ + fitIntercept?: boolean; + + /** + * Initial intercept value. + */ + intercept?: number; + + /** + * Maximum number of iterations to run. + */ + maxIter?: number; +} + +/** +* Interface describing a struct data structure. +*/ +declare class Struct { + /** + * Struct constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + constructor( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ); + + /** + * Regularization function to be used. + */ + penalty: number; + + /** + * Parameters specific to the regularization function being used. + */ + penaltyParams: T; + + /** + * Learning rate scheduler to be used. + */ + learningRate: number; + + /** + * Parameters specific to the learning rate scheduler being used. + */ + learningRateParams: T; + + /** + * Loss function to be used. + */ + lossFunction: number; + + /** + * Parameters specific to the loss function being used. + */ + lossFunctionParams: T; + + /** + * Boolean indicating whether to include intercept. + */ + fitIntercept: boolean; + + /** + * Initial intercept value. + */ + intercept: number; + + /** + * Maximum number of iterations to run. + */ + maxIter: number; +} + +/** +* Interface defining a struct constructor which is both "newable" and "callable". +*/ +interface StructConstructor { + /** + * Struct constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + new( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ): Struct; + + /** + * Struct constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + ( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ): Struct; +} + +/** +* Returns a new struct constructor tailored to a specified floating-point data type. +* +* @param dtype - floating-point data type for storing floating-point results +* @returns struct constructor +* +* @example +* var Struct = structFactory( 'float64' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ +declare function structFactory( dtype: 'float64' ): StructConstructor; + +/** +* Returns a new struct constructor tailored to a specified floating-point data type. +* +* @param dtype - floating-point data type for storing floating-point results +* @returns struct constructor +* +* @example +* var Struct = structFactory( 'float32' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ +declare function structFactory( dtype: 'float32' ): StructConstructor; + + +// EXPORTS // + +export = structFactory; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/test.ts new file mode 100644 index 000000000000..d468857951a5 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/test.ts @@ -0,0 +1,54 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 structFactory = require( './index' ); + + +// TESTS // + +// The function returns a function... +{ + structFactory( 'float64' ); // $ExpectType StructConstructor + structFactory( 'float32' ); // $ExpectType StructConstructor +} + +// The compiler throws an error if not provided a supported data type... +{ + structFactory( 10 ); // $ExpectError + structFactory( true ); // $ExpectError + structFactory( false ); // $ExpectError + structFactory( null ); // $ExpectError + structFactory( undefined ); // $ExpectError + structFactory( [] ); // $ExpectError + structFactory( {} ); // $ExpectError + structFactory( ( x: number ): number => x ); // $ExpectError +} + +// The function returns a function which returns a struct object... +{ + const Struct = structFactory( 'float64' ); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s1 = new Struct( new ArrayBuffer( 92 ) ); // $ExpectType Struct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s2 = new Struct( new ArrayBuffer( 100 ), 8 ); // $ExpectType Struct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const s3 = new Struct( new ArrayBuffer( 100 ), 8, 92 ); // $ExpectType Struct +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js new file mode 100644 index 000000000000..2e005dff188e --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 resolveLREnum = require( '@stdlib/ml/base/sgd-classification/learning-rate-resolve-enum' ); +var resolveLossFunctionEnum = require( '@stdlib/ml/base/sgd-classification/loss-function-resolve-enum' ); +var resolvePenaltyEnum = require( '@stdlib/ml/base/sgd-classification/penalty-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var structFactory = require( './../lib' ); + +// Note: each parameter list has a fixed length, and thus one must provide a list having the expected length, with any unused elements set to zero. Alternatively, for an option requiring no parameters (e.g., hinge loss), one may omit the respective list, as struct instances are zero-filled upon initialization. +var Struct = structFactory( 'float64' ); +var results = new Struct({ + 'penalty': resolvePenaltyEnum( 'l2' ), + 'penaltyParams': new Float64Array( [ 2.5, 0.0, 0.0 ] ), + 'learningRate': resolveLREnum( 'constant' ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunction': resolveLossFunctionEnum( 'hinge' ), + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500 +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); + +Struct = structFactory( 'float32' ); +results = new Struct({ + 'penalty': resolvePenaltyEnum( 'l2' ), + 'penaltyParams': new Float32Array( [ 2.5, 0.0, 0.0 ] ), + 'learningRate': resolveLREnum( 'constant' ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'lossFunction': resolveLossFunctionEnum( 'hinge' ), + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500 +}); + +str = results.toString({ + 'format': 'linear' +}); +console.log( str ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/index.js new file mode 100644 index 000000000000..f20f31a562a1 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* Create a new struct constructor tailored to a specified floating-point data type. +* +* @module @stdlib/ml/base/sgd/params/struct-factory +* +* @example +* var structFactory = require( '@stdlib/ml/base/sgd/params/struct-factory' ); +* +* var Struct = structFactory( 'float64' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js new file mode 100644 index 000000000000..2c76866897fd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js @@ -0,0 +1,118 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 struct = require( '@stdlib/dstructs/struct' ); + + +// VARIABLES // + +var PENALTY_PARAMS_LENGTH = 3; +var LEARNING_RATE_PARAMS_LENGTH = 2; +var LOSS_FUNCTION_PARAMS_LENGTH = 1; + + +// MAIN // + +/** +* Returns a new struct constructor tailored to a specified floating-point data type. +* +* ## Notes +* +* - Each parameter list is a fixed-length array which is zero-filled upon initialization. Consumers should only read as many elements as are applicable to the corresponding penalty, learning rate scheduler, or loss function, with any remaining elements being unused. +* +* @param {string} dtype - floating-point data type +* @returns {Function} struct constructor +* +* @example +* var Struct = factory( 'float64' ); +* // returns +* +* var s = new Struct(); +* // returns +*/ +function factory( dtype ) { + var schema = [ + { + 'name': 'penalty', + 'description': 'regularization function to be used', + 'type': 'int8', + 'castingMode': 'none' + }, + { + 'name': 'penaltyParams', + 'description': 'parameters specific to the regularization function being used', + 'type': dtype, + 'length': PENALTY_PARAMS_LENGTH, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'learningRate', + 'description': 'learning rate scheduler to be used', + 'type': 'int8', + 'castingMode': 'none' + }, + { + 'name': 'learningRateParams', + 'description': 'parameters specific to the learning rate scheduler being used', + 'type': dtype, + 'length': LEARNING_RATE_PARAMS_LENGTH, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'lossFunction', + 'description': 'loss function to be used', + 'type': 'int8', + 'castingMode': 'none' + }, + { + 'name': 'lossFunctionParams', + 'description': 'parameters specific to the loss function being used', + 'type': dtype, + 'length': LOSS_FUNCTION_PARAMS_LENGTH, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'fitIntercept', + 'description': 'boolean indicating whether to include intercept', + 'type': 'bool', + 'castingMode': 'none' + }, + { + 'name': 'intercept', + 'description': 'initial intercept value', + 'type': dtype, + 'castingMode': 'mostly-safe' + }, + { + 'name': 'maxIter', + 'description': 'maximum number of iterations to run', + 'type': 'int32', + 'castingMode': 'mostly-safe' + } + ]; + return struct( schema ); +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/package.json b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/package.json new file mode 100644 index 000000000000..089cf5b84b66 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/ml/base/sgd/params/struct-factory", + "version": "0.0.0", + "description": "Create a new struct constructor tailored to a specified floating-point data type.", + "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", + "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", + "stochastic gradient descent", + "trainer", + "utilities", + "utility", + "utils", + "util", + "struct", + "params", + "parameters" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js new file mode 100644 index 000000000000..c8d1a915b65d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js @@ -0,0 +1,209 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var resolveLREnum = require( '@stdlib/ml/base/sgd-classification/learning-rate-resolve-enum' ); +var resolveLossFunctionEnum = require( '@stdlib/ml/base/sgd-classification/loss-function-resolve-enum' ); +var resolvePenaltyEnum = require( '@stdlib/ml/base/sgd-classification/penalty-resolve-enum' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var structFactory = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof structFactory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a supported data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + structFactory( value ); + }; + } +}); + +tape( 'the function returns a constructor for creating a fixed-width parameters object (dtype=float64)', function test( t ) { + var expected; + var actual; + var Struct; + + Struct = structFactory( 'float64' ); + t.strictEqual( typeof Struct, 'function', 'returns expected value' ); + + actual = new Struct({ + 'penalty': resolvePenaltyEnum( 'l2' ), + 'penaltyParams': new Float64Array( [ 2.5, 0.0, 0.0 ] ), + 'learningRate': resolveLREnum( 'constant' ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunction': resolveLossFunctionEnum( 'hinge' ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'fitIntercept': true, + 'intercept': 0.5, + 'maxIter': 500 + }); + + expected = { + 'penalty': resolvePenaltyEnum( 'l2' ), + 'penaltyParams': new Float64Array( [ 2.5, 0.0, 0.0 ] ), + 'learningRate': resolveLREnum( 'constant' ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunction': resolveLossFunctionEnum( 'hinge' ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'fitIntercept': true, + 'intercept': 0.5, + 'maxIter': 500 + }; + + t.strictEqual( actual instanceof Struct, true, 'returns expected value' ); + t.strictEqual( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.fitIntercept, expected.fitIntercept, 'returns expected value' ); + t.strictEqual( actual.intercept, expected.intercept, 'returns expected value' ); + t.strictEqual( actual.maxIter, expected.maxIter, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width parameters object (dtype=float32)', function test( t ) { + var expected; + var actual; + var Struct; + + Struct = structFactory( 'float32' ); + t.strictEqual( typeof Struct, 'function', 'returns expected value' ); + + actual = new Struct({ + 'penalty': resolvePenaltyEnum( 'l2' ), + 'penaltyParams': new Float32Array( [ 2.5, 0.0, 0.0 ] ), + 'learningRate': resolveLREnum( 'constant' ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'lossFunction': resolveLossFunctionEnum( 'hinge' ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'fitIntercept': true, + 'intercept': f32( 0.5 ), + 'maxIter': 500 + }); + + expected = { + 'penalty': resolvePenaltyEnum( 'l2' ), + 'penaltyParams': new Float32Array( [ 2.5, 0.0, 0.0 ] ), + 'learningRate': resolveLREnum( 'constant' ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'lossFunction': resolveLossFunctionEnum( 'hinge' ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'fitIntercept': true, + 'intercept': f32( 0.5 ), + 'maxIter': 500 + }; + + t.strictEqual( actual instanceof Struct, true, 'returns expected value' ); + t.strictEqual( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.fitIntercept, expected.fitIntercept, 'returns expected value' ); + t.strictEqual( actual.intercept, expected.intercept, 'returns expected value' ); + t.strictEqual( actual.maxIter, expected.maxIter, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which zero-fills parameter lists which are not provided', function test( t ) { + var expected; + var actual; + var Struct; + + Struct = structFactory( 'float64' ); + + actual = new Struct({ + 'lossFunction': resolveLossFunctionEnum( 'hinge' ) + }); + + expected = { + 'penaltyParams': new Float64Array( [ 0.0, 0.0, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.0, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ) + }; + + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which throws an error if provided a parameter list having an unexpected length', function test( t ) { + var Struct; + var values; + var i; + + Struct = structFactory( 'float64' ); + + values = [ + new Float64Array( [] ), + new Float64Array( [ 2.5 ] ), + new Float64Array( [ 2.5, 0.0 ] ), + new Float64Array( [ 2.5, 0.0, 0.0, 0.0 ] ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an array having length ' + values[ i ].length ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Struct({ + 'penaltyParams': value + }); + }; + } +}); From 58edc9751e1125aa143dd40e9d139bfe5128cb07 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Wed, 5 Aug 2026 10:32:54 +0530 Subject: [PATCH 02/24] refactor: update import paths --- 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: na - task: lint_repl_help status: na - 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 --- --- .../@stdlib/ml/base/sgd/params/struct-factory/README.md | 8 ++++---- .../sgd/params/struct-factory/benchmark/benchmark.js | 2 +- .../base/sgd/params/struct-factory/docs/types/index.d.ts | 4 ++-- .../ml/base/sgd/params/struct-factory/docs/types/test.ts | 2 +- .../ml/base/sgd/params/struct-factory/examples/index.js | 9 ++++----- .../ml/base/sgd/params/struct-factory/lib/index.js | 2 +- .../ml/base/sgd/params/struct-factory/lib/main.js | 2 +- .../ml/base/sgd/params/struct-factory/test/test.js | 8 ++++---- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index e47068d50640..2e66e8054b87 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +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. @@ -94,9 +94,9 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin ```javascript -var resolveLREnum = require( '@stdlib/ml/base/sgd-classification/learning-rate-resolve-enum' ); -var resolveLossFunctionEnum = require( '@stdlib/ml/base/sgd-classification/loss-function-resolve-enum' ); -var resolvePenaltyEnum = require( '@stdlib/ml/base/sgd-classification/penalty-resolve-enum' ); +var resolveLREnum = require( '@stdlib/ml/base/sgd/learning-rate-resolve-enum' ); +var resolveLossFunctionEnum = require( '@stdlib/ml/base/sgd/loss-function-resolve-enum' ); +var resolvePenaltyEnum = require( '@stdlib/ml/base/sgd/penalty-resolve-enum' ); var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); var structFactory = require( '@stdlib/ml/base/sgd/params/struct-factory' ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/benchmark/benchmark.js index f4c4a1b9ec96..f06fde75adee 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index ca37ce059007..b323b32b69e4 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. @@ -19,7 +19,7 @@ // TypeScript Version: 4.1 /** -* Interface describing SGD trainer function parameters. +* Interface describing SGD trainer parameters. */ interface Params { /** diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/test.ts index d468857951a5..1857d7901cfb 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js index 2e005dff188e..f6ca6c90fba5 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. @@ -18,14 +18,13 @@ 'use strict'; -var resolveLREnum = require( '@stdlib/ml/base/sgd-classification/learning-rate-resolve-enum' ); -var resolveLossFunctionEnum = require( '@stdlib/ml/base/sgd-classification/loss-function-resolve-enum' ); -var resolvePenaltyEnum = require( '@stdlib/ml/base/sgd-classification/penalty-resolve-enum' ); +var resolveLREnum = require( '@stdlib/ml/base/sgd/learning-rate-resolve-enum' ); +var resolveLossFunctionEnum = require( '@stdlib/ml/base/sgd/loss-function-resolve-enum' ); +var resolvePenaltyEnum = require( '@stdlib/ml/base/sgd/penalty-resolve-enum' ); var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); var structFactory = require( './../lib' ); -// Note: each parameter list has a fixed length, and thus one must provide a list having the expected length, with any unused elements set to zero. Alternatively, for an option requiring no parameters (e.g., hinge loss), one may omit the respective list, as struct instances are zero-filled upon initialization. var Struct = structFactory( 'float64' ); var results = new Struct({ 'penalty': resolvePenaltyEnum( 'l2' ), diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/index.js index f20f31a562a1..578ebbe3aaed 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js index 2c76866897fd..59ce255e0e83 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js index c8d1a915b65d..e8b96bd330cb 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. @@ -25,9 +25,9 @@ var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); -var resolveLREnum = require( '@stdlib/ml/base/sgd-classification/learning-rate-resolve-enum' ); -var resolveLossFunctionEnum = require( '@stdlib/ml/base/sgd-classification/loss-function-resolve-enum' ); -var resolvePenaltyEnum = require( '@stdlib/ml/base/sgd-classification/penalty-resolve-enum' ); +var resolveLREnum = require( '@stdlib/ml/base/sgd/learning-rate-resolve-enum' ); +var resolveLossFunctionEnum = require( '@stdlib/ml/base/sgd/loss-function-resolve-enum' ); +var resolvePenaltyEnum = require( '@stdlib/ml/base/sgd/penalty-resolve-enum' ); var f32 = require( '@stdlib/number/float64/base/to-float32' ); var structFactory = require( './../lib' ); From 2acddf22b65b0c2db58be4f7784f9987ac85e512 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Wed, 5 Aug 2026 19:17:26 +0530 Subject: [PATCH 03/24] fix: update penalty params array size --- 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: na - task: lint_repl_help status: na - 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: na - 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: na - task: lint_license_headers status: passed --- --- .../ml/base/sgd/params/struct-factory/README.md | 4 ++-- .../base/sgd/params/struct-factory/examples/index.js | 4 ++-- .../ml/base/sgd/params/struct-factory/lib/main.js | 2 +- .../ml/base/sgd/params/struct-factory/test/test.js | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index 2e66e8054b87..cbe430bb49a1 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -105,7 +105,7 @@ var structFactory = require( '@stdlib/ml/base/sgd/params/struct-factory' ); var Struct = structFactory( 'float64' ); var params = new Struct({ 'penalty': resolvePenaltyEnum( 'l2' ), - 'penaltyParams': new Float64Array( [ 2.5, 0.0, 0.0 ] ), + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'learningRate': resolveLREnum( 'constant' ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), 'lossFunction': resolveLossFunctionEnum( 'hinge' ), @@ -122,7 +122,7 @@ console.log( str ); Struct = structFactory( 'float32' ); params = new Struct({ 'penalty': resolvePenaltyEnum( 'l2' ), - 'penaltyParams': new Float32Array( [ 2.5, 0.0, 0.0 ] ), + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'learningRate': resolveLREnum( 'constant' ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), 'lossFunction': resolveLossFunctionEnum( 'hinge' ), diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js index f6ca6c90fba5..ed7665d6c87a 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js @@ -28,7 +28,7 @@ var structFactory = require( './../lib' ); var Struct = structFactory( 'float64' ); var results = new Struct({ 'penalty': resolvePenaltyEnum( 'l2' ), - 'penaltyParams': new Float64Array( [ 2.5, 0.0, 0.0 ] ), + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'learningRate': resolveLREnum( 'constant' ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), 'lossFunction': resolveLossFunctionEnum( 'hinge' ), @@ -45,7 +45,7 @@ console.log( str ); Struct = structFactory( 'float32' ); results = new Struct({ 'penalty': resolvePenaltyEnum( 'l2' ), - 'penaltyParams': new Float32Array( [ 2.5, 0.0, 0.0 ] ), + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'learningRate': resolveLREnum( 'constant' ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), 'lossFunction': resolveLossFunctionEnum( 'hinge' ), diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js index 59ce255e0e83..aa65a44217ef 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js @@ -25,7 +25,7 @@ var struct = require( '@stdlib/dstructs/struct' ); // VARIABLES // -var PENALTY_PARAMS_LENGTH = 3; +var PENALTY_PARAMS_LENGTH = 2; var LEARNING_RATE_PARAMS_LENGTH = 2; var LOSS_FUNCTION_PARAMS_LENGTH = 1; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js index e8b96bd330cb..063db1e56803 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/test/test.js @@ -78,7 +78,7 @@ tape( 'the function returns a constructor for creating a fixed-width parameters actual = new Struct({ 'penalty': resolvePenaltyEnum( 'l2' ), - 'penaltyParams': new Float64Array( [ 2.5, 0.0, 0.0 ] ), + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'learningRate': resolveLREnum( 'constant' ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), 'lossFunction': resolveLossFunctionEnum( 'hinge' ), @@ -90,7 +90,7 @@ tape( 'the function returns a constructor for creating a fixed-width parameters expected = { 'penalty': resolvePenaltyEnum( 'l2' ), - 'penaltyParams': new Float64Array( [ 2.5, 0.0, 0.0 ] ), + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'learningRate': resolveLREnum( 'constant' ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), 'lossFunction': resolveLossFunctionEnum( 'hinge' ), @@ -123,7 +123,7 @@ tape( 'the function returns a constructor for creating a fixed-width parameters actual = new Struct({ 'penalty': resolvePenaltyEnum( 'l2' ), - 'penaltyParams': new Float32Array( [ 2.5, 0.0, 0.0 ] ), + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'learningRate': resolveLREnum( 'constant' ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), 'lossFunction': resolveLossFunctionEnum( 'hinge' ), @@ -135,7 +135,7 @@ tape( 'the function returns a constructor for creating a fixed-width parameters expected = { 'penalty': resolvePenaltyEnum( 'l2' ), - 'penaltyParams': new Float32Array( [ 2.5, 0.0, 0.0 ] ), + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'learningRate': resolveLREnum( 'constant' ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), 'lossFunction': resolveLossFunctionEnum( 'hinge' ), @@ -170,7 +170,7 @@ tape( 'the function returns a constructor which zero-fills parameter lists which }); expected = { - 'penaltyParams': new Float64Array( [ 0.0, 0.0, 0.0 ] ), + 'penaltyParams': new Float64Array( [ 0.0, 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.0, 0.0 ] ), 'lossFunctionParams': new Float64Array( [ 0.0 ] ) }; From 4c834e7e03cb3f4d67f39c8009e7dcfbe9adbd7d Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 6 Aug 2026 16:03:40 +0530 Subject: [PATCH 04/24] chore: update struct member ordering --- 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: na - task: lint_repl_help status: na - 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: na - 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 --- --- .../base/sgd/params/struct-factory/README.md | 30 ++++---- .../struct-factory/docs/types/index.d.ts | 76 +++++++++---------- .../params/struct-factory/examples/index.js | 30 ++++---- .../sgd/params/struct-factory/lib/main.js | 48 ++++++------ .../sgd/params/struct-factory/test/test.js | 56 ++++++++------ 5 files changed, 127 insertions(+), 113 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index cbe430bb49a1..32bf6a52cf73 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -58,15 +58,15 @@ The function supports the following parameters: A returned [`struct`][@stdlib/dstructs/struct] constructor supports the following fields: -- **penalty**: regularization function to be used. - **penaltyParams**: parameters specific to the regularization function being used. -- **learningRate**: learning rate scheduler to be used. - **learningRateParams**: parameters specific to the learning rate scheduler being used. -- **lossFunction**: loss function to be used. - **lossFunctionParams**: parameters specific to the loss function being used. -- **fitIntercept**: boolean indicating whether to include an intercept. - **intercept**: initial intercept value. - **maxIter**: maximum number of iterations to run. +- **penalty**: regularization function to be used. +- **learningRate**: learning rate scheduler to be used. +- **lossFunction**: loss function to be used. +- **fitIntercept**: boolean indicating whether to include an intercept. @@ -104,14 +104,15 @@ var structFactory = require( '@stdlib/ml/base/sgd/params/struct-factory' ); // Note: hinge loss requires no parameters, and thus we may omit the respective parameter list. var Struct = structFactory( 'float64' ); var params = new Struct({ - 'penalty': resolvePenaltyEnum( 'l2' ), 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), - 'learningRate': resolveLREnum( 'constant' ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - 'lossFunction': resolveLossFunctionEnum( 'hinge' ), - 'fitIntercept': true, + 'lossFunctionParams': new Float64Array( [ 0.0, 0.0 ] ), 'intercept': 0.0, - 'maxIter': 500 + 'maxIter': 500, + 'penalty': resolvePenaltyEnum( 'l2' ), + 'learningRate': resolveLREnum( 'constant' ), + 'lossFunction': resolveLossFunctionEnum( 'hinge' ), + 'fitIntercept': true }); var str = params.toString({ @@ -121,14 +122,15 @@ console.log( str ); Struct = structFactory( 'float32' ); params = new Struct({ - 'penalty': resolvePenaltyEnum( 'l2' ), 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), - 'learningRate': resolveLREnum( 'constant' ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), - 'lossFunction': resolveLossFunctionEnum( 'hinge' ), - 'fitIntercept': true, + 'lossFunctionParams': new Float32Array( [ 0.0, 0.0 ] ), 'intercept': 0.0, - 'maxIter': 500 + 'maxIter': 500, + 'penalty': resolvePenaltyEnum( 'l2' ), + 'learningRate': resolveLREnum( 'constant' ), + 'lossFunction': resolveLossFunctionEnum( 'hinge' ), + 'fitIntercept': true }); str = params.toString({ diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index b323b32b69e4..0d1985c8f478 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -23,49 +23,49 @@ */ interface Params { /** - * Regularization function to be used. + * Parameters specific to the regularization function being used. */ - penalty?: number; + penaltyParams?: T; /** - * Parameters specific to the regularization function being used. + * Parameters specific to the learning rate scheduler being used. */ - penaltyParams?: T; + learningRateParams?: T; /** - * Learning rate scheduler to be used. + * Parameters specific to the loss function being used. */ - learningRate?: number; + lossFunctionParams?: T; /** - * Parameters specific to the learning rate scheduler being used. + * Initial intercept value. */ - learningRateParams?: T; + intercept?: number; /** - * Loss function to be used. + * Maximum number of iterations to run. */ - lossFunction?: number; + maxIter?: number; /** - * Parameters specific to the loss function being used. + * Regularization function to be used. */ - lossFunctionParams?: T; + penalty?: number; /** - * Boolean indicating whether to include intercept. + * Learning rate scheduler to be used. */ - fitIntercept?: boolean; + learningRate?: number; /** - * Initial intercept value. + * Loss function to be used. */ - intercept?: number; + lossFunction?: number; /** - * Maximum number of iterations to run. + * Boolean indicating whether to include intercept. */ - maxIter?: number; + fitIntercept?: boolean; } /** @@ -83,49 +83,49 @@ declare class Struct { constructor( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ); /** - * Regularization function to be used. + * Parameters specific to the regularization function being used. */ - penalty: number; + penaltyParams: T; /** - * Parameters specific to the regularization function being used. + * Parameters specific to the learning rate scheduler being used. */ - penaltyParams: T; + learningRateParams: T; /** - * Learning rate scheduler to be used. + * Parameters specific to the loss function being used. */ - learningRate: number; + lossFunctionParams: T; /** - * Parameters specific to the learning rate scheduler being used. + * Initial intercept value. */ - learningRateParams: T; + intercept: number; /** - * Loss function to be used. + * Maximum number of iterations to run. */ - lossFunction: number; + maxIter: number; /** - * Parameters specific to the loss function being used. + * Regularization function to be used. */ - lossFunctionParams: T; + penalty: number; /** - * Boolean indicating whether to include intercept. + * Learning rate scheduler to be used. */ - fitIntercept: boolean; + learningRate: number; /** - * Initial intercept value. + * Loss function to be used. */ - intercept: number; + lossFunction: number; /** - * Maximum number of iterations to run. + * Boolean indicating whether to include intercept. */ - maxIter: number; + fitIntercept: boolean; } /** @@ -156,7 +156,7 @@ interface StructConstructor { /** * Returns a new struct constructor tailored to a specified floating-point data type. * -* @param dtype - floating-point data type for storing floating-point results +* @param dtype - floating-point data type for storing floating-point params * @returns struct constructor * * @example @@ -171,7 +171,7 @@ declare function structFactory( dtype: 'float64' ): StructConstructor Date: Thu, 6 Aug 2026 16:08:53 +0530 Subject: [PATCH 05/24] chore: update according to code review --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/ml/base/sgd/params/struct-factory/README.md | 4 ++-- .../ml/base/sgd/params/struct-factory/examples/index.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index 32bf6a52cf73..41eca54922f0 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -106,7 +106,7 @@ var Struct = structFactory( 'float64' ); var params = new Struct({ 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - 'lossFunctionParams': new Float64Array( [ 0.0, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'intercept': 0.0, 'maxIter': 500, 'penalty': resolvePenaltyEnum( 'l2' ), @@ -124,7 +124,7 @@ Struct = structFactory( 'float32' ); params = new Struct({ 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), - 'lossFunctionParams': new Float32Array( [ 0.0, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'intercept': 0.0, 'maxIter': 500, 'penalty': resolvePenaltyEnum( 'l2' ), diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js index cdb5d1e7c0cb..d6a7793cb9ff 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js @@ -29,7 +29,7 @@ var Struct = structFactory( 'float64' ); var params = new Struct({ 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - 'lossFunctionParams': new Float64Array( [ 0.0, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'intercept': 0.0, 'maxIter': 500, 'penalty': resolvePenaltyEnum( 'l2' ), @@ -47,7 +47,7 @@ Struct = structFactory( 'float32' ); params = new Struct({ 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), - 'lossFunctionParams': new Float32Array( [ 0.0, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'intercept': 0.0, 'maxIter': 500, 'penalty': resolvePenaltyEnum( 'l2' ), From b1a2405cd9f5cab6601cf3d8b0bbce0fe00723ad Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sat, 8 Aug 2026 21:54:17 +0530 Subject: [PATCH 06/24] docs: broaden JSDocs --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 --- --- .../base/sgd/params/struct-factory/README.md | 96 ++++++++++++++++--- .../struct-factory/docs/types/index.d.ts | 75 +++++++++++++++ .../params/struct-factory/examples/index.js | 3 +- 3 files changed, 161 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index 41eca54922f0..106ada8c89e2 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -58,15 +58,72 @@ The function supports the following parameters: A returned [`struct`][@stdlib/dstructs/struct] constructor supports the following fields: -- **penaltyParams**: parameters specific to the regularization function being used. -- **learningRateParams**: parameters specific to the learning rate scheduler being used. -- **lossFunctionParams**: parameters specific to the loss function being used. -- **intercept**: initial intercept value. +- **penalty**: regularization function to be used, provided as an enumeration constant (see [`@stdlib/ml/base/sgd/penalty-resolve-enum`][@stdlib/ml/base/sgd/penalty-resolve-enum]). Must be one of the following: + + - `'l1'`: L1 regularization (also called LASSO) which leads to sparse models by adding a penalty based on the absolute value of coefficients. + - `'l2'`: L2 regularization (also called ridge regression) which encourages smaller, more evenly distributed weights by adding a penalty based on the square of the coefficients. + - `'elasticnet'`: regularization method which linearly combines the L1 and L2 penalties of the lasso and ridge methods. + - `'none'`: no regularization. + +- **penaltyParams**: parameters specific to the regularization function being used. Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on `penalty`: + + - `'l1'`, `'l2'`: `[ lambda, 0.0 ]` + - `'elasticnet'`: `[ lambda, l1Ratio ]` + - `'none'`: `[ 0.0, 0.0 ]` (may be omitted) + + where + + - **lambda**: regularization parameter which determines the amount of shrinkage inflicted on the model coefficients. Higher values reduce the variance of the model coefficient estimates at the expense of introducing bias. + - **l1Ratio**: mixing parameter on the interval `[0,1]` which determines the relative contribution of the L1 and L2 penalties, according to the formula `(l1Ratio*L1) + ((1-l1Ratio)*L2)`. A value of `0` corresponds to pure L2 regularization, and a value of `1` corresponds to pure L1 regularization. + +- **learningRate**: learning rate scheduler to be used, provided as an enumeration constant (see [`@stdlib/ml/base/sgd/learning-rate-resolve-enum`][@stdlib/ml/base/sgd/learning-rate-resolve-enum]). The learning rate scheduler decides how fast or slow the model coefficients are updated toward the optimal coefficients. Must be one of the following: + + - `'basic'`: basic learning rate function according to the formula `10/(10+t)`, where `t` is the current iteration. + - `'constant'`: constant learning rate function. + - `'invscaling'`: inverse scaling learning rate function according to the formula `eta0/pow(t, powerT)`. + - `'pegasos'`: [Pegasos][@shalevshwartz:2011a] learning rate function according to the formula `1/(lambda*t)`, where `t` is the current iteration. + +- **learningRateParams**: parameters specific to the learning rate scheduler being used. Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on `learningRate`: + + - `'basic'`: `[ 0.0, 0.0 ]` (may be omitted) + - `'constant'`: `[ eta0, 0.0 ]` + - `'invscaling'`: `[ eta0, powerT ]` + - `'pegasos'`: `[ lambda, 0.0 ]` + + where + + - **eta0**: initial learning rate. When `learningRate` is `'constant'`, the learning rate is held fixed at `eta0` for all iterations. + - **powerT**: exponent controlling how quickly the learning rate decreases. Higher values cause the learning rate to decay more rapidly. + - **lambda**: regularization parameter. As the Pegasos scheduler derives its learning rate from the regularization parameter, one should provide the same value as provided for the corresponding element of `penaltyParams`. + +- **lossFunction**: loss function to be used, provided as an enumeration constant (see [`@stdlib/ml/base/sgd/loss-function-resolve-enum`][@stdlib/ml/base/sgd/loss-function-resolve-enum]). Must be one of the following: + + - `'epsilon-insensitive'`: 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 `threshold` 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. + - `'modified-huber'`: Huber loss function [variant][@zhang:2004a] for classification. + - `'perceptron'`: hinge loss function without a margin. Corresponds to the original perceptron by Rosenblatt (1957). + - `'squared-epsilon-insensitive'`: squared epsilon insensitive loss function. + - `'squared-error'`: squared error loss (i.e., the squared difference of the observed and fitted values). + - `'squared-hinge'`: squared hinge loss function SVM (L2-SVM). + +- **lossFunctionParams**: parameters specific to the loss function being used. Must be a list having length `1`. The expected list contents depend on `lossFunction`: + + - `'epsilon-insensitive'`, `'squared-epsilon-insensitive'`: `[ epsilon ]` + - `'huber'`: `[ threshold ]` + - all other loss functions: `[ 0.0 ]` (may be omitted) + + where + + - **epsilon**: insensitivity parameter. Errors whose absolute value is less than `epsilon` incur no penalty. + - **threshold**: error magnitude at which the loss transitions from squared-error loss to linear loss. Observations whose absolute error is less than `threshold` incur squared-error loss, and all other observations incur linear loss. Smaller values decrease the influence of outliers on the model fit. + +- **fitIntercept**: boolean indicating whether to include an intercept. If `true`, an element equal to one is implicitly added to each provided feature vector (note, however, that the model does not perform regularization of the intercept term). If `false`, the model assumes that feature vectors are already centered. + +- **intercept**: initial intercept value. Only applicable when `fitIntercept` is `true`. + - **maxIter**: maximum number of iterations to run. -- **penalty**: regularization function to be used. -- **learningRate**: learning rate scheduler to be used. -- **lossFunction**: loss function to be used. -- **fitIntercept**: boolean indicating whether to include an intercept. @@ -79,7 +136,8 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin ## Notes - A [`struct`][@stdlib/dstructs/struct] provides a fixed-width composite data structure for storing SGD trainer parameters and provides an ABI-stable data layout for JavaScript-C interoperation. -- Each parameter list is a fixed-length array which is large enough to accommodate the option requiring the most parameters (`penaltyParams`: `3`, `learningRateParams`: `2`, `lossFunctionParams`: `1`). Accordingly, one must provide a list having the expected length, with any unused elements set to zero. As struct instances are zero-filled upon initialization, one may omit a list when the corresponding option requires no parameters. +- Each parameter list is a fixed-length array which is large enough to accommodate the option requiring the most parameters (`penaltyParams`: `2`, `learningRateParams`: `2`, `lossFunctionParams`: `1`). Accordingly, one must provide a list having the expected length, with any unused elements set to zero (e.g., `[ lambda, 0.0 ]`), as providing a list having an unexpected length, including an empty list, raises an exception. As struct instances are zero-filled upon initialization, one may omit a list when the corresponding option requires no parameters. +- Consumers should only read as many elements as are applicable to the corresponding penalty, learning rate scheduler, or loss function, with any remaining elements being unused. @@ -106,7 +164,6 @@ var Struct = structFactory( 'float64' ); var params = new Struct({ 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'intercept': 0.0, 'maxIter': 500, 'penalty': resolvePenaltyEnum( 'l2' ), @@ -124,7 +181,6 @@ Struct = structFactory( 'float32' ); params = new Struct({ 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), - 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'intercept': 0.0, 'maxIter': 500, 'penalty': resolvePenaltyEnum( 'l2' ), @@ -145,8 +201,16 @@ console.log( str ); +* * * +
+## References + +- Rosenblatt, Frank. 1957. "The Perceptron–a perceiving and recognizing automaton." 85-460-1. Buffalo, NY, USA: Cornell Aeronautical Laboratory. +- Zhang, Tong. 2004. "Solving Large Scale Linear Prediction Problems Using Stochastic Gradient Descent Algorithms." In _Proceedings of the Twenty-First International Conference on Machine Learning_, 116. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/1015330.1015332][@zhang:2004a]. +- Shalev-Shwartz, Shai, Yoram Singer, Nathan Srebro, and Andrew Cotter. 2011. "Pegasos: primal estimated sub-gradient solver for SVM." _Mathematical Programming_ 127 (1): 3–30. doi:[10.1007/s10107-010-0420-4][@shalevshwartz:2011a]. +
@@ -165,6 +229,16 @@ console.log( str ); [@stdlib/dstructs/struct]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/dstructs/struct +[@stdlib/ml/base/sgd/penalty-resolve-enum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ml/base/sgd/penalty-resolve-enum + +[@stdlib/ml/base/sgd/learning-rate-resolve-enum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ml/base/sgd/learning-rate-resolve-enum + +[@stdlib/ml/base/sgd/loss-function-resolve-enum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ml/base/sgd/loss-function-resolve-enum + +[@zhang:2004a]: https://doi.org/10.1145/1015330.1015332 + +[@shalevshwartz:2011a]: https://doi.org/10.1007/s10107-010-0420-4 + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index 0d1985c8f478..aa284bd50294 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -24,21 +24,60 @@ interface Params { /** * Parameters specific to the regularization function being used. + * + * ## Notes + * + * - Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on the penalty: + * + * - `l1`, `l2`: `[ lambda, 0.0 ]` + * - `elasticnet`: `[ lambda, l1Ratio ]` + * - `none`: `[ 0.0, 0.0 ]` (may be omitted) + * + * `lambda`: regularization parameter which determines the amount of shrinkage inflicted on the model coefficients. + * `l1Ratio`: mixing parameter on the interval `[0,1]` which determines the relative contribution of the L1 and L2 penalties. */ penaltyParams?: T; /** * Parameters specific to the learning rate scheduler being used. + * + * ## Notes + * + * - Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on the learning rate scheduler: + * + * - `basic`: `[ 0.0, 0.0 ]` (may be omitted) + * - `constant`: `[ eta0, 0.0 ]` + * - `invscaling`: `[ eta0, powerT ]` + * - `pegasos`: `[ lambda, 0.0 ]` + * + * `eta0`: initial learning rate. + * `powerT`: exponent controlling how quickly the learning rate decreases. + * `lambda`: regularization parameter. */ learningRateParams?: T; /** * Parameters specific to the loss function being used. + * + * ## Notes + * + * - Must be a list having length `1`. The expected list contents depend on the loss function: + * + * - `epsilon-insensitive`, `squared-epsilon-insensitive`: `[ epsilon ]` + * - `huber`: `[ threshold ]` + * - all other loss functions: `[ 0.0 ]` (may be omitted) + * + * `epsilon`: insensitivity parameter (i.e., errors whose absolute value is less than `epsilon` incur no penalty). + * `threshold`: error magnitude at which the loss transitions from squared-error loss to linear loss. */ lossFunctionParams?: T; /** * Initial intercept value. + * + * ## Notes + * + * - Only applicable when `fitIntercept` is `true`. */ intercept?: number; @@ -49,21 +88,57 @@ interface Params { /** * Regularization function to be used. + * + * ## Notes + * + * - Must be provided as an enumeration constant (see `@stdlib/ml/base/sgd/penalty-resolve-enum`) resolved from one of the following: + * + * - `l1`: L1 regularization (also called LASSO) which leads to sparse models by adding a penalty based on the absolute value of coefficients. + * - `l2`: L2 regularization (also called ridge regression) which encourages smaller, more evenly distributed weights by adding a penalty based on the square of the coefficients. + * - `elasticnet`: regularization method which linearly combines the L1 and L2 penalties of the lasso and ridge methods. + * - `none`: no regularization. */ penalty?: number; /** * Learning rate scheduler to be used. + * + * ## Notes + * + * - Must be provided as an enumeration constant (see `@stdlib/ml/base/sgd/learning-rate-resolve-enum`) resolved from one of the following: + * + * - `basic`: basic learning rate function according to the formula `10/(10+t)`, where `t` is the current iteration. + * - `constant`: constant learning rate function. + * - `invscaling`: inverse scaling learning rate function according to the formula `eta0/pow(t, powerT)`. + * - `pegasos`: Pegasos learning rate function according to the formula `1/(lambda*t)`, where `t` is the current iteration. */ learningRate?: number; /** * Loss function to be used. + * + * ## Notes + * + * - Must be provided as an enumeration constant (see `@stdlib/ml/base/sgd/loss-function-resolve-enum`) resolved from one of the following: + * + * - `epsilon-insensitive`: 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 `threshold` in magnitude, linear loss otherwise. + * - `log`: logistic loss function. Corresponds to Logistic Regression. + * - `modified-huber`: Huber loss function variant for classification. + * - `perceptron`: hinge loss function without a margin. Corresponds to the original perceptron by Rosenblatt. + * - `squared-epsilon-insensitive`: squared epsilon insensitive loss function. + * - `squared-error`: squared error loss (i.e., the squared difference of the observed and fitted values). + * - `squared-hinge`: squared hinge loss function SVM (L2-SVM). */ lossFunction?: number; /** * Boolean indicating whether to include intercept. + * + * ## Notes + * + * - If `true`, an element equal to one is implicitly added to each provided feature vector. If `false`, the model assumes that feature vectors are already centered. */ fitIntercept?: boolean; } diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js index d6a7793cb9ff..45691140aab6 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js @@ -25,11 +25,11 @@ var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); var structFactory = require( './../lib' ); +// Note: hinge loss requires no parameters, and thus we may omit the respective parameter list. var Struct = structFactory( 'float64' ); var params = new Struct({ 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'intercept': 0.0, 'maxIter': 500, 'penalty': resolvePenaltyEnum( 'l2' ), @@ -47,7 +47,6 @@ Struct = structFactory( 'float32' ); params = new Struct({ 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), - 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'intercept': 0.0, 'maxIter': 500, 'penalty': resolvePenaltyEnum( 'l2' ), From 54406627354bf2eaf56b5b47ff339d19b6d923c8 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sat, 8 Aug 2026 22:05:01 +0530 Subject: [PATCH 07/24] docs: broaden JSDocs --- 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: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 --- --- .../params/struct-factory/docs/types/index.d.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index aa284bd50294..198de9efca84 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -33,8 +33,9 @@ interface Params { * - `elasticnet`: `[ lambda, l1Ratio ]` * - `none`: `[ 0.0, 0.0 ]` (may be omitted) * - * `lambda`: regularization parameter which determines the amount of shrinkage inflicted on the model coefficients. - * `l1Ratio`: mixing parameter on the interval `[0,1]` which determines the relative contribution of the L1 and L2 penalties. + * where: + * - `lambda`: regularization parameter which determines the amount of shrinkage inflicted on the model coefficients. + * - `l1Ratio`: mixing parameter on the interval `[0,1]` which determines the relative contribution of the L1 and L2 penalties. */ penaltyParams?: T; @@ -50,9 +51,10 @@ interface Params { * - `invscaling`: `[ eta0, powerT ]` * - `pegasos`: `[ lambda, 0.0 ]` * - * `eta0`: initial learning rate. - * `powerT`: exponent controlling how quickly the learning rate decreases. - * `lambda`: regularization parameter. + * where: + * - `eta0`: initial learning rate. + * - `powerT`: exponent controlling how quickly the learning rate decreases. + * - `lambda`: regularization parameter. */ learningRateParams?: T; @@ -67,8 +69,9 @@ interface Params { * - `huber`: `[ threshold ]` * - all other loss functions: `[ 0.0 ]` (may be omitted) * - * `epsilon`: insensitivity parameter (i.e., errors whose absolute value is less than `epsilon` incur no penalty). - * `threshold`: error magnitude at which the loss transitions from squared-error loss to linear loss. + * where: + * - `epsilon`: insensitivity parameter (i.e., errors whose absolute value is less than `epsilon` incur no penalty). + * - `threshold`: error magnitude at which the loss transitions from squared-error loss to linear loss. */ lossFunctionParams?: T; From c9ff466f258bd2d583f57251893e751bac1b698c Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:10:54 -0700 Subject: [PATCH 08/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../struct-factory/docs/types/index.d.ts | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index 198de9efca84..b6bcd80678d6 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -27,15 +27,17 @@ interface Params { * * ## Notes * - * - Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on the penalty: + * - Must be an array having length `2`, with any unused elements set to zero. The expected array contents depend on the penalty: * - * - `l1`, `l2`: `[ lambda, 0.0 ]` - * - `elasticnet`: `[ lambda, l1Ratio ]` - * - `none`: `[ 0.0, 0.0 ]` (may be omitted) + * - **l1**: `[ lambda, 0.0 ]` + * - **l2**: `[ lambda, 0.0 ]` + * - **elasticnet**: `[ lambda, l1Ratio ]` + * - `none`: **[ 0.0, 0.0 ]** (may be omitted) * * where: - * - `lambda`: regularization parameter which determines the amount of shrinkage inflicted on the model coefficients. - * - `l1Ratio`: mixing parameter on the interval `[0,1]` which determines the relative contribution of the L1 and L2 penalties. + * + * - **lambda**: regularization parameter which determines the amount of shrinkage inflicted on the model coefficients. + * - **l1Ratio**: mixing parameter on the interval `[0,1]` which determines the relative contribution of the L1 and L2 penalties. */ penaltyParams?: T; @@ -44,17 +46,18 @@ interface Params { * * ## Notes * - * - Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on the learning rate scheduler: + * - Must be an array having length `2`, with any unused elements set to zero. The expected array contents depend on the learning rate scheduler: * - * - `basic`: `[ 0.0, 0.0 ]` (may be omitted) - * - `constant`: `[ eta0, 0.0 ]` - * - `invscaling`: `[ eta0, powerT ]` - * - `pegasos`: `[ lambda, 0.0 ]` + * - `basic`: **[ 0.0, 0.0 ]** (may be omitted) + * - **constant**: `[ eta0, 0.0 ]` + * - **invscaling**: `[ eta0, powerT ]` + * - **pegasos**: `[ lambda, 0.0 ]` * * where: - * - `eta0`: initial learning rate. - * - `powerT`: exponent controlling how quickly the learning rate decreases. - * - `lambda`: regularization parameter. + * + * - **eta0**: initial learning rate. + * - **powerT**: exponent controlling how quickly the learning rate decreases. + * - **lambda**: regularization parameter. */ learningRateParams?: T; @@ -63,15 +66,17 @@ interface Params { * * ## Notes * - * - Must be a list having length `1`. The expected list contents depend on the loss function: + * - Must be an array having length `1`. The expected array contents depend on the loss function: * - * - `epsilon-insensitive`, `squared-epsilon-insensitive`: `[ epsilon ]` - * - `huber`: `[ threshold ]` + * - **epsilon-insensitive**: `[ epsilon ]` + * - **squared-epsilon-insensitive**: `[ epsilon ]` + * - **huber**: `[ threshold ]` * - all other loss functions: `[ 0.0 ]` (may be omitted) * * where: - * - `epsilon`: insensitivity parameter (i.e., errors whose absolute value is less than `epsilon` incur no penalty). - * - `threshold`: error magnitude at which the loss transitions from squared-error loss to linear loss. + * + * - **epsilon**: insensitivity parameter (i.e., errors whose absolute value is less than `epsilon` incur no penalty). + * - **threshold**: error magnitude at which the loss transitions from squared-error loss to linear loss. */ lossFunctionParams?: T; From caf17cb5b23a58b208de25fb8db6e86727b7198b Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:11:23 -0700 Subject: [PATCH 09/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../ml/base/sgd/params/struct-factory/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index b6bcd80678d6..1422c5c50674 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -32,7 +32,7 @@ interface Params { * - **l1**: `[ lambda, 0.0 ]` * - **l2**: `[ lambda, 0.0 ]` * - **elasticnet**: `[ lambda, l1Ratio ]` - * - `none`: **[ 0.0, 0.0 ]** (may be omitted) + * - **none**: `[ 0.0, 0.0 ]` (may be omitted) * * where: * From 11c4ce71837fd1b7d82e6f56a23a7441701c1c5a Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:12:07 -0700 Subject: [PATCH 10/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../ml/base/sgd/params/struct-factory/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index 1422c5c50674..fea7b74e858a 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -48,7 +48,7 @@ interface Params { * * - Must be an array having length `2`, with any unused elements set to zero. The expected array contents depend on the learning rate scheduler: * - * - `basic`: **[ 0.0, 0.0 ]** (may be omitted) + * - **basic**: `[ 0.0, 0.0 ]` (may be omitted) * - **constant**: `[ eta0, 0.0 ]` * - **invscaling**: `[ eta0, powerT ]` * - **pegasos**: `[ lambda, 0.0 ]` From fe86974528b4963a853320e4f9df0be7383807c6 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:14:18 -0700 Subject: [PATCH 11/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../struct-factory/docs/types/index.d.ts | 38 ++----------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index fea7b74e858a..d12931071756 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -95,49 +95,17 @@ interface Params { maxIter?: number; /** - * Regularization function to be used. - * - * ## Notes - * - * - Must be provided as an enumeration constant (see `@stdlib/ml/base/sgd/penalty-resolve-enum`) resolved from one of the following: - * - * - `l1`: L1 regularization (also called LASSO) which leads to sparse models by adding a penalty based on the absolute value of coefficients. - * - `l2`: L2 regularization (also called ridge regression) which encourages smaller, more evenly distributed weights by adding a penalty based on the square of the coefficients. - * - `elasticnet`: regularization method which linearly combines the L1 and L2 penalties of the lasso and ridge methods. - * - `none`: no regularization. + * Regularization function. */ penalty?: number; /** - * Learning rate scheduler to be used. - * - * ## Notes - * - * - Must be provided as an enumeration constant (see `@stdlib/ml/base/sgd/learning-rate-resolve-enum`) resolved from one of the following: - * - * - `basic`: basic learning rate function according to the formula `10/(10+t)`, where `t` is the current iteration. - * - `constant`: constant learning rate function. - * - `invscaling`: inverse scaling learning rate function according to the formula `eta0/pow(t, powerT)`. - * - `pegasos`: Pegasos learning rate function according to the formula `1/(lambda*t)`, where `t` is the current iteration. + * Learning rate scheduler. */ learningRate?: number; /** - * Loss function to be used. - * - * ## Notes - * - * - Must be provided as an enumeration constant (see `@stdlib/ml/base/sgd/loss-function-resolve-enum`) resolved from one of the following: - * - * - `epsilon-insensitive`: 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 `threshold` in magnitude, linear loss otherwise. - * - `log`: logistic loss function. Corresponds to Logistic Regression. - * - `modified-huber`: Huber loss function variant for classification. - * - `perceptron`: hinge loss function without a margin. Corresponds to the original perceptron by Rosenblatt. - * - `squared-epsilon-insensitive`: squared epsilon insensitive loss function. - * - `squared-error`: squared error loss (i.e., the squared difference of the observed and fitted values). - * - `squared-hinge`: squared hinge loss function SVM (L2-SVM). + * Loss function. */ lossFunction?: number; From 411aacba9e28ebfb8b0ba8769dd80189981dfb6f Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:18:51 -0700 Subject: [PATCH 12/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../ml/base/sgd/params/struct-factory/docs/types/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index d12931071756..e327cc1ac458 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -32,7 +32,7 @@ interface Params { * - **l1**: `[ lambda, 0.0 ]` * - **l2**: `[ lambda, 0.0 ]` * - **elasticnet**: `[ lambda, l1Ratio ]` - * - **none**: `[ 0.0, 0.0 ]` (may be omitted) + * - **none**: `[ 0.0, 0.0 ]` (unused) * * where: * @@ -48,7 +48,7 @@ interface Params { * * - Must be an array having length `2`, with any unused elements set to zero. The expected array contents depend on the learning rate scheduler: * - * - **basic**: `[ 0.0, 0.0 ]` (may be omitted) + * - **basic**: `[ 0.0, 0.0 ]` (unused) * - **constant**: `[ eta0, 0.0 ]` * - **invscaling**: `[ eta0, powerT ]` * - **pegasos**: `[ lambda, 0.0 ]` @@ -71,7 +71,7 @@ interface Params { * - **epsilon-insensitive**: `[ epsilon ]` * - **squared-epsilon-insensitive**: `[ epsilon ]` * - **huber**: `[ threshold ]` - * - all other loss functions: `[ 0.0 ]` (may be omitted) + * - all other loss functions: `[ 0.0 ]` (unused) * * where: * From fb7db0bcaabd4813f3922d4dd49aa0fdfd752354 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:19:23 -0700 Subject: [PATCH 13/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../ml/base/sgd/params/struct-factory/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index e327cc1ac458..f2d58f93d353 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -71,7 +71,7 @@ interface Params { * - **epsilon-insensitive**: `[ epsilon ]` * - **squared-epsilon-insensitive**: `[ epsilon ]` * - **huber**: `[ threshold ]` - * - all other loss functions: `[ 0.0 ]` (unused) + * - all other loss functions: `[ 0.0 ]` (unused) * * where: * From 9d43944247ce7f0ab32366b5bc675be3968dfa54 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:21:40 -0700 Subject: [PATCH 14/24] refactor: inline constants Signed-off-by: Athan --- .../ml/base/sgd/params/struct-factory/lib/main.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js index 778cae8c2448..00504531671d 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js @@ -23,13 +23,6 @@ var struct = require( '@stdlib/dstructs/struct' ); -// VARIABLES // - -var PENALTY_PARAMS_LENGTH = 2; -var LEARNING_RATE_PARAMS_LENGTH = 2; -var LOSS_FUNCTION_PARAMS_LENGTH = 1; - - // MAIN // /** @@ -55,21 +48,21 @@ function factory( dtype ) { 'name': 'penaltyParams', 'description': 'parameters specific to the regularization function being used', 'type': dtype, - 'length': PENALTY_PARAMS_LENGTH, + 'length': 2, 'castingMode': 'mostly-safe' }, { 'name': 'learningRateParams', 'description': 'parameters specific to the learning rate scheduler being used', 'type': dtype, - 'length': LEARNING_RATE_PARAMS_LENGTH, + 'length': 2, 'castingMode': 'mostly-safe' }, { 'name': 'lossFunctionParams', 'description': 'parameters specific to the loss function being used', 'type': dtype, - 'length': LOSS_FUNCTION_PARAMS_LENGTH, + 'length': 1, 'castingMode': 'mostly-safe' }, { From 40be548a600c088c6e469bdd35994aa5207b5372 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:23:07 -0700 Subject: [PATCH 15/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/ml/base/sgd/params/struct-factory/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js index 00504531671d..87d62621d4ab 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js @@ -75,7 +75,7 @@ function factory( dtype ) { 'name': 'maxIter', 'description': 'maximum number of iterations to run', 'type': 'int32', - 'castingMode': 'mostly-safe' + 'castingMode': 'none' }, { 'name': 'penalty', From d2795534baf09a77b55d9e5b40f44fcb7f315c26 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:23:23 -0700 Subject: [PATCH 16/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/ml/base/sgd/params/struct-factory/examples/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js index 45691140aab6..db4606f2bc44 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/examples/index.js @@ -25,7 +25,6 @@ var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); var structFactory = require( './../lib' ); -// Note: hinge loss requires no parameters, and thus we may omit the respective parameter list. var Struct = structFactory( 'float64' ); var params = new Struct({ 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), From 29a1642b35443aefe3289540a1ebbae6fe04a0ac Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:26:21 -0700 Subject: [PATCH 17/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/ml/base/sgd/params/struct-factory/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index 106ada8c89e2..cdf4daaea769 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -159,7 +159,6 @@ var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); var structFactory = require( '@stdlib/ml/base/sgd/params/struct-factory' ); -// Note: hinge loss requires no parameters, and thus we may omit the respective parameter list. var Struct = structFactory( 'float64' ); var params = new Struct({ 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), From 246f17f3d420d639635808f45733273644d6a8d7 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 02:33:50 -0700 Subject: [PATCH 18/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/ml/base/sgd/params/struct-factory/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js index 87d62621d4ab..00504531671d 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/lib/main.js @@ -75,7 +75,7 @@ function factory( dtype ) { 'name': 'maxIter', 'description': 'maximum number of iterations to run', 'type': 'int32', - 'castingMode': 'none' + 'castingMode': 'mostly-safe' }, { 'name': 'penalty', From bb071fe246a0e3275a387c1aaecffae42b7784d7 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sun, 9 Aug 2026 16:37:18 +0530 Subject: [PATCH 19/24] docs: remove unwanted details --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_license_headers status: passed --- --- .../base/sgd/params/struct-factory/README.md | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index cdf4daaea769..1e2ee02453cc 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -58,12 +58,7 @@ The function supports the following parameters: A returned [`struct`][@stdlib/dstructs/struct] constructor supports the following fields: -- **penalty**: regularization function to be used, provided as an enumeration constant (see [`@stdlib/ml/base/sgd/penalty-resolve-enum`][@stdlib/ml/base/sgd/penalty-resolve-enum]). Must be one of the following: - - - `'l1'`: L1 regularization (also called LASSO) which leads to sparse models by adding a penalty based on the absolute value of coefficients. - - `'l2'`: L2 regularization (also called ridge regression) which encourages smaller, more evenly distributed weights by adding a penalty based on the square of the coefficients. - - `'elasticnet'`: regularization method which linearly combines the L1 and L2 penalties of the lasso and ridge methods. - - `'none'`: no regularization. +- **penalty**: [regularization function][@stdlib/ml/base/sgd/penalties] to be used. - **penaltyParams**: parameters specific to the regularization function being used. Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on `penalty`: @@ -76,12 +71,7 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin - **lambda**: regularization parameter which determines the amount of shrinkage inflicted on the model coefficients. Higher values reduce the variance of the model coefficient estimates at the expense of introducing bias. - **l1Ratio**: mixing parameter on the interval `[0,1]` which determines the relative contribution of the L1 and L2 penalties, according to the formula `(l1Ratio*L1) + ((1-l1Ratio)*L2)`. A value of `0` corresponds to pure L2 regularization, and a value of `1` corresponds to pure L1 regularization. -- **learningRate**: learning rate scheduler to be used, provided as an enumeration constant (see [`@stdlib/ml/base/sgd/learning-rate-resolve-enum`][@stdlib/ml/base/sgd/learning-rate-resolve-enum]). The learning rate scheduler decides how fast or slow the model coefficients are updated toward the optimal coefficients. Must be one of the following: - - - `'basic'`: basic learning rate function according to the formula `10/(10+t)`, where `t` is the current iteration. - - `'constant'`: constant learning rate function. - - `'invscaling'`: inverse scaling learning rate function according to the formula `eta0/pow(t, powerT)`. - - `'pegasos'`: [Pegasos][@shalevshwartz:2011a] learning rate function according to the formula `1/(lambda*t)`, where `t` is the current iteration. +- **learningRate**: [learning rate scheduler][@stdlib/ml/base/sgd/learning-rates] to be used. - **learningRateParams**: parameters specific to the learning rate scheduler being used. Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on `learningRate`: @@ -96,17 +86,7 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin - **powerT**: exponent controlling how quickly the learning rate decreases. Higher values cause the learning rate to decay more rapidly. - **lambda**: regularization parameter. As the Pegasos scheduler derives its learning rate from the regularization parameter, one should provide the same value as provided for the corresponding element of `penaltyParams`. -- **lossFunction**: loss function to be used, provided as an enumeration constant (see [`@stdlib/ml/base/sgd/loss-function-resolve-enum`][@stdlib/ml/base/sgd/loss-function-resolve-enum]). Must be one of the following: - - - `'epsilon-insensitive'`: 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 `threshold` 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. - - `'modified-huber'`: Huber loss function [variant][@zhang:2004a] for classification. - - `'perceptron'`: hinge loss function without a margin. Corresponds to the original perceptron by Rosenblatt (1957). - - `'squared-epsilon-insensitive'`: squared epsilon insensitive loss function. - - `'squared-error'`: squared error loss (i.e., the squared difference of the observed and fitted values). - - `'squared-hinge'`: squared hinge loss function SVM (L2-SVM). +- **lossFunction**: [loss function][@stdlib/ml/base/sgd/loss-functions] to be used. - **lossFunctionParams**: parameters specific to the loss function being used. Must be a list having length `1`. The expected list contents depend on `lossFunction`: @@ -228,11 +208,11 @@ console.log( str ); [@stdlib/dstructs/struct]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/dstructs/struct -[@stdlib/ml/base/sgd/penalty-resolve-enum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ml/base/sgd/penalty-resolve-enum +[@stdlib/ml/base/sgd/penalties]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ml/base/sgd/penalties -[@stdlib/ml/base/sgd/learning-rate-resolve-enum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ml/base/sgd/learning-rate-resolve-enum +[@stdlib/ml/base/sgd/learning-rates]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ml/base/sgd/learning-rates -[@stdlib/ml/base/sgd/loss-function-resolve-enum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ml/base/sgd/loss-function-resolve-enum +[@stdlib/ml/base/sgd/loss-functions]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ml/base/sgd/loss-functions [@zhang:2004a]: https://doi.org/10.1145/1015330.1015332 From e9d922e0b6f85b4f86d974579280cc9cbe51f516 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 04:10:35 -0700 Subject: [PATCH 20/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/ml/base/sgd/params/struct-factory/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index 1e2ee02453cc..75979e2527dd 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -75,10 +75,10 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin - **learningRateParams**: parameters specific to the learning rate scheduler being used. Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on `learningRate`: - - `'basic'`: `[ 0.0, 0.0 ]` (may be omitted) - - `'constant'`: `[ eta0, 0.0 ]` - - `'invscaling'`: `[ eta0, powerT ]` - - `'pegasos'`: `[ lambda, 0.0 ]` + - **basic**: `[ 0.0, 0.0 ]` (unused) + - **constant**: `[ eta0, 0.0 ]` + - **invscaling**: `[ eta0, powerT ]` + - **pegasos**: `[ lambda, 0.0 ]` where From 49271099d32296578c3a4c1f49fd11e6afe3a525 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sun, 9 Aug 2026 16:54:30 +0530 Subject: [PATCH 21/24] docs: update according to code review --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 --- --- .../base/sgd/params/struct-factory/README.md | 36 +++++++++---------- .../struct-factory/docs/types/index.d.ts | 6 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index 75979e2527dd..27d98fae5449 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -60,46 +60,46 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin - **penalty**: [regularization function][@stdlib/ml/base/sgd/penalties] to be used. -- **penaltyParams**: parameters specific to the regularization function being used. Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on `penalty`: +- **penaltyParams**: parameters specific to the regularization function being used. Must be an array having length `2`, with any unused elements set to zero. The expected array contents depend on `penalty`: - `'l1'`, `'l2'`: `[ lambda, 0.0 ]` - `'elasticnet'`: `[ lambda, l1Ratio ]` - - `'none'`: `[ 0.0, 0.0 ]` (may be omitted) + - `'none'`: `[ 0.0, 0.0 ]` (unused) where - - **lambda**: regularization parameter which determines the amount of shrinkage inflicted on the model coefficients. Higher values reduce the variance of the model coefficient estimates at the expense of introducing bias. - - **l1Ratio**: mixing parameter on the interval `[0,1]` which determines the relative contribution of the L1 and L2 penalties, according to the formula `(l1Ratio*L1) + ((1-l1Ratio)*L2)`. A value of `0` corresponds to pure L2 regularization, and a value of `1` corresponds to pure L1 regularization. + - **lambda**: regularization parameter which determines the amount of shrinkage inflicted on the model coefficients. + - **l1Ratio**: mixing parameter on the interval `[0,1]` which determines the relative contribution of the L1 and L2 penalties. - **learningRate**: [learning rate scheduler][@stdlib/ml/base/sgd/learning-rates] to be used. -- **learningRateParams**: parameters specific to the learning rate scheduler being used. Must be a list having length `2`, with any unused elements set to zero. The expected list contents depend on `learningRate`: +- **learningRateParams**: parameters specific to the learning rate scheduler being used. Must be an array having length `2`, with any unused elements set to zero. The expected array contents depend on `learningRate`: - - **basic**: `[ 0.0, 0.0 ]` (unused) - - **constant**: `[ eta0, 0.0 ]` - - **invscaling**: `[ eta0, powerT ]` - - **pegasos**: `[ lambda, 0.0 ]` + - `'basic'`: `[ 0.0, 0.0 ]` (unused) + - `'constant'`: `[ eta0, 0.0 ]` + - `'invscaling'`: `[ eta0, powerT ]` + - `'pegasos'`: `[ lambda, 0.0 ]` where - - **eta0**: initial learning rate. When `learningRate` is `'constant'`, the learning rate is held fixed at `eta0` for all iterations. - - **powerT**: exponent controlling how quickly the learning rate decreases. Higher values cause the learning rate to decay more rapidly. - - **lambda**: regularization parameter. As the Pegasos scheduler derives its learning rate from the regularization parameter, one should provide the same value as provided for the corresponding element of `penaltyParams`. + - **eta0**: initial learning rate. + - **powerT**: exponent controlling how quickly the learning rate decreases. + - **lambda**: regularization parameter. - **lossFunction**: [loss function][@stdlib/ml/base/sgd/loss-functions] to be used. -- **lossFunctionParams**: parameters specific to the loss function being used. Must be a list having length `1`. The expected list contents depend on `lossFunction`: +- **lossFunctionParams**: parameters specific to the loss function being used. Must be an array having length `1`. The expected array contents depend on `lossFunction`: - `'epsilon-insensitive'`, `'squared-epsilon-insensitive'`: `[ epsilon ]` - `'huber'`: `[ threshold ]` - - all other loss functions: `[ 0.0 ]` (may be omitted) + - all other loss functions: `[ 0.0 ]` (unused) where - - **epsilon**: insensitivity parameter. Errors whose absolute value is less than `epsilon` incur no penalty. - - **threshold**: error magnitude at which the loss transitions from squared-error loss to linear loss. Observations whose absolute error is less than `threshold` incur squared-error loss, and all other observations incur linear loss. Smaller values decrease the influence of outliers on the model fit. + - **epsilon**: insensitivity parameter (i.e., errors whose absolute value is less than `epsilon` incur no penalty). + - **threshold**: error magnitude at which the loss transitions from squared-error loss to linear loss. -- **fitIntercept**: boolean indicating whether to include an intercept. If `true`, an element equal to one is implicitly added to each provided feature vector (note, however, that the model does not perform regularization of the intercept term). If `false`, the model assumes that feature vectors are already centered. +- **fitIntercept**: boolean indicating whether to include an intercept. If `true`, an element equal to one is implicitly added to each provided feature vector. If `false`, the model assumes that feature vectors are already centered. - **intercept**: initial intercept value. Only applicable when `fitIntercept` is `true`. @@ -116,7 +116,7 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin ## Notes - A [`struct`][@stdlib/dstructs/struct] provides a fixed-width composite data structure for storing SGD trainer parameters and provides an ABI-stable data layout for JavaScript-C interoperation. -- Each parameter list is a fixed-length array which is large enough to accommodate the option requiring the most parameters (`penaltyParams`: `2`, `learningRateParams`: `2`, `lossFunctionParams`: `1`). Accordingly, one must provide a list having the expected length, with any unused elements set to zero (e.g., `[ lambda, 0.0 ]`), as providing a list having an unexpected length, including an empty list, raises an exception. As struct instances are zero-filled upon initialization, one may omit a list when the corresponding option requires no parameters. +- Each parameter array is a fixed-length array which is large enough to accommodate the option requiring the most parameters (`penaltyParams`: `2`, `learningRateParams`: `2`, `lossFunctionParams`: `1`). Accordingly, one must provide an array having the expected length, with any unused elements set to zero (e.g., `[ lambda, 0.0 ]`), as providing an array having an unexpected length, including an empty array, raises an exception. As struct instances are zero-filled upon initialization, one may omit an array when the corresponding option requires no parameters. - Consumers should only read as many elements as are applicable to the corresponding penalty, learning rate scheduler, or loss function, with any remaining elements being unused. diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts index f2d58f93d353..099128ed58f4 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/docs/types/index.d.ts @@ -159,17 +159,17 @@ declare class Struct { maxIter: number; /** - * Regularization function to be used. + * Regularization function. */ penalty: number; /** - * Learning rate scheduler to be used. + * Learning rate scheduler. */ learningRate: number; /** - * Loss function to be used. + * Loss function. */ lossFunction: number; From 5807efb171288b1818139b2c834342a623156122 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sun, 9 Aug 2026 16:56:29 +0530 Subject: [PATCH 22/24] docs: remove unnecessary references --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_license_headers status: passed --- --- .../ml/base/sgd/params/struct-factory/README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index 27d98fae5449..4f2695dc99ed 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -184,12 +184,6 @@ console.log( str );
-## References - -- Rosenblatt, Frank. 1957. "The Perceptron–a perceiving and recognizing automaton." 85-460-1. Buffalo, NY, USA: Cornell Aeronautical Laboratory. -- Zhang, Tong. 2004. "Solving Large Scale Linear Prediction Problems Using Stochastic Gradient Descent Algorithms." In _Proceedings of the Twenty-First International Conference on Machine Learning_, 116. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/1015330.1015332][@zhang:2004a]. -- Shalev-Shwartz, Shai, Yoram Singer, Nathan Srebro, and Andrew Cotter. 2011. "Pegasos: primal estimated sub-gradient solver for SVM." _Mathematical Programming_ 127 (1): 3–30. doi:[10.1007/s10107-010-0420-4][@shalevshwartz:2011a]. -
@@ -214,10 +208,6 @@ console.log( str ); [@stdlib/ml/base/sgd/loss-functions]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ml/base/sgd/loss-functions -[@zhang:2004a]: https://doi.org/10.1145/1015330.1015332 - -[@shalevshwartz:2011a]: https://doi.org/10.1007/s10107-010-0420-4 - From b66237e7dd96cc0b9101c492cd1c1c5730e10efc Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 04:31:33 -0700 Subject: [PATCH 23/24] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/ml/base/sgd/params/struct-factory/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index 4f2695dc99ed..df05e5f7311b 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -58,7 +58,7 @@ The function supports the following parameters: A returned [`struct`][@stdlib/dstructs/struct] constructor supports the following fields: -- **penalty**: [regularization function][@stdlib/ml/base/sgd/penalties] to be used. +- **penalty**: [regularization function][@stdlib/ml/base/sgd/penalties]. - **penaltyParams**: parameters specific to the regularization function being used. Must be an array having length `2`, with any unused elements set to zero. The expected array contents depend on `penalty`: @@ -71,7 +71,7 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin - **lambda**: regularization parameter which determines the amount of shrinkage inflicted on the model coefficients. - **l1Ratio**: mixing parameter on the interval `[0,1]` which determines the relative contribution of the L1 and L2 penalties. -- **learningRate**: [learning rate scheduler][@stdlib/ml/base/sgd/learning-rates] to be used. +- **learningRate**: [learning rate scheduler][@stdlib/ml/base/sgd/learning-rates]. - **learningRateParams**: parameters specific to the learning rate scheduler being used. Must be an array having length `2`, with any unused elements set to zero. The expected array contents depend on `learningRate`: @@ -86,7 +86,7 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin - **powerT**: exponent controlling how quickly the learning rate decreases. - **lambda**: regularization parameter. -- **lossFunction**: [loss function][@stdlib/ml/base/sgd/loss-functions] to be used. +- **lossFunction**: [loss function][@stdlib/ml/base/sgd/loss-functions]. - **lossFunctionParams**: parameters specific to the loss function being used. Must be an array having length `1`. The expected array contents depend on `lossFunction`: From 53ce4355979119cdded96f7632f7f7872cad04af Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Aug 2026 04:34:49 -0700 Subject: [PATCH 24/24] chore: clean-up Signed-off-by: Athan --- .../base/sgd/params/struct-factory/README.md | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md index df05e5f7311b..9c966f7e84cd 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/struct-factory/README.md @@ -62,9 +62,10 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin - **penaltyParams**: parameters specific to the regularization function being used. Must be an array having length `2`, with any unused elements set to zero. The expected array contents depend on `penalty`: - - `'l1'`, `'l2'`: `[ lambda, 0.0 ]` - - `'elasticnet'`: `[ lambda, l1Ratio ]` - - `'none'`: `[ 0.0, 0.0 ]` (unused) + - **l1**: : `[ lambda, 0.0 ]` + - **l2**: `[ lambda, 0.0 ]` + - **elasticnet**: `[ lambda, l1Ratio ]` + - **none**: `[ 0.0, 0.0 ]` (unused) where @@ -75,10 +76,10 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin - **learningRateParams**: parameters specific to the learning rate scheduler being used. Must be an array having length `2`, with any unused elements set to zero. The expected array contents depend on `learningRate`: - - `'basic'`: `[ 0.0, 0.0 ]` (unused) - - `'constant'`: `[ eta0, 0.0 ]` - - `'invscaling'`: `[ eta0, powerT ]` - - `'pegasos'`: `[ lambda, 0.0 ]` + - **basic**: `[ 0.0, 0.0 ]` (unused) + - **constant**: `[ eta0, 0.0 ]` + - **invscaling**: `[ eta0, powerT ]` + - **pegasos**: `[ lambda, 0.0 ]` where @@ -90,8 +91,9 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin - **lossFunctionParams**: parameters specific to the loss function being used. Must be an array having length `1`. The expected array contents depend on `lossFunction`: - - `'epsilon-insensitive'`, `'squared-epsilon-insensitive'`: `[ epsilon ]` - - `'huber'`: `[ threshold ]` + - **epsilon-insensitive**: `[ epsilon ]` + - **squared-epsilon-insensitive**: `[ epsilon ]` + - **huber**: `[ threshold ]` - all other loss functions: `[ 0.0 ]` (unused) where @@ -116,7 +118,7 @@ A returned [`struct`][@stdlib/dstructs/struct] constructor supports the followin ## Notes - A [`struct`][@stdlib/dstructs/struct] provides a fixed-width composite data structure for storing SGD trainer parameters and provides an ABI-stable data layout for JavaScript-C interoperation. -- Each parameter array is a fixed-length array which is large enough to accommodate the option requiring the most parameters (`penaltyParams`: `2`, `learningRateParams`: `2`, `lossFunctionParams`: `1`). Accordingly, one must provide an array having the expected length, with any unused elements set to zero (e.g., `[ lambda, 0.0 ]`), as providing an array having an unexpected length, including an empty array, raises an exception. As struct instances are zero-filled upon initialization, one may omit an array when the corresponding option requires no parameters. +- Each parameter array is a fixed-length array which is large enough to accommodate the option requiring the most parameters (`penaltyParams`: `2`, `learningRateParams`: `2`, `lossFunctionParams`: `1`). Accordingly, one must provide an array having the expected length, with any unused elements set to zero (e.g., `[ lambda, 0.0 ]`), as providing an array having an unexpected length, including an empty array, raises an exception. As `struct` instances are zero-filled upon initialization, one may omit an array when the corresponding option requires no parameters. - Consumers should only read as many elements as are applicable to the corresponding penalty, learning rate scheduler, or loss function, with any remaining elements being unused. @@ -180,8 +182,6 @@ console.log( str ); -* * * -