statsample-timeseries 0.0.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ module Statsample
2
+ module TimeSeries
3
+ VERSION = '0.3.0'
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statsample-timeseries/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'statsample-timeseries'
8
+ spec.version = Statsample::TimeSeries::VERSION
9
+ spec.authors = ['Ankur Goel', 'Sameer Deshmukh']
10
+ spec.email = ['sameer.deshmukh93@gmail.com']
11
+ spec.summary = %q{statsample-timeseries is a statsample extension which includes many functions for time series analysis.}
12
+ spec.description = %q{Various functions for time series analysis.}
13
+ spec.homepage = ''
14
+ spec.license = 'BSD-2'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'statsample', '~> 2.0'
22
+ spec.add_runtime_dependency 'daru', '~> 0.1'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.10'
25
+ spec.add_development_dependency 'rb-gsl', '~> 1.16'
26
+ spec.add_development_dependency 'rake', '~> 10.4'
27
+ spec.add_development_dependency 'minitest', '~> 5.7'
28
+ spec.add_development_dependency 'mocha', '~> 1.1'
29
+ spec.add_development_dependency 'shoulda', '~> 3.5'
30
+ spec.add_development_dependency 'awesome_print'
31
+ end
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'bundler'
3
2
  begin
4
3
  Bundler.setup(:default, :development)
@@ -7,10 +6,11 @@ rescue Bundler::BundlerError => e
7
6
  $stderr.puts "Run `bundle install` to install missing gems"
8
7
  exit e.status_code
9
8
  end
10
- require 'minitest/unit'
9
+ require 'minitest/autorun'
11
10
  require 'shoulda'
12
11
  require 'shoulda-context'
13
12
  require 'mocha/setup'
13
+ require 'awesome_print'
14
14
 
15
15
  #require 'statsample-timeseries'
16
16
 
@@ -18,8 +18,8 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
18
  $LOAD_PATH.unshift(File.dirname(__FILE__))
19
19
  require 'statsample-timeseries'
20
20
  module MiniTest
21
- class Unit
22
- class TestCase
21
+ # class Unit
22
+ class Test
23
23
  include Shoulda::Context::Assertions
24
24
  include Shoulda::Context::InstanceMethods
25
25
  extend Shoulda::Context::ClassMethods
@@ -33,31 +33,9 @@ module MiniTest
33
33
  end
34
34
  end
35
35
  end
36
- end
36
+ # end
37
37
 
38
38
  module Assertions
39
- def assert_similar_vector(exp, obs, delta=1e-10,msg=nil)
40
- msg||="Different vectors #{exp} - #{obs}"
41
- assert_equal(exp.size, obs.size)
42
- exp.data_with_nils.each_with_index {|v,i|
43
- assert_in_delta(v,obs[i],delta)
44
- }
45
- end
46
- def assert_equal_vector(exp,obs,delta=1e-10,msg=nil)
47
- assert_equal(exp.size, obs.size, "Different size.#{msg}")
48
- exp.size.times {|i|
49
- assert_in_delta(exp[i],obs[i],delta, "Different element #{i}. \nExpected:\n#{exp}\nObserved:\n#{obs}.#{msg}")
50
- }
51
- end
52
- def assert_equal_matrix(exp,obs,delta=1e-10,msg=nil)
53
- assert_equal(exp.row_size, obs.row_size, "Different row size.#{msg}")
54
- assert_equal(exp.column_size, obs.column_size, "Different column size.#{msg}")
55
- exp.row_size.times {|i|
56
- exp.column_size.times {|j|
57
- assert_in_delta(exp[i,j],obs[i,j], delta, "Different element #{i},#{j}\nExpected:\n#{exp}\nObserved:\n#{obs}.#{msg}")
58
- }
59
- }
60
- end
61
39
  alias :assert_raise :assert_raises unless method_defined? :assert_raise
62
40
  alias :assert_not_equal :refute_equal unless method_defined? :assert_not_equal
