Created
August 2, 2015 18:45
-
-
Save v0dro/aeca5867c315a3dc9b65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'daru' | |
require 'gnuplotrb' | |
require 'statsample-timeseries' | |
index = Daru::DateTimeIndex.date_range :start => '2012', :periods => 500 | |
iteration_count = 500 | |
actual_values = Daru::Vector.new(iteration_count.times.map { |j| -0.37727 + j * j * 0.00001}, index: index) | |
noisy_data = Daru::Vector.new(actual_values.map { |actual_val| rand * 0.6 - 0.3 + actual_val }, index: index) | |
GnuplotRB::Plot.new( | |
[actual_values, with: 'line', title: 'Actual Values'], | |
[noisy_data, with: 'line', title: 'Noisy Data']) | |
# This yields this graph: https://drive.google.com/file/d/0B5WTqLfjBC0pNFktTnhzSldOQmc/view?usp=sharing | |
# Inputs to KalmanFilter are: | |
# Data to be passed into filter - noisy_data | |
# Autoregressive order - 2 | |
# Integrated part order - 1 | |
# Moving average order - 1 | |
a=Statsample::TimeSeries::Arima::KalmanFilter.new(noisy_data, 2,1,1) | |
# Moving average coefficients | |
a.ma #=>[0.4] | |
# Autocorrelation coefficients | |
a.ar #=>[0.5, 0.0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment