src/kul.forbes/helpers/Accelerators/LBFGS.cs
/// <summary>
/// Calculates to step towards the minima
/// --> if no updates have been made, it returns -gradient
/// </summary>
Calculates to step towards the minima
> if no updates have been made, it returns -gradient
Calculates to step towards the minima > if no updates have been made it returns - gradient
public Vector<double> GetStep(Location location)
        {
            if (activeCacheSize == 0) return -location.Evaluated.Gradient;
            var outputDirection = location.Evaluated.Gradient;
            var rho = Vector<double>.Build.Dense(config.CacheSize);
            var alpha = Vector<double>.Build.Dense(config.CacheSize);
            Enumerable.Range(0, activeCacheSize)
                .Select(GetFloatingIndex)
                .ToList()
                .ForEach(i => 
                {
                    rho[i] = 1 / (s.Column(i).DotProduct(y.Column(i)));
                    alpha[i] = rho[i] * (s.Column(i).DotProduct(outputDirection));
                    outputDirection = outputDirection - (alpha[i] * y.Column(i));
                });
            outputDirection = outputDirection * hessianEstimate;
            Enumerable.Range(0, activeCacheSize)
                .Reverse()
                .Select(GetFloatingIndex)
                .ToList()
                .ForEach(i=>
                {
                    var beta = rho[i] * (y.Column(i).DotProduct(outputDirection));
                    outputDirection = outputDirection + ((alpha[i] - beta) * s.Column(i));
                });
            return -outputDirection;
        }
public Vector < double > GetStep ( Location location ) { if ( activeCacheSize == 0 ) return - location . Evaluated . Gradient ; var outputDirection = location . Evaluated . Gradient ; var rho = Vector < double > . Build . Dense ( config . CacheSize ) ; var alpha = Vector < double > . Build . Dense ( config . CacheSize ) ; Enumerable . Range ( 0 , activeCacheSize ) . Select ( GetFloatingIndex ) . ToList ( ) . ForEach ( i => { rho [ i ] = 1 / ( s . Column ( i ) . DotProduct ( y . Column ( i ) ) ) ; alpha [ i ] = rho [ i ] * ( s . Column ( i ) . DotProduct ( outputDirection ) ) ; outputDirection = outputDirection - ( alpha [ i ] * y . Column ( i ) ) ; } ) ; outputDirection = outputDirection * hessianEstimate ; Enumerable . Range ( 0 , activeCacheSize ) . Reverse ( ) . Select ( GetFloatingIndex ) . ToList ( ) . ForEach ( i => { var beta = rho [ i ] * ( y . Column ( i ) . DotProduct ( outputDirection ) ) ; outputDirection = outputDirection + ( ( alpha [ i ] - beta ) * s . Column ( i ) ) ; } ) ; return - outputDirection ; }
Calculates to step towards the minima
> if no updates have been made, it returns -gradient
Calculates to step towards the minima > if no updates have been made it returns - gradient
location
Location