63
41
  alias :assert_not_same :refute_same unless method_defined? :assert_not_same
@@ -77,5 +55,4 @@ module MiniTest
77
55
  end
78
56
  end
79
57
 
80
- MiniTest::Unit.autorun
81
-
58
+ MiniTest.autorun
@@ -0,0 +1,41 @@
1
+ require(File.expand_path(File.dirname(__FILE__)+'/helper.rb'))
2
+
3
+ class StatsampleTimeSeriesPacfTestCase < MiniTest::Test
4
+ context Statsample::TimeSeries do
5
+ include Statsample::TimeSeries
6
+
7
+ setup do
8
+ Daru.lazy_update = true
9
+ @timeseries = Daru::Vector.new((1..20).map { |e| e * 10 })
10
+ end
11
+
12
+ teardown do
13
+ Daru.lazy_update = false
14
+ end
15
+
16
+ should "cross-check ACF for 10 lags" do
17
+ lags = 10
18
+ result = @timeseries.acf(lags)
19
+ assert_equal result.size, 11
20
+ assert_equal result, [1.0, 0.85, 0.7015037593984963, 0.556015037593985,
21
+ 0.4150375939849624, 0.2800751879699248, 0.15263157894736842,
22
+ 0.034210526315789476, -0.07368421052631578, -0.16954887218045114,
23
+ -0.2518796992481203]
24
+ end
25
+
26
+ should "cross-check ACF for 5 lags" do
27
+ lags = 5
28
+ result = @timeseries.acf(lags)
29
+ assert_equal result.size, 6
30
+ assert_equal result, [1.0, 0.85, 0.7015037593984963, 0.556015037593985,
31
+ 0.4150375939849624, 0.2800751879699248]
32
+ end
33
+
34
+ should "first value should be 1" do
35
+ lags = 2
36
+ result = @timeseries.acf(lags)
37
+ assert_equal result.size, 3
38
+ assert_equal result.first, 1.0
39
+ end
40
+ end
41
+ end
@@ -1,25 +1,34 @@
1
1
  require(File.expand_path(File.dirname(__FILE__)+'/helper.rb'))
2
2
 
3
- class StatsampleArimaKSTestCase < MiniTest::Unit::TestCase
3
+ class StatsampleArimaKSTestCase < MiniTest::Test
4
4
 
5
5
  context("AR(0.5) simulation") do
6
6
  #include Statsample::TimeSeries
7
7
  setup do
