Class Dobjects::Function
In: ext/Dobjects/Dvector/dvector.c
lib/Dobjects/Function_extras.rb
Parent: Object

Function is a class that embeds two Dvectors, one for X data and one for Y data. It provides

And getting bigger (almost) everyday…

Methods

Public Class methods

Sorts x, while ensuring that the corresponding y values keep matching. Should be pretty fast, as it is derived from glibc‘s quicksort.

 a = Dvector[3,2,1]
 b = a * 2                 -> [6,4,2]
 Function.joint_sort(a,b)  -> [[1,2,3], [2,4,6]]

Creates a Function object with given x and y values.

Public Instance methods

Returns a Dvector with two elements: the X and Y values of the point at the given index.

This function browses the points inside the Function and stores in the resulting new function only points which are within boundaries, and the points just next to them (so the general direction on the sides looks fine).

Make sure xmin < xmax and ymin < ymax, else you simply won‘t get any output.

Returns [xmin, ymin, xmax, ymax]

Interpolates the value of the function at the points given. Returns a brand new Dvector. The X values must be sorted !

Computes spline data and caches it inside the object. Both X and Y vectors are cleared (see Dvector#clear) to make sure the cache is kept up-to-date. If the function is not sorted, sorts it.

Computes the derivative of the Function and returns it as a new Function. The newly created function shares the X vector with the previous one.

WARNING: this is a very naive 3-points algorithm; you should consider using diff_5p

Computes a 4th order accurate second derivative of the Function.

This function requires that there are at the very least 5 data points!

Computes a 4th order accurate derivative of the Function.

This function requires that there are at the very least 5 data points !

Returns the distance of the function to the given point. Optionnal xscale and yscale says by how much we should divide the x and y coordinates before computing the distance. Use it if the distance is not homogeneous.

Iterates over all the points in the Function, yielding X and Y for each point.

Fuzzy substraction of two curves. Substracts the Y values of op to the current Function, by making sure that the Y value substracted to a given point corresponds to the closest X_ value of the point in op. This function somehow assumes that the data is reasonably organised, and will never go backwards to find a matching X value in op.

In any case, you really should consider using split_monotonic on it first.

: Returns the value of the integral of the function between the two indexes given, or over the whole function if no indexes are specified.

Computes interpolated values of the data contained in f and returns a Function object holding both x_values and the computed Y values. x_values will be sorted if necessary.

With the second form, specify only the number of points, and the function will construct the appropriate vector with equally spaced points within the function range.

is_sorted()

Alias for sorted?

length()

Alias for size

Returns an interpolant that can be fed to Special_Paths#append_interpolant_to_path to make nice splines.

Can be used this way:

 f = Function.new(x,y)
 t.append_interpolant_to_path(f.make_interpolant)
 t.stroke

Returns the point where Y is the maximum

Returns the point where Y is the minimum

Returns a Dvector with two elements: the X and Y values of the point at the given index.

Computes the primitive of the Function (whose value for the first point is 0) and returns it as a new Function. The newly created function shares the X vector with the previous one.

Performs a linear regression of the Function; returns the pair

 [ a, b]

where f(x) = a*x + b

if the optional arguments first and last are provided, they represent the indices of the first and last elements.

 Reverses the function. Equivalent to doing

 x.reverse!
 y.reverse!

excepted that it is faster (though not much faster).

Returns the number of points inside the function.

Attempts to pick a smooth value for a point, according to the algorithm implented for "smooth" markers in Soas. See DOI: 10.1016/j.bioelechem.2009.02.010

Warning: be wary of this function as it will return a correct value only for rather noisy data !

Sorts the X values while keeping the matching Y values.

Checks if the X values of the Function are sorted.

Filters the Function through interpolation. params holds a hash with the following values:

  ??

It returns a hash.

Splits the function into strictly monotonic sub-functions. Returns the array of the subfunctions. The returned values are necessarily new values.

Splits the function on NaN values for x, y or xy, depending on whether sym is +:x+, +:y+ or +:xy+ (or, as a matter of fact, anything else than +:x+ or +:y+).

This returns an array of new Function objects.

This function will return empty Function objects between consecutive NaN values.

Strips all the points containing NaN values from the function, and returns the number of points stripped.

The X vector.

The Y vector.

[Validate]