AlgART Home

net.algart.math.functions
Interface Func

All Known Subinterfaces:
Func.Updatable
All Known Implementing Classes:
AbstractFunc, ApertureFilteredFunc, AverageExceptingNaN, ConstantFunc, ContrastingFunc, CoordinateTransformedFunc, DividingFunc, ExpFunc, FirstExceptingNaN, HyperboloidOfRevolutionFunc, InverseNumberFunc, InverseNumberFunc.Updatable, LastExceptingNaN, LinearFunc, LinearFunc.Updatable, LogFunc, MaxExceptingNaN, MaxFromTwoSelectedNumbersFunc, MinExceptingNaN, MinFromTwoSelectedNumbersFunc, MultiplyingFunc, ParaboloidOfRevolutionFunc, PowerFunc, PowerFunc.Updatable, RectangularFunc, SelectConstantFunc, UpperHalfEllipsoidOfRevolutionFunc, WeightedMeanFunc

public interface Func

Abstract mathematical function f(x0, x1, ..., xn-1), or f(x), where x is a point of the n-dimensional space.

Implementations of this interface are usually immutable and always thread-safe: get methods of this interface may be freely used while simultaneous accessing to the same instance from several threads. All implementations of this interface from this package are immutable.

AlgART Laboratory 2007-2013

Since:
JDK 1.5
Version:
1.2
Author:
Daniel Alievsky

Nested Class Summary
Modifier and Type Interface and Description
static interface Func.Updatable
          "Updatable" mathematical function: an extension of Func interface allowing assigning values to the function result, that leads to corresponding correction of arguments.
 
Field Summary
Modifier and Type Field and Description
static Func ABS
          Absolute value function: f(x0) = |x0|.
static Func ABS_DIFF
          Absolute value of the difference of 2 numbers: f(x0, x1) = |x0-x1|.
static LinearFunc HALF_X_MINUS_Y
          An instance of LinearFunc class, describing the linear function (x0 - x1)/2: LinearFunc.getInstance(0.0, 0.5, -0.5).
static LinearFunc HALF_X_PLUS_Y
          An instance of LinearFunc class, describing the linear function (x0 + x1)/2: LinearFunc.getInstance(0.0, 0.5, 0.5).
static LinearFunc HALF_Y_MINUS_X
          An instance of LinearFunc class, describing the linear function (x1 - x0)/2: LinearFunc.getInstance(0.0, -0.5, 0.5).
static Func IDENTITY
          Identity function, just returning its first argument: f(x0, x1, ..., xn-1) = x0.
static Func MAX
          Maximum from several numbers: f(x0, x1, ..., xn-1) = min(x0, x1, ..., xn-1).
static Func MIN
          Minimum from several numbers: f(x0, x1, ..., xn-1) = min(x0, x1, ..., xn-1).
static Func POSITIVE_DIFF
          Positive difference of 2 numbers: f(x0, x1) = max(x0-x1,0).
static LinearFunc REVERSE
          An instance of LinearFunc class, describing the linear function 1.0 - x0: LinearFunc.getInstance(1.0, -1.0).
static Func SELECT
          Select function: f(x0, x1, ..., xn-1) = xi+1, where i is x0 cast to integer type: i=(int)x[0].
static Func SELECT_FROM_8_DIRECTIONS_2D
          Selecting from 8 "integer" directions on 2D plane: f(x0, x1) = integer code from 1 to 8.
static Func SELECT_IF_GREATER
          Select function: f(x0, x1, x2, x3) = x0 > x1 ? x2 : x3.
static Func SELECT_IF_GREATER_OR_EQUAL
          Select function: f(x0, x1, x2, x3) = x0 >= x1 ? x2 : x3.
static java.util.List<IPoint> SHIFTS_ALONG_8_DIRECTIONS_2D
          Vectors, corresponding to 8 directions recognized by SELECT_FROM_8_DIRECTIONS_2D function.
