Method: GnuplotRB::Fit#fit

Defined in:
lib/gnuplotrb/fit.rb

#fit(data, function: 'a2*x*x+a1*x+a0', initials: { a2: 1, a1: 1, a0: 1 }, term_options: {}, **options) ⇒ Hash

Fit given data with function.

Fit waits for output from gnuplot Settings.max_fit_delay and throw exception if gets nothing. One can change this value in order to wait longer (if huge datasets is fitted).

Examples:

fit(some_data, function: 'exp(a/x)', initials: {a: 10}, term_option: { xrange: 1..100 })
fit(some_dataset, using: '1:2:3')


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gnuplotrb/fit.rb', line 36

def fit(data, function: 'a2*x*x+a1*x+a0', initials: { a2: 1, a1: 1, a0: 1 }, term_options: {}, **options)
  dataset = data.is_a?(Dataset) ? Dataset.new(data.data) : Dataset.new(data)
  opts_str = OptionHandling.ruby_class_to_gnuplot(options)
  output = gnuplot_fit(function, dataset, opts_str, initials, term_options)
  res = parse_output(initials.keys, function, output)
  {
    formula_ds: Dataset.new(res[2], title: 'Fit formula'),
    coefficients: res[0],
    deltas: res[1],
    data: dataset
  }
end