Skip to content

Commit 53db728

Browse files
committed
update Fit docs for YARD
1 parent 70374cf commit 53db728

File tree

1 file changed

+68
-47
lines changed

1 file changed

+68
-47
lines changed

lib/gnuplotrb/fit.rb

Lines changed: 68 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
module GnuplotRB
22
##
3-
# Contains methods relating to Gnuplot's fit function.
3+
# Contains methods relating to Gnuplot's fit function. Covered in
4+
# {fit notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/fitting_data.ipynb].
5+
#
6+
# You can also see original gnuplot's fit in gnuplot
7+
# doc - http://www.gnuplot.info/docs_5.0/gnuplot.pdf p. 122.
48
module Fit
59
##
6-
# ====== Overview
7-
# Fit given data with function. Covered in
8-
# {fit notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/fitting_data.ipynb].
9-
# ====== Arguments
10-
# * *data* - method accepts the same sources as Dataset.new
10+
# Fit given data with function.
11+
#
12+
# Fit waits for output from gnuplot Settings.max_fit_delay and throw exception if gets nothing.
13+
# One can change this value in order to wait longer (if huge datasets is fitted).
14+
#
15+
# @param data [#to_gnuplot_points] method accepts the same sources as Dataset.new
1116
# and Dataset object
12-
# * *:function* - function to fit data with. Default 'a2*x*x+a1*x+a0'
13-
# * *:initials* - initial values for coefficients used in fitting.
14-
# Default: {a2: 1, a1: 1, a0: 1}
15-
# * *:term_options* - terminal options that should be setted to terminal before fit.
16-
# You can see them in Plot's documentation (or even better in gnuplot doc).
17+
# @param :function [String] function to fit data with
18+
# @param :initials [Hash] initial values for coefficients used in fitting
19+
# @param :term_options [Hash] terminal options that should be setted to terminal before fit.
20+
# You can see them in Plot's documentation (or even better in gnuplot doc)
1721
# Most useful here are ranges (xrange, yrange etc) and fit option which tunes fit parameters
18-
# (see {gnuplot doc}[http://www.gnuplot.info/docs_5.0/gnuplot.pdf] p. 122).
19-
# * *options* - options passed to Gnuplot's fit such as *using*. They are covered in
20-
# {gnuplot doc}[http://www.gnuplot.info/docs_5.0/gnuplot.pdf](pp. 69-74)
21-
# ====== Return value
22-
# Fit returns hash of 4 elements:
23-
# * *:formula_ds* - dataset with best fit curve as data
24-
# * *:coefficients* - hash of calculated coefficients. So if you gave {via: [:a, :b, :c]} or
25-
# {initials: {a: 1, b: 1, c: 1} } it will return hash with keys :a, :b, :c and its values
26-
# * *:deltas* - Gnuplot calculates possible deltas for coefficients during fitting and
27-
# *deltas* hash contains this deltas
28-
# * *:data* - pointer to Datablock with given data
29-
# ====== Examples
22+
# (see gnuplot doc - http://www.gnuplot.info/docs_5.0/gnuplot.pdf p. 122)
23+
# @param options [Hash] options passed to Gnuplot's fit such as *using*. They are covered in
24+
# gnuplot doc - http://www.gnuplot.info/docs_5.0/gnuplot.pdf (pp. 69-74)
25+
#
26+
# @return [Hash] hash with four elements:
27+
# - :formula_ds - dataset with best fit curve as data
28+
# - :coefficients - hash of calculated coefficients. So if you gave
29+
# ``{ initials: {a: 1, b: 1, c: 1} }`` it will return hash with keys :a, :b, :c and its values
30+
# - :deltas - Gnuplot calculates possible deltas for coefficients during fitting and
31+
# deltas hash contains this deltas
32+
# - :data - pointer to Datablock with given data
33+
# @example
3034
# fit(some_data, function: 'exp(a/x)', initials: {a: 10}, term_option: { xrange: 1..100 })
3135
# fit(some_dataset, using: '1:2:3')
3236
def fit(data, function: 'a2*x*x+a1*x+a0', initials: { a2: 1, a1: 1, a0: 1 }, term_options: {}, **options)
@@ -43,17 +47,24 @@ def fit(data, function: 'a2*x*x+a1*x+a0', initials: { a2: 1, a1: 1, a0: 1 }, ter
4347
end
4448

4549
##
46-
# ====== Overview
4750
# Shortcut for fit with polynomial. Degree here is max power of *x* in polynomial.
48-
# ====== Arguments
49-
# * *data* - method accepts the same sources as Dataset.new and Dataset object
50-
# * *:degree* - degree of polynomial
51-
# * *options* - all of this options will be passed to *#fit* so you
52-
# can set here any *term_options*. If you pass here *:initials* hash, it
53-
# will be merged into default initals hash (all values are 1).
54-
# ====== Return value
55-
# See the same section for #fit.
56-
# ====== Examples
51+
#
52+
# @param data [#to_gnuplot_points] method accepts the same sources as Dataset.new
53+
# and Dataset object
54+
# @param :degree [Integer] degree of polynomial
55+
# @param options [Hash] all of this options will be passed to #fit so you
56+
# can set here any options listed in its docs. If you pass here :initials hash, it
57+
# will be merged into default initals hash. Formula by default is
58+
# "xn*x**n + ... + x0*x**0", initials by default "{ an: 1, ..., a0: 1 }"
59+
#
60+
# @return [Hash] hash with four elements:
61+
# - :formula_ds - dataset with best fit curve as data
62+
# - :coefficients - hash of calculated coefficients. So for degree = 3
63+
# it will return hash with keys :a3, :a2, :a1, :a0 and calculated values
64+
# - :deltas - Gnuplot calculates possible deltas for coefficients during fitting and
65+
# deltas hash contains this deltas
66+
# - :data - pointer to Datablock with given data
67+
# @example
5768
# fit_poly(some_data, degree: 5, initials: { a4: 10, a2: -1 }, term_option: { xrange: 1..100 })
5869
# #=> The same as:
5970
# #=> fit(
@@ -72,22 +83,29 @@ def fit_poly(data, degree: 2, **options)
7283
end
7384

7485
##
75-
# :method: fit_<function>
76-
# :call-seq:
77-
# fit_exp(data, **options) -> Hash
78-
# fit_log(data, **options) -> Hash
79-
# fit_sin(data, **options) -> Hash
86+
# @!method fit_exp(data, **options)
87+
# @!method fit_log(data, **options)
88+
# @!method fit_sin(data, **options)
8089
#
81-
# ====== Overview
8290
# Shortcuts for fitting with several math functions (exp, log, sin).
83-
# ====== Arguments
84-
# * *data* - method accepts the same sources as Dataset.new and Dataset object
85-
# * *options* - all of this options will be passed to *#fit* so you
86-
# can set here any *term_options*. If you pass here *:initials* hash, it
87-
# will be merged into default initals hash { yoffset: 0.1, xoffset: 0.1, yscale: 1, xscale: 1 }
88-
# ====== Return value
89-
# See the same section for #fit.
90-
# ====== Examples
91+
#
92+
# @param data [#to_gnuplot_points] method accepts the same sources as Dataset.new
93+
# and Dataset object
94+
# @param options [Hash] all of this options will be passed to #fit so you
95+
# can set here any options listed in its docs. If you pass here :initials hash, it
96+
# will be merged into default initals hash. Formula by default is
97+
# "yscale * (yoffset + #{function name}((x - xoffset) / xscale))", initials by default
98+
# "{ yoffset: 0.1, xoffset: 0.1, yscale: 1, xscale: 1 }"
99+
#
100+
# @return [Hash] hash with four elements:
101+
# - :formula_ds - dataset with best fit curve as data
102+
# - :coefficients - hash of calculated coefficients. So for this case
103+
# it will return hash with keys :yoffset, :xoffset, :yscale, :xscale and calculated values
104+
# - :deltas - Gnuplot calculates possible deltas for coefficients during fitting and
105+
# deltas hash contains this deltas
106+
# - :data - pointer to Datablock with given data
107+
#
108+
# @example
91109
# fit_exp(some_data, initials: { yoffset: -11 }, term_option: { xrange: 1..100 })
92110
# #=> The same as:
93111
# #=> fit(
@@ -116,6 +134,9 @@ def fit_poly(data, degree: 2, **options)
116134
##
117135
# It takes some time to produce output so here we need
118136
# to wait for it.
137+
#
138+
# Max time to wait is stored in Settings.max_fit_delay, so one
139+
# can change it in order to wait longer.
119140
def wait_for_output(term, variables)
120141
# now we should catch 'error' from terminal: it will contain approximation data
121142
# but we can get a real error instead of output, so lets wait for limited time

0 commit comments

Comments
 (0)