8
- @s = [-1.16025577,0.64758021,0.77158601,0.14989543,2.31358162,3.49213868,1.14826956,0.58169457,-0.30813868,-0.34741084,-1.41175595,0.06040081, -0.78230232,0.86734837,0.95015787,-0.49781397,0.53247330,1.56495187,0.30936619,0.09750217,1.09698829,-0.81315490,-0.79425607,-0.64568547,-1.06460320,1.24647894,0.66695937,1.50284551,1.17631218,1.64082872,1.61462736,0.06443761,-0.17583741,0.83918339,0.46610988,-0.54915270,-0.56417108,-1.27696654,0.89460084,1.49970338,0.24520493,0.26249138,-1.33744834,-0.57725961,1.55819543,1.62143157,0.44421891,-0.74000084 ,0.57866347,3.51189333,2.39135077,1.73046244,1.81783890,0.21454040,0.43520890,-1.42443856,-2.72124685,-2.51313877,-1.20243091,-1.44268002 ,-0.16777305,0.05780661,2.03533992,0.39187242,0.54987983,0.57865693,-0.96592469,-0.93278473,-0.75962671,-0.63216906,1.06776183, 0.17476059 ,0.06635860,0.94906227,2.44498583,-1.04990407,-0.88440073,-1.99838258,-1.12955558,-0.62654882,-1.36589161,-2.67456821,-0.97187696, -0.84431782 ,-0.10051809,0.54239549,1.34622861,1.25598105,0.19707759,3.29286114,3.52423499,1.69146333,-0.10150024,0.45222903,-0.01730516, -0.49828727, -1.18484684,-1.09531773,-1.17190808,0.30207662].to_ts
8
+ Daru.lazy_update = true
9
+ @s = Daru::Vector.new([-1.16025577,0.64758021,0.77158601,0.14989543,2.31358162,3.49213868,1.14826956,0.58169457,-0.30813868,-0.34741084,-1.41175595,0.06040081, -0.78230232,0.86734837,0.95015787,-0.49781397,0.53247330,1.56495187,0.30936619,0.09750217,1.09698829,-0.81315490,-0.79425607,-0.64568547,-1.06460320,1.24647894,0.66695937,1.50284551,1.17631218,1.64082872,1.61462736,0.06443761,-0.17583741,0.83918339,0.46610988,-0.54915270,-0.56417108,-1.27696654,0.89460084,1.49970338,0.24520493,0.26249138,-1.33744834,-0.57725961,1.55819543,1.62143157,0.44421891,-0.74000084 ,0.57866347,3.51189333,2.39135077,1.73046244,1.81783890,0.21454040,0.43520890,-1.42443856,-2.72124685,-2.51313877,-1.20243091,-1.44268002 ,-0.16777305,0.05780661,2.03533992,0.39187242,0.54987983,0.57865693,-0.96592469,-0.93278473,-0.75962671,-0.63216906,1.06776183, 0.17476059 ,0.06635860,0.94906227,2.44498583,-1.04990407,-0.88440073,-1.99838258,-1.12955558,-0.62654882,-1.36589161,-2.67456821,-0.97187696, -0.84431782 ,-0.10051809,0.54239549,1.34622861,1.25598105,0.19707759,3.29286114,3.52423499,1.69146333,-0.10150024,0.45222903,-0.01730516, -0.49828727, -1.18484684,-1.09531773,-1.17190808,0.30207662])
9
10
  end
11
+
12
+ teardown do
13
+ Daru.lazy_update = false
14
+ end
15
+
10
16
  if Statsample.has_gsl?
11
17
  context "passed through the Kalman Filter" do
12
18
  setup do
13
19
  @kf=Statsample::TimeSeries::ARIMA.ks(@s,1,0,0)
14
20
  end
21
+
15
22
  should "return correct object" do
16
23
  assert_instance_of Statsample::TimeSeries::Arima::KalmanFilter, @kf
17
24
  end
25
+
18
26
  should "return correct parameters" do
19
27
  assert_equal @kf.p,1
20
28
  assert_equal @kf.q,0
21
29
  assert_equal @kf.i,0
22
30
  end
31
+
23
32
  should "return correct ar estimators" do
24
33
  assert_equal @kf.ar.length,1
25
34
  assert_in_delta @kf.ar[0], 0.700 #0.564
@@ -31,8 +40,10 @@ class StatsampleArimaKSTestCase < MiniTest::Unit::TestCase
31
40
  end
32
41
  context "passed through the Kalman Filter with AR(0.564)" do
33
42
  setup do
34
- @kf_likehood=Statsample::TimeSeries::Arima::KalmanFilter.log_likelihood([0.564],@s,1,0)
43
+ @kf_likehood = Statsample::TimeSeries::Arima::KalmanFilter.
44
+ log_likelihood([0.564],@s,1,0)
35
45
  end
46
+
36
47
  should "return correct object for log_likehood" do
37
48
  assert_instance_of Statsample::TimeSeries::Arima::KF::LogLikelihood, @kf_likehood
38
49
  end
@@ -45,8 +56,8 @@ class StatsampleArimaKSTestCase < MiniTest::Unit::TestCase
45
56
  should "return correct AIC value" do
46
57
  assert_in_delta 301.44, @kf_likehood.aic, 0.1
47
58
  end
48
-
49
59
  end
60
+
50
61
  context "passed through the Kalman Filter with AR(0.2)" do