static Func.Updatable UPDATABLE_IDENTITY
          Updatable version of IDENTITY function.
static LinearFunc X_MINUS_Y
          An instance of LinearFunc class, describing the linear function x0 - x1: LinearFunc.getInstance(0.0, 1.0, -1.0).
static LinearFunc X_PLUS_Y
          An instance of LinearFunc class, describing the linear function x0 + x1: LinearFunc.getInstance(0.0, 1.0, 1.0).
static LinearFunc Y_MINUS_X
          An instance of LinearFunc class, describing the linear function x1 - x0: LinearFunc.getInstance(0.0, -1.0, 1.0).
 
Method Summary
Modifier and Type Method and Description
 double get()
          Equivalent to get(new double[0]).
 double get(double... x)
          Returns the result of this function for the given arguments: f(x0, x1, ..., xx.length-1).
 double get(double x0)
          Equivalent to get(new double[] {x0}).
 double get(double x0, double x1)
          Equivalent to get(new double[] {x0, x1}).
 double get(double x0, double x1, double x2)
          Equivalent to get(new double[] {x0, x1, x2}).
 double get(double x0, double x1, double x2, double x3)
          Equivalent to get(new double[] {x0, x1, x2, x3}).
 

Field Detail

IDENTITY

static final Func IDENTITY
Identity function, just returning its first argument: f(x0, x1, ..., xn-1) = x0. The get(double...) method of this object requires at least 1 argument and throws IndexOutOfBoundsException if the number of arguments is 0.

This instance is immutable and thread-safe: there are no ways to modify its settings.


UPDATABLE_IDENTITY

static final Func.Updatable UPDATABLE_IDENTITY
Updatable version of IDENTITY function.

This instance is immutable and thread-safe: there are no ways to modify its settings.


MAX

static final Func MAX
Maximum from several numbers: f(x0, x1, ..., xn-1) = min(x0, x1, ..., xn-1). The get(double...) method of this object may process any number of arguments. If the number of arguments is 0, it returns Double.NEGATIVE_INFINITY.

Unlike standard Math.max method, this function supposes that max(x,y) = x>y ? x : y

This instance is immutable and thread-safe: there are no ways to modify its settings.


MIN

static final Func MIN
Minimum from several numbers: f(x0, x1, ..., xn-1) = min(x0, x1, ..., xn-1). The get(double...) method of this object may process any number of arguments. If the number of arguments is 0, it returns Double.POSITIVE_INFINITY.

Unlike standard Math.min method, this function supposes that min(x,y) = x<y ? x : y

This instance is immutable and thread-safe: there are no ways to modify its settings.


ABS

static final Func ABS
Absolute value function: f(x0) = |x0|. More precisely, the result of this function is StrictMath.abs(x[0]). The get(double...) method of this object requires at least 1 argument and throws IndexOutOfBoundsException if the number of arguments is 0. All calculations are performed in strictfp mode, so the result is absolutely identical on all platforms.

This instance is immutable and thread-safe: there are no ways to modify its settings.


ABS_DIFF

static final Func ABS_DIFF
Absolute value of the difference of 2 numbers: f(x0, x1) = |x0-x1|. The get(double...) method of this object requires at least 2 arguments and throws IndexOutOfBoundsException if the number of arguments is 0 or 1. All calculations are performed in strictfp mode, so the result is absolutely identical on all platforms.

This instance is immutable and thread-safe: there are no ways to modify its settings.


POSITIVE_DIFF

static final Func POSITIVE_DIFF
Positive difference of 2 numbers: f(x0, x1) = max(x0-x1,0). The get(double...) method of this object requires at least 2 arguments and throws IndexOutOfBoundsException if the number of arguments is 0 or 1. All calculations are performed in strictfp mode, so the result is absolutely identical on all platforms.

This instance is immutable and thread-safe: there are no ways to modify its settings.


X_PLUS_Y

static final LinearFunc X_PLUS_Y
An instance of LinearFunc class, describing the linear function x0 + x1: LinearFunc.getInstance(0.0, 1.0, 1.0).

This instance is immutable and thread-safe: there are no ways to modify its settings.


X_MINUS_Y

static final LinearFunc X_MINUS_Y
An instance of LinearFunc class, describing the linear function x0 - x1: LinearFunc.getInstance(0.0, 1.0, -1.0).

This instance is immutable and thread-safe: there are no ways to modify its settings.


Y_MINUS_X

static final LinearFunc Y_MINUS_X
An instance of LinearFunc class, describing the linear function x1 - x0: LinearFunc.getInstance(0.0, -1.0, 1.0).

This instance is immutable and thread-safe: there are no ways to modify its settings.


HALF_X_PLUS_Y

static final LinearFunc HALF_X_PLUS_Y
An instance of LinearFunc class, describing the linear function (x0 + x1)/2: LinearFunc.getInstance(0.0, 0.5, 0.5).

This instance is immutable and thread-safe: there are no ways to modify its settings.


HALF_X_MINUS_Y

static final LinearFunc HALF_X_MINUS_Y
An instance of LinearFunc class, describing the linear function (x0 - x1)/2: LinearFunc.getInstance(0.0, 0.5, -0.5).

This instance is immutable and thread-safe: there are no ways to modify its settings.


HALF_Y_MINUS_X

static final LinearFunc HALF_Y_MINUS_X
An instance of LinearFunc class, describing the linear function (x1 - x0)/2: LinearFunc.getInstance(0.0, -0.5, 0.5).

This instance is immutable and thread-safe: there are no ways to modify its settings.


REVERSE

static final LinearFunc REVERSE
An instance of LinearFunc class, describing the linear function 1.0 - x0: LinearFunc.getInstance(1.0, -1.0). This instance describes logical NOT operation in a case when the arguments are bits (0 and 1 values).

This instance is immutable and thread-safe: there are no ways to modify its settings.


SELECT

static final Func SELECT
Select function: f(x0, x1, ..., xn-1) = xi+1, where i is x0 cast to integer type: i=(int)x[0]. The get(double...) method of this object requires at least 2 arguments and throws IndexOutOfBoundsException if the number of arguments is 0 or 1.

This instance is immutable and thread-safe: there are no ways to modify its settings.


SELECT_IF_GREATER

static final Func SELECT_IF_GREATER
Select function: f(x0, x1, x2, x3) = x0 > x1 ? x2 : x3. The get(double...) method of this object requires at least 4 arguments and throws IndexOutOfBoundsException if the number of arguments is 0, 1, 2 or 3.

Note: call of this function is almost equivalent to calling SELECT_IF_GREATER_OR_EQUAL function with another order of the arguments: f(x1, x0, x3, x2), that is x1 >= x0 ? x3 : x2. The only difference is connected with processing Double.NaN values of x0 and x1: this function will choose x3, but the corresponding call of SELECT_IF_GREATER_OR_EQUAL will choose x2, because in Java any comparison with Double.NaN returns false.

This instance is immutable and thread-safe: there are no ways to modify its settings.


SELECT_IF_GREATER_OR_EQUAL

static final Func SELECT_IF_GREATER_OR_EQUAL
Select function: f(x0, x1, x2, x3) = x0 >= x1 ? x2 : x3. The get(double...) method of this object requires at least 4 arguments and throws IndexOutOfBoundsException if the number of arguments is 0, 1, 2 or 3.

Note: call of this function is almost equivalent to calling SELECT_IF_GREATER function with another order of the arguments: f(x1, x0, x3, x2), that is x1 > x0 ? x3 : x2. The only difference is connected with processing Double.NaN values of x0 and x1: this function will choose x3, but the corresponding call of SELECT_IF_GREATER will choose x2, because in Java any comparison with Double.NaN returns false.

This instance is immutable and thread-safe: there are no ways to modify its settings.


SELECT_FROM_8_DIRECTIONS_2D

