'use strict';

/**
* Returns a function to retrieve the current learning rate.
*
* @param {string} type - string denoting the learning rate to use. Can be `constant`, `pegasos` or `basic`.
* @param {PositiveNumber} eta0 - constant learning rate
* @param {NonNegativeNumber} lambda - regularization parameter
* @throws {Error} first argument must be `basic`, `constant` or `pegasos`
* @returns {Function} getEta function
*/
function closure( type, eta0, lambda ) {
	var ret;
	var _it;

	_it = 1;

	switch ( type ) {
	case 'basic':
		// Default case: 'basic'
		ret = function getEta() {
			var eta = 1000.0 / ( _it + 1000.0 );
			_it += 1;
			return eta;
		};
	break;
	case 'constant':
		ret = function getEta() {
			_it += 1;
			return eta0;
		};
	break;
	case 'pegasos':
		ret = function getEta() {
			var eta = 1.0 / ( lambda * _it );
			_it += 1;
			return eta;
		};
	break;
	default:
		throw Error( 'invalid input value. `learningRate` must be either `basic`, `constant` or `pegasos`. Value: `' + type + '`' );
	}

	return ret;
} // end FUNCTION closure()


// EXPORTS //

module.exports = closure;

'use strict';

// MODULES //

var constantFunction = require( '@stdlib/utils/constant-function' );


// FUNCTIONS //

/**
* Returns a function to retrieve a learning rate.
*
* @private
* @returns {Function} function to retrieve learning rate
*/
function basic() {
	var i = 1;
	return getEta;

	/**
	* Returns a learning rate.
	*
	* @private
	* @returns {number} learning rate
	*/
	function getEta() {
		var eta = 1000.0 / ( i + 1000.0 );
		i += 1;
		return eta;
	} // end FUNCTION getEta()
} // end FUNCTION basic()

/**
* Returns a function to retrieve a learning rate.
*
* @private
* @param {NonNegativeNumber} lambda - regularization parameter
* @returns {Function} function to retrieve learning rate
*/
function pegasos( lambda ) {
	var i = 1;
	return getEta;

	/**
	* Returns a learning rate.
	*
	* @private
	* @returns {number} learning rate
	*/
	function getEta() {
		var eta = 1.0 / ( lambda * i );
		i += 1;
		return eta;
	} // end FUNCTION getEta()
} // end FUNCTION pegasos()


// MAIN //

/**
* Returns a function to retrieve the current learning rate.
*
* @param {string} type - string denoting the learning rate to use
* @param {PositiveNumber} eta0 - constant learning rate
* @param {NonNegativeNumber} lambda - regularization parameter
* @throws {Error} first argument must be a recognized learning rate
* @returns {Function} function to retrieve current learning rate
*/
function getEta( type, eta0, lambda ) {
	if ( type === 'basic' ) {
		return basic();
	}
	else if ( type === 'constant' ) {
		return constantFunction( eta0 );
	}
	else if ( type === 'pegasos' ) {
		return pegasos( lambda );
	}
	throw Error( 'invalid input value. First argument must be a recognized learning rate. Value: `' + type + '`.' );
} // end FUNCTION getEta()


// EXPORTS //

module.exports = getEta;

Refactor and fix lint errors