/**
 * Some useful Maths methods.
 */ export class PSMath { public static log ( base , x ) { return Math . log ( x ) / Math . log ( base ) ; } public static log10 ( x ) { return PSMath . log ( 10 , x ) ; } public static meanSimple ( values ) { let sum = 0 ; for ( let i = 0 ; i < values . length ; i ++ ) { sum += values [ i ] ; } return sum / values . length ; } public static meanWeighted ( values , weights ) { if ( values . length !== weights . length || values . length === 0 ) { return 0 ; } let sumWeigtedValues = 0 ; let sumWeights = 0 ; for ( let i = 0 ; i < values . length ; i ++ ) { const weight = weights [ i ] ; sumWeigtedValues += values [ i ] * weight ; sumWeights += weight ; } return sumWeigtedValues / sumWeights ; } }