51
62
  setup do
52
63
  @kf_likehood=Statsample::TimeSeries::Arima::KalmanFilter.log_likelihood([0.2],@s,1,0)
@@ -60,14 +71,14 @@ class StatsampleArimaKSTestCase < MiniTest::Unit::TestCase
60
71
  should "return correct sigma" do
61
72
  assert_in_delta 1.378693, @kf_likehood.sigma, 0.01
62
73
  end
63
-
64
74
  end
65
75
  end
66
76
 
67
77
  context("ARMA(1, 1) process") do
68
78
  setup do
69
- @s = [-1.16025577,0.64758021,0.77158601,0.14989543,2.31358162,3.49213868,1.14826956,0.58169457,-0.30813868,-0.34741084,-1.41175595,0.06040081, -0.78230232,0.86734837,0.95015787,-0.49781397,0.53247330,1.56495187,0.30936619,0.09750217,1.09698829,-0.81315490,-0.79425607,-0.64568547,-1.06460320,1.24647894,0.66695937,1.50284551,1.17631218,1.64082872,1.61462736,0.06443761,-0.17583741,0.83918339,0.46610988,-0.54915270,-0.56417108,-1.27696654,0.89460084,1.49970338,0.24520493,0.26249138,-1.33744834,-0.57725961,1.55819543,1.62143157,0.44421891,-0.74000084 ,0.57866347,3.51189333,2.39135077,1.73046244,1.81783890,0.21454040,0.43520890,-1.42443856,-2.72124685,-2.51313877,-1.20243091,-1.44268002 ,-0.16777305,0.05780661,2.03533992,0.39187242,0.54987983,0.57865693,-0.96592469,-0.93278473,-0.75962671,-0.63216906,1.06776183, 0.17476059 ,0.06635860,0.94906227,2.44498583,-1.04990407,-0.88440073,-1.99838258,-1.12955558,-0.62654882,-1.36589161,-2.67456821,-0.97187696, -0.84431782 ,-0.10051809,0.54239549,1.34622861,1.25598105,0.19707759,3.29286114,3.52423499,1.69146333,-0.10150024,0.45222903,-0.01730516, -0.49828727, -1.18484684,-1.09531773,-1.17190808,0.30207662].to_ts
79
+ @s = Daru::Vector.new([-1.16025577,0.64758021,0.77158601,0.14989543,2.31358162,3.49213868,1.14826956,0.58169457,-0.30813868,-0.34741084,-1.41175595,0.06040081, -0.78230232,0.86734837,0.95015787,-0.49781397,0.53247330,1.56495187,0.30936619,0.09750217,1.09698829,-0.81315490,-0.79425607,-0.64568547,-1.06460320,1.24647894,0.66695937,1.50284551,1.17631218,1.64082872,1.61462736,0.06443761,-0.17583741,0.83918339,0.46610988,-0.54915270,-0.56417108,-1.27696654,0.89460084,1.49970338,0.24520493,0.26249138,-1.33744834,-0.57725961,1.55819543,1.62143157,0.44421891,-0.74000084 ,0.57866347,3.51189333,2.39135077,1.73046244,1.81783890,0.21454040,0.43520890,-1.42443856,-2.72124685,-2.51313877,-1.20243091,-1.44268002 ,-0.16777305,0.05780661,2.03533992,0.39187242,0.54987983,0.57865693,-0.96592469,-0.93278473,-0.75962671,-0.63216906,1.06776183, 0.17476059 ,0.06635860,0.94906227,2.44498583,-1.04990407,-0.88440073,-1.99838258,-1.12955558,-0.62654882,-1.36589161,-2.67456821,-0.97187696, -0.84431782 ,-0.10051809,0.54239549,1.34622861,1.25598105,0.19707759,3.29286114,3.52423499,1.69146333,-0.10150024,0.45222903,-0.01730516, -0.49828727, -1.18484684,-1.09531773,-1.17190808,0.30207662])
70
80
  end
