Skip to content

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

Description

@nakul-krishnakumar

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working.Machine LearningIssue or pull request specific to machine learning functionality.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions