feat: add ml/strided/dsgd-trainer - #13614
Conversation
|
I have the following doubts:
sklearn sgd implementation: Ref cc: @kgryte |
|
Also please note that I kept some comments only for the sake of understanding, will remove them once we finalize the implementation. |
|
Quick aside: I am wondering if we should namespace the strided routines. E.g., The current package base name, as is, is a bit unwieldy. Thoughts? |
|
For packages which are applicable across ML algos, they can go directly in And actually, is squared epsilon insensitive so specific to sgd-trainer that it shouldn't be broadly applicable? I am just curious where we draw the line. |
Yeah we could do that, we had discussed this earlier but decided not to until we add more packages and it becomes harder to track. |
Here, yes it is specific to function dsgdTrainer( loss, .... ) {
...
g = dsgdLossGradient( loss, x, e, y, p );
...
}This was our first choice but decided on implementing individual cc: @kgryte |
ml/strided/dsgd-trainer-squared-epsilon-insensitiveml/strided/dsgd-trainer
| * | ||
| * Note: | ||
| * | ||
| * - Here `params` => `[ ]` (empty) |
There was a problem hiding this comment.
| * - Here `params` => `[ ]` (empty) | |
| * - Here `params` => `[ eta0 ]` (empty) |
| * - Here `params` => `[ lambda ]` | ||
| * | ||
| * @private | ||
| * @param {NonNegativeInteger} t - current iteration. | ||
| * @param {Float64Array} params - strided array containing scheduler specific parameters. | ||
| * @returns {number} learning rate | ||
| */ | ||
| function pegasos( t, params ) { | ||
| return 1.0 / ( params[ 0 ]*t ); | ||
| } |
There was a problem hiding this comment.
| * - Here `params` => `[ lambda ]` | |
| * | |
| * @private | |
| * @param {NonNegativeInteger} t - current iteration. | |
| * @param {Float64Array} params - strided array containing scheduler specific parameters. | |
| * @returns {number} learning rate | |
| */ | |
| function pegasos( t, params ) { | |
| return 1.0 / ( params[ 0 ]*t ); | |
| } | |
| * - Here `params` => `[ eta0, lambda ]` | |
| * | |
| * @private | |
| * @param {NonNegativeInteger} t - current iteration. | |
| * @param {Float64Array} params - strided array containing scheduler specific parameters. | |
| * @returns {number} learning rate | |
| */ | |
| function pegasos( t, params ) { | |
| return 1.0 / ( params[ 1 ]*t ); | |
| } |
| * - Here `params` => `[ eta, lambda, l1Ratio ]` | ||
| * | ||
| * @private | ||
| * @param {NonNegativeInteger} scaleFactor - current iteration. | ||
| * @param {Float64Array} params - strided array containing regularizer specific parameters. | ||
| * @returns {number} scale factor | ||
| */ | ||
| function l2Decay( scaleFactor, params ) { | ||
| return scaleFactor * max( 0.0, 1.0 - ( ( 1.0 - params[ 2 ] ) * params[ 0 ] * params[ 1 ] ) ); // eslint-disable-line max-len | ||
| } |
There was a problem hiding this comment.
| * - Here `params` => `[ eta, lambda, l1Ratio ]` | |
| * | |
| * @private | |
| * @param {NonNegativeInteger} scaleFactor - current iteration. | |
| * @param {Float64Array} params - strided array containing regularizer specific parameters. | |
| * @returns {number} scale factor | |
| */ | |
| function l2Decay( scaleFactor, params ) { | |
| return scaleFactor * max( 0.0, 1.0 - ( ( 1.0 - params[ 2 ] ) * params[ 0 ] * params[ 1 ] ) ); // eslint-disable-line max-len | |
| } | |
| * - Here `params` => `[ lambda, l1Ratio ]` | |
| * | |
| * @private | |
| * @param {NonNegativeInteger} scaleFactor - current iteration. | |
| * @param {Float64Array} params - strided array containing regularizer specific parameters. | |
| * @returns {number} scale factor | |
| */ | |
| function l2Decay( scaleFactor, eta, params ) { | |
| return scaleFactor * max( 0.0, 1.0 - ( ( 1.0 - params[ 2 ] ) * eta * params[ 1 ] ) ); // eslint-disable-line max-len | |
| } |
| function identityDecay( scaleFactor, params ) { // eslint-disable-line no-unused-vars | ||
| return scaleFactor; | ||
| } |
There was a problem hiding this comment.
| function identityDecay( scaleFactor, params ) { // eslint-disable-line no-unused-vars | |
| return scaleFactor; | |
| } | |
| function identityDecay( scaleFactor, eta, params ) { // eslint-disable-line no-unused-vars | |
| return scaleFactor; | |
| } |
| if ( penalty === 'l2' ) { | ||
| l1Ratio = 0.0; | ||
| } else if ( penalty === 'l1' ) { | ||
| l1Ratio = 1.0; | ||
| } |
There was a problem hiding this comment.
| if ( penalty === 'l2' ) { | |
| l1Ratio = 0.0; | |
| } else if ( penalty === 'l1' ) { | |
| l1Ratio = 1.0; | |
| } | |
| if ( penalty === 'l2' ) { | |
| penaltyParams[ 1 ] = 0.0; | |
| } else if ( penalty === 'l1' ) { | |
| penaltyParams[ 1 ] = 1.0; | |
| } |
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown_pkg_readmes
status: na
- task: lint_markdown_docs
status: na
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
| /** | ||
| * Struct for storing SGD parameters. | ||
| */ | ||
| struct stdlib_ml_sgd_params_float64_params { |
There was a problem hiding this comment.
| struct stdlib_ml_sgd_params_float64_params { | |
| struct stdlib_ml_sgd_float64_params { |
Resolves a part of #12875.
Description
This pull request:
ml/strided/dsgd-trainer.Related Issues
This pull request has the following related issues:
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
I used both Claude Code and ChatGPT to help me refer the sklearn implementation and write the code.
@stdlib-js/reviewers