static final Func SELECT_FROM_8_DIRECTIONS_2D
Selecting from 8 "integer" directions on 2D plane: f(x0, x1) = integer code from 1 to 8. The result of this function is the index of one of 8 sectors, where the 2-dimensional vector (x0,x1) lies. Namely, let φ=Math.atan2(x1,x0), more precisely, an equivalent angle in 0°..360° range. The result of this function is:

(A strange formula "337.5° < φ ≤ 22.5°" just means that the direction lies between 337.5°=-22.5° and +22.5° — in other words, "almost rightward" along X axis.)

This function is useful while processing 2-dimensional matrices, for example, in algorithms like Canny edge detector.

The get(double...) method of this object requires at least 2 arguments and throws IndexOutOfBoundsException if the number of arguments is 0 or 1. All calculations are performed in strictfp mode, so the result is absolutely identical on all platforms.

This instance is immutable and thread-safe: there are no ways to modify its settings.


SHIFTS_ALONG_8_DIRECTIONS_2D

static final java.util.List<IPoint> SHIFTS_ALONG_8_DIRECTIONS_2D
Vectors, corresponding to 8 directions recognized by SELECT_FROM_8_DIRECTIONS_2D function. More precisely, if is an unmodifiable list consisting of the following elements:
  1. IPoint.valueOf(1,0),
  2. IPoint.valueOf(1,1),
  3. IPoint.valueOf(0,1),
  4. IPoint.valueOf(-1,1),
  5. IPoint.valueOf(-1,0),
  6. IPoint.valueOf(-1,-1),
  7. IPoint.valueOf(0,-1),
  8. IPoint.valueOf(1,-1).

So, if the direction returned by SELECT_FROM_8_DIRECTIONS_2D is n, then the corresponding "rounding" direction is described by SHIFTS_ALONG_8_DIRECTIONS_2D.get(n).

This instance is immutable and thread-safe: there are no ways to modify it.

Method Detail

get

double get(double... x)
Returns the result of this function for the given arguments: f(x0, x1, ..., xx.length-1).

This method must not change the values of x elements!

Parameters:
x - the function arguments.
Returns:
the function result.
Throws:
java.lang.IndexOutOfBoundsException - may be thrown if the number of passed arguments is less than the required number of this function arguments.

get

double get()
Equivalent to get(new double[0]). Provides better performance because it does not require Java array creation.

Returns:
the function result.
Throws:
java.lang.IndexOutOfBoundsException - may be thrown this function requires at least 1 argument.

get

double get(double x0)
Equivalent to get(new double[] {x0}). Provides better performance because it does not require Java array creation.

Parameters:
x0 - the function argument.
Returns:
the function result.
Throws:
java.lang.IndexOutOfBoundsException - may be thrown this function requires at least 2 arguments.

get

double get(double x0,
           double x1)
Equivalent to get(new double[] {x0, x1}). Provides better performance because it does not require Java array creation.

Parameters:
x0 - the first function argument.
x1 - the second function argument.
Returns:
the function result.
Throws:
java.lang.IndexOutOfBoundsException - may be thrown this function requires at least 3 arguments.

get

double get(double x0,
           double x1,
           double x2)
Equivalent to get(new double[] {x0, x1, x2}). Provides better performance because it does not require Java array creation.

Parameters:
x0 - the first function argument.
x1 - the second function argument.
x2 - the third function argument.
Returns:
the function result.
Throws:
java.lang.IndexOutOfBoundsException - may be thrown this function requires at least 4 arguments.

get

double get(double x0,
           double x1,
           double x2,
           double x3)
Equivalent to get(new double[] {x0, x1, x2, x3}). Provides better performance because it does not require Java array creation.

Parameters:
x0 - the first function argument.
x1 - the second function argument.
x2 - the third function argument.
x3 - the fourth function argument.
Returns:
the function result.
Throws:
java.lang.IndexOutOfBoundsException - may be thrown this function requires at least 5 arguments.