org.geotoolkit.math
Class ObjectiveAnalysis

Object
  extended by ObjectiveAnalysis

public class ObjectiveAnalysis
extends Object

Computes values at the location of grid cells from a set of values at random locations. This class is typically used for computing values on a regular grid (the output) from a set of values at random locations (the input). However the class can also be used for creating non-regular grids. For creating a non-regular grid, user should subclass ObjectiveAnalysis and override the getOutputLocation(...) method.

Since:
3.09 (derived from 1.0)
Version:
3.09
Author:
Martin Desruisseaux (IRD, Geomatys), Howard Freeland (MPO, for algorithmic inspiration)
Module:
analytics/geotk-analytics (download)    View source code for this class

Constructor Summary
ObjectiveAnalysis(Rectangle2D gridRegion, int nx, int ny, PixelOrientation cellLocation)
          Creates a new instance for interpolating values in the given region.
 
Method Summary
protected  double correlation(Point2D.Double P1, Point2D.Double P2)
          Returns the correlation between the values at the two given points.
 RenderedImage createImage()
          Creates an image from the values interpolated at the locations defined by the getOutputLocation(...) method.
 int getOutputLength()
          Returns the number of points to be computed by this instance.
 Point2D.Double getOutputLocation(int index, Point2D.Double dest)
          Returns the (x,y) coordinate of the point evaluated at the given index.
 double[] interpolate(double[] dest)
          Uses the values given to the setInputs(...)
 float[] interpolate(float[] dest)
          Uses the values given to the setInputs(...)
 void setInputs(double[] xp, double[] yp, double[] zp)
          Sets the input values at the given points.
 void setInputs(float[] xp, float[] yp, float[] zp)
          Sets the input values at the given points.
 void setInputs(Vector xp, Vector yp, Vector zp)
          Sets the input values at the given points.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectiveAnalysis

public ObjectiveAnalysis(Rectangle2D gridRegion,
                         int nx,
                         int ny,
                         PixelOrientation cellLocation)
Creates a new instance for interpolating values in the given region.

Parameters:
gridRegion - The grid bounding box. The maximal ordinates are inclusive.
nx - The number of grid cells along the x axis.
ny - The number of grid cells along the y axis.
cellLocation - The position to evaluate in each grid cell.
Method Detail

setInputs

public void setInputs(double[] xp,
                      double[] yp,
                      double[] zp)
Sets the input values at the given points. Those values will be used by the interpolate methods for interpolating new values at the locations defined by getOutputLocation(int, Point2D.Double).

This convenience method wraps the given arrays in Vector objects and delegates to setInputs(Vector, Vector, Vector).

Parameters:
xp - The x ordinates of a random set of points.
yp - The y ordinates of a random set of points.
zp - The z values at the (x,y) coordinates defined by the xp and yp arguments.

setInputs

public void setInputs(float[] xp,
                      float[] yp,
                      float[] zp)
Sets the input values at the given points. Those values will be used by the interpolate methods for interpolating new values at the locations defined by getOutputLocation(int, Point2D.Double).

This convenience method wraps the given arrays in Vector objects and delegates to setInputs(Vector, Vector, Vector).

Parameters:
xp - The x ordinates of a random set of points.
yp - The y ordinates of a random set of points.
zp - The z values at the (x,y) coordinates defined by the xp and yp arguments.

setInputs

public void setInputs(Vector xp,
                      Vector yp,
                      Vector zp)
Sets the input values at the given points. Those values will be used by the interpolate methods for interpolating new values at the locations defined by getOutputLocation(int, Point2D.Double).

Parameters:
xp - The x ordinates of a random set of points.
yp - The y ordinates of a random set of points.
zp - The z values at the (x,y) coordinates defined by the xp and yp arguments.

getOutputLength

public int getOutputLength()
Returns the number of points to be computed by this instance. This is the number of grid cells. The interpolate(...) method will return an array of this length.

Returns:
The number of points to be computed.

getOutputLocation

public Point2D.Double getOutputLocation(int index,
                                        Point2D.Double dest)
Returns the (x,y) coordinate of the point evaluated at the given index. This is the spatial location of values[index] where values is the array returned by the interpolate(...) method.

If the dest argument is non-null, then the result will be written in the given Point2D instance and this method returns dest. Otherwise this method returns a newly allocated Point2D instance.

Parameters:
index - Index (in the [0 … length-1] range) of an interpolated value.
dest - A pre-allocated Point2D to reuse, or null if none.
Returns:
The (x,y) coordinate of the value at the index.

interpolate

public double[] interpolate(double[] dest)
Uses the values given to the setInputs(...) method for interpolating new values at the locations defined by the getOutputLocation(...) method. The results are stored in the given array if it is not-null, or in a newly allocated array otherwise.

This method performs the following steps:

  1. If dest is null, then a new array is allocated with new double[getOutputLength()].
  2. For each element i in the above array, the spatial location (used for the interpolation in the next step) is defined by getOutputLocation(i, ...).
  3. The value at the above spatial location is interpolated from the values given by the xp, yp and zp vector using the Objective Analysis algorithm.

Parameters:
dest - A pre-allocated array, or null if none.
Returns:
The interpolated values as an array of length getOutputLength().

interpolate

public float[] interpolate(float[] dest)
Uses the values given to the setInputs(...) method for interpolating new values at the locations defined by the getOutputLocation(...) method. This method performs the same work than interpolate(double[]), but using single-precision numbers instead than double-precision.

Parameters:
dest - A pre-allocated array, or null if none.
Returns:
The interpolated values as an array of length getOutputLength().

createImage

public RenderedImage createImage()
Creates an image from the values interpolated at the locations defined by the getOutputLocation(...) method. The default implementation assumes that the locations are defined in a row-major fashion, with the row on the top of the image first and the row at the bottom of the image last.

Returns:
The image created from interpolated values.

correlation

protected double correlation(Point2D.Double P1,
                             Point2D.Double P2)
Returns the correlation between the values at the two given points. For example if P1 and P2 are the location of measurement stations and time series are available for those stations, then this method shall returns the correlation coefficient between the data at station 1 and the data at station 2.

This method should be overridden by subclasses, typically with a correlation estimated from the distance between the two stations. The value returned by this method must be in the [0…1] range.

Default implementation
Current implementation assumes that the correlation has a gaussian distribution, with a value approaching zero as the distance between the two stations increase. The calibration coefficients in current implementation are totally arbitrary and may change in any future version.

Parameters:
P1 - The first location. Implementors shall not modify this value.
P2 - The second location. Implementors shall not modify this value.
Returns:
The correlation coefficient (in the [0…1] range) between the values at the two given locations.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.