Sha256: 26df5fdc60adfff7c070fcc84cb74ecb43187cbab8040a10ba1b6dae57aff7f1

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe SPCore::Statistics do
  describe '.mean' do
    it 'should calculate the proper mean' do
      cases = {
        [1,2,3,4,5] => 3,
        [11,25,60,4,22,48,40] => 30,
        [100,200] => 150,
      }
      
      cases.each do |values,ideal_mean|
        actual_mean = Statistics.mean values
        actual_mean.should eq(ideal_mean)
      end
    end
  end
  
  describe '.std_dev' do
    it 'should determine the proper standard deviation' do
      cases = {
        [4,2,5,8,6] => 2.24,
        [2,4,4,4,5,5,7,9] => 2,
        [1,2,3,4,5] => 1.414
      }
      
      cases.each do |inputs,expected_output|
        actual_output = Statistics.std_dev inputs
        actual_output.should be_within(0.01).of(expected_output)
      end      
    end
  end
  
  describe '.correlation' do
    context 'image => triangular window' do
      before :all do
        @size = size = 48
        @triangle = TriangularWindow.new(size * 2).data
      end
      
      context 'feature => rising ramp (half size of triangular window)' do
        it 'should have maximum correlation at beginning' do
          rising_ramp = Array.new(@size){|i| i / @size.to_f }
          correlation = Statistics.correlation(@triangle, rising_ramp)
          correlation.first.should eq(correlation.max)
        end
      end
      
      context 'feature => falling ramp (half size of triangular window)' do
        it 'should have maximum correlation at end' do
          falling_ramp = Array.new(@size){|i| (@size - i) / @size.to_f }
          correlation = Statistics.correlation(@triangle, falling_ramp)
          correlation.last.should eq(correlation.max)
          
          #Plotter.plot_1d "correlate falling ramp" => correlation
        end
      end
    end  
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spcore-0.2.1 spec/analysis/statistics_spec.rb