Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@
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) ) );
} else if ( d < 1.0 ) {
this._add( x, 2.0*eta*( y-(d*y) ) );
}
Comment on lines 342 to 346

@nakul-krishnakumar nakul-krishnakumar Sep 28, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look correct to me as here else if comes after an else. According to sklearn, the correct branching should be:

if ( d >= 1.0 ) {
    // no update
} else if ( d >= -1.0 ) {
    this._add( x, 2.0*eta*( y-(d*y) ) );
} else {
    this._add( x, 4.0*eta*y );
}

Reference

To make it simpler we can do this:

if ( d < -1.0 ) {
    this._add( x, 4.0*eta*y );
} else if ( d < 1.0 ) {
    this._add( x, 2.0*eta*( y-(d*y) ) );
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another reference is our @stdlib/ml/base/loss/float64/modified-huber-gradient implementation.

return this;
});
Expand All @@ -357,7 +357,7 @@
* [@shalevshwartz:2011a]: https://doi.org/10.1007/s10107-010-0420-4
*
* @private
* @name _pegasos

Check warning on line 360 in lib/node_modules/@stdlib/ml/incr/binary-classification/lib/model.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "pegasos"
* @memberof Model.prototype
* @type {Function}
* @returns {number} learning rate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
// MODULES //

var tape = require( 'tape' );
var array = require( '@stdlib/ndarray/array' );
var Float64Array = require( '@stdlib/array/float64' );
var Model = require( './../lib/model.js' );


Expand All @@ -32,4 +34,41 @@ tape( 'main export is a function', function test( t ) {
t.end();
});

// TODO: add tests
tape( 'the function supports modified Huber loss', function test( t ) {
var expected;
var model;
var opts;
var eta;
var x;

eta = 0.1;
opts = {
'lambda': 0.0,
'learningRate': [ 'constant', eta ],
'loss': 'modifiedHuber',
'intercept': false
};
x = array( new Float64Array( [ 1.0 ] ) );

// Case 1: `-1 <= y*f(x) < 1` (quadratically smoothed region):
model = new Model( 1, opts );
model._weights[ 0 ] = 0.3; // eslint-disable-line no-underscore-dangle
model.update( x, 1 );
expected = 0.3 + ( 2.0*eta*( 1.0-(0.3*1.0) ) );
t.strictEqual( model._weights[ 0 ], expected, 'returns expected value' ); // eslint-disable-line no-underscore-dangle

// Case 2: `y*f(x) >= 1`, where the gradient is zero and the weights are unchanged:
model = new Model( 1, opts );
model._weights[ 0 ] = 2.0; // eslint-disable-line no-underscore-dangle
model.update( x, 1 );
t.strictEqual( model._weights[ 0 ], 2.0, 'returns expected value' ); // eslint-disable-line no-underscore-dangle

// Case 3: `y*f(x) < -1`:
model = new Model( 1, opts );
model._weights[ 0 ] = -2.0; // eslint-disable-line no-underscore-dangle
model.update( x, 1 );
expected = -2.0 + ( 4.0*eta*1.0 );
t.strictEqual( model._weights[ 0 ], expected, 'returns expected value' ); // eslint-disable-line no-underscore-dangle

t.end();
});
Loading