81
+
71
82
  if Statsample.has_gsl?
72
83
  context "passed through the Kalman Filter" do
73
84
  setup do
@@ -79,11 +90,13 @@ class StatsampleArimaKSTestCase < MiniTest::Unit::TestCase
79
90
  assert_equal @kf.q, 1
80
91
  assert_equal @kf.i, 0
81
92
  end
93
+
82
94
  should "return correct AR estimators" do
83
95
  assert_equal @kf.ar.length, 2
84
- assert_in_delta @kf.ar[0], 0.45, 0.01
85
- assert_in_delta @kf.ar[1], 0.016, 0.01
96
+ assert_in_delta @kf.ar[0], 0.46, 0.01
97
+ assert_in_delta @kf.ar[1], -0.22, 0.01
86
98
  end
99
+
87
100
  should "return correct ma estimators" do
88
101
  assert_equal @kf.ma.length, 1
89
102
  assert_in_delta @kf.ma[0], 0.18, 0.01
@@ -93,18 +106,21 @@ class StatsampleArimaKSTestCase < MiniTest::Unit::TestCase
93
106
 
94
107
  context "passed through the LogLikelihood with ARMA([0.45, 0.16, 0.18])" do
95
108
  setup do
96
- @ll = Statsample::TimeSeries::Arima::KF::LogLikelihood.new([0.45, 0.16, 0.18], @s, 2, 1)
109
+ log_likelihood = Statsample::TimeSeries::Arima::KF::LogLikelihood
110
+ @ll = log_likelihood.new([0.45, 0.16, 0.18], @s, 2, 1)
97
111
  end
112
+
98
113
  should "return correct log likelihood" do
99
- assert_in_delta -149.55, @ll.log_likelihood, 0.01
114
+ assert_in_delta -148.22, @ll.log_likelihood, 0.01
100
115
  end
116
+
101
117
  should "return correct sigma" do
102
118
  assert_in_delta 1.14, @ll.sigma, 0.1
103
119
  end
120
+
104
121
  should "return correct AIC value" do
105
- assert_in_delta 307.11, @ll.aic, 0.01
122
+ assert_in_delta 304.44, @ll.aic, 0.01
106
123
  end
107
124
  end
108
125
  end
109
-
110
126
  end
@@ -1,71 +1,88 @@
1
1
  require(File.expand_path(File.dirname(__FILE__)+'/helper.rb'))
2
2
 
3
- class StatsampleArimaSimulatorsTest < MiniTest::Unit::TestCase
3
+ class StatsampleArimaSimulatorsTest < MiniTest::Test
4
+ def setup
5
+ Daru.lazy_update = true
6
+ end
7
+
8
+ def teardown
9
+ Daru.lazy_update = false
10
+ end
11
+
4
12
  def generate_acf(simulation)
5
- ts = simulation.to_ts
13
+ ts = Daru::Vector.new(simulation)
6
14
  ts.acf
7
15
  end
8
16
 
9
17
  def generate_pacf(simulation)
10
- ts = simulation.to_ts
18
+ ts = Daru::Vector.new(simulation)
11
19
  ts.pacf
12
20
  end
21
+
13
22
  context("AR(1) simulations") do
14
23
  include Statsample
24
+ def self.generate_acf(simulation)
25
+ ts = Daru::Vector.new(simulation)
26
+ ts.acf
27
+ end
15
28
 
16
- setup do
17
- @series = TimeSeries.arima
18
- @ar_1_positive = @series.ar_sim(1500, [0.9], 2)
19
- @ar_1_negative = @series.ar_sim(1500, [-0.9], 2)
29
+ def self.generate_pacf(simulation)
30
+ ts = Daru::Vector.new(simulation)
31
+ ts.pacf
32
+ end
20
33
 
21
- #generating acf
22
- @positive_acf = generate_acf(@ar_1_positive)
23
- @negative_acf = generate_acf(@ar_1_negative)
34
+ # TODO: Try to speed this up.
35
+ @@series = TimeSeries.arima
36
+ @@ar_1_positive = @@series.ar_sim(1500, [0.9], 2)
37
+ @@ar_1_negative = @@series.ar_sim(1500, [-0.9], 2)
24
38
 
25
- #generating pacf
26
- @positive_pacf = generate_pacf(@ar_1_positive)
27
- @negative_pacf = generate_pacf(@ar_1_negative)
28
- end
39
+ #generating acf
40
+ @@positive_acf = generate_acf(@@ar_1_positive)
41
+ @@negative_acf = generate_acf(@@ar_1_negative)
42
+
43
+ #generating pacf
44
+ @@positive_pacf = generate_pacf(@@ar_1_positive)
45
+ @@negative_pacf = generate_pacf(@@ar_1_negative)
29
46
 
30
47
 
31
48
  should "have exponential decay of acf on positive side with phi > 0" do
32
- @acf = @positive_acf
33
- assert_equal @acf[0], 1.0
34
- assert_operator @acf[1], :>=, 0.7
35
- assert_operator @acf[@acf.size - 1], :<=, 0.2
49
+ acf = @@positive_acf
50
+ assert_equal acf[0], 1.0
51
+ assert_operator acf[1], :>=, 0.7
52
+ assert_operator acf[acf.size - 1], :<=, 0.2
36
53
  #visualization:
37
54
  #https://dl.dropboxusercontent.com/u/102071534/sciruby/AR%281%29_positive_phi_acf.png
38
55
  #https://dl.dropboxusercontent.com/u/102071534/sciruby/AR%281%29_positive_phi_acf_line.png
39
56
  end
40
57
 
41
58
  should "have series with alternating sign on acf starting on negative side with phi < 0" do
42
- @acf = @negative_acf
43
- assert_equal @acf[0], 1.0
59
+ acf = @@negative_acf
60
+ assert_equal acf[0], 1.0
44
61
  #testing for alternating series
45
- assert_operator @acf[1], :<, 0
46
- assert_operator @acf[2], :>, 0
47
- assert_operator @acf[3], :<, 0
48
- assert_operator @acf[4], :>, 0
62
+ assert_operator acf[1], :<, 0
63
+ assert_operator acf[2], :>, 0
64
+ assert_operator acf[3], :<, 0
65
+ assert_operator acf[4], :>, 0
49
66
  #visualization:
50
67
  #https://dl.dropboxusercontent.com/u/102071534/sciruby/AR%281%29_negative_phi_acf.png
51
68
  #https://dl.dropboxusercontent.com/u/102071534/sciruby/AR%281%29_negative_phi_acf_line.png
52
69
  end
53
70
 
54
71
  should "have positive spike on pacf at lag 1 for phi > 0" do
55
- @pacf = @positive_pacf
56
- assert_operator @pacf[1], :>=, 0.7
57
- assert_operator @pacf[2], :<=, 0.2
58
- assert_operator @pacf[3], :<=, 0.14
72
+ pacf = @@positive_pacf
73
+ assert_operator pacf[1], :>=, 0.7
74
+ assert_operator pacf[2], :<=, 0.2
75
+ assert_operator pacf[3], :<=, 0.14
59
76
  #visualization:
60
77
  #https://dl.dropboxusercontent.com/u/102071534/sciruby/AR%281%29_postive_phi_pacf.png
61
78
  #https://dl.dropboxusercontent.com/u/102071534/sciruby/AR%281%29_postive_phi_pacf_line.png
62
79
  end
63
80
 
64
81
  should "have negative spike on pacf at lag 1 for phi < 0" do
65
- @pacf = @negative_pacf
66
- assert_operator @pacf[1], :<=, 0
67
- assert_operator @pacf[1], :<=, -0.5
68
- assert_operator @pacf[2], :>=, -0.5
82
+ pacf = @@negative_pacf
83
+ assert_operator pacf[1], :<=, 0
84
+ assert_operator pacf[1], :<=, -0.5
85
+ assert_operator pacf[2], :>=, -0.5
69
86
  #visualizaton:
