Class: Loess::Interpolator

Inherits:
Object
  • Object
show all
Defined in:
lib/loess.rb

Constant Summary collapse

DEFAULT_ACCURACY =

Sane Defaults as per Apache

1e-12
DEFAULT_BANDWIDTH =

A sensible value is usually 0.25 to 0.5

0.3
DEFAULT_ROBUSTNESS_FACTOR =

number of iterations to refine over 1 or 2 is usually good enough

2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = [], options = {}) ⇒ Interpolator

data: Accepts array of [x, y] pairs e.g. [ [1, 2], [3, 4], [5, 6], [0, 42] ] For options, refer to defaults above



16
17
18
19
20
21
22
23
# File 'lib/loess.rb', line 16

def initialize(data = [], options = {})
  @xval, @yval           = split_up(data)
  self.accuracy          = Float(options[:accuracy] || DEFAULT_ACCURACY)
  self.bandwidth         = Float(options[:bandwidth] || DEFAULT_BANDWIDTH)
  self.robustness_factor = Integer(options[:robustness_factor] || DEFAULT_ROBUSTNESS_FACTOR)
  @klass                 = Rjb::import('org.apache.commons.math3.analysis.interpolation.LoessInterpolator')
  @interpolator          = @klass.new(bandwidth, robustness_factor, accuracy)
end

Instance Attribute Details

#accuracyObject

Returns the value of attribute accuracy.



7
8
9
# File 'lib/loess.rb', line 7

def accuracy
  @accuracy
end

#bandwidthObject

Returns the value of attribute bandwidth.



7
8
9
# File 'lib/loess.rb', line 7

def bandwidth
  @bandwidth
end

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/loess.rb', line 7

def data
  @data
end

#robustness_factorObject

Returns the value of attribute robustness_factor.



7
8
9
# File 'lib/loess.rb', line 7

def robustness_factor
  @robustness_factor
end

Class Method Details

.interpolate(data, options = {}) ⇒ Object

Accepts array of [x, y] pairs e.g. [ [1, 2], [3, 4], [5, 6], [0, 42] ]



41
42
43
# File 'lib/loess.rb', line 41

def self.interpolate(data, options = {})
  new(data, options).interpolate
end

Instance Method Details

#interpolate(data = nil) ⇒ Object

Accepts array of [x, y] pairs e.g. [ [1, 2], [3, 4], [5, 6], [0, 42] ]



27
28
29
30
# File 'lib/loess.rb', line 27

def interpolate(data = nil)
  @xval, @yval = split_up(data) if data
  @interpolator.smooth(@xval, @yval)
end

#spline_interpolator(data = nil) ⇒ Object

Accepts array of [x, y] pairs e.g. [ [1, 2], [3, 4], [5, 6], [0, 42] ]



34
35
36
37
# File 'lib/loess.rb', line 34

def spline_interpolator(data = nil)
  @xval, @yval = split_up(data) if data
  @interpolator.interpolator(@xval, smooth(@xval, @yval))
end