void test_diag_std() { const int N = 25; double_vector_type * data = double_vector_alloc( 0,0); rng_type * rng = rng_alloc(MZRAN , INIT_DEV_URANDOM ); matrix_type * m = matrix_alloc( N , N ); double sum1 = 0; double sum2 = 0; int i; for (i=0; i < N; i++) { double R = rng_get_double( rng ); matrix_iset(m , i , i , R); double_vector_iset( data , i , R ); sum1 += R; sum2 += R*R; } { double mean = sum1 / N; double std = sqrt( sum2 / N - mean * mean ); test_assert_double_equal( std , matrix_diag_std( m , mean )); test_assert_double_equal( statistics_std( data ) , matrix_diag_std( m , mean )); test_assert_double_equal( statistics_mean( data ) , mean ); } matrix_free( m ); rng_free( rng ); }
void matrix_random_init(matrix_type * matrix , rng_type * rng) { int i,j; for (j=0; j < matrix->columns; j++) for (i=0; i < matrix->rows; i++) matrix->data[ GET_INDEX(matrix , i , j) ] = rng_get_double( rng ); }