Repository navigation
feat: add ml/base/loss/float64/hinge - #11953
nakul-krishnakumar wants to merge 19 commits into
Conversation
---
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
status: passed
- 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: passed
- task: lint_c_examples
status: passed
- task: lint_c_benchmarks
status: passed
- 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
---
Coverage Report
The above coverage report was generated for the changes in this PR. |
|
Clarifications required:
|
|
/stdlib update-copyright-years |
---
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
status: passed
- 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: na
- 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: passed
- task: lint_c_examples
status: passed
- task: lint_c_benchmarks
status: passed
- 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
---
Co-authored-by: Athan <kgryte@gmail.com> Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
|
Before this gets merged, I wanted to discuss a possibility. If we were supposed to add a |
|
@nakul-krishnakumar Yes, fine with adding a threshold argument. Although, it need not be restricted to |
|
/stdlib merge |
---
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: skipped
- task: lint_markdown_pkg_readmes
status: passed
- task: lint_markdown_docs
status: na
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: 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: passed
- task: lint_c_examples
status: passed
- task: lint_c_benchmarks
status: passed
- 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
---
| v = hinge( 2.0, 1.0, -0.9 ); | ||
| // returns 2.9 | ||
| ``` | ||
|
|
|
|
||
| #### hinge( t, y, p ) | ||
|
|
||
| Computes the [hinge loss][hinge-loss] between two double-precision floating-point numbers. |
There was a problem hiding this comment.
Why "between two double-precision floating-point numbers"? Why not "with respect to a model parameter" as you did for hinge-gradient? Question applies throughout this PR.
There was a problem hiding this comment.
Here, “with respect to a model parameter” would not be applicable, since we are not differentiating the loss function with respect to a model parameter, as we would when computing the loss gradient. However, I’m open to changing the description to something more appropriate if you have a better suggestion.
There was a problem hiding this comment.
To make things more clear:
- Hinge Loss function
- Hinge loss function gradient
Here it is being differentiated wrt to model parameter.
|
@nakul-krishnakumar Would you be up for moving this PR along? Cheers! |
|
|
||
|
|
| var v = hinge( 1.0, NaN, 12.0 ); | ||
| // returns NaN | ||
|
|
||
| v = hinge( 2.0, 5.0, NaN ); |
There was a problem hiding this comment.
| v = hinge( 2.0, 5.0, NaN ); | |
| v = hinge( 2.0, 1.0, NaN ); |
y = 5.0 already returns NaN, so this example doesn't show the NaN case for p.
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> |
There was a problem hiding this comment.
| <!-- /.usage --> | |
| <!-- /.usage --> | |
| <section class="notes"> | |
| ## Notes | |
| - When `t = 1.0`, we get the loss used by SVM; whereas, when `t = 0.0`, we get the loss used by the Perceptron. | |
| </section> | |
| <!-- /.notes --> |
Same note as hinge-gradient. t was added so this package could also serve as the Perceptron loss.
|
|
||
| The function accepts the following arguments: | ||
|
|
||
| - **t**: `[in] double` threshold value. |
There was a problem hiding this comment.
| - **t**: `[in] double` threshold value. | |
| - **t**: `[in] double` margin threshold. |
Matches line 63 and hinge-gradient. Same in lib/main.js:32, lib/native.js:32, docs/types/index.d.ts:28, src/main.c:27 and docs/repl.txt:12 (Margin threshold.).
|
|
||
| /** | ||
| * Computes the hinge loss between two double-precision floating-point numbers. | ||
| * |
There was a problem hiding this comment.
| * | |
| * | |
| * ## Notes | |
| * | |
| * - If `y` is not +1 or -1, the function returns `NaN`. | |
| * - When `t = 1.0`, we get the loss used by SVM, whereas when `t = 0.0`, we get the loss used by the Perceptron. | |
| * |
Matches hinge-gradient/lib/main.js. Add the SVM/Perceptron note in docs/types/index.d.ts:26 and after docs/repl.txt:7 as well.
| * // returns 2.099 | ||
| * | ||
| * @example | ||
| * var v = hinge( 5.0, -1.0, 0.234 ); |
There was a problem hiding this comment.
| * var v = hinge( 5.0, -1.0, 0.234 ); | |
| * var v = hinge( 5.0, -1.0, 0.234 ); |
Same in lib/native.js:50, lib/index.js:38 and docs/types/index.d.ts:46.
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Resolves None.
Description
This pull request:
ml/base/loss/float64/hinge.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
None.
@stdlib-js/reviewers