Sha256: f789ec2842d6d16fe2b271588055dba8d52978faaa194f31ce76d61d58cd4295
Contents?: true
Size: 1.69 KB
Versions: 3
Compression:
Stored size: 1.69 KB
Contents
$:.unshift(File.dirname(__FILE__)+'/../lib/') require 'test/unit' require 'statsample' class StatsampleMatrixTestCase < Test::Unit::TestCase def setup end def test_subindex matrix=Matrix[[1,2,3],[4,5,6],[7,8,9]] assert_equal(5, matrix[1,1]) assert_equal(Matrix[[1,2,3]], matrix[0,:*]) assert_equal(Matrix[[1],[4],[7]], matrix[:*,0]) assert_equal(Matrix[[1,2],[4,5],[7,8]], matrix[:*,0..1]) assert_equal(Matrix[[1,2],[4,5]], matrix[0..1,0..1]) end def test_sums matrix=Matrix[[1,2,3],[4,5,6],[7,8,9]] assert_equal(6,matrix.row_sum[0]) assert_equal(12,matrix.column_sum[0]) assert_equal(45,matrix.total_sum) end def test_covariate a=Matrix[[1.0, 0.3, 0.2], [0.3, 1.0, 0.5], [0.2, 0.5, 1.0]] a.extend Statsample::CovariateMatrix a.fields=%w{a b c} assert_equal(:correlation, a.type) assert_equal(Matrix[[0.5],[0.3]], a.submatrix(%w{c a}, %w{b})) assert_equal(Matrix[[1.0, 0.2] , [0.2, 1.0]], a.submatrix(%w{c a})) assert_equal(:correlation, a.submatrix(%w{c a}).type) a=Matrix[[20,30,10], [30,60,50], [10,50,50]] a.extend Statsample::CovariateMatrix assert_equal(:covariance, a.type) a=100.times.collect {rand()}.to_scale b=100.times.collect {rand()}.to_scale c=100.times.collect {rand()}.to_scale ds={'a'=>a,'b'=>b,'c'=>c}.to_dataset corr=Statsample::Bivariate.correlation_matrix(ds) real=Statsample::Bivariate.covariance_matrix(ds).correlation corr.row_size.times do |i| corr.column_size.times do |j| assert_in_delta(corr[i,j], real[i,j],1e-15) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
statsample-0.7.0 | test/test_matrix.rb |
statsample-0.6.7 | test/test_matrix.rb |
statsample-0.6.5 | test/test_matrix.rb |