/**
 * 协方差
 */ import { Mean } from "./Mean" ; param { Array < number > } . . value_a param { Array < number > } . . value_b return { number } function Covariance ( [ ... value_a ] , [ ... value_b ] ) { if ( value_a . length == value_b . length ) { let mean = Mean ( [ ... value_a ] ) ; let mean_b = Mean ( [ ... value_b ] ) ; let total = 0 ; for ( let i = 0 ; i <= value_a . length ; i ++ ) { total += ( value_a [ i ] - mean ) * ( value_b [ i ] - mean_b ) ; } return total / value_a . length ; } else { throw Error ( "两个集合不均等!" ) ; } } export { Covariance as Cov } ;