org.opensha.sra.riskmaps.func
Class DiscreteInterpExterpFunc

java.lang.Object
  extended by org.opensha.sra.riskmaps.func.DiscreteFunction
      extended by org.opensha.sra.riskmaps.func.DiscreteInterpExterpFunc
All Implemented Interfaces:
FunctionAPI

public class DiscreteInterpExterpFunc
extends DiscreteFunction

This class behaves much like the DiscreteFunction class, however it allows for values between the discrete domain values to be interpolated, and values outside the domain altogether to be extrapolated. This interpolation/extrapolation can be done in different arithmetic spaces to allow for a “best fit” regression curve. Extrapolation follows one of four different approaches for each side of the curve. See the predefined constants for a list of options and their meanings.

 -=* CHANGE LOG *=-
 07/07/08 -- EMM: Original implementation.

Version:
0.0.1
Author:
Eric Martinez

Field Summary
static int EXTRAP_EXTEND
          Extrapolation should continue a linear regression of the final points.
static int EXTRAP_FLATTEN
          Extrapolation should assume the constant value of the endpoint.
static int EXTRAP_INFINITY
          Extrapolation should jump to +/- infinity (slope dependent).
static int EXTRAP_ZERO
          Extrapolation should just drop values to zero.
protected  int extrapAbove
           
protected  int extrapBelow
           
protected  int interpType
           
static int LINEAR_LINEAR
          Identifies interpolation in linear-x, linear-y domains.
static int LINEAR_LOG
          Identifies interpolation in linear-x, logarithmic-y domains.
static int LOG_LINEAR
          Identifies interpolation in logarithmic-x, linear-y domains.
static int LOG_LOG
          Identifies interpolation in logarithmic-x, logarithmic-y domains.
 
Fields inherited from class org.opensha.sra.riskmaps.func.DiscreteFunction
xvals, yvals
 
Constructor Summary
DiscreteInterpExterpFunc(double[] xvals, double[] yvals)
          Creates a discrete function with interpolation and extrapolation methods based on the given xvals and yvals.
DiscreteInterpExterpFunc(double[] xvals, double[] yvals, String name)
          Creates a discrete function with interpolation and extrapolation methods based on the given xvals, yvals and name.
DiscreteInterpExterpFunc(double[] xvals, double[] yvals, String name, int interpType, int extrapBelow, int extrapAbove)
          Creates a discrete function with interpolation and extrapolation methods based on the given xvals, yvals and name.
 
Method Summary
static DiscreteInterpExterpFunc fromArbDistFunc(DiscretizedFunc func)
           
 int getExtrapAbove()
           
 int getExtrapBelow()
           
 int getInterp()
           
 void setExtrapMethod(int extrapAbove, int extrapBelow)
          Attempts to set the extrapolation methods used for this discrete function.
 void setInterpMethod(int interpType)
          Attempts to set the interpolataion method used for this discrete function.
 double valueOf(double x)
          For the given value x returns the function value f(x) for this function.
 double[] valueOf(double[] x)
          For the given array of x values, a corresponding array of f(x) values is created and returned according to the computation methods described in valueOf(double x).
 
Methods inherited from class org.opensha.sra.riskmaps.func.DiscreteFunction
equals, getDomain, getName, getRange, getXVals, getYVals, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LINEAR_LINEAR

public static final int LINEAR_LINEAR
Identifies interpolation in linear-x, linear-y domains.

See Also:
Constant Field Values

LINEAR_LOG

public static final int LINEAR_LOG
Identifies interpolation in linear-x, logarithmic-y domains.

See Also:
Constant Field Values

LOG_LINEAR

public static final int LOG_LINEAR
Identifies interpolation in logarithmic-x, linear-y domains.

See Also:
Constant Field Values

LOG_LOG

public static final int LOG_LOG
Identifies interpolation in logarithmic-x, logarithmic-y domains.

See Also:
Constant Field Values

EXTRAP_ZERO

public static final int EXTRAP_ZERO
Extrapolation should just drop values to zero.

See Also:
Constant Field Values

EXTRAP_FLATTEN

public static final int EXTRAP_FLATTEN
Extrapolation should assume the constant value of the endpoint.

See Also:
Constant Field Values

