[BUG]: missing multiplication in `_modifiedHuberLoss` implementation in `ml/incr/binary-classification`

Open Beginner friendly
#13,111 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
javascript

Research direction

Read lib/node_modules/@stdlib/ml/incr/binary-classification/lib/model.js, starting at Model.prototype._modifiedHuberLoss, and compare the else branch with the expected gradient and referenced implementations. Done means the implementation applies the proposed factor of 2 consistently with the stated derivative and preserves the existing behavior of the other branch.

Written by the indexing model from the issue text.

Description

Bug Machine Learning
Description

I was going through the wikipedia pages as well as other library implementations of loss functions to implement standalone loss functions and their gradients under ml/base/loss/float64/*.
I noticed a possible bug in _modifiedHuberLoss function implemented under ml/incr/binary-classification

Current implementation:

setReadOnly( Model.prototype, '_modifiedHuberLoss', function modifiedHuber( x, y ) {
	var eta;
	var d;

	eta = this[ this._learningRateMethod ]();
	this._regularize( eta );

	d = y * this._dot( x.data, x.strides[ 0 ], x.offset );
	if ( d < -1.0 ) {
		this._add( x, 4.0*eta*y );
	} else {
		this._add( x, eta*( y-(d*y) ) );
	}
	return this;
});

Link

I believe in the else branch, it should be this._add( x, eta*2*( y-(d*y) ) ) instead of this._add( x, eta*( y-(d*y) ) ). That is, it seems like it is missing a multiplication with 2 here.

References:
Wikipedia
sklearn

cc: @Planeshifter

Related Issues

No response

Questions

No.

Demo

No response

Reproduction
  • a
  • b
  • c
Expected Results
\frac{\partial \ell}{\partial p} =
\begin{cases}
-4y & \text{if } yp < -1 \\
-2y(1 - yp) & \text{if } -1 \le yp \le 1 \\
0 & \text{if } yp > 1
\end{cases}
Actual Results

Version

No response

Environments

N/A

Browser Version

No response

Node.js / npm Version

No response

Platform

No response

Checklist
  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
Dominant language
JavaScript
Stars
6k
Forks
1.3k
Avg merge
1d 1h
Merged PRs (30d)
559

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stdlib-js/stdlib

All issues in stdlib-js/stdlib

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.