From d0d85348f84d8d41031d79523408eddb0325341d Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 6 Aug 2026 00:29:46 +0530 Subject: [PATCH 1/8] feat: add `ml/base/sgd/params/to-string` --- 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 --- --- .../ml/base/sgd/params/to-string/README.md | 152 +++++ .../params/to-string/benchmark/benchmark.js | 56 ++ .../base/sgd/params/to-string/docs/repl.txt | 40 ++ .../params/to-string/docs/types/index.d.ts | 132 +++++ .../sgd/params/to-string/docs/types/test.ts | 111 ++++ .../sgd/params/to-string/examples/index.js | 37 ++ .../ml/base/sgd/params/to-string/lib/index.js | 54 ++ .../ml/base/sgd/params/to-string/lib/main.js | 139 +++++ .../ml/base/sgd/params/to-string/package.json | 65 +++ .../ml/base/sgd/params/to-string/test/test.js | 523 ++++++++++++++++++ 10 files changed, 1309 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-string/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-string/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md new file mode 100644 index 000000000000..4e74c6e95e5c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md @@ -0,0 +1,152 @@ + + +# res2str + +> Serialize an SGD trainer params object as a formatted string. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var res2str = require( '@stdlib/ml/base/sgd/params/to-string' ); +``` + +#### res2str( params\[, options] ) + +Serializes an SGD trainer params object as a formatted string. + +```javascript +var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); + +var params = new Float64Params(); + +// ... + +var s = res2str( params ); +// returns +``` + +The function supports the following parameters: + +- **params**: SGD trainer params object. +- **options**: function options. + +The function supports the following options: + +- **digits**: number of digits to display after decimal points. Default: `4`. + +
+ + + + + +
+ +## Notes + +- Example output: + + ```text + + Stochastic Gradient Descent + + penalty: l2 + learning rate: constant + loss function: hinge + lambda: 2.5000 + eta0: 0.0100 + fit intercept: true + intercept: 0.0000 + max iterations: 1000 + + ``` + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); +var Float64Array = require( '@stdlib/array/float64' ); +var res2str = require( '@stdlib/ml/base/sgd/params/to-string' ); + +var params = new Float64Params(); +params.penalty = 'l2'; +params.learningRate = 'constant'; +params.lossFunction = 'hinge'; +params.intercept = 0.0; +params.maxIter = 500; +params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); +params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); +params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +params.fitIntercept = true; + +var s = res2str( params ); +console.log( s ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/benchmark/benchmark.js new file mode 100644 index 000000000000..b1cfb9749a27 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @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 Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); +var Float32Params = require( '@stdlib/ml/base/sgd/params/float32' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var res2str = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + new Float64Params(), + new Float32Params() + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = res2str( values[ i%values.length ] ); + if ( typeof v !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/repl.txt new file mode 100644 index 000000000000..853d6cc9801d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/repl.txt @@ -0,0 +1,40 @@ + +{{alias}}( params[, options] ) + Serializes an SGD trainer params object as a formatted string. + + Parameters + ---------- + params: Object + SGD params object. + + options: Object (optional) + Function options. + + options.digits: number (optional) + Number of digits to display after decimal points. Default: 4. + + Returns + ------- + out: string + Serialized params. + + Examples + -------- + > var params = { + ... 'penalty': 'l2', + ... 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + ... 'learningRate': 'constant', + ... 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + ... 'lossFunction': 'hinge', + ... 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + ... 'fitIntercept': true, + ... 'intercept': 0.0, + ... 'maxIter': 1000, + ... 'method': 'Stochastic Gradient Descent', + ... }; + > var s = {{alias}}( params ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts new file mode 100644 index 000000000000..2a9986bc0dd6 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts @@ -0,0 +1,132 @@ +/* +* @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 parameters. +*/ +interface Params { + /** + * Regularization function to be used. + */ + penalty: string; + + /** + * Parameters specific to the regularization function being used. + */ + penaltyParams: Float64Array | Float32Array; + + /** + * Learning rate scheduler to be used. + */ + learningRate: string; + + /** + * Parameters specific to the learning rate scheduler being used. + */ + learningRateParams: Float64Array | Float32Array; + + /** + * Loss function to be used. + */ + lossFunction: string; + + /** + * Parameters specific to the loss function being used. + */ + lossFunctionParams: Float64Array | Float32Array; + + /** + * Boolean indicating whether to include intercept. + */ + fitIntercept: boolean; + + /** + * Initial intercept value. + */ + intercept: number; + + /** + * Maximum number of iterations to run. + */ + maxIter: number; +} + +/** +* Interface describing function options. +*/ +interface Options { + /** + * Number of digits to display after decimal points. Default: 4. + */ + digits?: number; +} + +/** +* Serializes an SGD trainer params object as a formatted string. +* +* ## Notes +* +* - Example output: +* +* ```text +* +* Stochastic Gradient Descent +* +* penalty: l2 +* learning rate: constant +* loss function: hinge +* lambda: 2.5000 +* eta0: 0.0100 +* fit intercept: true +* intercept: 0.0000 +* max iterations: 1000 +* +* ``` +* +* @param params - SGD trainer params object +* @param options - options object +* @param options.digits - number of digits to display after decimal points +* @returns serialized params +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var params = { +* 'penalty': 'l2', +* 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), +* 'learningRate': 'constant', +* 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), +* 'lossFunction': 'hinge', +* 'lossFunctionParams': new Float64Array( [ 0.0 ] ), +* 'fitIntercept': true, +* 'intercept': 0.0, +* 'maxIter': 1000, +* 'method': 'Stochastic Gradient Descent', +* }; +* +* var str = res2str( params ); +* // returns +*/ +declare function res2str( params: Params, options?: Options ): string; + + +// EXPORTS // + +export = res2str; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts new file mode 100644 index 000000000000..cd1db11cf7ff --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts @@ -0,0 +1,111 @@ +/* +* @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 res2str = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + const params = { + 'penalty': 'l2', + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRate': 'constant', + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunction': 'hinge', + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 1000, + 'method': 'Stochastic Gradient Descent' + }; + res2str( params ); // $ExpectType string + res2str( params, {} ); // $ExpectType string +} + +// The compiler throws an error if provided first argument which is not a params object... +{ + res2str( '10' ); // $ExpectError + res2str( 10 ); // $ExpectError + res2str( true ); // $ExpectError + res2str( false ); // $ExpectError + res2str( null ); // $ExpectError + res2str( undefined ); // $ExpectError + res2str( [] ); // $ExpectError + res2str( {} ); // $ExpectError + res2str( ( x: number ): number => x ); // $ExpectError + + res2str( '10', {} ); // $ExpectError + res2str( 10, {} ); // $ExpectError + res2str( true, {} ); // $ExpectError + res2str( false, {} ); // $ExpectError + res2str( null, {} ); // $ExpectError + res2str( undefined, {} ); // $ExpectError + res2str( [], {} ); // $ExpectError + res2str( {}, {} ); // $ExpectError + res2str( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if provided a second argument which is not an object... +{ + const params = { + 'penalty': 'l2', + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRate': 'constant', + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunction': 'hinge', + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 1000, + 'method': 'Stochastic Gradient Descent' + }; + + res2str( params, '10' ); // $ExpectError + res2str( params, 10 ); // $ExpectError + res2str( params, true ); // $ExpectError + res2str( params, false ); // $ExpectError + res2str( params, null ); // $ExpectError + res2str( params, [] ); // $ExpectError + res2str( params, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if provided a `digits` option which is not a number... +{ + const params = { + 'penalty': 'l2', + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRate': 'constant', + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunction': 'hinge', + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 1000, + 'method': 'Stochastic Gradient Descent' + }; + + res2str( params, { 'digits': '10' } ); // $ExpectError + res2str( params, { 'digits': true } ); // $ExpectError + res2str( params, { 'digits': false } ); // $ExpectError + res2str( params, { 'digits': null } ); // $ExpectError + res2str( params, { 'digits': [] } ); // $ExpectError + res2str( params, { 'digits': {} } ); // $ExpectError + res2str( params, { 'digits': ( x: number ): number => x } ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js new file mode 100644 index 000000000000..889125483846 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); +var Float64Array = require( '@stdlib/array/float64' ); +var res2str = require( './../lib' ); + +var params = new Float64Params(); +params.penalty = 'l2'; +params.learningRate = 'constant'; +params.lossFunction = 'hinge'; +params.intercept = 0.0; +params.maxIter = 500; +params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); +params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); +params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +params.fitIntercept = true; + +var s = res2str( params ); +console.log( s ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js new file mode 100644 index 000000000000..22a23216a445 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.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'; + +/** +* Serialize an SGD trainer params object as a formatted string. +* +* @module @stdlib/ml/base/sgd/params/to-string +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var res2str = require( '@stdlib/ml/base/sgd/params/to-string' ); +* +* var params = { +* 'penalty': 'l2', +* 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), +* 'learningRate': 'constant', +* 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), +* 'lossFunction': 'hinge', +* 'lossFunctionParams': new Float64Array( [ 0.0 ] ), +* 'fitIntercept': true, +* 'intercept': 0.0, +* 'maxIter': 1000, +* 'method': 'Stochastic Gradient Descent', +* }; +* +* var str = res2str( params ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/main.js new file mode 100644 index 000000000000..33860fc904d1 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/main.js @@ -0,0 +1,139 @@ +/** +* @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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); +var isObject = require( '@stdlib/assert/is-plain-object' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Serializes an SGD trainer params object as a formatted string. +* +* ## Notes +* +* - Example output: +* +* ```text +* +* Stochastic Gradient Descent +* +* penalty: l2 +* learning rate: constant +* loss function: hinge +* lambda: 2.5000 +* eta0: 0.0100 +* fit intercept: true +* intercept: 0.0000 +* max iterations: 1000 +* +* ``` +* +* @param {Object} params - SGD trainer params object +* @param {Options} [opts] - options object +* @param {PositiveInteger} [opts.digits=4] - number of digits to display after decimal points +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {string} serialized params +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var params = { +* 'penalty': 'l2', +* 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), +* 'learningRate': 'constant', +* 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), +* 'lossFunction': 'hinge', +* 'lossFunctionParams': new Float64Array( [ 0.0 ] ), +* 'fitIntercept': true, +* 'intercept': 0.0, +* 'maxIter': 1000, +* 'method': 'Stochastic Gradient Descent', +* }; +* +* var str = toString( params ); +* // returns +*/ +function toString( params, opts ) { // eslint-disable-line stdlib/no-redeclare + var fitIntercept; + var dgts; + var out; + + dgts = 4; + if ( arguments.length > 1 ) { + if ( !isObject( opts ) ) { + throw new TypeError( format( 'invalid argument. Must provide an object. Value: `%s`.', opts ) ); + } + if ( hasOwnProp( opts, 'digits' ) ) { + if ( !isPositiveInteger( opts.digits ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'digits', opts.digits ) ); + } + dgts = opts.digits; + } + } + + fitIntercept = 'false'; + if ( params.fitIntercept === true ) { + fitIntercept = 'true'; + } + + out = [ + '', + params.method, + '', + format( ' penalty: %s', params.penalty ), + format( ' learning rate: %s', params.learningRate ), + format( ' loss function: %s', params.lossFunction ) + ]; + if ( params.penalty !== 'none' ) { + out.push( format( ' lambda: %0.'+dgts+'f', params.penaltyParams[ 0 ] ) ); + } + else if ( params.penalty === 'elasticnet' ) { + out.push( format( ' l1 ratio: %0.'+dgts+'f', params.penaltyParams[ 1 ] ) ); + } + if ( params.learningRate === 'constant' ) { + out.push( format( ' eta0: %0.'+dgts+'f', params.learningRateParams[ 0 ] ) ); + } + else if ( params.learningRate === 'invscaling' ) { + out.push( format( ' eta0: %0.'+dgts+'f', params.learningRateParams[ 0 ] ) ); + out.push( format( ' powerT: %0.'+dgts+'f', params.learningRateParams[ 1 ] ) ); + } else if ( params.learningRate === 'pegasos' && params.penalty === 'none' ) { + out.push( format( ' lambda: %0.'+dgts+'f', params.learningRateParams[ 1 ] ) ); + } + if ( params.lossFunction === 'epsilon-insensitive' || params.lossFunction === 'squared-epsilon-insensitive' ) { + out.push( format( ' epsilon: %0.'+dgts+'f', params.lossFunctionParams[ 0 ] ) ); + } + out.push( format( ' fit intercept: %s', fitIntercept ) ); + if ( params.fitIntercept === true ) { + out.push( format( ' intercept: %0.'+dgts+'f', params.intercept ) ); + } + out.push( format( ' max iterations: %d', params.maxIter ) ); + return out.join( '\n' ); +} + + +// EXPORTS // + +module.exports = toString; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/package.json b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/package.json new file mode 100644 index 000000000000..2fd1b2a2c7cd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/ml/base/sgd/params/to-string", + "version": "0.0.0", + "description": "Serialize an SGD trainer params object as a formatted string.", + "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", + "params", + "utilities", + "utility", + "utils", + "util", + "string" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js new file mode 100644 index 000000000000..40e6a9b3d00a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js @@ -0,0 +1,523 @@ +/** +* @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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var Float64Array = require( '@stdlib/array/float64' ); +var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); +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 res2str = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof res2str, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { + var params; + var values; + var i; + + params = new Float64Params(); + + 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() { + res2str( params, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `digits` option which is not a positive integer', function test( t ) { + var params; + var values; + var i; + + params = new Float64Params(); + + 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() { + res2str( params, { + 'digits': value + }); + }; + } +}); + +tape( 'the function serializes a params object to a string (l1,l2 penalty)', function test( t ) { + var expected; + var lambda; + var actual; + var value; + var eta0; + + lambda = 2.5; + eta0 = 0.01; + + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); + value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); + value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.fitIntercept = true; + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Stochastic Gradient Descent', + '', + ' penalty: l2', + ' learning rate: constant', + ' loss function: hinge', + ' lambda: 2.5000', + ' eta0: 0.0100', + ' fit intercept: true', + ' intercept: 0.0000', + ' max iterations: 1000', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a params object to a string (elasticnet penalty)', function test( t ) { + var expected; + var l1Ratio; + var lambda; + var actual; + var value; + var eta0; + + l1Ratio = 0.6; + lambda = 2.5; + eta0 = 0.01; + + value.penalty = resolvePenaltyEnum( 'elasticnet' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, l1Ratio ] ); + value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); + value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.fitIntercept = true; + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Stochastic Gradient Descent', + '', + ' penalty: elasticnet', + ' learning rate: constant', + ' loss function: hinge', + ' lambda: 2.5000', + ' l1 ratio: 0.6000', + ' eta0: 0.0100', + ' fit intercept: true', + ' intercept: 0.0000', + ' max iterations: 1000', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a params object to a string (no penalty)', function test( t ) { + var expected; + var lambda; + var actual; + var value; + var eta0; + + lambda = 2.5; + eta0 = 0.01; + + value.penalty = resolvePenaltyEnum( 'none' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); + value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); + value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.fitIntercept = true; + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Stochastic Gradient Descent', + '', + ' penalty: none', + ' learning rate: constant', + ' loss function: hinge', + ' eta0: 0.0100', + ' fit intercept: true', + ' intercept: 0.0000', + ' max iterations: 1000', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a params object to a string (basic learning rate)', function test( t ) { + var expected; + var lambda; + var actual; + var value; + + lambda = 2.5; + + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'basic' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); + value.learningRateParams = new Float64Array( [ 0.0, 0.0 ] ); + value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.fitIntercept = true; + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Stochastic Gradient Descent', + '', + ' penalty: l2', + ' learning rate: basic', + ' loss function: hinge', + ' lambda: 2.5000', + ' fit intercept: true', + ' intercept: 0.0000', + ' max iterations: 1000', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a params object to a string (constant learning rate)', function test( t ) { + var expected; + var lambda; + var actual; + var value; + var eta0; + + lambda = 2.5; + eta0 = 0.01; + + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); + value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); + value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.fitIntercept = true; + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Stochastic Gradient Descent', + '', + ' penalty: l2', + ' learning rate: constant', + ' loss function: hinge', + ' lambda: 2.5000', + ' eta0: 0.0100', + ' fit intercept: true', + ' intercept: 0.0000', + ' max iterations: 1000', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a params object to a string (invscaling learning rate)', function test( t ) { + var expected; + var powerT; + var lambda; + var actual; + var value; + var eta0; + + powerT = 2.0; + lambda = 2.5; + eta0 = 0.01; + + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'invscaling' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); + value.learningRateParams = new Float64Array( [ eta0, powerT ] ); + value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.fitIntercept = true; + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Stochastic Gradient Descent', + '', + ' penalty: l2', + ' learning rate: invscaling', + ' loss function: hinge', + ' lambda: 2.5000', + ' eta0: 0.0100', + ' powerT: 2.0000', + ' fit intercept: true', + ' intercept: 0.0000', + ' max iterations: 1000', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a params object to a string (pegasos learning rate)', function test( t ) { + var expected; + var lambda; + var actual; + var value; + + lambda = 2.5; + + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'pegasos' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); + value.learningRateParams = new Float64Array( [ lambda, 0.0 ] ); + value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.fitIntercept = true; + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Stochastic Gradient Descent', + '', + ' penalty: l2', + ' learning rate: pegasos', + ' loss function: hinge', + ' lambda: 2.5000', + ' fit intercept: true', + ' intercept: 0.0000', + ' max iterations: 1000', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a params object to a string (epsilon insensitive, squared epsilon insensitive loss function)', function test( t ) { + var expected; + var epsilon; + var lambda; + var actual; + var value; + var eta0; + + epsilon = 0.2; + lambda = 2.5; + eta0 = 0.01; + + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'squared-epsilon-insensitive' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); + value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); + value.lossFunctionParams = new Float64Array( [ epsilon ] ); + value.fitIntercept = true; + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Stochastic Gradient Descent', + '', + ' penalty: l2', + ' learning rate: invscaling', + ' loss function: hinge', + ' lambda: 2.5000', + ' eta0: 0.0100', + ' epsilon: 0.2000', + ' fit intercept: true', + ' intercept: 0.0000', + ' max iterations: 1000', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a params object to a string (no intercept)', function test( t ) { + var expected; + var lambda; + var actual; + var value; + var eta0; + + lambda = 2.5; + eta0 = 0.01; + + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); + value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); + value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.fitIntercept = false; + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Stochastic Gradient Descent', + '', + ' penalty: l2', + ' learning rate: constant', + ' loss function: hinge', + ' lambda: 2.5000', + ' eta0: 0.0100', + ' fit intercept: false', + ' max iterations: 1000', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the number of displayed digits (digits=2)', function test( t ) { + var expected; + var lambda; + var actual; + var value; + var eta0; + + lambda = 2.5; + eta0 = 0.01; + + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); + value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); + value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.fitIntercept = true; + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Stochastic Gradient Descent', + '', + ' penalty: l2', + ' learning rate: constant', + ' loss function: hinge', + ' lambda: 2.50', + ' eta0: 0.01', + ' fit intercept: true', + ' intercept: 0.00', + ' max iterations: 1000', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From a3f1f90d89495c59896e79ba99533565bb3306f0 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 6 Aug 2026 00:46:54 +0530 Subject: [PATCH 2/8] feat: add `ml/base/sgd/params/to-json` --- 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 --- --- .../ml/base/sgd/params/to-json/README.md | 131 ++++++++++++++++++ .../sgd/params/to-json/benchmark/benchmark.js | 56 ++++++++ .../ml/base/sgd/params/to-json/docs/repl.txt | 34 +++++ .../sgd/params/to-json/docs/types/index.d.ts | 101 ++++++++++++++ .../sgd/params/to-json/docs/types/test.ts | 51 +++++++ .../base/sgd/params/to-json/examples/index.js | 40 ++++++ .../ml/base/sgd/params/to-json/lib/index.js | 54 ++++++++ .../ml/base/sgd/params/to-json/lib/main.js | 71 ++++++++++ .../ml/base/sgd/params/to-json/package.json | 65 +++++++++ .../ml/base/sgd/params/to-json/test/test.js | 86 ++++++++++++ 10 files changed, 689 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-json/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-json/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-json/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-json/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/to-json/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/README.md new file mode 100644 index 000000000000..90fc6b997f5e --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/README.md @@ -0,0 +1,131 @@ + + +# params2json + +> Serialize an SGD trainer params object as a JSON object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var params2json = require( '@stdlib/ml/base/sgd/params/to-json' ); +``` + +#### params2json( params ) + +Serializes an SGD trainer params object as a JSON object. + +```javascript +var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); + +var params = new Float64Params(); + +// ... + +var o = params2json( params ); +// returns {...} +``` + +The function supports the following parameters: + +- **params**: SGD trainer params object. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); +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 params2json = require( '@stdlib/ml/base/sgd/params/to-json' ); + +var params = new Float64Params(); +params.penalty = resolvePenaltyEnum( 'l2' ); +params.learningRate = resolveLREnum( 'constant' ); +params.lossFunction = resolveLossFunctionEnum( 'hinge' ); +params.intercept = 0.0; +params.maxIter = 500; +params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); +params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); +params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +params.fitIntercept = true; + +var o = params2json( params ); +console.log( o ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/benchmark/benchmark.js new file mode 100644 index 000000000000..153dc894c869 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @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 Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); +var Float32Params = require( '@stdlib/ml/base/sgd/params/float32' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var pkg = require( './../package.json' ).name; +var params2json = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + new Float64Params(), + new Float32Params() + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = params2json( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isPlainObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/repl.txt new file mode 100644 index 000000000000..a87cb5aaecba --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( params ) + Serializes an SGD trainer params object as a JSON object. + + Parameters + ---------- + params: Object + SGD params object. + + Returns + ------- + out: Object + Serialized object. + + Examples + -------- + > var params = { + ... 'penalty': 'l2', + ... 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + ... 'learningRate': 'constant', + ... 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + ... 'lossFunction': 'hinge', + ... 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + ... 'fitIntercept': true, + ... 'intercept': 0.0, + ... 'maxIter': 1000, + ... 'method': 'Stochastic Gradient Descent', + ... }; + > var o = {{alias}}( params ) + {...} + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/index.d.ts new file mode 100644 index 000000000000..371337b8620d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/index.d.ts @@ -0,0 +1,101 @@ +/* +* @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 parameters. +*/ +interface Params { + /** + * Regularization function to be used. + */ + penalty: string; + + /** + * Parameters specific to the regularization function being used. + */ + penaltyParams: Float64Array | Float32Array; + + /** + * Learning rate scheduler to be used. + */ + learningRate: string; + + /** + * Parameters specific to the learning rate scheduler being used. + */ + learningRateParams: Float64Array | Float32Array; + + /** + * Loss function to be used. + */ + lossFunction: string; + + /** + * Parameters specific to the loss function being used. + */ + lossFunctionParams: Float64Array | Float32Array; + + /** + * Boolean indicating whether to include intercept. + */ + fitIntercept: boolean; + + /** + * Initial intercept value. + */ + intercept: number; + + /** + * Maximum number of iterations to run. + */ + maxIter: number; +} + +/** +* Serializes an SGD trainer params object as a JSON object. +* +* @param params - SGD trainer params object +* @returns serialized object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var params = { +* 'penalty': 'l2', +* 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), +* 'learningRate': 'constant', +* 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), +* 'lossFunction': 'hinge', +* 'lossFunctionParams': new Float64Array( [ 0.0 ] ), +* 'fitIntercept': true, +* 'intercept': 0.0, +* 'maxIter': 1000, +* 'method': 'Stochastic Gradient Descent', +* }; +* +* var obj = params2json( params ); +* // returns {...} +*/ +declare function params2json( params: Params ): Params; + + +// EXPORTS // + +export = params2json; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/test.ts new file mode 100644 index 000000000000..45e9fb15d45c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/test.ts @@ -0,0 +1,51 @@ +/* +* @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 params2json = require( './index' ); + + +// TESTS // + +// The function returns an object... +{ + const params = { + 'penalty': 'l2', + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRate': 'constant', + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunction': 'hinge', + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 1000, + 'method': 'Stochastic Gradient Descent' + }; + params2json( params ); // $ExpectType Params +} + +// The compiler throws an error if not provided a params object... +{ + params2json( 10 ); // $ExpectError + params2json( true ); // $ExpectError + params2json( false ); // $ExpectError + params2json( null ); // $ExpectError + params2json( undefined ); // $ExpectError + params2json( [] ); // $ExpectError + params2json( {} ); // $ExpectError + params2json( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/examples/index.js new file mode 100644 index 000000000000..ee22b79d31c5 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/examples/index.js @@ -0,0 +1,40 @@ +/** +* @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 Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); +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 params2json = require( './../lib' ); + +var params = new Float64Params(); +params.penalty = resolvePenaltyEnum( 'l2' ); +params.learningRate = resolveLREnum( 'constant' ); +params.lossFunction = resolveLossFunctionEnum( 'hinge' ); +params.intercept = 0.0; +params.maxIter = 500; +params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); +params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); +params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +params.fitIntercept = true; + +var o = params2json( params ); +console.log( o ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/index.js new file mode 100644 index 000000000000..57b4adc00b6b --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/index.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'; + +/** +* Serialize an SGD trainer params object as a JSON object. +* +* @module @stdlib/ml/base/sgd/params/to-json +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var params2json = require( '@stdlib/ml/base/sgd/params/to-json' ); +* +* var params = { +* 'penalty': 'l2', +* 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), +* 'learningRate': 'constant', +* 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), +* 'lossFunction': 'hinge', +* 'lossFunctionParams': new Float64Array( [ 0.0 ] ), +* 'fitIntercept': true, +* 'intercept': 0.0, +* 'maxIter': 1000, +* 'method': 'Stochastic Gradient Descent', +* }; +* +* var obj = params2json( params ); +* // returns {...} +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/main.js new file mode 100644 index 000000000000..ea8a4acdfeb2 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/main.js @@ -0,0 +1,71 @@ +/** +* @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 typedarray2json = require( '@stdlib/array/to-json' ); + + +// MAIN // + +/** +* Serializes an SGD trainer params object as a JSON object. +* +* @param {Object} params - SGD trainer params object +* @returns {Object} serialized object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var params = { +* 'penalty': 'l2', +* 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), +* 'learningRate': 'constant', +* 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), +* 'lossFunction': 'hinge', +* 'lossFunctionParams': new Float64Array( [ 0.0 ] ), +* 'fitIntercept': true, +* 'intercept': 0.0, +* 'maxIter': 1000, +* 'method': 'Stochastic Gradient Descent', +* }; +* +* var obj = toJSON( params ); +* // returns {...} +*/ +function toJSON( params ) { + return { + 'fitIntercept': params.fitIntercept, + 'intercept': params.intercept, + 'maxIter': params.maxIter, + 'penalty': params.penalty, + 'learningRate': params.learningRate, + 'lossFunction': params.lossFunction, + 'penaltyParams': typedarray2json( params.penaltyParams ), + 'learningRateParams': typedarray2json( params.learningRateParams ), + 'lossFunctionParams': typedarray2json( params.lossFunctionParams ), + 'method': params.method + }; +} + + +// EXPORTS // + +module.exports = toJSON; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/package.json b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/package.json new file mode 100644 index 000000000000..0df12f43e9bc --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/ml/base/sgd/params/to-json", + "version": "0.0.0", + "description": "Serialize an SGD trainer params object as a JSON object.", + "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", + "params", + "utilities", + "utility", + "utils", + "util", + "json" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/test/test.js new file mode 100644 index 000000000000..9c734ea3a169 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/test/test.js @@ -0,0 +1,86 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); +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 params2json = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof params2json, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function serializes a params object to JSON', function test( t ) { + var expected; + var lambda; + var actual; + var value; + var eta0; + + lambda = 2.5; + eta0 = 0.01; + + value = new Float64Params(); + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); + value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); + value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.fitIntercept = true; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 1000, + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge', + 'penaltyParams': { + 'type': 'Float64Array', + 'data': [ 2.5, 0.0 ] + }, + 'learningRateParams': { + 'type': 'Float64Array', + 'data': [ 0.01, 0.0 ] + }, + 'lossFunctionParams': { + 'type': 'Float64Array', + 'data': [ 0.0 ] + }, + 'method': 'Stochastic Gradient Descent' + }; + + actual = params2json( value ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); From 799c50099f2de9a0358718de81bd1655937cc8ee Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 6 Aug 2026 12:08:34 +0530 Subject: [PATCH 3/8] feat: add `ml/base/sgd/params/float64` --- .../ml/base/sgd/params/float64/README.md | 449 ++++++++++++++++ .../sgd/params/float64/benchmark/benchmark.js | 71 +++ .../ml/base/sgd/params/float64/docs/repl.txt | 29 + .../sgd/params/float64/docs/types/index.d.ts | 240 +++++++++ .../sgd/params/float64/docs/types/test.ts | 143 +++++ .../base/sgd/params/float64/examples/index.js | 37 ++ .../stdlib/ml/base/sgd/params/float64.h | 57 ++ .../ml/base/sgd/params/float64/lib/index.js | 54 ++ .../ml/base/sgd/params/float64/lib/main.js | 63 +++ .../ml/base/sgd/params/float64/manifest.json | 36 ++ .../ml/base/sgd/params/float64/package.json | 67 +++ .../ml/base/sgd/params/float64/test/test.js | 500 ++++++++++++++++++ 12 files changed, 1746 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/manifest.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float64/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md new file mode 100644 index 000000000000..e014941fdb80 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md @@ -0,0 +1,449 @@ + + +# Float64Params + +> Create an SGD double-precision floating-point params object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); +``` + +#### Float64Params( \[arg\[, byteOffset\[, byteLength]]] ) + +Returns an SGD double-precision floating-point params object. + +```javascript +var params = new Float64Params(); +// returns {...} +``` + +The function supports the following parameters: + +- **arg**: an [`ArrayBuffer`][@stdlib/array/buffer] or a data object (_optional_). +- **byteOffset**: byte offset (_optional_). +- **byteLength**: maximum byte length (_optional_). + +A data object argument is an object having one or more of the following properties: + +- **penalty**: regularization function to be used (e.g., `'l1'`, `'l2'`, `'elasticnet'` or `'none'`). + +- **penaltyParams**: parameters specific to the regularization function being used as a [`Float64Array`][@stdlib/array/float64]. + + - When `'penalty = {l1,l2}`, `'penaltyParams' => [ lambda ]` + - When `'penalty = elasticnet`, `'penaltyParams' => [ lambda, l1Ratio ]` + - When `'penalty = none`, `'penaltyParams' => [ ]` + +- **learningRate**: learning rate scheduler to be used (e.g., `'basic'`, `'constant'`, `'invscaling'` or `'pegasos'`). + +- **learningRateParams**: parameters specific to the learning rate scheduler being used as a [`Float64Array`][@stdlib/array/float64]. + + - When `'learningRate = basic`, `'learningRateParams' => [ ]` + - When `'learningRate = constant`, `'learningRateParams' => [ eta0 ]` + - When `'learningRate = invscaling`, `'learningRateParams' => [ eta0, powerT ]` + - When `'learningRate = pegasos`, `'learningRateParams' => [ lambda ]` + +- **lossFunction**: loss function to be used (e.g., `'epsilon-insensitive'`, `'hinge'`, `'huber'`, `'log'`, `'modified-huber'`, `'perceptron'`, `'squared-epsilon-insensitive'`, `'squared-error'`, or `'squared-hinge'`). + +- **lossFunctionParams**: parameters specific to the loss function being used as a [`Float64Array`][@stdlib/array/float64]. + + - When `'lossFunction = {epsilon-insensitive,squared-epsilon-insensitive}`, `'lossFunctionParams' => [ epsilon ]` + - Else, `'lossFunctionParams' => [ ]` + +- **fitIntercept**: boolean indicating whether to include intercept. + +- **intercept**: initial intercept value. + +- **maxIter**: maximum number of iterations to run. + +#### Float64Params.prototype.penalty + +Regularization function to be used. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.penalty; +// returns +``` + +#### Float64Params.prototype.penaltyParams + +Parameters specific to the regularization function being used. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.penaltyParams; +// returns +``` + +#### Float64Params.prototype.learningRate + +Learning rate scheduler to be used. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.learningRate; +// returns +``` + +#### Float64Params.prototype.learningRateParams + +Parameters specific to the learning rate scheduler being used. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.learningRateParams; +// returns +``` + +#### Float64Params.prototype.lossFunction + +Loss function to be used. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.lossFunction; +// returns +``` + +#### Float64Params.prototype.lossFunctionParams + +Parameters specific to the loss function being used. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.lossFunctionParams; +// returns +``` + +#### Float64Params.prototype.fitIntercept + +Boolean indicating whether to include intercept. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.fitIntercept; +// returns +``` + +#### Float64Params.prototype.intercept + +Initial intercept value. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.intercept; +// returns +``` + +#### Float64Params.prototype.maxIter + +Maximum number of iterations to run. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.maxIter; +// returns +``` + +#### Float64Params.prototype.toString( \[options] ) + +Serializes a params object to a formatted string. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.toString(); +// returns +``` + +The method supports the following options: + +- **digits**: number of digits to display after decimal points. Default: `4`. + +Example output: + +```text + +Stochastic Gradient Descent + + penalty: l2 + learning rate: constant + loss function: hinge + lambda: 2.5000 + eta0: 0.0100 + fit intercept: true + intercept: 0.0000 + max iterations: 1000 + +``` + +#### Float64Params.prototype.toJSON( \[options] ) + +Serializes a params object as a JSON object. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.toJSON(); +// returns {...} +``` + +`JSON.stringify()` implicitly calls this method when stringifying a params instance. + +#### Float64Params.prototype.toDataView() + +Returns a [`DataView`][@stdlib/array/dataview] of a params object. + +```javascript +var params = new Float64Params(); +// returns {...} + +// ... + +var v = params.toDataView(); +// returns +``` + +
+ + + + + +
+ +## Notes + +- A params object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing SGD trainer params and providing an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Params = require( '@stdlib/ml/base/sgd/params/float64' ); + +var params = new Params({ + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' +}); + +var str = params.toString(); +console.log( str ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ml/base/sgd/params/float64.h" +``` + +#### stdlib_ml_sgd_params_float64_params + +Structure for holding double-precision floating-point SGD params. + + + +```c +#include +#include + +struct stdlib_ml_sgd_params_float64_params { + // Regularization function to be used: + int8_t penalty; + + // Parameters specific to the regularization function being used: + double penaltyParams[ 2 ]; + + // Learning rate scheduler to be used: + int8_t learningRate; + + // Parameters specific to the learning rate scheduler being used: + double learningRateParams[ 2 ]; + + // Loss function to be used: + int8_t lossFunction; + + // Parameters specific to the loss function being used: + double lossFunctionParams[ 1 ]; + + // Boolean indicating whether to include intercept: + bool fitIntercept; + + // Initial intercept value: + double intercept; + + // Maximum number of iterations to run: + int32_t maxIter; +}; +``` + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/benchmark/benchmark.js new file mode 100644 index 000000000000..5cc8ca3ffed3 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/benchmark/benchmark.js @@ -0,0 +1,71 @@ +/** +* @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 isObject = require( '@stdlib/assert/is-object' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float64Params = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::constructor,new', pkg ), function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new Float64Params(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::constructor,no_new', pkg ), function benchmark( b ) { + var params; + var v; + var i; + + params = Float64Params; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = params(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/repl.txt new file mode 100644 index 000000000000..a22f9c69c720 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( [arg[, byteOffset[, byteLength]]] ) + Returns an SGD double-precision floating-point params object. + + Parameters + ---------- + arg: Object|ArrayBuffer (optional) + ArrayBuffer or data object. + + byteOffset: integer (optional) + Byte offset. + + byteLength: integer (optional) + Maximum byte length. + + Returns + ------- + out: Object + Params object. + + Examples + -------- + > var r = new {{alias}}(); + > r.toString() + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts new file mode 100644 index 000000000000..b172f9d9699a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts @@ -0,0 +1,240 @@ +/* +* @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 + +/** +* Regularization Function. +*/ +type Penalty = 'elasticnet' | 'l1' | 'l2' | 'none'; + +/** +* Learning Rate. +*/ +type LearningRate = 'basic' | 'constant' | 'invscaling' | 'pegasos'; + +/** +* Loss Function. +*/ +type LossFunction = 'epsilon-insensitive' | 'hinge' | 'huber' | 'log' | 'modified-huber' | 'perceptron' | 'squared-epsilon-insensitive' | 'squared-error' | 'squared-hinge'; + +/** +* Interface describing SGD trainer parameters. +*/ +interface Params { + /** + * Regularization function to be used. + */ + penalty?: Penalty; + + /** + * Parameters specific to the regularization function being used. + */ + penaltyParams?: Float64Array; + + /** + * Learning rate scheduler to be used. + */ + learningRate?: LearningRate; + + /** + * Parameters specific to the learning rate scheduler being used. + */ + learningRateParams?: Float64Array; + + /** + * Loss function to be used. + */ + lossFunction?: LossFunction; + + /** + * Parameters specific to the loss function being used. + */ + lossFunctionParams?: Float64Array; + + /** + * Boolean indicating whether to include intercept. + */ + fitIntercept?: boolean; + + /** + * Initial intercept value. + */ + intercept?: number; + + /** + * Maximum number of iterations to run. + */ + maxIter?: number; +} + +/** +* Interface describing options when serializing a params object to a string. +*/ +interface ToStringOptions { + /** + * Number of digits to display after decimal points. Default: `4`. + */ + digits?: number; +} + +/** +* Interface describing a params data structure. +*/ +declare class ParamsStruct { + /** + * Params constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns params + */ + constructor( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ); + + /** + * Regularization function to be used. + */ + penalty: Penalty; + + /** + * Parameters specific to the regularization function being used. + */ + penaltyParams: Float64Array; + + /** + * Learning rate scheduler to be used. + */ + learningRate: LearningRate; + + /** + * Parameters specific to the learning rate scheduler being used. + */ + learningRateParams: Float64Array; + + /** + * Loss function to be used. + */ + lossFunction: LossFunction; + + /** + * Parameters specific to the loss function being used. + */ + lossFunctionParams: Float64Array; + + /** + * Boolean indicating whether to include intercept. + */ + fitIntercept: boolean; + + /** + * Initial intercept value. + */ + intercept: number; + + /** + * Maximum number of iterations to run. + */ + maxIter: number; + + /** + * Test method. + */ + method: string; + + /** + * Serializes a params object as a formatted string. + * + * @param options - options object + * @returns serialized params + */ + toString( options?: ToStringOptions ): string; + + /** + * Serializes a params object as a JSON object. + * + * @returns serialized object + */ + toJSON(): object; + + /** + * Returns a DataView of a params object. + * + * @returns DataView + */ + toDataView(): DataView; +} + +/** +* Interface defining a params constructor which is both "newable" and "callable". +*/ +interface ParamsConstructor { + /** + * Params constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns params object + */ + new( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ): ParamsStruct; + + /** + * Params constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns params object + */ + ( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ): ParamsStruct; +} + +/** +* Returns an SGD double-precision floating-point params object. +* +* @param arg - buffer or data object +* @param byteOffset - byte offset +* @param byteLength - maximum byte length +* @returns params object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var params = new Params(); +* // returns +* +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); +* params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); +* params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +* params.fitIntercept = true; +* +* var str = params.toString(); +* // returns +*/ +declare var Params: ParamsConstructor; + + +// EXPORTS // + +export = Params; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/test.ts new file mode 100644 index 000000000000..7dc5fcc95f0a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/test.ts @@ -0,0 +1,143 @@ +/* +* @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 Params = require( './index' ); + + +// TESTS // + +// The constructor returns a params object... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r0 = new Params( {} ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = new Params( new ArrayBuffer( 80 ) ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = new Params( new ArrayBuffer( 80 ), 8 ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = new Params( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ParamsStruct +} + +// The constructor can be invoked without `new`... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r0 = Params( {} ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = Params( new ArrayBuffer( 80 ) ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = Params( new ArrayBuffer( 80 ), 8 ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = Params( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ParamsStruct +} + +// The params object has the expected properties... +{ + const r = new Params( {} ); + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.penalty; // $ExpectType Penalty + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.penaltyParams; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.learningRate; // $ExpectType LearningRate + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.learningRateParams; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.lossFunction; // $ExpectType LossFunction + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.lossFunctionParams; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.fitIntercept; // $ExpectType boolean + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.intercept; // $ExpectType number + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.maxIter; // $ExpectType number + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.method; // $ExpectType string +} + +// The compiler throws an error if the constructor is provided a first argument which is not an ArrayBuffer or object... +{ + new Params( 'abc' ); // $ExpectError + new Params( 123 ); // $ExpectError + new Params( true ); // $ExpectError + new Params( false ); // $ExpectError + new Params( null ); // $ExpectError + new Params( [] ); // $ExpectError + new Params( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided a second argument which is not a number... +{ + new Params( new ArrayBuffer( 80 ), 'abc' ); // $ExpectError + new Params( new ArrayBuffer( 80 ), true ); // $ExpectError + new Params( new ArrayBuffer( 80 ), false ); // $ExpectError + new Params( new ArrayBuffer( 80 ), null ); // $ExpectError + new Params( new ArrayBuffer( 80 ), [] ); // $ExpectError + new Params( new ArrayBuffer( 80 ), {} ); // $ExpectError + new Params( new ArrayBuffer( 80 ), ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided a third argument which is not a number... +{ + new Params( new ArrayBuffer( 80 ), 8, 'abc' ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, true ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, false ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, null ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, [] ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, {} ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, ( x: number ): number => x ); // $ExpectError +} + +// The params object has a `toString` method... +{ + const r = new Params( {} ); + + r.toString(); // $ExpectType string + r.toString( {} ); // $ExpectType string + r.toString( { 'digits': 4 } ); // $ExpectType string +} + +// The params object has a `toJSON` method... +{ + const r = new Params( {} ); + + r.toJSON(); // $ExpectType object +} + +// The params object has a `toDataView` method... +{ + const r = new Params( {} ); + + r.toDataView(); // $ExpectType DataView +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/examples/index.js new file mode 100644 index 000000000000..24f6a503404f --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Params = require( './../lib' ); + +var params = new Params({ + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' +}); + +var str = params.toString(); +console.log( str ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h new file mode 100644 index 000000000000..15ad6cbdf458 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h @@ -0,0 +1,57 @@ +/** +* @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. +*/ + +#ifndef STDLIB_ML_BASE_SGD_PARAMS_FLOAT64_H +#define STDLIB_ML_BASE_SGD_PARAMS_FLOAT64_H + +#include +#include + +/** +* Struct for storing SGD parameters. +*/ +struct stdlib_ml_sgd_params_float64_params { + // Regularization function to be used: + int8_t penalty; + + // Parameters specific to the regularization function being used: + double penaltyParams[ 2 ]; + + // Learning rate scheduler to be used: + int8_t learningRate; + + // Parameters specific to the learning rate scheduler being used: + double learningRateParams[ 2 ]; + + // Loss function to be used: + int8_t lossFunction; + + // Parameters specific to the loss function being used: + double lossFunctionParams[ 1 ]; + + // Boolean indicating whether to include intercept: + bool fitIntercept; + + // Initial intercept value: + double intercept; + + // Maximum number of iterations to run: + int32_t maxIter; +}; + +#endif // !STDLIB_ML_BASE_SGD_PARAMS_FLOAT64_H diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/index.js new file mode 100644 index 000000000000..ae8f0dd8f161 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/index.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'; + +/** +* Create an SGD double-precision floating-point params object. +* +* @module @stdlib/ml/base/sgd/params/float64 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Params = require( '@stdlib/ml/base/sgd/params/float64' ); +* +* var params = new Params(); +* // returns +* +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); +* params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); +* params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +* params.fitIntercept = true; +* +* var str = params.toString(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/main.js new file mode 100644 index 000000000000..d09da53d4497 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/main.js @@ -0,0 +1,63 @@ +/** +* @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 factory = require( '@stdlib/ml/base/sgd/params/factory' ); + + +// MAIN // + +/** +* Returns an SGD double-precision floating-point params object. +* +* @name Params +* @constructor +* @type {Function} +* @param {(ArrayBuffer|Object)} [arg] - underlying byte buffer or data object +* @param {NonNegativeInteger} [byteOffset] - byte offset +* @param {NonNegativeInteger} [byteLength] - maximum byte length +* @returns {Params} params object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var params = new Params(); +* // returns +* +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); +* params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); +* params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +* params.fitIntercept = true; +* +* var str = params.toString(); +* // returns +*/ +var Params = factory( 'float64' ); + + +// EXPORTS // + +module.exports = Params; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/manifest.json b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/package.json b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/package.json new file mode 100644 index 000000000000..471748d81893 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/ml/base/sgd/params/float64", + "version": "0.0.0", + "description": "Create an SGD double-precision floating-point params object.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "ml", + "machine learning", + "sgd", + "stochastic gradient descent", + "utilities", + "utility", + "utils", + "util", + "constructor", + "ctor", + "params" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/test/test.js new file mode 100644 index 000000000000..57d95de56194 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/test/test.js @@ -0,0 +1,500 @@ +/** +* @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 isDataView = require( '@stdlib/assert/is-dataview' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var Float64Array = require( '@stdlib/array/float64' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var Float64Params = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float64Params, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ArrayBuffer or data object', function test( t ) { + var params; + var values; + var i; + + params = Float64Params; + + 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() { + params( value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { + var params; + var values; + var i; + + params = Float64Params; + + values = [ + '5', + -5, + 3.14, + 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() { + params( new ArrayBuffer( 1024 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not a nonnegative integer', function test( t ) { + var params; + var values; + var i; + + params = Float64Params; + + values = [ + '5', + -5, + 3.14, + 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() { + params( new ArrayBuffer( 1024 ), 0, value ); + }; + } +}); + +tape( 'the function is a constructor which does not require the `new` operator', function test( t ) { + var params; + var p; + + params = Float64Params; + + p = params(); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( {} ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( new ArrayBuffer( 1024 ) ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( new ArrayBuffer( 1024 ), 0 ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( new ArrayBuffer( 1024 ), 0, 1024 ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object ', function test( t ) { + var expected; + var actual; + + actual = new Float64Params({ + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }); + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float64Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object (no arguments)', function test( t ) { + var expected; + var actual; + + actual = new Float64Params(); + + actual.fitIntercept = true; + actual.intercept = 0.0; + actual.maxIter = 500; + actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); + actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float64Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object (empty object)', function test( t ) { + var expected; + var actual; + + actual = new Float64Params( {} ); + + actual.fitIntercept = true; + actual.intercept = 0.0; + actual.maxIter = 500; + actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); + actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float64Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object (ArrayBuffer)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float64Params( buf ); + + actual.fitIntercept = true; + actual.intercept = 0.0; + actual.maxIter = 500; + actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); + actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float64Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object (ArrayBuffer, byteOffset)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float64Params( buf, 16 ); + + actual.fitIntercept = true; + actual.intercept = 0.0; + actual.maxIter = 500; + actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); + actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float64Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object (ArrayBuffer, byteOffset, byteLength)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float64Params( buf, 16, 160 ); + + actual.fitIntercept = true; + actual.intercept = 0.0; + actual.maxIter = 500; + actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); + actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float64Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a method property', function test( t ) { + var params = new Float64Params(); + + t.strictEqual( params.method, 'Stochastic Gradient Descent', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toString` method', function test( t ) { + var params; + var actual; + + params = new Float64Params(); + + actual = params.toString(); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + + actual = params.toString({ + 'digits': 2 + }); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toJSON` method', function test( t ) { + var params = new Float64Params(); + t.strictEqual( typeof params.toJSON, 'function', 'returns expected value' ); + t.strictEqual( typeof params.toJSON(), 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toDataView` method', function test( t ) { + var params = new Float64Params(); + t.strictEqual( typeof params.toDataView, 'function', 'returns expected value' ); + t.strictEqual( isDataView( params.toDataView() ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `name` property', function test( t ) { + t.strictEqual( typeof Float64Params.name, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has an `alignment` property', function test( t ) { + t.strictEqual( typeof Float64Params.alignment, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteLength` property', function test( t ) { + t.strictEqual( typeof Float64Params.byteLength, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `fields` property', function test( t ) { + t.strictEqual( isStringArray( Float64Params.fields ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `layout` property', function test( t ) { + t.strictEqual( typeof Float64Params.layout, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `bufferOf` method', function test( t ) { + t.strictEqual( typeof Float64Params.bufferOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteLengthOf` method', function test( t ) { + t.strictEqual( typeof Float64Params.byteLengthOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteOffsetOf` method', function test( t ) { + t.strictEqual( typeof Float64Params.byteOffsetOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `descriptionOf` method', function test( t ) { + t.strictEqual( typeof Float64Params.descriptionOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has an `isStruct` method', function test( t ) { + t.strictEqual( typeof Float64Params.isStruct, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `viewOf` method', function test( t ) { + t.strictEqual( typeof Float64Params.viewOf, 'function', 'returns expected value' ); + t.end(); +}); From a7de9af717420b17199950e58c54982312697243 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 6 Aug 2026 12:17:19 +0530 Subject: [PATCH 4/8] feat: add `ml/base/sgd/params/float32` --- .../ml/base/sgd/params/float32/README.md | 449 ++++++++++++++++ .../sgd/params/float32/benchmark/benchmark.js | 71 +++ .../ml/base/sgd/params/float32/docs/repl.txt | 29 + .../sgd/params/float32/docs/types/index.d.ts | 240 +++++++++ .../sgd/params/float32/docs/types/test.ts | 143 +++++ .../base/sgd/params/float32/examples/index.js | 37 ++ .../stdlib/ml/base/sgd/params/float32.h | 57 ++ .../ml/base/sgd/params/float32/lib/index.js | 54 ++ .../ml/base/sgd/params/float32/lib/main.js | 63 +++ .../ml/base/sgd/params/float32/manifest.json | 36 ++ .../ml/base/sgd/params/float32/package.json | 67 +++ .../ml/base/sgd/params/float32/test/test.js | 507 ++++++++++++++++++ 12 files changed, 1753 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/include/stdlib/ml/base/sgd/params/float32.h create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/manifest.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md new file mode 100644 index 000000000000..c14309e83932 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md @@ -0,0 +1,449 @@ + + +# Float32Params + +> Create an SGD single-precision floating-point params object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Float32Params = require( '@stdlib/ml/base/sgd/params/float32' ); +``` + +#### Float32Params( \[arg\[, byteOffset\[, byteLength]]] ) + +Returns an SGD single-precision floating-point params object. + +```javascript +var params = new Float32Params(); +// returns {...} +``` + +The function supports the following parameters: + +- **arg**: an [`ArrayBuffer`][@stdlib/array/buffer] or a data object (_optional_). +- **byteOffset**: byte offset (_optional_). +- **byteLength**: maximum byte length (_optional_). + +A data object argument is an object having one or more of the following properties: + +- **penalty**: regularization function to be used (e.g., `'l1'`, `'l2'`, `'elasticnet'` or `'none'`). + +- **penaltyParams**: parameters specific to the regularization function being used as a [`Float32Array`][@stdlib/array/float32]. + + - When `'penalty = {l1,l2}`, `'penaltyParams' => [ lambda ]` + - When `'penalty = elasticnet`, `'penaltyParams' => [ lambda, l1Ratio ]` + - When `'penalty = none`, `'penaltyParams' => [ ]` + +- **learningRate**: learning rate scheduler to be used (e.g., `'basic'`, `'constant'`, `'invscaling'` or `'pegasos'`). + +- **learningRateParams**: parameters specific to the learning rate scheduler being used as a [`Float32Array`][@stdlib/array/float32]. + + - When `'learningRate = basic`, `'learningRateParams' => [ ]` + - When `'learningRate = constant`, `'learningRateParams' => [ eta0 ]` + - When `'learningRate = invscaling`, `'learningRateParams' => [ eta0, powerT ]` + - When `'learningRate = pegasos`, `'learningRateParams' => [ lambda ]` + +- **lossFunction**: loss function to be used (e.g., `'epsilon-insensitive'`, `'hinge'`, `'huber'`, `'log'`, `'modified-huber'`, `'perceptron'`, `'squared-epsilon-insensitive'`, `'squared-error'`, or `'squared-hinge'`). + +- **lossFunctionParams**: parameters specific to the loss function being used as a [`Float32Array`][@stdlib/array/float32]. + + - When `'lossFunction = {epsilon-insensitive,squared-epsilon-insensitive}`, `'lossFunctionParams' => [ epsilon ]` + - Else, `'lossFunctionParams' => [ ]` + +- **fitIntercept**: boolean indicating whether to include intercept. + +- **intercept**: initial intercept value. + +- **maxIter**: maximum number of iterations to run. + +#### Float32Params.prototype.penalty + +Regularization function to be used. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.penalty; +// returns +``` + +#### Float32Params.prototype.penaltyParams + +Parameters specific to the regularization function being used. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.penaltyParams; +// returns +``` + +#### Float32Params.prototype.learningRate + +Learning rate scheduler to be used. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.learningRate; +// returns +``` + +#### Float32Params.prototype.learningRateParams + +Parameters specific to the learning rate scheduler being used. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.learningRateParams; +// returns +``` + +#### Float32Params.prototype.lossFunction + +Loss function to be used. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.lossFunction; +// returns +``` + +#### Float32Params.prototype.lossFunctionParams + +Parameters specific to the loss function being used. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.lossFunctionParams; +// returns +``` + +#### Float32Params.prototype.fitIntercept + +Boolean indicating whether to include intercept. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.fitIntercept; +// returns +``` + +#### Float32Params.prototype.intercept + +Initial intercept value. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.intercept; +// returns +``` + +#### Float32Params.prototype.maxIter + +Maximum number of iterations to run. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.maxIter; +// returns +``` + +#### Float32Params.prototype.toString( \[options] ) + +Serializes a params object to a formatted string. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.toString(); +// returns +``` + +The method supports the following options: + +- **digits**: number of digits to display after decimal points. Default: `4`. + +Example output: + +```text + +Stochastic Gradient Descent + + penalty: l2 + learning rate: constant + loss function: hinge + lambda: 2.5000 + eta0: 0.0100 + fit intercept: true + intercept: 0.0000 + max iterations: 1000 + +``` + +#### Float32Params.prototype.toJSON( \[options] ) + +Serializes a params object as a JSON object. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.toJSON(); +// returns {...} +``` + +`JSON.stringify()` implicitly calls this method when stringifying a params instance. + +#### Float32Params.prototype.toDataView() + +Returns a [`DataView`][@stdlib/array/dataview] of a params object. + +```javascript +var params = new Float32Params(); +// returns {...} + +// ... + +var v = params.toDataView(); +// returns +``` + +
+ + + + + +
+ +## Notes + +- A params object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing SGD trainer params and providing an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var Params = require( '@stdlib/ml/base/sgd/params/float32' ); + +var params = new Params({ + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' +}); + +var str = params.toString(); +console.log( str ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ml/base/sgd/params/float32.h" +``` + +#### stdlib_ml_sgd_params_float32_params + +Structure for holding single-precision floating-point test params. + + + +```c +#include +#include + +struct stdlib_ml_sgd_params_float32_params { + // Regularization function to be used: + int8_t penalty; + + // Parameters specific to the regularization function being used: + float penaltyParams[ 2 ]; + + // Learning rate scheduler to be used: + int8_t learningRate; + + // Parameters specific to the learning rate scheduler being used: + float learningRateParams[ 2 ]; + + // Loss function to be used: + int8_t lossFunction; + + // Parameters specific to the loss function being used: + float lossFunctionParams[ 1 ]; + + // Boolean indicating whether to include intercept: + bool fitIntercept; + + // Initial intercept value: + float intercept; + + // Maximum number of iterations to run: + int32_t maxIter; +}; +``` + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/benchmark/benchmark.js new file mode 100644 index 000000000000..d1d5951be3dc --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/benchmark/benchmark.js @@ -0,0 +1,71 @@ +/** +* @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 isObject = require( '@stdlib/assert/is-object' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float32Params = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::constructor,new', pkg ), function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new Float32Params(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::constructor,no_new', pkg ), function benchmark( b ) { + var params; + var v; + var i; + + params = Float32Params; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = params(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/repl.txt new file mode 100644 index 000000000000..79d886f817cb --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( [arg[, byteOffset[, byteLength]]] ) + Returns an SGD single-precision floating-point params object. + + Parameters + ---------- + arg: Object|ArrayBuffer (optional) + ArrayBuffer or data object. + + byteOffset: integer (optional) + Byte offset. + + byteLength: integer (optional) + Maximum byte length. + + Returns + ------- + out: Object + Params object. + + Examples + -------- + > var r = new {{alias}}(); + > r.toString() + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts new file mode 100644 index 000000000000..51ab8ebb8f23 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts @@ -0,0 +1,240 @@ +/* +* @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 + +/** +* Regularization Function. +*/ +type Penalty = 'elasticnet' | 'l1' | 'l2' | 'none'; + +/** +* Learning Rate. +*/ +type LearningRate = 'basic' | 'constant' | 'invscaling' | 'pegasos'; + +/** +* Loss Function. +*/ +type LossFunction = 'epsilon-insensitive' | 'hinge' | 'huber' | 'log' | 'modified-huber' | 'perceptron' | 'squared-epsilon-insensitive' | 'squared-error' | 'squared-hinge'; + +/** +* Interface describing SGD trainer parameters. +*/ +interface Params { + /** + * Regularization function to be used. + */ + penalty?: Penalty; + + /** + * Parameters specific to the regularization function being used. + */ + penaltyParams?: Float64Array; + + /** + * Learning rate scheduler to be used. + */ + learningRate?: LearningRate; + + /** + * Parameters specific to the learning rate scheduler being used. + */ + learningRateParams?: Float64Array; + + /** + * Loss function to be used. + */ + lossFunction?: LossFunction; + + /** + * Parameters specific to the loss function being used. + */ + lossFunctionParams?: Float64Array; + + /** + * Boolean indicating whether to include intercept. + */ + fitIntercept?: boolean; + + /** + * Initial intercept value. + */ + intercept?: number; + + /** + * Maximum number of iterations to run. + */ + maxIter?: number; +} + +/** +* Interface describing options when serializing a params object to a string. +*/ +interface ToStringOptions { + /** + * Number of digits to display after decimal points. Default: `4`. + */ + digits?: number; +} + +/** +* Interface describing a params data structure. +*/ +declare class ParamsStruct { + /** + * Params constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns params + */ + constructor( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ); + + /** + * Regularization function to be used. + */ + penalty: Penalty; + + /** + * Parameters specific to the regularization function being used. + */ + penaltyParams: Float64Array; + + /** + * Learning rate scheduler to be used. + */ + learningRate: LearningRate; + + /** + * Parameters specific to the learning rate scheduler being used. + */ + learningRateParams: Float64Array; + + /** + * Loss function to be used. + */ + lossFunction: LossFunction; + + /** + * Parameters specific to the loss function being used. + */ + lossFunctionParams: Float64Array; + + /** + * Boolean indicating whether to include intercept. + */ + fitIntercept: boolean; + + /** + * Initial intercept value. + */ + intercept: number; + + /** + * Maximum number of iterations to run. + */ + maxIter: number; + + /** + * Test method. + */ + method: string; + + /** + * Serializes a params object as a formatted string. + * + * @param options - options object + * @returns serialized params + */ + toString( options?: ToStringOptions ): string; + + /** + * Serializes a params object as a JSON object. + * + * @returns serialized object + */ + toJSON(): object; + + /** + * Returns a DataView of a params object. + * + * @returns DataView + */ + toDataView(): DataView; +} + +/** +* Interface defining a params constructor which is both "newable" and "callable". +*/ +interface ParamsConstructor { + /** + * Params constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns params object + */ + new( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ): ParamsStruct; + + /** + * Params constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns params object + */ + ( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ): ParamsStruct; +} + +/** +* Returns an SGD single-precision floating-point params object. +* +* @param arg - buffer or data object +* @param byteOffset - byte offset +* @param byteLength - maximum byte length +* @returns params object +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var params = new Params(); +* // returns +* +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); +* params.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); +* params.lossFunctionParams = new Float32Array( [ 0.0 ] ); +* params.fitIntercept = true; +* +* var str = params.toString(); +* // returns +*/ +declare var Params: ParamsConstructor; + + +// EXPORTS // + +export = Params; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/test.ts new file mode 100644 index 000000000000..7dc5fcc95f0a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/test.ts @@ -0,0 +1,143 @@ +/* +* @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 Params = require( './index' ); + + +// TESTS // + +// The constructor returns a params object... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r0 = new Params( {} ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = new Params( new ArrayBuffer( 80 ) ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = new Params( new ArrayBuffer( 80 ), 8 ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = new Params( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ParamsStruct +} + +// The constructor can be invoked without `new`... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r0 = Params( {} ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = Params( new ArrayBuffer( 80 ) ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = Params( new ArrayBuffer( 80 ), 8 ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = Params( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ParamsStruct +} + +// The params object has the expected properties... +{ + const r = new Params( {} ); + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.penalty; // $ExpectType Penalty + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.penaltyParams; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.learningRate; // $ExpectType LearningRate + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.learningRateParams; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.lossFunction; // $ExpectType LossFunction + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.lossFunctionParams; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.fitIntercept; // $ExpectType boolean + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.intercept; // $ExpectType number + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.maxIter; // $ExpectType number + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.method; // $ExpectType string +} + +// The compiler throws an error if the constructor is provided a first argument which is not an ArrayBuffer or object... +{ + new Params( 'abc' ); // $ExpectError + new Params( 123 ); // $ExpectError + new Params( true ); // $ExpectError + new Params( false ); // $ExpectError + new Params( null ); // $ExpectError + new Params( [] ); // $ExpectError + new Params( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided a second argument which is not a number... +{ + new Params( new ArrayBuffer( 80 ), 'abc' ); // $ExpectError + new Params( new ArrayBuffer( 80 ), true ); // $ExpectError + new Params( new ArrayBuffer( 80 ), false ); // $ExpectError + new Params( new ArrayBuffer( 80 ), null ); // $ExpectError + new Params( new ArrayBuffer( 80 ), [] ); // $ExpectError + new Params( new ArrayBuffer( 80 ), {} ); // $ExpectError + new Params( new ArrayBuffer( 80 ), ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided a third argument which is not a number... +{ + new Params( new ArrayBuffer( 80 ), 8, 'abc' ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, true ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, false ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, null ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, [] ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, {} ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, ( x: number ): number => x ); // $ExpectError +} + +// The params object has a `toString` method... +{ + const r = new Params( {} ); + + r.toString(); // $ExpectType string + r.toString( {} ); // $ExpectType string + r.toString( { 'digits': 4 } ); // $ExpectType string +} + +// The params object has a `toJSON` method... +{ + const r = new Params( {} ); + + r.toJSON(); // $ExpectType object +} + +// The params object has a `toDataView` method... +{ + const r = new Params( {} ); + + r.toDataView(); // $ExpectType DataView +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/examples/index.js new file mode 100644 index 000000000000..924a666940a5 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var Params = require( './../lib' ); + +var params = new Params({ + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' +}); + +var str = params.toString(); +console.log( str ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/include/stdlib/ml/base/sgd/params/float32.h b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/include/stdlib/ml/base/sgd/params/float32.h new file mode 100644 index 000000000000..0abde6985947 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/include/stdlib/ml/base/sgd/params/float32.h @@ -0,0 +1,57 @@ +/** +* @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. +*/ + +#ifndef STDLIB_ML_BASE_SGD_PARAMS_FLOAT32_H +#define STDLIB_ML_BASE_SGD_PARAMS_FLOAT32_H + +#include +#include + +/** +* Struct for storing test params. +*/ +struct stdlib_ml_sgd_params_float32_params { + // Regularization function to be used: + int8_t penalty; + + // Parameters specific to the regularization function being used: + float penaltyParams[ 2 ]; + + // Learning rate scheduler to be used: + int8_t learningRate; + + // Parameters specific to the learning rate scheduler being used: + float learningRateParams[ 2 ]; + + // Loss function to be used: + int8_t lossFunction; + + // Parameters specific to the loss function being used: + float lossFunctionParams[ 1 ]; + + // Boolean indicating whether to include intercept: + bool fitIntercept; + + // Initial intercept value: + float intercept; + + // Maximum number of iterations to run: + int32_t maxIter; +}; + +#endif // !STDLIB_ML_BASE_SGD_PARAMS_FLOAT32_H diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/index.js new file mode 100644 index 000000000000..d9d7c20abdce --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/index.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'; + +/** +* Create an SGD single-precision floating-point params object. +* +* @module @stdlib/ml/base/sgd/params/float32 +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Params = require( '@stdlib/ml/base/sgd/params/float32' ); +* +* var params = new Params(); +* // returns +* +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); +* params.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); +* params.lossFunctionParams = new Float32Array( [ 0.0 ] ); +* params.fitIntercept = true; +* +* var str = params.toString(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/main.js new file mode 100644 index 000000000000..7dacdf594e13 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/main.js @@ -0,0 +1,63 @@ +/** +* @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 factory = require( '@stdlib/ml/base/sgd/params/factory' ); + + +// MAIN // + +/** +* Returns an SGD single-precision floating-point params object. +* +* @name Params +* @constructor +* @type {Function} +* @param {(ArrayBuffer|Object)} [arg] - underlying byte buffer or data object +* @param {NonNegativeInteger} [byteOffset] - byte offset +* @param {NonNegativeInteger} [byteLength] - maximum byte length +* @returns {Params} params object +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var params = new Params(); +* // returns +* +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); +* params.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); +* params.lossFunctionParams = new Float32Array( [ 0.0 ] ); +* params.fitIntercept = true; +* +* var str = params.toString(); +* // returns +*/ +var Params = factory( 'float32' ); + + +// EXPORTS // + +module.exports = Params; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/manifest.json b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/package.json b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/package.json new file mode 100644 index 000000000000..689abf2f6fd4 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/ml/base/sgd/params/float32", + "version": "0.0.0", + "description": "Create an SGD single-precision floating-point params object.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "ml", + "machine learning", + "sgd", + "stochastic gradient descent", + "utilities", + "utility", + "utils", + "util", + "constructor", + "ctor", + "params" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js new file mode 100644 index 000000000000..0a163b75ee42 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js @@ -0,0 +1,507 @@ +/** +* @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 isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isDataView = require( '@stdlib/assert/is-dataview' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var Float32Array = require( '@stdlib/array/float32' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Params = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float32Params, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ArrayBuffer or data object', function test( t ) { + var params; + var values; + var i; + + params = Float32Params; + + 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() { + params( value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { + var params; + var values; + var i; + + params = Float32Params; + + values = [ + '5', + -5, + 3.14, + 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() { + params( new ArrayBuffer( 1024 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not a nonnegative integer', function test( t ) { + var params; + var values; + var i; + + params = Float32Params; + + values = [ + '5', + -5, + 3.14, + 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() { + params( new ArrayBuffer( 1024 ), 0, value ); + }; + } +}); + +tape( 'the function is a constructor which does not require the `new` operator', function test( t ) { + var params; + var p; + + params = Float32Params; + + p = params(); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( {} ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( new ArrayBuffer( 1024 ) ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( new ArrayBuffer( 1024 ), 0 ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( new ArrayBuffer( 1024 ), 0, 1024 ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object ', function test( t ) { + var expected; + var actual; + + actual = new Float32Params({ + 'fitIntercept': true, + 'intercept': f32( 0.0 ), + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }); + + expected = { + 'fitIntercept': true, + 'intercept': f32( 0.0 ), + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float32Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object (no arguments)', function test( t ) { + var expected; + var actual; + + actual = new Float32Params(); + + actual.fitIntercept = true; + actual.intercept = f32( 0.0 ); + actual.maxIter = 500; + actual.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float32Array( [ 0.0 ] ); + actual.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': f32( 0.0 ), + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float32Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object (empty object)', function test( t ) { + var expected; + var actual; + + actual = new Float32Params( {} ); + + actual.fitIntercept = true; + actual.intercept = f32( 0.0 ); + actual.maxIter = 500; + actual.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float32Array( [ 0.0 ] ); + actual.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': f32( 0.0 ), + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float32Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object (ArrayBuffer)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float32Params( buf ); + + actual.fitIntercept = true; + actual.intercept = f32( 0.0 ); + actual.maxIter = 500; + actual.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float32Array( [ 0.0 ] ); + actual.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': f32( 0.0 ), + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float32Params, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 0, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object (ArrayBuffer, byteOffset)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float32Params( buf, 16 ); + + actual.fitIntercept = true; + actual.intercept = f32( 0.0 ); + actual.maxIter = 500; + actual.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float32Array( [ 0.0 ] ); + actual.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': f32( 0.0 ), + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float32Params, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width params object (ArrayBuffer, byteOffset, byteLength)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float32Params( buf, 16, 160 ); + + actual.fitIntercept = true; + actual.intercept = f32( 0.0 ); + actual.maxIter = 500; + actual.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float32Array( [ 0.0 ] ); + actual.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': f32( 0.0 ), + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Float32Params, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a method property', function test( t ) { + var params = new Float32Params(); + + t.strictEqual( params.method, 'Stochastic Gradient Descent', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toString` method', function test( t ) { + var params; + var actual; + + params = new Float32Params(); + + actual = params.toString(); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + + actual = params.toString({ + 'decision': false + }); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toJSON` method', function test( t ) { + var params = new Float32Params(); + t.strictEqual( typeof params.toJSON, 'function', 'returns expected value' ); + t.strictEqual( typeof params.toJSON(), 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toDataView` method', function test( t ) { + var params = new Float32Params(); + t.strictEqual( typeof params.toDataView, 'function', 'returns expected value' ); + t.strictEqual( isDataView( params.toDataView() ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `name` property', function test( t ) { + t.strictEqual( typeof Float32Params.name, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has an `alignment` property', function test( t ) { + t.strictEqual( typeof Float32Params.alignment, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteLength` property', function test( t ) { + t.strictEqual( typeof Float32Params.byteLength, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `fields` property', function test( t ) { + t.strictEqual( isStringArray( Float32Params.fields ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `layout` property', function test( t ) { + t.strictEqual( typeof Float32Params.layout, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `bufferOf` method', function test( t ) { + t.strictEqual( typeof Float32Params.bufferOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteLengthOf` method', function test( t ) { + t.strictEqual( typeof Float32Params.byteLengthOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteOffsetOf` method', function test( t ) { + t.strictEqual( typeof Float32Params.byteOffsetOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `descriptionOf` method', function test( t ) { + t.strictEqual( typeof Float32Params.descriptionOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has an `isStruct` method', function test( t ) { + t.strictEqual( typeof Float32Params.isStruct, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `viewOf` method', function test( t ) { + t.strictEqual( typeof Float32Params.viewOf, 'function', 'returns expected value' ); + t.end(); +}); From 119752098021462db147abb7e48b90e81ef2d7aa Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 6 Aug 2026 12:34:09 +0530 Subject: [PATCH 5/8] feat: add `ml/base/sgd/params/factory` --- .../ml/base/sgd/params/factory/README.md | 153 ++++ .../sgd/params/factory/benchmark/benchmark.js | 106 +++ .../ml/base/sgd/params/factory/docs/repl.txt | 24 + .../sgd/params/factory/docs/types/index.d.ts | 236 ++++++ .../sgd/params/factory/docs/types/test.ts | 199 +++++ .../base/sgd/params/factory/examples/index.js | 59 ++ .../ml/base/sgd/params/factory/lib/index.js | 56 ++ .../ml/base/sgd/params/factory/lib/main.js | 507 ++++++++++++ .../ml/base/sgd/params/factory/package.json | 66 ++ .../ml/base/sgd/params/factory/test/test.js | 754 ++++++++++++++++++ 10 files changed, 2160 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/factory/README.md create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/factory/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/factory/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/factory/package.json create mode 100644 lib/node_modules/@stdlib/ml/base/sgd/params/factory/test/test.js diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/README.md new file mode 100644 index 000000000000..86605644d766 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/README.md @@ -0,0 +1,153 @@ + + +# paramsFactory + +> Create a new constructor for creating an SGD trainer params object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var paramsFactory = require( '@stdlib/ml/base/sgd/params/factory' ); +``` + +#### paramsFactory( dtype ) + +Returns a new constructor for creating an SGD trainer params object. + +```javascript +var Params = paramsFactory( 'float64' ); +// returns + +var r = new Params(); +// returns +``` + +The function supports the following parameters: + +- **dtype**: floating-point data type for storing floating-point params. Must be either `'float64'` or `'float32'`. + +
+ + + + + +
+ +## Notes + +- A params object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing SGD trainer params and providing an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var paramsFactory = require( '@stdlib/ml/base/sgd/params/factory' ); + +var Params = paramsFactory( 'float64' ); +var params = new Params({ + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' +}); + +var str = params.toString({ + 'format': 'linear' +}); +console.log( str ); + +Params = paramsFactory( 'float32' ); +params = new Params({ + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' +}); + +str = params.toString({ + 'format': 'linear' +}); +console.log( str ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/benchmark/benchmark.js new file mode 100644 index 000000000000..54e2d1466769 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @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 isObject = require( '@stdlib/assert/is-object' ); +var format = require( '@stdlib/string/format' ); +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(); +}); + +bench( format( '%s::constructor,new', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + values = [ + factory( 'float64' ), + factory( 'float32' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new ( values[ i%values.length ] )(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::constructor,no_new', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + values = [ + factory( 'float64' ), + factory( 'float32' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = values[ i%values.length ](); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/repl.txt new file mode 100644 index 000000000000..a8f2703bf094 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/repl.txt @@ -0,0 +1,24 @@ + +{{alias}}( dtype ) + Returns a constructor for creating an SGD trainer params object. + + Parameters + ---------- + dtype: string + Floating-point data type for storing floating-point params. + + Returns + ------- + fcn: Function + Constructor. + + Examples + -------- + > var R = {{alias}}( 'float64' ); + > var r = new R(); + > r.toString() + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/index.d.ts new file mode 100644 index 000000000000..1009fb32aedb --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/index.d.ts @@ -0,0 +1,236 @@ +/* +* @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 + +/** +* Regularization Function. +*/ +type Penalty = 'elasticnet' | 'l1' | 'l2' | 'none'; + +/** +* Learning Rate Scheduler. +*/ +type LearningRate = 'basic' | 'constant' | 'invscaling' | 'pegasos'; + +/** +* Loss Function. +*/ +type LossFunction = 'epsilon-insensitive' | 'hinge' | 'huber' | 'log' | 'modified-huber' | 'perceptron' | 'squared-epsilon-insensitive' | 'squared-error' | 'squared-hinge'; + +/** +* Interface describing SGD trainer parameters. +*/ +interface Params { + /** + * Regularization function to be used. + */ + penalty?: Penalty; + + /** + * Parameters specific to the regularization function being used. + */ + penaltyParams?: T; + + /** + * Learning rate scheduler to be used. + */ + learningRate?: LearningRate; + + /** + * Parameters specific to the learning rate scheduler being used. + */ + learningRateParams?: T; + + /** + * Loss function to be used. + */ + lossFunction?: LossFunction; + + /** + * 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 options when serializing a params object to a string. +*/ +interface ToStringOptions { + /** + * Number of digits to display after decimal points. Default: `4`. + */ + digits?: number; +} + +/** +* Interface describing a params data structure. +*/ +declare class ParamsStruct { + /** + * Params constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns params + */ + constructor( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ); + + /** + * Regularization function to be used. + */ + penalty: Penalty; + + /** + * Parameters specific to the regularization function being used. + */ + penaltyParams: T; + + /** + * Learning rate scheduler to be used. + */ + learningRate: LearningRate; + + /** + * Parameters specific to the learning rate scheduler being used. + */ + learningRateParams: T; + + /** + * Loss function to be used. + */ + lossFunction: LossFunction; + + /** + * 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; + + /** + * Serializes a params object as a formatted string. + * + * @param options - options object + * @returns serialized params + */ + toString( options?: ToStringOptions ): string; + + /** + * Serializes a params object as a JSON object. + * + * @returns serialized object + */ + toJSON(): object; + + /** + * Returns a DataView of a params object. + * + * @returns DataView + */ + toDataView(): DataView; +} + +/** +* Interface defining a params constructor which is both "newable" and "callable". +*/ +interface ParamsConstructor { + /** + * Params constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns params object + */ + new( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ): ParamsStruct; + + /** + * Params constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns params object + */ + ( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ): ParamsStruct; +} + +/** +* Returns a new params constructor for creating an SGD trainer params object. +* +* @param dtype - floating-point data type for storing floating-point params +* @returns params constructor +* +* @example +* var Params = paramsFactory( 'float64' ); +* // returns +* +* var r = new Params(); +* // returns +*/ +declare function paramsFactory( dtype: 'float64' ): ParamsConstructor; + +/** +* Returns a constructor for creating an SGD trainer params object. +* +* @param dtype - floating-point data type for storing floating-point params +* @returns params constructor +* +* @example +* var Params = paramsFactory( 'float32' ); +* // returns +* +* var r = new Params(); +* // returns +*/ +declare function paramsFactory( dtype: 'float32' ): ParamsConstructor; + + +// EXPORTS // + +export = paramsFactory; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/test.ts new file mode 100644 index 000000000000..7ce1624e5f18 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/test.ts @@ -0,0 +1,199 @@ +/* +* @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 paramsFactory = require( './index' ); + + +// TESTS // + +// The function returns a function... +{ + paramsFactory( 'float64' ); // $ExpectType ParamsConstructor + paramsFactory( 'float32' ); // $ExpectType ParamsConstructor +} + +// The compiler throws an error if not provided a supported data type... +{ + paramsFactory( 10 ); // $ExpectError + paramsFactory( true ); // $ExpectError + paramsFactory( false ); // $ExpectError + paramsFactory( null ); // $ExpectError + paramsFactory( undefined ); // $ExpectError + paramsFactory( [] ); // $ExpectError + paramsFactory( {} ); // $ExpectError + paramsFactory( ( x: number ): number => x ); // $ExpectError +} + +// The function returns a function which returns a params object... +{ + const Params = paramsFactory( 'float64' ); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = new Params( new ArrayBuffer( 80 ) ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = new Params( new ArrayBuffer( 80 ), 8 ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = new Params( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ParamsStruct +} + +// The returned constructor can be invoked without `new`... +{ + const Params = paramsFactory( 'float64' ); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = Params( new ArrayBuffer( 80 ) ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = Params( new ArrayBuffer( 80 ), 8 ); // $ExpectType ParamsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = Params( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ParamsStruct +} + +// The params object has the expected properties (float64)... +{ + const Params = paramsFactory( 'float64' ); + const r = new Params( {} ); + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.penalty; // $ExpectType Penalty + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.penaltyParams; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.learningRate; // $ExpectType LearningRate + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.learningRateParams; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.lossFunction; // $ExpectType LossFunction + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.lossFunctionParams; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.fitIntercept; // $ExpectType boolean + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.intercept; // $ExpectType number + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.maxIter; // $ExpectType number +} + +// The params object has the expected properties (float32)... +{ + const Params = paramsFactory( 'float32' ); + const r = new Params( {} ); + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.penalty; // $ExpectType Penalty + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.penaltyParams; // $ExpectType Float32Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.learningRate; // $ExpectType LearningRate + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.learningRateParams; // $ExpectType Float32Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.lossFunction; // $ExpectType LossFunction + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.lossFunctionParams; // $ExpectType Float32Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.fitIntercept; // $ExpectType boolean + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.intercept; // $ExpectType number + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.maxIter; // $ExpectType number +} + +// The compiler throws an error if the constructor is provided a first argument which is not an ArrayBuffer or object... +{ + const Params = paramsFactory( 'float64' ); + + new Params( 'abc' ); // $ExpectError + new Params( 123 ); // $ExpectError + new Params( true ); // $ExpectError + new Params( false ); // $ExpectError + new Params( null ); // $ExpectError + new Params( [] ); // $ExpectError + new Params( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided a second argument which is not a number... +{ + const Params = paramsFactory( 'float64' ); + + new Params( new ArrayBuffer( 80 ), 'abc' ); // $ExpectError + new Params( new ArrayBuffer( 80 ), true ); // $ExpectError + new Params( new ArrayBuffer( 80 ), false ); // $ExpectError + new Params( new ArrayBuffer( 80 ), null ); // $ExpectError + new Params( new ArrayBuffer( 80 ), [] ); // $ExpectError + new Params( new ArrayBuffer( 80 ), {} ); // $ExpectError + new Params( new ArrayBuffer( 80 ), ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided a third argument which is not a number... +{ + const Params = paramsFactory( 'float64' ); + + new Params( new ArrayBuffer( 80 ), 8, 'abc' ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, true ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, false ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, null ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, [] ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, {} ); // $ExpectError + new Params( new ArrayBuffer( 80 ), 8, ( x: number ): number => x ); // $ExpectError +} + +// The params object has a `toString` method... +{ + const Params = paramsFactory( 'float64' ); + const r = new Params( {} ); + + r.toString(); // $ExpectType string + r.toString( {} ); // $ExpectType string + r.toString( { 'digits': 4 } ); // $ExpectType string +} + +// The params object has a `toJSON` method... +{ + const Params = paramsFactory( 'float64' ); + const r = new Params( {} ); + + r.toJSON(); // $ExpectType object +} + +// The params object has a `toDataView` method... +{ + const Params = paramsFactory( 'float64' ); + const r = new Params( {} ); + + r.toDataView(); // $ExpectType DataView +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/examples/index.js new file mode 100644 index 000000000000..5e0b00811c61 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/examples/index.js @@ -0,0 +1,59 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var paramsFactory = require( './../lib' ); + +var Params = paramsFactory( 'float64' ); +var params = new Params({ + 'penalty': 'l2', + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRate': 'constant', + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunction': 'hinge', + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500 +}); + +var str = params.toString({ + 'format': 'linear' +}); +console.log( str ); + +Params = paramsFactory( 'float32' ); +params = new Params({ + 'penalty': 'l2', + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'learningRate': 'constant', + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'lossFunction': 'hinge', + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + '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/factory/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/index.js new file mode 100644 index 000000000000..9c70032be4fc --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/index.js @@ -0,0 +1,56 @@ +/** +* @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'; + +/** +* Return a constructor for creating an SGD trainer params object. +* +* @module @stdlib/ml/base/sgd/params/factory +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var paramsFactory = require( '@stdlib/ml/base/sgd/params/factory' ); +* +* var Params = paramsFactory( 'float64' ); +* +* var params = new Params(); +* // returns +* +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); +* params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); +* params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +* params.fitIntercept = true; +* +* var str = params.toString(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/main.js new file mode 100644 index 000000000000..2e5d3a8f9447 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/main.js @@ -0,0 +1,507 @@ +/** +* @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. +*/ + +/* eslint-disable no-invalid-this, no-restricted-syntax */ + +'use strict'; + +// MODULES // + +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isObject = require( '@stdlib/assert/is-object' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var setReadWriteAccessor = require( '@stdlib/utils/define-nonenumerable-read-write-accessor' ); +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var propertyDescriptor = require( '@stdlib/utils/property-descriptor' ); +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var join = require( '@stdlib/array/base/join' ); +var objectAssign = require( '@stdlib/object/assign' ); +var inherit = require( '@stdlib/utils/inherit' ); +var resolvePenaltyStr = require( '@stdlib/ml/base/sgd/penalty-resolve-str' ); +var resolveLRStr = require( '@stdlib/ml/base/sgd/learning-rate-resolve-str' ); +var resolveLossFnStr = require( '@stdlib/ml/base/sgd/loss-function-resolve-str' ); +var resolvePenaltyEnum = require( '@stdlib/ml/base/sgd/penalty-resolve-enum' ); +var resolveLREnum = require( '@stdlib/ml/base/sgd/learning-rate-resolve-enum' ); +var resolveLossFnEnum = require( '@stdlib/ml/base/sgd/loss-function-resolve-enum' ); +var structFactory = require( '@stdlib/ml/base/sgd/params/struct-factory' ); +var params2json = require( '@stdlib/ml/base/sgd/params/to-json' ); +var params2str = require( '@stdlib/ml/base/sgd/params/to-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var DTYPES = [ + 'float64', + 'float32' +]; + +var isDataType = contains( DTYPES ); + + +// MAIN // + +/** +* Returns a constructor for creating an SGD trainer params object. +* +* @param {string} dtype - storage data type for floating-point values +* @throws {TypeError} first argument must be a supported data type +* @returns {Function} constructor +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var Params = factory( 'float64' ); +* +* var params = new Params(); +* // returns +* +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); +* params.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); +* params.fitIntercept = true; +* +* var str = params.toString(); +* // returns +*/ +function factory( dtype ) { + var learningRateDescriptor; + var lossFunctionDescriptor; + var penaltyDescriptor; + var Struct; + + if ( !isDataType( dtype ) ) { + throw new TypeError( format( 'invalid argument. First argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, ', ' ), dtype ) ); + } + + // Create a struct constructor: + Struct = structFactory( dtype ); + + // Cache a reference to a property descriptors on the parent prototype so that we can intercept the return value: + learningRateDescriptor = propertyDescriptor( Struct.prototype, 'learningRate' ); + lossFunctionDescriptor = propertyDescriptor( Struct.prototype, 'lossFunction' ); + penaltyDescriptor = propertyDescriptor( Struct.prototype, 'penalty' ); + + /** + * Returns an SGD trainer params object. + * + * @private + * @constructor + * @param {(ArrayBuffer|Object)} [arg] - underlying byte buffer or a data object + * @param {NonNegativeInteger} [byteOffset] - byte offset + * @param {NonNegativeInteger} [byteLength] - maximum byte length + * @throws {TypeError} first argument must be an ArrayBuffer or a data object + * @returns {Params} params object + */ + function Params( arg, byteOffset, byteLength ) { + var nargs; + var args; + var v; + var i; + + nargs = arguments.length; + if ( !( this instanceof Params ) ) { + if ( nargs === 0 ) { + return new Params(); + } + if ( nargs === 1 ) { + return new Params( arg ); + } + if ( nargs === 2 ) { + return new Params( arg, byteOffset ); + } + return new Params( arg, byteOffset, byteLength ); + } + args = []; + if ( nargs > 0 ) { + if ( isArrayBuffer( arg ) ) { + for ( i = 0; i < nargs; i++ ) { + args.push( arguments[ i ] ); + } + } else if ( isObject( arg ) ) { + if ( hasProp( arg, 'learningRate' ) ) { + args.push( objectAssign( {}, arg ) ); + v = resolveLREnum( args[ 0 ].learningRate ); + args[ 0 ].learningRate = ( v === null ) ? NaN : v; + } + if ( hasProp( arg, 'lossFunction' ) ) { + args.push( objectAssign( {}, arg ) ); + v = resolveLossFnEnum( args[ 0 ].lossFunction ); + args[ 0 ].lossFunction = ( v === null ) ? NaN : v; + } + if ( hasProp( arg, 'penalty' ) ) { + args.push( objectAssign( {}, arg ) ); + v = resolvePenaltyEnum( args[ 0 ].penalty ); + args[ 0 ].penalty = ( v === null ) ? NaN : v; + } + } else { + throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer or a data object. Value: `%s`.', arg ) ); + } + } + // Call the parent constructor... + Struct.apply( this, args ); + return this; + } + + /* + * Inherit from the parent constructor. + */ + inherit( Params, Struct ); + + /** + * Constructor name. + * + * @private + * @name name + * @memberof Params + * @readonly + * @type {string} + */ + setReadOnly( Params, 'name', Struct.name ); + + /** + * Alignment. + * + * @private + * @name alignment + * @memberof Params + * @readonly + * @type {PositiveInteger} + */ + setReadOnly( Params, 'alignment', Struct.alignment ); + + /** + * Size (in bytes) of the `struct`. + * + * @private + * @name byteLength + * @memberof Params + * @readonly + * @type {PositiveInteger} + */ + setReadOnly( Params, 'byteLength', Struct.byteLength ); + + /** + * Returns a list of `struct` fields. + * + * @private + * @name fields + * @memberof Params + * @readonly + * @type {Array} + */ + setReadOnlyAccessor( Params, 'fields', function get() { + return Struct.fields; + }); + + /** + * Returns a string corresponding to the `struct` layout. + * + * @private + * @name layout + * @memberof Params + * @readonly + * @type {string} + */ + setReadOnlyAccessor( Params, 'layout', function get() { + return Struct.layout; + }); + + /** + * Returns the underlying byte buffer of a `struct`. + * + * @private + * @name bufferOf + * @memberof Params + * @readonly + * @type {Function} + * @param {Object} obj - struct instance + * @throws {TypeError} must provide a `struct` instance + * @returns {ArrayBuffer} underlying byte buffer + */ + setReadOnly( Params, 'bufferOf', Struct.bufferOf ); + + /** + * Returns the length, in bytes, of the value specified by the provided field name. + * + * @private + * @name byteLengthOf + * @memberof Params + * @readonly + * @type {Function} + * @param {string} name - field name + * @throws {Error} struct must have at least one field + * @throws {TypeError} must provide a recognized field name + * @returns {NonNegativeInteger} byte length + */ + setReadOnly( Params, 'byteLengthOf', Struct.byteLengthOf ); + + /** + * Returns the offset, in bytes, from the beginning of a `struct` to the value specified by the provided field name. + * + * @private + * @name byteOffsetOf + * @memberof Params + * @readonly + * @type {Function} + * @param {string} name - field name + * @throws {Error} struct must have at least one field + * @throws {TypeError} must provide a recognized field name + * @returns {NonNegativeInteger} byte offset + */ + setReadOnly( Params, 'byteOffsetOf', Struct.byteOffsetOf ); + + /** + * Returns the description associated with a provided field name. + * + * @private + * @name descriptionOf + * @memberof Params + * @readonly + * @type {Function} + * @param {string} name - field name + * @throws {Error} struct must have at least one field + * @throws {TypeError} must provide a recognized field name + * @returns {string} description + */ + setReadOnly( Params, 'descriptionOf', Struct.descriptionOf ); + + /** + * Returns a boolean indicating whether a provided value is a `struct` instance. + * + * @private + * @name isStruct + * @memberof Params + * @readonly + * @type {Function} + * @param {*} value - input value + * @returns {boolean} boolean indicating whether a value is a `struct` instance + */ + setReadOnly( Params, 'isStruct', Struct.isStruct ); + + /** + * Returns the type associated with a provided field name. + * + * @private + * @name typeOf + * @memberof Params + * @readonly + * @type {Function} + * @param {string} name - field name + * @throws {Error} struct must have at least one field + * @throws {TypeError} must provide a recognized field name + * @returns {(string|Object)} type + */ + setReadOnly( Params, 'typeOf', Struct.typeOf ); + + /** + * Returns the underlying byte buffer of a `struct` as a `DataView`. + * + * @private + * @name viewOf + * @memberof Params + * @readonly + * @type {Function} + * @param {Object} obj - struct instance + * @throws {TypeError} must provide a `struct` instance + * @returns {DataView} view of underlying byte buffer + */ + setReadOnly( Params, 'viewOf', Struct.viewOf ); + + /** + * Test name. + * + * @private + * @name method + * @memberof Params.prototype + * @type {string} + * @default 'Stochastic Gradient Descent' + */ + setReadOnly( Params.prototype, 'method', 'Stochastic Gradient Descent' ); + + /** + * Regularization Function. + * + * @private + * @name penalty + * @memberof Params.prototype + * @type {string} + */ + setReadWriteAccessor( Params.prototype, 'penalty', getPenalty, setPenalty ); + + /** + * Learning Rate Scheduler. + * + * @private + * @name penalty + * @memberof Params.prototype + * @type {string} + */ + setReadWriteAccessor( Params.prototype, 'learningRate', getLearningRate, setLearningRate ); + + /** + * Loss Function. + * + * @private + * @name penalty + * @memberof Params.prototype + * @type {string} + */ + setReadWriteAccessor( Params.prototype, 'lossFunction', getLossFunction, setLossFunction ); + + /** + * Serializes a params object as a string. + * + * ## Notes + * + * - Example output: + * + * ```text + * + * Stochastic Gradient Descent + * + * penalty: l2 + * learning rate: constant + * loss function: hinge + * lambda: 2.5000 + * eta0: 0.0100 + * fit intercept: true + * intercept: 0.0000 + * max iterations: 1000 + * + * ``` + * + * @private + * @name toString + * @memberof Params.prototype + * @type {Function} + * @param {Options} [opts] - options object + * @param {PositiveInteger} [opts.digits=4] - number of digits after the decimal point + * @throws {TypeError} options argument must be an object + * @throws {TypeError} must provide valid options + * @returns {string} serialized params + */ + setReadOnly( Params.prototype, 'toString', function toString( opts ) { + if ( arguments.length ) { + return params2str( this, opts ); + } + return params2str( this ); + }); + + /** + * Serializes a params object as a JSON object. + * + * ## Notes + * + * - `JSON.stringify()` implicitly calls this method when stringifying a `Params` instance. + * + * @private + * @name toJSON + * @memberof Params.prototype + * @type {Function} + * @returns {Object} serialized object + */ + setReadOnly( Params.prototype, 'toJSON', function toJSON() { + return params2json( this ); + }); + + /** + * Returns a DataView of a params object. + * + * @private + * @name toDataView + * @memberof Params.prototype + * @type {Function} + * @returns {DataView} DataView + */ + setReadOnly( Params.prototype, 'toDataView', function toDataView() { + return Struct.viewOf( this ); + }); + + return Params; + + /** + * Returns the regularization function. + * + * @private + * @returns {string} regularization function + */ + function getPenalty() { + return resolvePenaltyStr( penaltyDescriptor.get.call( this ) ); + } + + /** + * Sets the regularization function. + * + * @private + * @param {string} value - regularization function + */ + function setPenalty( value ) { + penaltyDescriptor.set.call( this, resolvePenaltyEnum( value ) ); + } + + /** + * Returns the learning rate scheduler. + * + * @private + * @returns {string} learning rate scheduler + */ + function getLearningRate() { + return resolveLRStr( learningRateDescriptor.get.call( this ) ); + } + + /** + * Sets the learning rate scheduler. + * + * @private + * @param {string} value - learning rate scheduler + */ + function setLearningRate( value ) { + learningRateDescriptor.set.call( this, resolveLREnum( value ) ); + } + + /** + * Returns the loss function. + * + * @private + * @returns {string} loss function + */ + function getLossFunction() { + return resolveLossFnStr( lossFunctionDescriptor.get.call( this ) ); + } + + /** + * Sets the loss function. + * + * @private + * @param {string} value - loss function + */ + function setLossFunction( value ) { + lossFunctionDescriptor.set.call( this, resolveLossFnEnum( value ) ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/package.json b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/package.json new file mode 100644 index 000000000000..8b440c61f475 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ml/base/sgd/params/factory", + "version": "0.0.0", + "description": "Return a constructor for creating an SGD trainer params object.", + "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", + "utilities", + "utility", + "utils", + "util", + "constructor", + "ctor", + "params" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/test/test.js new file mode 100644 index 000000000000..3740aa6a643d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/test/test.js @@ -0,0 +1,754 @@ +/** +* @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 isDataView = require( '@stdlib/assert/is-dataview' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var paramsFactory = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof paramsFactory, '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() { + paramsFactory( value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided a first argument which is not an ArrayBuffer or data object', function test( t ) { + var params; + var values; + var i; + + params = paramsFactory( 'float64' ); + + 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() { + params( value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { + var params; + var values; + var i; + + params = paramsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + 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() { + params( new ArrayBuffer( 1024 ), value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided a third argument which is not a nonnegative integer', function test( t ) { + var params; + var values; + var i; + + params = paramsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + 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() { + params( new ArrayBuffer( 1024 ), 0, value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided an invalid `penalty` property value', function test( t ) { + var params; + var values; + var i; + + params = paramsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + 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() { + params({ + 'penalty': value + }); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided an invalid `learningRate` property value', function test( t ) { + var params; + var values; + var i; + + params = paramsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + 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() { + params({ + 'learningRate': value + }); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided an invalid `lossFunction` property value', function test( t ) { + var params; + var values; + var i; + + params = paramsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + 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() { + params({ + 'lossFunction': value + }); + }; + } +}); + +tape( 'the function returns a constructor which does not require the `new` operator', function test( t ) { + var params; + var p; + + params = paramsFactory( 'float64' ); + + p = params(); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( {} ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( new ArrayBuffer( 1024 ) ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( new ArrayBuffer( 1024 ), 0 ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + p = params( new ArrayBuffer( 1024 ), 0, 1024 ); + t.strictEqual( p instanceof params, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width params object (dtype=float64)', function test( t ) { + var expected; + var Params; + var actual; + + Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + actual = new Params({ + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }); + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width params object (dtype=float32)', function test( t ) { + var expected; + var Params; + var actual; + + Params = paramsFactory( 'float32' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + actual = new Params({ + 'fitIntercept': true, + 'intercept': f32( 0.0 ), + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }); + + expected = { + 'fitIntercept': true, + 'intercept': f32( 0.0 ), + 'maxIter': 500, + 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), + 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width params object (no arguments)', function test( t ) { + var expected; + var Params; + var actual; + + Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + actual = new Params(); + + actual.fitIntercept = true; + actual.intercept = 0.0; + actual.maxIter = 500; + actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); + actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width params object (empty object)', function test( t ) { + var expected; + var Params; + var actual; + + Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + actual = new Params( {} ); + + actual.fitIntercept = true; + actual.intercept = 0.0; + actual.maxIter = 500; + actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); + actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Params, true, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width params object (ArrayBuffer)', function test( t ) { + var expected; + var Params; + var actual; + var buf; + + Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + buf = new ArrayBuffer( 1024 ); + actual = new Params( buf ); + + actual.fitIntercept = true; + actual.intercept = 0.0; + actual.maxIter = 500; + actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); + actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Params, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 0, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width params object (ArrayBuffer, byteOffset)', function test( t ) { + var expected; + var Params; + var actual; + var buf; + + Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + buf = new ArrayBuffer( 1024 ); + actual = new Params( buf, 16 ); + + actual.fitIntercept = true; + actual.intercept = 0.0; + actual.maxIter = 500; + actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); + actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Params, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width params object (ArrayBuffer, byteOffset, byteLength)', function test( t ) { + var expected; + var Params; + var actual; + var buf; + + Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + buf = new ArrayBuffer( 1024 ); + actual = new Params( buf, 16, 160 ); + + actual.fitIntercept = true; + actual.intercept = 0.0; + actual.maxIter = 500; + actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); + actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.penalty = 'l2'; + actual.learningRate = 'constant'; + actual.lossFunction = 'hinge'; + + expected = { + 'fitIntercept': true, + 'intercept': 0.0, + 'maxIter': 500, + 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), + 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'lossFunctionParams': new Float64Array( [ 0.0 ] ), + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge' + }; + + t.strictEqual( actual instanceof Params, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, '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( actual.penalty, expected.penalty, 'returns expected value' ); + t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); + t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a method property', function test( t ) { + var Params; + var params; + + Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + params = new Params(); + + t.strictEqual( params.method, 'Stochastic Gradient Descent', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a `toString` method', function test( t ) { + var Params; + var params; + var actual; + + Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + params = new Params(); + + actual = params.toString(); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + + actual = params.toString({ + 'decision': false + }); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a `toJSON` method', function test( t ) { + var Params; + var params; + + Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + params = new Params(); + t.strictEqual( typeof params.toJSON, 'function', 'returns expected value' ); + t.strictEqual( typeof params.toJSON(), 'object', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a `toDataView` method', function test( t ) { + var Params; + var params; + + Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + + params = new Params(); + t.strictEqual( typeof params.toDataView, 'function', 'returns expected value' ); + t.strictEqual( isDataView( params.toDataView() ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a constructor having a `name` property', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( typeof Params.name, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having an `alignment` property', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( typeof Params.alignment, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `byteLength` property', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( typeof Params.byteLength, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `fields` property', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( isStringArray( Params.fields ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `layout` property', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( typeof Params.layout, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `bufferOf` method', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( typeof Params.bufferOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `byteLengthOf` method', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( typeof Params.byteLengthOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `byteOffsetOf` method', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( typeof Params.byteOffsetOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `descriptionOf` method', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( typeof Params.descriptionOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having an `isStruct` method', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( typeof Params.isStruct, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `viewOf` method', function test( t ) { + var Params = paramsFactory( 'float64' ); + t.strictEqual( typeof Params, 'function', 'returns expected value' ); + t.strictEqual( typeof Params.viewOf, 'function', 'returns expected value' ); + t.end(); +}); From 985590033e02739f09d92c5283b2ccde6d9d5848 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 6 Aug 2026 12:35:36 +0530 Subject: [PATCH 6/8] chore: update according to code review --- .../sgd/params/float32/docs/types/index.d.ts | 2 +- .../ml/base/sgd/params/float32/test/test.js | 2 +- .../sgd/params/float64/docs/types/index.d.ts | 2 +- .../ml/base/sgd/params/to-string/README.md | 12 ++-- .../params/to-string/benchmark/benchmark.js | 4 +- .../params/to-string/docs/types/index.d.ts | 6 +- .../sgd/params/to-string/docs/types/test.ts | 70 +++++++++---------- .../sgd/params/to-string/examples/index.js | 4 +- .../ml/base/sgd/params/to-string/lib/index.js | 4 +- .../ml/base/sgd/params/to-string/test/test.js | 28 ++++---- 10 files changed, 67 insertions(+), 67 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts index 51ab8ebb8f23..de1872f7b511 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts @@ -24,7 +24,7 @@ type Penalty = 'elasticnet' | 'l1' | 'l2' | 'none'; /** -* Learning Rate. +* Learning Rate Scheduler. */ type LearningRate = 'basic' | 'constant' | 'invscaling' | 'pegasos'; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js index 0a163b75ee42..00abeb2ca0b8 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js @@ -431,7 +431,7 @@ tape( 'the constructor returns an instance having a `toString` method', function t.strictEqual( typeof actual, 'string', 'returns expected value' ); actual = params.toString({ - 'decision': false + 'digits': 4 }); t.strictEqual( typeof actual, 'string', 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts index b172f9d9699a..8b4b107ff645 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts @@ -24,7 +24,7 @@ type Penalty = 'elasticnet' | 'l1' | 'l2' | 'none'; /** -* Learning Rate. +* Learning Rate Scheduler. */ type LearningRate = 'basic' | 'constant' | 'invscaling' | 'pegasos'; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md index 4e74c6e95e5c..a9ed6b2c8d93 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# res2str +# params2str > Serialize an SGD trainer params object as a formatted string. @@ -37,10 +37,10 @@ limitations under the License. ## Usage ```javascript -var res2str = require( '@stdlib/ml/base/sgd/params/to-string' ); +var params2str = require( '@stdlib/ml/base/sgd/params/to-string' ); ``` -#### res2str( params\[, options] ) +#### params2str( params\[, options] ) Serializes an SGD trainer params object as a formatted string. @@ -51,7 +51,7 @@ var params = new Float64Params(); // ... -var s = res2str( params ); +var s = params2str( params ); // returns ``` @@ -106,7 +106,7 @@ The function supports the following options: ```javascript var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); var Float64Array = require( '@stdlib/array/float64' ); -var res2str = require( '@stdlib/ml/base/sgd/params/to-string' ); +var params2str = require( '@stdlib/ml/base/sgd/params/to-string' ); var params = new Float64Params(); params.penalty = 'l2'; @@ -119,7 +119,7 @@ params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); params.lossFunctionParams = new Float64Array( [ 0.0 ] ); params.fitIntercept = true; -var s = res2str( params ); +var s = params2str( params ); console.log( s ); ``` diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/benchmark/benchmark.js index b1cfb9749a27..0588ea220c37 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/benchmark/benchmark.js @@ -25,7 +25,7 @@ var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); var Float32Params = require( '@stdlib/ml/base/sgd/params/float32' ); var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var pkg = require( './../package.json' ).name; -var res2str = require( './../lib' ); +var params2str = require( './../lib' ); // MAIN // @@ -42,7 +42,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = res2str( values[ i%values.length ] ); + v = params2str( values[ i%values.length ] ); if ( typeof v !== 'string' ) { b.fail( 'should return a string' ); } diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts index 2a9986bc0dd6..56c9bd0e860a 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts @@ -121,12 +121,12 @@ interface Options { * 'method': 'Stochastic Gradient Descent', * }; * -* var str = res2str( params ); +* var str = params2str( params ); * // returns */ -declare function res2str( params: Params, options?: Options ): string; +declare function params2str( params: Params, options?: Options ): string; // EXPORTS // -export = res2str; +export = params2str; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts index cd1db11cf7ff..31c5a3f09499 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts @@ -16,7 +16,7 @@ * limitations under the License. */ -import res2str = require( './index' ); +import params2str = require( './index' ); // TESTS // @@ -35,31 +35,31 @@ import res2str = require( './index' ); 'maxIter': 1000, 'method': 'Stochastic Gradient Descent' }; - res2str( params ); // $ExpectType string - res2str( params, {} ); // $ExpectType string + params2str( params ); // $ExpectType string + params2str( params, {} ); // $ExpectType string } // The compiler throws an error if provided first argument which is not a params object... { - res2str( '10' ); // $ExpectError - res2str( 10 ); // $ExpectError - res2str( true ); // $ExpectError - res2str( false ); // $ExpectError - res2str( null ); // $ExpectError - res2str( undefined ); // $ExpectError - res2str( [] ); // $ExpectError - res2str( {} ); // $ExpectError - res2str( ( x: number ): number => x ); // $ExpectError + params2str( '10' ); // $ExpectError + params2str( 10 ); // $ExpectError + params2str( true ); // $ExpectError + params2str( false ); // $ExpectError + params2str( null ); // $ExpectError + params2str( undefined ); // $ExpectError + params2str( [] ); // $ExpectError + params2str( {} ); // $ExpectError + params2str( ( x: number ): number => x ); // $ExpectError - res2str( '10', {} ); // $ExpectError - res2str( 10, {} ); // $ExpectError - res2str( true, {} ); // $ExpectError - res2str( false, {} ); // $ExpectError - res2str( null, {} ); // $ExpectError - res2str( undefined, {} ); // $ExpectError - res2str( [], {} ); // $ExpectError - res2str( {}, {} ); // $ExpectError - res2str( ( x: number ): number => x, {} ); // $ExpectError + params2str( '10', {} ); // $ExpectError + params2str( 10, {} ); // $ExpectError + params2str( true, {} ); // $ExpectError + params2str( false, {} ); // $ExpectError + params2str( null, {} ); // $ExpectError + params2str( undefined, {} ); // $ExpectError + params2str( [], {} ); // $ExpectError + params2str( {}, {} ); // $ExpectError + params2str( ( x: number ): number => x, {} ); // $ExpectError } // The compiler throws an error if provided a second argument which is not an object... @@ -77,13 +77,13 @@ import res2str = require( './index' ); 'method': 'Stochastic Gradient Descent' }; - res2str( params, '10' ); // $ExpectError - res2str( params, 10 ); // $ExpectError - res2str( params, true ); // $ExpectError - res2str( params, false ); // $ExpectError - res2str( params, null ); // $ExpectError - res2str( params, [] ); // $ExpectError - res2str( params, ( x: number ): number => x ); // $ExpectError + params2str( params, '10' ); // $ExpectError + params2str( params, 10 ); // $ExpectError + params2str( params, true ); // $ExpectError + params2str( params, false ); // $ExpectError + params2str( params, null ); // $ExpectError + params2str( params, [] ); // $ExpectError + params2str( params, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if provided a `digits` option which is not a number... @@ -101,11 +101,11 @@ import res2str = require( './index' ); 'method': 'Stochastic Gradient Descent' }; - res2str( params, { 'digits': '10' } ); // $ExpectError - res2str( params, { 'digits': true } ); // $ExpectError - res2str( params, { 'digits': false } ); // $ExpectError - res2str( params, { 'digits': null } ); // $ExpectError - res2str( params, { 'digits': [] } ); // $ExpectError - res2str( params, { 'digits': {} } ); // $ExpectError - res2str( params, { 'digits': ( x: number ): number => x } ); // $ExpectError + params2str( params, { 'digits': '10' } ); // $ExpectError + params2str( params, { 'digits': true } ); // $ExpectError + params2str( params, { 'digits': false } ); // $ExpectError + params2str( params, { 'digits': null } ); // $ExpectError + params2str( params, { 'digits': [] } ); // $ExpectError + params2str( params, { 'digits': {} } ); // $ExpectError + params2str( params, { 'digits': ( x: number ): number => x } ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js index 889125483846..65699b6d122b 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js @@ -20,7 +20,7 @@ var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); var Float64Array = require( '@stdlib/array/float64' ); -var res2str = require( './../lib' ); +var params2str = require( './../lib' ); var params = new Float64Params(); params.penalty = 'l2'; @@ -33,5 +33,5 @@ params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); params.lossFunctionParams = new Float64Array( [ 0.0 ] ); params.fitIntercept = true; -var s = res2str( params ); +var s = params2str( params ); console.log( s ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js index 22a23216a445..2ba5889d9344 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js @@ -25,7 +25,7 @@ * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var res2str = require( '@stdlib/ml/base/sgd/params/to-string' ); +* var params2str = require( '@stdlib/ml/base/sgd/params/to-string' ); * * var params = { * 'penalty': 'l2', @@ -40,7 +40,7 @@ * 'method': 'Stochastic Gradient Descent', * }; * -* var str = res2str( params ); +* var str = params2str( params ); * // returns */ diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js index 40e6a9b3d00a..51c280b56f49 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js @@ -27,14 +27,14 @@ var Float64Params = require( '@stdlib/ml/base/sgd/params/float64' ); 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 res2str = require( './../lib' ); +var params2str = require( './../lib' ); // TESTS // tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof res2str, 'function', 'main export is a function' ); + t.strictEqual( typeof params2str, 'function', 'main export is a function' ); t.end(); }); @@ -63,7 +63,7 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - res2str( params, value ); + params2str( params, value ); }; } }); @@ -94,7 +94,7 @@ tape( 'the function throws an error if provided a `digits` option which is not a function badValue( value ) { return function badValue() { - res2str( params, { + params2str( params, { 'digits': value }); }; @@ -121,7 +121,7 @@ tape( 'the function serializes a params object to a string (l1,l2 penalty)', fun value.lossFunctionParams = new Float64Array( [ 0.0 ] ); value.fitIntercept = true; - actual = res2str( value ); + actual = params2str( value ); t.strictEqual( isString( actual ), true, 'returns expected value' ); expected = [ @@ -165,7 +165,7 @@ tape( 'the function serializes a params object to a string (elasticnet penalty)' value.lossFunctionParams = new Float64Array( [ 0.0 ] ); value.fitIntercept = true; - actual = res2str( value ); + actual = params2str( value ); t.strictEqual( isString( actual ), true, 'returns expected value' ); expected = [ @@ -208,7 +208,7 @@ tape( 'the function serializes a params object to a string (no penalty)', functi value.lossFunctionParams = new Float64Array( [ 0.0 ] ); value.fitIntercept = true; - actual = res2str( value ); + actual = params2str( value ); t.strictEqual( isString( actual ), true, 'returns expected value' ); expected = [ @@ -247,7 +247,7 @@ tape( 'the function serializes a params object to a string (basic learning rate) value.lossFunctionParams = new Float64Array( [ 0.0 ] ); value.fitIntercept = true; - actual = res2str( value ); + actual = params2str( value ); t.strictEqual( isString( actual ), true, 'returns expected value' ); expected = [ @@ -288,7 +288,7 @@ tape( 'the function serializes a params object to a string (constant learning ra value.lossFunctionParams = new Float64Array( [ 0.0 ] ); value.fitIntercept = true; - actual = res2str( value ); + actual = params2str( value ); t.strictEqual( isString( actual ), true, 'returns expected value' ); expected = [ @@ -332,7 +332,7 @@ tape( 'the function serializes a params object to a string (invscaling learning value.lossFunctionParams = new Float64Array( [ 0.0 ] ); value.fitIntercept = true; - actual = res2str( value ); + actual = params2str( value ); t.strictEqual( isString( actual ), true, 'returns expected value' ); expected = [ @@ -373,7 +373,7 @@ tape( 'the function serializes a params object to a string (pegasos learning rat value.lossFunctionParams = new Float64Array( [ 0.0 ] ); value.fitIntercept = true; - actual = res2str( value ); + actual = params2str( value ); t.strictEqual( isString( actual ), true, 'returns expected value' ); expected = [ @@ -416,7 +416,7 @@ tape( 'the function serializes a params object to a string (epsilon insensitive, value.lossFunctionParams = new Float64Array( [ epsilon ] ); value.fitIntercept = true; - actual = res2str( value ); + actual = params2str( value ); t.strictEqual( isString( actual ), true, 'returns expected value' ); expected = [ @@ -459,7 +459,7 @@ tape( 'the function serializes a params object to a string (no intercept)', func value.lossFunctionParams = new Float64Array( [ 0.0 ] ); value.fitIntercept = false; - actual = res2str( value ); + actual = params2str( value ); t.strictEqual( isString( actual ), true, 'returns expected value' ); expected = [ @@ -500,7 +500,7 @@ tape( 'the function supports specifying the number of displayed digits (digits=2 value.lossFunctionParams = new Float64Array( [ 0.0 ] ); value.fitIntercept = true; - actual = res2str( value ); + actual = params2str( value ); t.strictEqual( isString( actual ), true, 'returns expected value' ); expected = [ From 653640a7ea237df0a61518ed4d8286a19e355b3d Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Fri, 7 Aug 2026 10:22:54 +0530 Subject: [PATCH 7/8] refactor: update struct member ordering --- .../ml/base/sgd/params/factory/README.md | 16 +-- .../sgd/params/factory/docs/types/index.d.ts | 72 ++++++------ .../sgd/params/factory/docs/types/test.ts | 36 +++--- .../base/sgd/params/factory/examples/index.js | 22 ++-- .../ml/base/sgd/params/factory/lib/index.js | 10 +- .../ml/base/sgd/params/factory/lib/main.js | 9 +- .../ml/base/sgd/params/factory/test/test.js | 108 +++++++++--------- .../ml/base/sgd/params/float32/README.md | 4 +- .../sgd/params/float32/docs/types/index.d.ts | 84 +++++++------- .../sgd/params/float32/docs/types/test.ts | 21 ++-- .../base/sgd/params/float32/examples/index.js | 8 +- .../stdlib/ml/base/sgd/params/float32.h | 26 ++--- .../ml/base/sgd/params/float32/lib/index.js | 10 +- .../ml/base/sgd/params/float32/lib/main.js | 10 +- .../ml/base/sgd/params/float32/test/test.js | 86 +++++++------- .../ml/base/sgd/params/float64/README.md | 4 +- .../sgd/params/float64/docs/types/index.d.ts | 2 +- .../stdlib/ml/base/sgd/params/float64.h | 2 +- 18 files changed, 264 insertions(+), 266 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/README.md index 86605644d766..822d19e8324b 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/README.md @@ -87,15 +87,15 @@ var paramsFactory = require( '@stdlib/ml/base/sgd/params/factory' ); var Params = paramsFactory( 'float64' ); var params = new Params({ - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }); var str = params.toString({ @@ -105,15 +105,15 @@ console.log( str ); Params = paramsFactory( 'float32' ); params = new Params({ - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }); str = params.toString({ diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/index.d.ts index 1009fb32aedb..3f24f5f0b8d7 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/index.d.ts @@ -38,49 +38,49 @@ type LossFunction = 'epsilon-insensitive' | 'hinge' | 'huber' | 'log' | 'modifie */ interface Params { /** - * Regularization function to be used. + * Parameters specific to the regularization function being used. */ - penalty?: Penalty; + 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?: LearningRate; + 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?: LossFunction; + maxIter?: number; /** - * Parameters specific to the loss function being used. + * Regularization function to be used. */ - lossFunctionParams?: T; + penalty?: Penalty; /** - * Boolean indicating whether to include intercept. + * Learning rate scheduler to be used. */ - fitIntercept?: boolean; + learningRate?: LearningRate; /** - * Initial intercept value. + * Loss function to be used. */ - intercept?: number; + lossFunction?: LossFunction; /** - * Maximum number of iterations to run. + * Boolean indicating whether to include intercept. */ - maxIter?: number; + fitIntercept?: boolean; } /** @@ -108,49 +108,49 @@ declare class ParamsStruct { constructor( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ); /** - * Regularization function to be used. + * Parameters specific to the regularization function being used. */ - penalty: Penalty; + 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: LearningRate; + 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: LossFunction; + maxIter: number; /** - * Parameters specific to the loss function being used. + * Regularization function to be used. */ - lossFunctionParams: T; + penalty: Penalty; /** - * Boolean indicating whether to include intercept. + * Learning rate scheduler to be used. */ - fitIntercept: boolean; + learningRate: LearningRate; /** - * Initial intercept value. + * Loss function to be used. */ - intercept: number; + lossFunction: LossFunction; /** - * Maximum number of iterations to run. + * Boolean indicating whether to include intercept. */ - maxIter: number; + fitIntercept: boolean; /** * Serializes a params object as a formatted string. diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/test.ts index 7ce1624e5f18..f48ac4129b1e 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/docs/types/test.ts @@ -73,31 +73,31 @@ import paramsFactory = require( './index' ); const r = new Params( {} ); // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.penalty; // $ExpectType Penalty + r.penaltyParams; // $ExpectType Float64Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.penaltyParams; // $ExpectType Float64Array + r.learningRateParams; // $ExpectType Float64Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.learningRate; // $ExpectType LearningRate + r.lossFunctionParams; // $ExpectType Float64Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.learningRateParams; // $ExpectType Float64Array + r.intercept; // $ExpectType number // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.lossFunction; // $ExpectType LossFunction + r.maxIter; // $ExpectType number // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.lossFunctionParams; // $ExpectType Float64Array + r.penalty; // $ExpectType Penalty // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.fitIntercept; // $ExpectType boolean + r.learningRate; // $ExpectType LearningRate // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.intercept; // $ExpectType number + r.lossFunction; // $ExpectType LossFunction // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.maxIter; // $ExpectType number + r.fitIntercept; // $ExpectType boolean } // The params object has the expected properties (float32)... @@ -106,31 +106,31 @@ import paramsFactory = require( './index' ); const r = new Params( {} ); // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.penalty; // $ExpectType Penalty + r.penaltyParams; // $ExpectType Float32Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.penaltyParams; // $ExpectType Float32Array + r.learningRateParams; // $ExpectType Float32Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.learningRate; // $ExpectType LearningRate + r.lossFunctionParams; // $ExpectType Float32Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.learningRateParams; // $ExpectType Float32Array + r.intercept; // $ExpectType number // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.lossFunction; // $ExpectType LossFunction + r.maxIter; // $ExpectType number // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.lossFunctionParams; // $ExpectType Float32Array + r.penalty; // $ExpectType Penalty // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.fitIntercept; // $ExpectType boolean + r.learningRate; // $ExpectType LearningRate // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.intercept; // $ExpectType number + r.lossFunction; // $ExpectType LossFunction // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.maxIter; // $ExpectType number + r.fitIntercept; // $ExpectType boolean } // The compiler throws an error if the constructor is provided a first argument which is not an ArrayBuffer or object... diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/examples/index.js index 5e0b00811c61..1ee9f41ff884 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/examples/index.js @@ -24,15 +24,15 @@ var paramsFactory = require( './../lib' ); var Params = paramsFactory( 'float64' ); var params = new Params({ - 'penalty': 'l2', 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), - 'learningRate': 'constant', 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - 'lossFunction': 'hinge', 'lossFunctionParams': new Float64Array( [ 0.0 ] ), - 'fitIntercept': true, 'intercept': 0.0, - 'maxIter': 500 + 'maxIter': 500, + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge', + 'fitIntercept': true }); var str = params.toString({ @@ -42,15 +42,15 @@ console.log( str ); Params = paramsFactory( 'float32' ); params = new Params({ - 'penalty': 'l2', 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), - 'learningRate': 'constant', 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), - 'lossFunction': 'hinge', - 'lossFunctionParams': new Float64Array( [ 0.0 ] ), - 'fitIntercept': true, + 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'intercept': 0.0, - 'maxIter': 500 + 'maxIter': 500, + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge', + 'fitIntercept': true }); str = params.toString({ diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/index.js index 9c70032be4fc..8438ca49f683 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/index.js @@ -32,14 +32,14 @@ * var params = new Params(); * // returns * -* params.penalty = 'l2'; -* params.learningRate = 'constant'; -* params.lossFunction = 'hinge'; -* params.intercept = 0.0; -* params.maxIter = 500; * params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); * params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); * params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; * params.fitIntercept = true; * * var str = params.toString(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/main.js index 2e5d3a8f9447..3df8ef9a8231 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/lib/main.js @@ -72,13 +72,14 @@ var isDataType = contains( DTYPES ); * var params = new Params(); * // returns * +* params.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); +* params.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); +* params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +* params.intercept = 0.0; +* params.maxIter = 500; * params.penalty = 'l2'; * params.learningRate = 'constant'; * params.lossFunction = 'hinge'; -* params.intercept = 0.0; -* params.maxIter = 500; -* params.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); -* params.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); * params.fitIntercept = true; * * var str = params.toString(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/test/test.js index 3740aa6a643d..56417815abe0 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/factory/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/factory/test/test.js @@ -297,27 +297,27 @@ tape( 'the function returns a constructor for creating a fixed-width params obje t.strictEqual( typeof Params, 'function', 'returns expected value' ); actual = new Params({ - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }); expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Params, true, 'returns expected value' ); @@ -342,27 +342,27 @@ tape( 'the function returns a constructor for creating a fixed-width params obje t.strictEqual( typeof Params, 'function', 'returns expected value' ); actual = new Params({ - 'fitIntercept': true, - 'intercept': f32( 0.0 ), - 'maxIter': 500, 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'intercept': f32( 0.0 ), + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }); expected = { - 'fitIntercept': true, - 'intercept': f32( 0.0 ), - 'maxIter': 500, 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'intercept': f32( 0.0 ), + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Params, true, 'returns expected value' ); @@ -372,9 +372,9 @@ tape( 'the function returns a constructor for creating a fixed-width params obje t.strictEqual( actual.penalty, expected.penalty, 'returns expected value' ); t.strictEqual( actual.lossFunction, expected.lossFunction, 'returns expected value' ); t.strictEqual( actual.learningRate, expected.learningRate, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.penaltyParams, expected.penaltyParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.lossFunctionParams, expected.lossFunctionParams ), true, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.learningRateParams, expected.learningRateParams ), true, 'returns expected value' ); t.end(); }); @@ -388,26 +388,26 @@ tape( 'the function returns a constructor for creating a fixed-width params obje actual = new Params(); - actual.fitIntercept = true; - actual.intercept = 0.0; - actual.maxIter = 500; actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.intercept = 0.0; + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Params, true, 'returns expected value' ); @@ -433,26 +433,26 @@ tape( 'the function returns a constructor for creating a fixed-width params obje actual = new Params( {} ); - actual.fitIntercept = true; - actual.intercept = 0.0; - actual.maxIter = 500; actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.intercept = 0.0; + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Params, true, 'returns expected value' ); @@ -480,26 +480,26 @@ tape( 'the function returns a constructor for creating a fixed-width params obje buf = new ArrayBuffer( 1024 ); actual = new Params( buf ); - actual.fitIntercept = true; - actual.intercept = 0.0; - actual.maxIter = 500; actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.intercept = 0.0; + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Params, true, 'returns expected value' ); @@ -529,26 +529,26 @@ tape( 'the function returns a constructor for creating a fixed-width params obje buf = new ArrayBuffer( 1024 ); actual = new Params( buf, 16 ); - actual.fitIntercept = true; - actual.intercept = 0.0; - actual.maxIter = 500; actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.intercept = 0.0; + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Params, true, 'returns expected value' ); @@ -578,26 +578,26 @@ tape( 'the function returns a constructor for creating a fixed-width params obje buf = new ArrayBuffer( 1024 ); actual = new Params( buf, 16, 160 ); - actual.fitIntercept = true; - actual.intercept = 0.0; - actual.maxIter = 500; actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.intercept = 0.0; + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Params, true, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md index c14309e83932..bf03bd686a75 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md @@ -352,7 +352,7 @@ console.log( str ); #include "stdlib/ml/base/sgd/params/float32.h" ``` -#### stdlib_ml_sgd_params_float32_params +#### stdlib_ml_sgd_float32_params Structure for holding single-precision floating-point test params. @@ -362,7 +362,7 @@ Structure for holding single-precision floating-point test params. #include #include -struct stdlib_ml_sgd_params_float32_params { +struct stdlib_ml_sgd_float32_params { // Regularization function to be used: int8_t penalty; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts index de1872f7b511..2fb4f74855f0 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/index.d.ts @@ -38,49 +38,49 @@ type LossFunction = 'epsilon-insensitive' | 'hinge' | 'huber' | 'log' | 'modifie */ interface Params { /** - * Regularization function to be used. + * Parameters specific to the regularization function being used. */ - penalty?: Penalty; + penaltyParams?: Float32Array; /** - * Parameters specific to the regularization function being used. + * Parameters specific to the learning rate scheduler being used. */ - penaltyParams?: Float64Array; + learningRateParams?: Float32Array; /** - * Learning rate scheduler to be used. + * Parameters specific to the loss function being used. */ - learningRate?: LearningRate; + lossFunctionParams?: Float32Array; /** - * Parameters specific to the learning rate scheduler being used. + * Initial intercept value. */ - learningRateParams?: Float64Array; + intercept?: number; /** - * Loss function to be used. + * Maximum number of iterations to run. */ - lossFunction?: LossFunction; + maxIter?: number; /** - * Parameters specific to the loss function being used. + * Regularization function to be used. */ - lossFunctionParams?: Float64Array; + penalty?: Penalty; /** - * Boolean indicating whether to include intercept. + * Learning rate scheduler to be used. */ - fitIntercept?: boolean; + learningRate?: LearningRate; /** - * Initial intercept value. + * Loss function to be used. */ - intercept?: number; + lossFunction?: LossFunction; /** - * Maximum number of iterations to run. + * Boolean indicating whether to include intercept. */ - maxIter?: number; + fitIntercept?: boolean; } /** @@ -108,52 +108,52 @@ declare class ParamsStruct { constructor( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ); /** - * Regularization function to be used. + * Parameters specific to the regularization function being used. */ - penalty: Penalty; + penaltyParams: Float32Array; /** - * Parameters specific to the regularization function being used. + * Parameters specific to the learning rate scheduler being used. */ - penaltyParams: Float64Array; + learningRateParams: Float32Array; /** - * Learning rate scheduler to be used. + * Parameters specific to the loss function being used. */ - learningRate: LearningRate; + lossFunctionParams: Float32Array; /** - * Parameters specific to the learning rate scheduler being used. + * Initial intercept value. */ - learningRateParams: Float64Array; + intercept: number; /** - * Loss function to be used. + * Maximum number of iterations to run. */ - lossFunction: LossFunction; + maxIter: number; /** - * Parameters specific to the loss function being used. + * Regularization function to be used. */ - lossFunctionParams: Float64Array; + penalty: Penalty; /** - * Boolean indicating whether to include intercept. + * Learning rate scheduler to be used. */ - fitIntercept: boolean; + learningRate: LearningRate; /** - * Initial intercept value. + * Loss function to be used. */ - intercept: number; + lossFunction: LossFunction; /** - * Maximum number of iterations to run. + * Boolean indicating whether to include intercept. */ - maxIter: number; + fitIntercept: boolean; /** - * Test method. + * Algorithm name. */ method: string; @@ -219,14 +219,14 @@ interface ParamsConstructor { * var params = new Params(); * // returns * -* params.penalty = 'l2'; -* params.learningRate = 'constant'; -* params.lossFunction = 'hinge'; -* params.intercept = 0.0; -* params.maxIter = 500; * params.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); * params.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); * params.lossFunctionParams = new Float32Array( [ 0.0 ] ); +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; * params.fitIntercept = true; * * var str = params.toString(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/test.ts index 7dc5fcc95f0a..2747f02040ed 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/docs/types/test.ts @@ -56,34 +56,31 @@ import Params = require( './index' ); const r = new Params( {} ); // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.penalty; // $ExpectType Penalty - - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.penaltyParams; // $ExpectType Float64Array + r.penaltyParams; // $ExpectType Float32Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.learningRate; // $ExpectType LearningRate + r.learningRateParams; // $ExpectType Float32Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.learningRateParams; // $ExpectType Float64Array + r.lossFunctionParams; // $ExpectType Float32Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.lossFunction; // $ExpectType LossFunction + r.intercept; // $ExpectType number // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.lossFunctionParams; // $ExpectType Float64Array + r.maxIter; // $ExpectType number // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.fitIntercept; // $ExpectType boolean + r.penalty; // $ExpectType Penalty // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.intercept; // $ExpectType number + r.learningRate; // $ExpectType LearningRate // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.maxIter; // $ExpectType number + r.lossFunction; // $ExpectType LossFunction // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.method; // $ExpectType string + r.fitIntercept; // $ExpectType boolean } // The compiler throws an error if the constructor is provided a first argument which is not an ArrayBuffer or object... diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/examples/index.js index 924a666940a5..cc0c7487f9d1 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/examples/index.js @@ -22,15 +22,15 @@ var Float32Array = require( '@stdlib/array/float32' ); var Params = require( './../lib' ); var params = new Params({ - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }); var str = params.toString(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/include/stdlib/ml/base/sgd/params/float32.h b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/include/stdlib/ml/base/sgd/params/float32.h index 0abde6985947..0884e49f3447 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/include/stdlib/ml/base/sgd/params/float32.h +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/include/stdlib/ml/base/sgd/params/float32.h @@ -25,33 +25,33 @@ /** * Struct for storing test params. */ -struct stdlib_ml_sgd_params_float32_params { - // Regularization function to be used: - int8_t penalty; - +struct stdlib_ml_sgd_float32_params { // Parameters specific to the regularization function being used: float penaltyParams[ 2 ]; - // Learning rate scheduler to be used: - int8_t learningRate; - // Parameters specific to the learning rate scheduler being used: float learningRateParams[ 2 ]; - // Loss function to be used: - int8_t lossFunction; - // Parameters specific to the loss function being used: float lossFunctionParams[ 1 ]; - // Boolean indicating whether to include intercept: - bool fitIntercept; - // Initial intercept value: float intercept; // Maximum number of iterations to run: int32_t maxIter; + + // Regularization function to be used: + int8_t penalty; + + // Learning rate scheduler to be used: + int8_t learningRate; + + // Loss function to be used: + int8_t lossFunction; + + // Boolean indicating whether to include intercept: + bool fitIntercept; }; #endif // !STDLIB_ML_BASE_SGD_PARAMS_FLOAT32_H diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/index.js index d9d7c20abdce..00024cce024c 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/index.js @@ -30,14 +30,14 @@ * var params = new Params(); * // returns * -* params.penalty = 'l2'; -* params.learningRate = 'constant'; -* params.lossFunction = 'hinge'; -* params.intercept = 0.0; -* params.maxIter = 500; * params.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); * params.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); * params.lossFunctionParams = new Float32Array( [ 0.0 ] ); +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; * params.fitIntercept = true; * * var str = params.toString(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/main.js index 7dacdf594e13..75e643d84fd9 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/lib/main.js @@ -42,14 +42,14 @@ var factory = require( '@stdlib/ml/base/sgd/params/factory' ); * var params = new Params(); * // returns * -* params.penalty = 'l2'; -* params.learningRate = 'constant'; -* params.lossFunction = 'hinge'; -* params.intercept = 0.0; -* params.maxIter = 500; * params.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); * params.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); * params.lossFunctionParams = new Float32Array( [ 0.0 ] ); +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; * params.fitIntercept = true; * * var str = params.toString(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js index 00abeb2ca0b8..d52c9ca26e75 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/test/test.js @@ -161,27 +161,27 @@ tape( 'the function is a constructor for a fixed-width params object ', function var actual; actual = new Float32Params({ - 'fitIntercept': true, - 'intercept': f32( 0.0 ), - 'maxIter': 500, 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'intercept': f32( 0.0 ), + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }); expected = { - 'fitIntercept': true, - 'intercept': f32( 0.0 ), - 'maxIter': 500, 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'intercept': f32( 0.0 ), + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float32Params, true, 'returns expected value' ); @@ -203,26 +203,26 @@ tape( 'the function is a constructor for a fixed-width params object (no argumen actual = new Float32Params(); - actual.fitIntercept = true; - actual.intercept = f32( 0.0 ); - actual.maxIter = 500; actual.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float32Array( [ 0.0 ] ); actual.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); + actual.intercept = f32( 0.0 ); + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': f32( 0.0 ), - 'maxIter': 500, 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'intercept': f32( 0.0 ), + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float32Params, true, 'returns expected value' ); @@ -244,26 +244,26 @@ tape( 'the function is a constructor for a fixed-width params object (empty obje actual = new Float32Params( {} ); - actual.fitIntercept = true; - actual.intercept = f32( 0.0 ); - actual.maxIter = 500; actual.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float32Array( [ 0.0 ] ); actual.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); + actual.intercept = f32( 0.0 ); + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': f32( 0.0 ), - 'maxIter': 500, 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'intercept': f32( 0.0 ), + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float32Params, true, 'returns expected value' ); @@ -287,26 +287,26 @@ tape( 'the function is a constructor for a fixed-width params object (ArrayBuffe buf = new ArrayBuffer( 1024 ); actual = new Float32Params( buf ); - actual.fitIntercept = true; - actual.intercept = f32( 0.0 ); - actual.maxIter = 500; actual.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float32Array( [ 0.0 ] ); actual.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); + actual.intercept = f32( 0.0 ); + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': f32( 0.0 ), - 'maxIter': 500, 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'intercept': f32( 0.0 ), + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float32Params, true, 'returns expected value' ); @@ -332,26 +332,26 @@ tape( 'the function is a constructor for a fixed-width params object (ArrayBuffe buf = new ArrayBuffer( 1024 ); actual = new Float32Params( buf, 16 ); - actual.fitIntercept = true; - actual.intercept = f32( 0.0 ); - actual.maxIter = 500; actual.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float32Array( [ 0.0 ] ); actual.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); + actual.intercept = f32( 0.0 ); + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': f32( 0.0 ), - 'maxIter': 500, 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'intercept': f32( 0.0 ), + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float32Params, true, 'returns expected value' ); @@ -377,26 +377,26 @@ tape( 'the function is a constructor for a fixed-width params object (ArrayBuffe buf = new ArrayBuffer( 1024 ); actual = new Float32Params( buf, 16, 160 ); - actual.fitIntercept = true; - actual.intercept = f32( 0.0 ); - actual.maxIter = 500; actual.penaltyParams = new Float32Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float32Array( [ 0.0 ] ); actual.learningRateParams = new Float32Array( [ 0.01, 0.0 ] ); + actual.intercept = f32( 0.0 ); + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': f32( 0.0 ), - 'maxIter': 500, 'penaltyParams': new Float32Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float32Array( [ 0.0 ] ), 'learningRateParams': new Float32Array( [ 0.01, 0.0 ] ), + 'intercept': f32( 0.0 ), + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float32Params, true, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md index e014941fdb80..7b54c9648a11 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md @@ -352,7 +352,7 @@ console.log( str ); #include "stdlib/ml/base/sgd/params/float64.h" ``` -#### stdlib_ml_sgd_params_float64_params +#### stdlib_ml_sgd_float64_params Structure for holding double-precision floating-point SGD params. @@ -362,7 +362,7 @@ Structure for holding double-precision floating-point SGD params. #include #include -struct stdlib_ml_sgd_params_float64_params { +struct stdlib_ml_sgd_float64_params { // Regularization function to be used: int8_t penalty; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts index 8b4b107ff645..1578956030a5 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts @@ -153,7 +153,7 @@ declare class ParamsStruct { maxIter: number; /** - * Test method. + * Algorithm name. */ method: string; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h index 15ad6cbdf458..830826fd0fb9 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h @@ -25,7 +25,7 @@ /** * Struct for storing SGD parameters. */ -struct stdlib_ml_sgd_params_float64_params { +struct stdlib_ml_sgd_float64_params { // Regularization function to be used: int8_t penalty; From 80522c93b5e2b6a025d5db72b9304f482eb3c65b Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Fri, 7 Aug 2026 12:40:13 +0530 Subject: [PATCH 8/8] refactor: update struct member ordering --- .../ml/base/sgd/params/float32/README.md | 24 ++--- .../ml/base/sgd/params/float64/README.md | 32 +++--- .../sgd/params/float64/docs/types/index.d.ts | 82 +++++++------- .../sgd/params/float64/docs/types/test.ts | 20 ++-- .../base/sgd/params/float64/examples/index.js | 8 +- .../stdlib/ml/base/sgd/params/float64.h | 24 ++--- .../ml/base/sgd/params/float64/lib/index.js | 10 +- .../ml/base/sgd/params/float64/lib/main.js | 10 +- .../ml/base/sgd/params/float64/test/test.js | 86 +++++++-------- .../ml/base/sgd/params/to-json/README.md | 10 +- .../ml/base/sgd/params/to-json/docs/repl.txt | 8 +- .../sgd/params/to-json/docs/types/index.d.ts | 46 ++++---- .../sgd/params/to-json/docs/types/test.ts | 8 +- .../base/sgd/params/to-json/examples/index.js | 10 +- .../ml/base/sgd/params/to-json/lib/index.js | 8 +- .../ml/base/sgd/params/to-json/lib/main.js | 8 +- .../ml/base/sgd/params/to-json/test/test.js | 22 ++-- .../ml/base/sgd/params/to-string/README.md | 10 +- .../base/sgd/params/to-string/docs/repl.txt | 8 +- .../params/to-string/docs/types/index.d.ts | 44 ++++---- .../sgd/params/to-string/docs/types/test.ts | 24 ++--- .../sgd/params/to-string/examples/index.js | 10 +- .../ml/base/sgd/params/to-string/lib/index.js | 8 +- .../ml/base/sgd/params/to-string/lib/main.js | 8 +- .../ml/base/sgd/params/to-string/test/test.js | 100 +++++++++--------- 25 files changed, 314 insertions(+), 314 deletions(-) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md index bf03bd686a75..840ad39a5e77 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float32/README.md @@ -363,32 +363,32 @@ Structure for holding single-precision floating-point test params. #include struct stdlib_ml_sgd_float32_params { - // Regularization function to be used: - int8_t penalty; - // Parameters specific to the regularization function being used: float penaltyParams[ 2 ]; - // Learning rate scheduler to be used: - int8_t learningRate; - // Parameters specific to the learning rate scheduler being used: float learningRateParams[ 2 ]; - // Loss function to be used: - int8_t lossFunction; - // Parameters specific to the loss function being used: float lossFunctionParams[ 1 ]; - // Boolean indicating whether to include intercept: - bool fitIntercept; - // Initial intercept value: float intercept; // Maximum number of iterations to run: int32_t maxIter; + + // Regularization function to be used: + int8_t penalty; + + // Learning rate scheduler to be used: + int8_t learningRate; + + // Loss function to be used: + int8_t lossFunction; + + // Boolean indicating whether to include intercept: + bool fitIntercept; }; ``` diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md index 7b54c9648a11..d9902191ac45 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/README.md @@ -307,15 +307,15 @@ var Float64Array = require( '@stdlib/array/float64' ); var Params = require( '@stdlib/ml/base/sgd/params/float64' ); var params = new Params({ - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true, }); var str = params.toString(); @@ -363,32 +363,32 @@ Structure for holding double-precision floating-point SGD params. #include struct stdlib_ml_sgd_float64_params { - // Regularization function to be used: - int8_t penalty; - // Parameters specific to the regularization function being used: double penaltyParams[ 2 ]; - // Learning rate scheduler to be used: - int8_t learningRate; - // Parameters specific to the learning rate scheduler being used: double learningRateParams[ 2 ]; - // Loss function to be used: - int8_t lossFunction; - // Parameters specific to the loss function being used: double lossFunctionParams[ 1 ]; - // Boolean indicating whether to include intercept: - bool fitIntercept; - // Initial intercept value: double intercept; // Maximum number of iterations to run: int32_t maxIter; + + // Regularization function to be used: + int8_t penalty; + + // Learning rate scheduler to be used: + int8_t learningRate; + + // Loss function to be used: + int8_t lossFunction; + + // Boolean indicating whether to include intercept: + bool fitIntercept; }; ``` diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts index 1578956030a5..c20bd2486397 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/index.d.ts @@ -38,49 +38,49 @@ type LossFunction = 'epsilon-insensitive' | 'hinge' | 'huber' | 'log' | 'modifie */ interface Params { /** - * Regularization function to be used. + * Parameters specific to the regularization function being used. */ - penalty?: Penalty; + penaltyParams?: Float64Array; /** - * Parameters specific to the regularization function being used. + * Parameters specific to the learning rate scheduler being used. */ - penaltyParams?: Float64Array; + learningRateParams?: Float64Array; /** - * Learning rate scheduler to be used. + * Parameters specific to the loss function being used. */ - learningRate?: LearningRate; + lossFunctionParams?: Float64Array; /** - * Parameters specific to the learning rate scheduler being used. + * Initial intercept value. */ - learningRateParams?: Float64Array; + intercept?: number; /** - * Loss function to be used. + * Maximum number of iterations to run. */ - lossFunction?: LossFunction; + maxIter?: number; /** - * Parameters specific to the loss function being used. + * Regularization function to be used. */ - lossFunctionParams?: Float64Array; + penalty?: Penalty; /** - * Boolean indicating whether to include intercept. + * Learning rate scheduler to be used. */ - fitIntercept?: boolean; + learningRate?: LearningRate; /** - * Initial intercept value. + * Loss function to be used. */ - intercept?: number; + lossFunction?: LossFunction; /** - * Maximum number of iterations to run. + * Boolean indicating whether to include intercept. */ - maxIter?: number; + fitIntercept?: boolean; } /** @@ -108,49 +108,49 @@ declare class ParamsStruct { constructor( arg?: ArrayBuffer | Params, byteOffset?: number, byteLength?: number ); /** - * Regularization function to be used. + * Parameters specific to the regularization function being used. */ - penalty: Penalty; + penaltyParams: Float64Array; /** - * Parameters specific to the regularization function being used. + * Parameters specific to the learning rate scheduler being used. */ - penaltyParams: Float64Array; + learningRateParams: Float64Array; /** - * Learning rate scheduler to be used. + * Parameters specific to the loss function being used. */ - learningRate: LearningRate; + lossFunctionParams: Float64Array; /** - * Parameters specific to the learning rate scheduler being used. + * Initial intercept value. */ - learningRateParams: Float64Array; + intercept: number; /** - * Loss function to be used. + * Maximum number of iterations to run. */ - lossFunction: LossFunction; + maxIter: number; /** - * Parameters specific to the loss function being used. + * Regularization function to be used. */ - lossFunctionParams: Float64Array; + penalty: Penalty; /** - * Boolean indicating whether to include intercept. + * Learning rate scheduler to be used. */ - fitIntercept: boolean; + learningRate: LearningRate; /** - * Initial intercept value. + * Loss function to be used. */ - intercept: number; + lossFunction: LossFunction; /** - * Maximum number of iterations to run. + * Boolean indicating whether to include intercept. */ - maxIter: number; + fitIntercept: boolean; /** * Algorithm name. @@ -219,14 +219,14 @@ interface ParamsConstructor { * var params = new Params(); * // returns * -* params.penalty = 'l2'; -* params.learningRate = 'constant'; -* params.lossFunction = 'hinge'; -* params.intercept = 0.0; -* params.maxIter = 500; * params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); * params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); * params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; * params.fitIntercept = true; * * var str = params.toString(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/test.ts index 7dc5fcc95f0a..19fd2c06ff80 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/docs/types/test.ts @@ -55,32 +55,32 @@ import Params = require( './index' ); { const r = new Params( {} ); - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.penalty; // $ExpectType Penalty - // eslint-disable-next-line @typescript-eslint/no-unused-expressions r.penaltyParams; // $ExpectType Float64Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.learningRate; // $ExpectType LearningRate + r.learningRateParams; // $ExpectType Float64Array // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.learningRateParams; // $ExpectType Float64Array + r.lossFunctionParams; // $ExpectType Float64Array + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + r.intercept; // $ExpectType number // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.lossFunction; // $ExpectType LossFunction + r.maxIter; // $ExpectType number // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.lossFunctionParams; // $ExpectType Float64Array + r.penalty; // $ExpectType Penalty // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.fitIntercept; // $ExpectType boolean + r.learningRate; // $ExpectType LearningRate // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.intercept; // $ExpectType number + r.lossFunction; // $ExpectType LossFunction // eslint-disable-next-line @typescript-eslint/no-unused-expressions - r.maxIter; // $ExpectType number + r.fitIntercept; // $ExpectType boolean // eslint-disable-next-line @typescript-eslint/no-unused-expressions r.method; // $ExpectType string diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/examples/index.js index 24f6a503404f..c21716cb74d0 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/examples/index.js @@ -22,15 +22,15 @@ var Float64Array = require( '@stdlib/array/float64' ); var Params = require( './../lib' ); var params = new Params({ - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, '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': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }); var str = params.toString(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h index 830826fd0fb9..c7ba6839f6a3 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/include/stdlib/ml/base/sgd/params/float64.h @@ -26,32 +26,32 @@ * Struct for storing SGD parameters. */ struct stdlib_ml_sgd_float64_params { - // Regularization function to be used: - int8_t penalty; - // Parameters specific to the regularization function being used: double penaltyParams[ 2 ]; - // Learning rate scheduler to be used: - int8_t learningRate; - // Parameters specific to the learning rate scheduler being used: double learningRateParams[ 2 ]; - // Loss function to be used: - int8_t lossFunction; - // Parameters specific to the loss function being used: double lossFunctionParams[ 1 ]; - // Boolean indicating whether to include intercept: - bool fitIntercept; - // Initial intercept value: double intercept; // Maximum number of iterations to run: int32_t maxIter; + + // Regularization function to be used: + int8_t penalty; + + // Learning rate scheduler to be used: + int8_t learningRate; + + // Loss function to be used: + int8_t lossFunction; + + // Boolean indicating whether to include intercept: + bool fitIntercept; }; #endif // !STDLIB_ML_BASE_SGD_PARAMS_FLOAT64_H diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/index.js index ae8f0dd8f161..63598683536d 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/index.js @@ -30,14 +30,14 @@ * var params = new Params(); * // returns * -* params.penalty = 'l2'; -* params.learningRate = 'constant'; -* params.lossFunction = 'hinge'; -* params.intercept = 0.0; -* params.maxIter = 500; * params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); * params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); * params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; * params.fitIntercept = true; * * var str = params.toString(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/main.js index d09da53d4497..1039d3077479 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/lib/main.js @@ -42,14 +42,14 @@ var factory = require( '@stdlib/ml/base/sgd/params/factory' ); * var params = new Params(); * // returns * -* params.penalty = 'l2'; -* params.learningRate = 'constant'; -* params.lossFunction = 'hinge'; -* params.intercept = 0.0; -* params.maxIter = 500; * params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); * params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); * params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +* params.intercept = 0.0; +* params.maxIter = 500; +* params.penalty = 'l2'; +* params.learningRate = 'constant'; +* params.lossFunction = 'hinge'; * params.fitIntercept = true; * * var str = params.toString(); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/test/test.js index 57d95de56194..4cd9746d5215 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/float64/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/float64/test/test.js @@ -160,27 +160,27 @@ tape( 'the function is a constructor for a fixed-width params object ', function var actual; actual = new Float64Params({ - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'intercept': 0.0, + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }); expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'intercept': 0.0, + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float64Params, true, 'returns expected value' ); @@ -202,26 +202,26 @@ tape( 'the function is a constructor for a fixed-width params object (no argumen actual = new Float64Params(); - actual.fitIntercept = true; - actual.intercept = 0.0; - actual.maxIter = 500; actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.intercept = 0.0; + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'intercept': 0.0, + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float64Params, true, 'returns expected value' ); @@ -243,26 +243,26 @@ tape( 'the function is a constructor for a fixed-width params object (empty obje actual = new Float64Params( {} ); - actual.fitIntercept = true; - actual.intercept = 0.0; - actual.maxIter = 500; actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.intercept = 0.0; + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'intercept': 0.0, + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float64Params, true, 'returns expected value' ); @@ -286,26 +286,26 @@ tape( 'the function is a constructor for a fixed-width params object (ArrayBuffe buf = new ArrayBuffer( 1024 ); actual = new Float64Params( buf ); - actual.fitIntercept = true; - actual.intercept = 0.0; - actual.maxIter = 500; actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.intercept = 0.0; + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'intercept': 0.0, + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float64Params, true, 'returns expected value' ); @@ -329,26 +329,26 @@ tape( 'the function is a constructor for a fixed-width params object (ArrayBuffe buf = new ArrayBuffer( 1024 ); actual = new Float64Params( buf, 16 ); - actual.fitIntercept = true; - actual.intercept = 0.0; - actual.maxIter = 500; actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.intercept = 0.0; + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'intercept': 0.0, + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float64Params, true, 'returns expected value' ); @@ -372,26 +372,26 @@ tape( 'the function is a constructor for a fixed-width params object (ArrayBuffe buf = new ArrayBuffer( 1024 ); actual = new Float64Params( buf, 16, 160 ); - actual.fitIntercept = true; - actual.intercept = 0.0; - actual.maxIter = 500; actual.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); actual.lossFunctionParams = new Float64Array( [ 0.0 ] ); actual.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + actual.intercept = 0.0; + actual.maxIter = 500; actual.penalty = 'l2'; actual.learningRate = 'constant'; actual.lossFunction = 'hinge'; + actual.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 500, 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), 'lossFunctionParams': new Float64Array( [ 0.0 ] ), 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), + 'intercept': 0.0, + 'maxIter': 500, 'penalty': 'l2', 'learningRate': 'constant', - 'lossFunction': 'hinge' + 'lossFunction': 'hinge', + 'fitIntercept': true }; t.strictEqual( actual instanceof Float64Params, true, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/README.md index 90fc6b997f5e..b502f894d94e 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/README.md @@ -88,14 +88,14 @@ var Float64Array = require( '@stdlib/array/float64' ); var params2json = require( '@stdlib/ml/base/sgd/params/to-json' ); var params = new Float64Params(); -params.penalty = resolvePenaltyEnum( 'l2' ); -params.learningRate = resolveLREnum( 'constant' ); -params.lossFunction = resolveLossFunctionEnum( 'hinge' ); -params.intercept = 0.0; -params.maxIter = 500; params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +params.intercept = 0.0; +params.maxIter = 500; +params.penalty = resolvePenaltyEnum( 'l2' ); +params.learningRate = resolveLREnum( 'constant' ); +params.lossFunction = resolveLossFunctionEnum( 'hinge' ); params.fitIntercept = true; var o = params2json( params ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/repl.txt index a87cb5aaecba..7e88fb438d7e 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/repl.txt +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/repl.txt @@ -15,15 +15,15 @@ Examples -------- > var params = { - ... 'penalty': 'l2', ... 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), - ... 'learningRate': 'constant', ... 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - ... 'lossFunction': 'hinge', ... 'lossFunctionParams': new Float64Array( [ 0.0 ] ), - ... 'fitIntercept': true, ... 'intercept': 0.0, ... 'maxIter': 1000, + ... 'penalty': 'l2', + ... 'learningRate': 'constant', + ... 'lossFunction': 'hinge', + ... 'fitIntercept': true, ... 'method': 'Stochastic Gradient Descent', ... }; > var o = {{alias}}( params ) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/index.d.ts index 371337b8620d..c3d330b7b2fa 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/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: string; + penaltyParams: Float64Array | Float32Array; /** - * Parameters specific to the regularization function being used. + * Parameters specific to the learning rate scheduler being used. */ - penaltyParams: Float64Array | Float32Array; + learningRateParams: Float64Array | Float32Array; /** - * Learning rate scheduler to be used. + * Parameters specific to the loss function being used. */ - learningRate: string; + lossFunctionParams: Float64Array | Float32Array; /** - * Parameters specific to the learning rate scheduler being used. + * Initial intercept value. */ - learningRateParams: Float64Array | Float32Array; + intercept: number; /** - * Loss function to be used. + * Maximum number of iterations to run. */ - lossFunction: string; + maxIter: number; /** - * Parameters specific to the loss function being used. + * Regularization function to be used. */ - lossFunctionParams: Float64Array | Float32Array; + penalty: string; /** - * Boolean indicating whether to include intercept. + * Learning rate scheduler to be used. */ - fitIntercept: boolean; + learningRate: string; /** - * Initial intercept value. + * Loss function to be used. */ - intercept: number; + lossFunction: string; /** - * Maximum number of iterations to run. + * Boolean indicating whether to include intercept. */ - maxIter: number; + fitIntercept: boolean; } /** @@ -78,16 +78,16 @@ interface Params { * var Float64Array = require( '@stdlib/array/float64' ); * * var params = { -* 'penalty': 'l2', * 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), -* 'learningRate': 'constant', * 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), -* 'lossFunction': 'hinge', * 'lossFunctionParams': new Float64Array( [ 0.0 ] ), -* 'fitIntercept': true, * 'intercept': 0.0, * 'maxIter': 1000, -* 'method': 'Stochastic Gradient Descent', +* 'penalty': 'l2', +* 'learningRate': 'constant', +* 'lossFunction': 'hinge', +* 'fitIntercept': true, +* 'method': 'Stochastic Gradient Descent' * }; * * var obj = params2json( params ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/test.ts index 45e9fb15d45c..1ba23b6213e4 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/docs/types/test.ts @@ -24,15 +24,15 @@ import params2json = require( './index' ); // The function returns an object... { const params = { - 'penalty': 'l2', 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), - 'learningRate': 'constant', 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - 'lossFunction': 'hinge', 'lossFunctionParams': new Float64Array( [ 0.0 ] ), - 'fitIntercept': true, 'intercept': 0.0, 'maxIter': 1000, + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge', + 'fitIntercept': true, 'method': 'Stochastic Gradient Descent' }; params2json( params ); // $ExpectType Params diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/examples/index.js index ee22b79d31c5..433b0339ba7f 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/examples/index.js @@ -26,14 +26,14 @@ var Float64Array = require( '@stdlib/array/float64' ); var params2json = require( './../lib' ); var params = new Float64Params(); -params.penalty = resolvePenaltyEnum( 'l2' ); -params.learningRate = resolveLREnum( 'constant' ); -params.lossFunction = resolveLossFunctionEnum( 'hinge' ); -params.intercept = 0.0; -params.maxIter = 500; params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +params.intercept = 0.0; +params.maxIter = 500; +params.penalty = resolvePenaltyEnum( 'l2' ); +params.learningRate = resolveLREnum( 'constant' ); +params.lossFunction = resolveLossFunctionEnum( 'hinge' ); params.fitIntercept = true; var o = params2json( params ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/index.js index 57b4adc00b6b..18f9f3251366 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/index.js @@ -28,15 +28,15 @@ * var params2json = require( '@stdlib/ml/base/sgd/params/to-json' ); * * var params = { -* 'penalty': 'l2', * 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), -* 'learningRate': 'constant', * 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), -* 'lossFunction': 'hinge', * 'lossFunctionParams': new Float64Array( [ 0.0 ] ), -* 'fitIntercept': true, * 'intercept': 0.0, * 'maxIter': 1000, +* 'penalty': 'l2', +* 'learningRate': 'constant', +* 'lossFunction': 'hinge', +* 'fitIntercept': true, * 'method': 'Stochastic Gradient Descent', * }; * diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/main.js index ea8a4acdfeb2..e0a116458c5b 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/lib/main.js @@ -35,15 +35,15 @@ var typedarray2json = require( '@stdlib/array/to-json' ); * var Float64Array = require( '@stdlib/array/float64' ); * * var params = { -* 'penalty': 'l2', * 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), -* 'learningRate': 'constant', * 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), -* 'lossFunction': 'hinge', * 'lossFunctionParams': new Float64Array( [ 0.0 ] ), -* 'fitIntercept': true, * 'intercept': 0.0, * 'maxIter': 1000, +* 'penalty': 'l2', +* 'learningRate': 'constant', +* 'lossFunction': 'hinge', +* 'fitIntercept': true, * 'method': 'Stochastic Gradient Descent', * }; * diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/test/test.js index 9c734ea3a169..44e5215fd9b3 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-json/test/test.js @@ -48,23 +48,17 @@ tape( 'the function serializes a params object to JSON', function test( t ) { eta0 = 0.01; value = new Float64Params(); - value.penalty = resolvePenaltyEnum( 'l2' ); - value.learningRate = resolveLREnum( 'constant' ); - value.lossFunction = resolveLossFunctionEnum( 'hinge' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); value.fitIntercept = true; expected = { - 'fitIntercept': true, - 'intercept': 0.0, - 'maxIter': 1000, - 'penalty': 'l2', - 'learningRate': 'constant', - 'lossFunction': 'hinge', 'penaltyParams': { 'type': 'Float64Array', 'data': [ 2.5, 0.0 ] @@ -77,6 +71,12 @@ tape( 'the function serializes a params object to JSON', function test( t ) { 'type': 'Float64Array', 'data': [ 0.0 ] }, + 'intercept': 0.0, + 'maxIter': 1000, + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge', + 'fitIntercept': true, 'method': 'Stochastic Gradient Descent' }; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md index a9ed6b2c8d93..7ddba3578bd8 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/README.md @@ -109,14 +109,14 @@ var Float64Array = require( '@stdlib/array/float64' ); var params2str = require( '@stdlib/ml/base/sgd/params/to-string' ); var params = new Float64Params(); -params.penalty = 'l2'; -params.learningRate = 'constant'; -params.lossFunction = 'hinge'; -params.intercept = 0.0; -params.maxIter = 500; params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +params.intercept = 0.0; +params.maxIter = 500; +params.penalty = 'l2'; +params.learningRate = 'constant'; +params.lossFunction = 'hinge'; params.fitIntercept = true; var s = params2str( params ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/repl.txt index 853d6cc9801d..5185404bff28 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/repl.txt +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/repl.txt @@ -21,15 +21,15 @@ Examples -------- > var params = { - ... 'penalty': 'l2', ... 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), - ... 'learningRate': 'constant', ... 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - ... 'lossFunction': 'hinge', ... 'lossFunctionParams': new Float64Array( [ 0.0 ] ), - ... 'fitIntercept': true, ... 'intercept': 0.0, ... 'maxIter': 1000, + ... 'penalty': 'l2', + ... 'learningRate': 'constant', + ... 'lossFunction': 'hinge', + ... 'fitIntercept': true, ... 'method': 'Stochastic Gradient Descent', ... }; > var s = {{alias}}( params ) diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts index 56c9bd0e860a..7c5365dddd8a 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/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: string; + penaltyParams: Float64Array | Float32Array; /** - * Parameters specific to the regularization function being used. + * Parameters specific to the learning rate scheduler being used. */ - penaltyParams: Float64Array | Float32Array; + learningRateParams: Float64Array | Float32Array; /** - * Learning rate scheduler to be used. + * Parameters specific to the loss function being used. */ - learningRate: string; + lossFunctionParams: Float64Array | Float32Array; /** - * Parameters specific to the learning rate scheduler being used. + * Initial intercept value. */ - learningRateParams: Float64Array | Float32Array; + intercept: number; /** - * Loss function to be used. + * Maximum number of iterations to run. */ - lossFunction: string; + maxIter: number; /** - * Parameters specific to the loss function being used. + * Regularization function to be used. */ - lossFunctionParams: Float64Array | Float32Array; + penalty: string; /** - * Boolean indicating whether to include intercept. + * Learning rate scheduler to be used. */ - fitIntercept: boolean; + learningRate: string; /** - * Initial intercept value. + * Loss function to be used. */ - intercept: number; + lossFunction: string; /** - * Maximum number of iterations to run. + * Boolean indicating whether to include intercept. */ - maxIter: number; + fitIntercept: boolean; } /** @@ -109,15 +109,15 @@ interface Options { * var Float64Array = require( '@stdlib/array/float64' ); * * var params = { -* 'penalty': 'l2', * 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), -* 'learningRate': 'constant', * 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), -* 'lossFunction': 'hinge', * 'lossFunctionParams': new Float64Array( [ 0.0 ] ), -* 'fitIntercept': true, * 'intercept': 0.0, * 'maxIter': 1000, +* 'penalty': 'l2', +* 'learningRate': 'constant', +* 'lossFunction': 'hinge', +* 'fitIntercept': true, * 'method': 'Stochastic Gradient Descent', * }; * diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts index 31c5a3f09499..09f624dc40d3 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/docs/types/test.ts @@ -24,15 +24,15 @@ import params2str = require( './index' ); // The function returns a string... { const params = { - 'penalty': 'l2', 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), - 'learningRate': 'constant', 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - 'lossFunction': 'hinge', 'lossFunctionParams': new Float64Array( [ 0.0 ] ), - 'fitIntercept': true, 'intercept': 0.0, 'maxIter': 1000, + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge', + 'fitIntercept': true, 'method': 'Stochastic Gradient Descent' }; params2str( params ); // $ExpectType string @@ -65,15 +65,15 @@ import params2str = require( './index' ); // The compiler throws an error if provided a second argument which is not an object... { const params = { - 'penalty': 'l2', 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), - 'learningRate': 'constant', 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - 'lossFunction': 'hinge', 'lossFunctionParams': new Float64Array( [ 0.0 ] ), - 'fitIntercept': true, 'intercept': 0.0, 'maxIter': 1000, + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge', + 'fitIntercept': true, 'method': 'Stochastic Gradient Descent' }; @@ -89,15 +89,15 @@ import params2str = require( './index' ); // The compiler throws an error if provided a `digits` option which is not a number... { const params = { - 'penalty': 'l2', 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), - 'learningRate': 'constant', 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), - 'lossFunction': 'hinge', 'lossFunctionParams': new Float64Array( [ 0.0 ] ), - 'fitIntercept': true, 'intercept': 0.0, 'maxIter': 1000, + 'penalty': 'l2', + 'learningRate': 'constant', + 'lossFunction': 'hinge', + 'fitIntercept': true, 'method': 'Stochastic Gradient Descent' }; diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js index 65699b6d122b..dff958dc9bbb 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/examples/index.js @@ -23,14 +23,14 @@ var Float64Array = require( '@stdlib/array/float64' ); var params2str = require( './../lib' ); var params = new Float64Params(); -params.penalty = 'l2'; -params.learningRate = 'constant'; -params.lossFunction = 'hinge'; -params.intercept = 0.0; -params.maxIter = 500; params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); params.lossFunctionParams = new Float64Array( [ 0.0 ] ); +params.intercept = 0.0; +params.maxIter = 500; +params.penalty = 'l2'; +params.learningRate = 'constant'; +params.lossFunction = 'hinge'; params.fitIntercept = true; var s = params2str( params ); diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js index 2ba5889d9344..a934370bb7e0 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/index.js @@ -28,15 +28,15 @@ * var params2str = require( '@stdlib/ml/base/sgd/params/to-string' ); * * var params = { -* 'penalty': 'l2', * 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), -* 'learningRate': 'constant', * 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), -* 'lossFunction': 'hinge', * 'lossFunctionParams': new Float64Array( [ 0.0 ] ), -* 'fitIntercept': true, * 'intercept': 0.0, * 'maxIter': 1000, +* 'penalty': 'l2', +* 'learningRate': 'constant', +* 'lossFunction': 'hinge', +* 'fitIntercept': true, * 'method': 'Stochastic Gradient Descent', * }; * diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/main.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/main.js index 33860fc904d1..56aab8b4a298 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/main.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/lib/main.js @@ -61,15 +61,15 @@ var format = require( '@stdlib/string/format' ); * var Float64Array = require( '@stdlib/array/float64' ); * * var params = { -* 'penalty': 'l2', * 'penaltyParams': new Float64Array( [ 2.5, 0.0 ] ), -* 'learningRate': 'constant', * 'learningRateParams': new Float64Array( [ 0.01, 0.0 ] ), -* 'lossFunction': 'hinge', * 'lossFunctionParams': new Float64Array( [ 0.0 ] ), -* 'fitIntercept': true, * 'intercept': 0.0, * 'maxIter': 1000, +* 'penalty': 'l2', +* 'learningRate': 'constant', +* 'lossFunction': 'hinge', +* 'fitIntercept': true, * 'method': 'Stochastic Gradient Descent', * }; * diff --git a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js index 51c280b56f49..affb56e8f043 100644 --- a/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js +++ b/lib/node_modules/@stdlib/ml/base/sgd/params/to-string/test/test.js @@ -111,14 +111,14 @@ tape( 'the function serializes a params object to a string (l1,l2 penalty)', fun lambda = 2.5; eta0 = 0.01; - value.penalty = resolvePenaltyEnum( 'l2' ); - value.learningRate = resolveLREnum( 'constant' ); - value.lossFunction = resolveLossFunctionEnum( 'hinge' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); value.fitIntercept = true; actual = params2str( value ); @@ -155,14 +155,14 @@ tape( 'the function serializes a params object to a string (elasticnet penalty)' lambda = 2.5; eta0 = 0.01; - value.penalty = resolvePenaltyEnum( 'elasticnet' ); - value.learningRate = resolveLREnum( 'constant' ); - value.lossFunction = resolveLossFunctionEnum( 'hinge' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, l1Ratio ] ); value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'elasticnet' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); value.fitIntercept = true; actual = params2str( value ); @@ -198,14 +198,14 @@ tape( 'the function serializes a params object to a string (no penalty)', functi lambda = 2.5; eta0 = 0.01; - value.penalty = resolvePenaltyEnum( 'none' ); - value.learningRate = resolveLREnum( 'constant' ); - value.lossFunction = resolveLossFunctionEnum( 'hinge' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'none' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); value.fitIntercept = true; actual = params2str( value ); @@ -237,14 +237,14 @@ tape( 'the function serializes a params object to a string (basic learning rate) lambda = 2.5; - value.penalty = resolvePenaltyEnum( 'l2' ); - value.learningRate = resolveLREnum( 'basic' ); - value.lossFunction = resolveLossFunctionEnum( 'hinge' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); value.learningRateParams = new Float64Array( [ 0.0, 0.0 ] ); value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'basic' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); value.fitIntercept = true; actual = params2str( value ); @@ -278,14 +278,14 @@ tape( 'the function serializes a params object to a string (constant learning ra lambda = 2.5; eta0 = 0.01; - value.penalty = resolvePenaltyEnum( 'l2' ); - value.learningRate = resolveLREnum( 'constant' ); - value.lossFunction = resolveLossFunctionEnum( 'hinge' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); value.fitIntercept = true; actual = params2str( value ); @@ -322,14 +322,14 @@ tape( 'the function serializes a params object to a string (invscaling learning lambda = 2.5; eta0 = 0.01; - value.penalty = resolvePenaltyEnum( 'l2' ); - value.learningRate = resolveLREnum( 'invscaling' ); - value.lossFunction = resolveLossFunctionEnum( 'hinge' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); value.learningRateParams = new Float64Array( [ eta0, powerT ] ); value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'invscaling' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); value.fitIntercept = true; actual = params2str( value ); @@ -363,14 +363,14 @@ tape( 'the function serializes a params object to a string (pegasos learning rat lambda = 2.5; - value.penalty = resolvePenaltyEnum( 'l2' ); - value.learningRate = resolveLREnum( 'pegasos' ); - value.lossFunction = resolveLossFunctionEnum( 'hinge' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); value.learningRateParams = new Float64Array( [ lambda, 0.0 ] ); value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'pegasos' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); value.fitIntercept = true; actual = params2str( value ); @@ -406,14 +406,14 @@ tape( 'the function serializes a params object to a string (epsilon insensitive, lambda = 2.5; eta0 = 0.01; - value.penalty = resolvePenaltyEnum( 'l2' ); - value.learningRate = resolveLREnum( 'constant' ); - value.lossFunction = resolveLossFunctionEnum( 'squared-epsilon-insensitive' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); value.lossFunctionParams = new Float64Array( [ epsilon ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'squared-epsilon-insensitive' ); value.fitIntercept = true; actual = params2str( value ); @@ -449,14 +449,14 @@ tape( 'the function serializes a params object to a string (no intercept)', func lambda = 2.5; eta0 = 0.01; - value.penalty = resolvePenaltyEnum( 'l2' ); - value.learningRate = resolveLREnum( 'constant' ); - value.lossFunction = resolveLossFunctionEnum( 'hinge' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); value.fitIntercept = false; actual = params2str( value ); @@ -490,14 +490,14 @@ tape( 'the function supports specifying the number of displayed digits (digits=2 lambda = 2.5; eta0 = 0.01; - value.penalty = resolvePenaltyEnum( 'l2' ); - value.learningRate = resolveLREnum( 'constant' ); - value.lossFunction = resolveLossFunctionEnum( 'hinge' ); - value.intercept = 0.0; - value.maxIter = 1000; value.penaltyParams = new Float64Array( [ lambda, 0.0 ] ); value.learningRateParams = new Float64Array( [ eta0, 0.0 ] ); value.lossFunctionParams = new Float64Array( [ 0.0 ] ); + value.intercept = 0.0; + value.maxIter = 1000; + value.penalty = resolvePenaltyEnum( 'l2' ); + value.learningRate = resolveLREnum( 'constant' ); + value.lossFunction = resolveLossFunctionEnum( 'hinge' ); value.fitIntercept = true; actual = params2str( value );