EXTRAP_EXTEND

public static final int EXTRAP_EXTEND
Extrapolation should continue a linear regression of the final points.

See Also:
Constant Field Values

EXTRAP_INFINITY

public static final int EXTRAP_INFINITY
Extrapolation should jump to +/- infinity (slope dependent).

See Also:
Constant Field Values

interpType

protected int interpType

extrapBelow

protected int extrapBelow

extrapAbove

protected int extrapAbove
Constructor Detail

DiscreteInterpExterpFunc

public DiscreteInterpExterpFunc(double[] xvals,
                                double[] yvals)
Creates a discrete function with interpolation and extrapolation methods based on the given xvals and yvals. The name of this function will be the default name, and the interpolation and extrapoltion methods will be the defaults as well.

Parameters:
xvals - The x-values of this discrete function.
yvals - The y-values of this descrete function.

DiscreteInterpExterpFunc

public DiscreteInterpExterpFunc(double[] xvals,
                                double[] yvals,
                                String name)
Creates a discrete function with interpolation and extrapolation methods based on the given xvals, yvals and name. The interpolation and extrapolation methods will be the defaults.

Parameters:
xvals - The x-values of this discrete function.
yvals - The y-values of this discrete function.
name - The name of this discrete function.

DiscreteInterpExterpFunc

public DiscreteInterpExterpFunc(double[] xvals,
                                double[] yvals,
                                String name,
                                int interpType,
                                int extrapBelow,
                                int extrapAbove)
Creates a discrete function with interpolation and extrapolation methods based on the given xvals, yvals and name. Assuming the interpType, extrapBelow and/or extrapAbove correspond to a well-known method, they will be used as the respective interpolation/extrapolation methods. Otherwise the defaults will be used.

Parameters:
xvals - The x-values of this discrete function.
yvals - The y-values of this discrete function.
name - The name of this discrete function.
interpType - The arithmetic space in which to interpolate.
extrapBelow - The method of extrapolation for values below the lower bound of the function domain.
extrapAbove - The method of extrapolation for the values above the upper bound of the function domain.
Method Detail

setInterpMethod

public void setInterpMethod(int interpType)
Attempts to set the interpolataion method used for this discrete function. If the given interpType does not correspond to a known interpolation type, then nothing is done.

Parameters:
interpType - The new interpolation type to use.

setExtrapMethod

public void setExtrapMethod(int extrapAbove,
                            int extrapBelow)
Attempts to set the extrapolation methods used for this discrete function. If the given extrapBelow or extrapAbove does not correspond to a known extrapolation method, then the respective value is not set.

Parameters:
extrapBelow - The extrapolation method used for values below the lower bound of the domain of this discrete function.
extrapAbove - The extrapolation method used for values above the upper bound of the domain of this discrete function.

getInterp

public int getInterp()
Returns:
The current interpolation scheme used for this function.

getExtrapBelow

public int getExtrapBelow()
Returns:
The current extrapolation method used for values below the lower bound of the domain of this function.

getExtrapAbove

public int getExtrapAbove()
Returns:
The current extrapolation method used for values above the upper bound of the domain of this function.

valueOf

public double valueOf(double x)
For the given value x returns the function value f(x) for this function. If x is one of the discrete defining values of this function, its corresponding discrete y-value is returned. If x is somehwere within the bounds of the domain of this discrete function, then an interpolation is performed according to the current interpolation type and that interpolated value is returned. If x is above or below the upper or lower bounds of this discrete function's domain (respectively), then the funcntion value of x is extrapolated according to the current extrapolation method for values above/below the domain (respectively).

Specified by:
valueOf in interface FunctionAPI
Overrides:
valueOf in class DiscreteFunction
Parameters:
x - The value for which we want to know f(x).
Returns:
The function value f(x), interpolated or extrapolated as needed.

valueOf

public double[] valueOf(double[] x)
For the given array of x values, a corresponding array of f(x) values is created and returned according to the computation methods described in valueOf(double x).

Parameters:
x - The array of x-values for which you want to know y-values.
Returns:
An array of function values for the input array of x.

fromArbDistFunc

public static DiscreteInterpExterpFunc fromArbDistFunc(DiscretizedFunc func)