70
87
  #https://dl.dropboxusercontent.com/u/102071534/sciruby/AR%281%29_negative_phi_pacf.png
71
88
  #[hided @pacf[0] = 1 to convey accurate picture]
@@ -74,17 +91,19 @@ class StatsampleArimaSimulatorsTest < MiniTest::Unit::TestCase
74
91
 
75
92
  context("AR(p) simulations") do
76
93
  include Statsample
77
-
78
94
  setup do
95
+ Daru.lazy_update = true
79
96
  @series = TimeSeries.arima
80
97
  @ar_p_positive = @series.ar_sim(1500, [0.3, 0.5], 2)
81
98
  @ar_p_negative = @series.ar_sim(1500, [-0.3, -0.5], 2)
82
99
  end
83
100
 
101
+ teardown do
102
+ Daru.lazy_update = false
103
+ end
84
104
 
85
105
  should "have damped sine wave starting on positive side on acf" do
86
- @ar = @ar_p_positive
87
- @acf = generate_acf(@ar)
106
+ @acf = generate_acf(@ar_p_positive)
88
107
  assert_operator @acf[0], :>=, @acf[1]
89
108
  assert_operator @acf[1], :>=, 0.0
90
109
  #caution: sine curve can split on cartesian plane,
@@ -93,8 +112,7 @@ class StatsampleArimaSimulatorsTest < MiniTest::Unit::TestCase
93
112
  end
94
113
 
95
114
  should "have damped sine wave starting on negative side on acf" do
96
- @ar = @ar_p_negative
97
- @acf = generate_acf(@ar)
115
+ @acf = generate_acf(@ar_p_negative)
98
116
  assert_operator @acf[0], :>=, @acf[1]
99
117
  assert_operator @acf[1], :<=, 0.0
100
118
  assert_operator @acf[1], :>=, @acf[2]
@@ -105,8 +123,7 @@ class StatsampleArimaSimulatorsTest < MiniTest::Unit::TestCase
105
123
 
106
124
  should "have spikes from 1 to p for pacf" do
107
125
  #here p = 2
108
- @ar = @ar_p_positive
109
- @pacf = generate_pacf(@ar)
126
+ @pacf = generate_pacf(@ar_p_positive)
110
127
  assert_equal @pacf[0], 1.0
111
128
  assert_operator @pacf[1], :>, @pacf[3]
112
129
  assert_operator @pacf[1], :>, @pacf[4]
@@ -149,7 +166,6 @@ class StatsampleArimaSimulatorsTest < MiniTest::Unit::TestCase
149
166
  #positive_vs_negative:
150
167
  #https://dl.dropboxusercontent.com/u/102071534/sciruby/MA%281%29_acf_positive_vs_negative.png
151
168
  end
152
-
153
169
  end
154
170
 
155
171
  context("MA(q) simulations") do
@@ -177,10 +193,11 @@ class StatsampleArimaSimulatorsTest < MiniTest::Unit::TestCase
177
193
  include Statsample
178
194
 
179
195
  setup do
180
- @timeseries = 100.times.map { rand }.to_ts
196
+ @timeseries = Daru::Vector.new(100.times.map { rand })
181
197
  @arma_simulation =->(n) { @timeseries.ar(n, k)}
182
198
  end
183
- #to write test
199
+
200
+ # TODO: write tests
184
201
  end
185
202
  end
186
203
 
@@ -1,5 +1,5 @@
1
1
  require(File.expand_path(File.dirname(__FILE__)+'/helper.rb'))
2
- class StatsampleMatrixTestCase < MiniTest::Unit::TestCase
2
+ class StatsampleMatrixTestCase < MiniTest::Test
3
3
 
4
4
  def setup_square_matrix(arr, n)
5
5
  #returns n * n matrix by slicing arr