export const cost = ( expectation ) => ( result ) : number => Math . pow ( result - expectation , 2 ) ; export const costDerivative = ( expectation ) => ( result ) : number => 2 * ( result - expectation ) ; export const denormalizeLinear = ( topValue ) => ( value ) : number => topValue * value ; export const denormalizeMatrix = ( topValue ) => ( matrix ) : number [ ] [ ] => matrix . map ( ( row ) => row . map ( denormalizeLinear ( topValue ) ) ) ; export const descentStep = ( learningSpeed ) => ( slope ) : number => - slope * learningSpeed ; export const normalizeLinear = ( topValue ) => ( value ) : number => value / topValue ; export const normalizeMatrix = ( topValue ) => ( matrix ) : number [ ] [ ] => matrix . map ( ( row ) => row . map ( normalizeLinear ( topValue ) ) ) ; export const powerRuleDerivative = ( exponent ) => ( value ) : number => exponent * Math . pow ( value , exponent - 1 ) ; export const polynomial = ( factors ) => ( value ) : number => factors . reduce ( ( total , factor , exponent ) => total + factor * Math . pow ( value , exponent ) , 0 ) ; export const polynomialDerivative = ( factors ) => ( value ) : number => factors . reduce ( ( total , factor , exponent ) => total + factor * powerRuleDerivative ( exponent ) ( value ) , 0 ) ;