edu.mines.jtk.opt
Class ArrayVect1f

java.lang.Object
  extended by edu.mines.jtk.opt.ArrayVect1f
All Implemented Interfaces:
Vect, VectConst, java.io.Serializable, java.lang.Cloneable

public class ArrayVect1f
extends java.lang.Object
implements Vect

Implements a Vect by wrapping an array of floats. The embedded data are exposed by a getData method. For all practical purposes this member is public, except that this class must always point to the same array. The implementation as an array is the point of this class, to avoid duplicate implementations elsewhere. Multiple inheritance is prohibited and prevents the mixin pattern, but you can share the wrapped array as a private member of your own class, and easily delegate all implemented methods.

Author:
W.S. Harlan
See Also:
Serialized Form

Field Summary
protected  float[] _data
          Array of wrapped data
protected  int _firstSample
          This is the first sample to treat as non-zero.
protected  double _variance
          Variance of each ArrayVect1f
 
Constructor Summary
protected ArrayVect1f()
          Constructor for derived classes that call init()
  ArrayVect1f(float[] data, int firstSample, double variance)
          Construct from an array of data.
 
Method Summary
 void add(double scaleThis, double scaleOther, VectConst other)
          Add a scaled version of another vector to a scaled version of this vector.
 ArrayVect1f clone()
           
 void constrain()
          Optionally apply a hard constraint (such as an inequality) to the current vector.
 void dispose()
          Optionally free any resources held by this object.
 double dot(VectConst other)
          Return the Cartesian dot product of this vector with another vector (not including any inverse covariance).
static void extractContainer(float[][] data, VectContainer container)
          Extract 2D array from a VectContainer with instances of ArrayVect1f.
static void fillContainer(VectContainer container, int[] firstSamples, float[][] data, double variance)
          Fill a VectContainer with instances of ArrayVect1f from a 2D array.
 float[] getData()
          Get the embedded data
 int getFirstSample()
          This is the first sample to treat as non-zero.
 int getSize()
          Return the size of the embedded array
protected  void init(float[] data, int firstSample, double variance)
          Construct from an array of data.
 double magnitude()
          This is the dot product of the vector with itself premultiplied by the inverse covariance.
 void multiplyInverseCovariance()
          Optionally multiply a vector by the inverse covariance matrix.
 void postCondition()
          Apply a linear filter that enhances components that should be optimized first, and suppresses components of lesser importance.
 void project(double scaleThis, double scaleOther, VectConst other)
          Project another vector onto the space of this vector, then scale, and add to a scaled version of this vector.
 void setData(float[] data)
          Set the internal data array to new values.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_data

protected float[] _data
Array of wrapped data


_variance

protected double _variance
Variance of each ArrayVect1f


_firstSample

protected int _firstSample
This is the first sample to treat as non-zero. Earlier samples should be constrained to zero.

Constructor Detail

ArrayVect1f

public ArrayVect1f(float[] data,
                   int firstSample,
                   double variance)
Construct from an array of data.

Parameters:
data - This is the data that will be manipulated.
firstSample - This is the first sample to treat as non-zero. Earlier samples should be constrained to zero.
variance - The method multiplyInverseCovariance() will divide all samples by this number. Pass a value of 1 if you do not care.

ArrayVect1f

protected ArrayVect1f()
Constructor for derived classes that call init()

Method Detail

init

protected void init(float[] data,
                    int firstSample,
                    double variance)
Construct from an array of data.

Parameters:
data - This is the data that will be manipulated.
firstSample - This is the first sample to treat as non-zero. Earlier samples should be constrained to zero.
variance - The method multiplyInverseCovariance() will divide all samples by this number. Pass a value of 1 if you do not care.

getFirstSample

public int getFirstSample()
This is the first sample to treat as non-zero.

Returns:
first non-zero sample

getSize

public int getSize()
Return the size of the embedded array

Returns:
size of embedded array

getData

public float[] getData()
Get the embedded data

Returns:
Same array as passed to constructor.

setData

public void setData(float[] data)
Set the internal data array to new values.

Parameters:
data - Copy this data into the internal wrapped array.

fillContainer

public static void fillContainer(VectContainer container,
                                 int[] firstSamples,
                                 float[][] data,
                                 double variance)
Fill a VectContainer with instances of ArrayVect1f from a 2D array.

Parameters:
container - Container to be filled with instances of float[] wrapped as ArrayVect1f.
data - Array of data to be wrapped.
firstSamples - Array of first non-zero samples in each array.
variance - Variance of each ArrayVect1f

extractContainer

public static void extractContainer(float[][] data,
                                    VectContainer container)
Extract 2D array from a VectContainer with instances of ArrayVect1f.

Parameters:
data - Array of data to be extracted.
container - Container of ArrayVect1f to be extracted from.

clone

public ArrayVect1f clone()
Specified by:
clone in interface Vect
Specified by:
clone in interface VectConst
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

dot

public double dot(VectConst other)
Description copied from interface: VectConst
Return the Cartesian dot product of this vector with another vector (not including any inverse covariance). [Feel free to normalize by the number of elements in the array, if the inverse convariance is defined consistently.]

Specified by:
dot in interface VectConst
Parameters:
other - The vector to be dotted.
Returns:
The dot product.

dispose

public void dispose()
Description copied from interface: Vect
Optionally free any resources held by this object. Will not be used again. This method can safely do nothing.

Specified by:
dispose in interface Vect

multiplyInverseCovariance

public void multiplyInverseCovariance()
Description copied from interface: Vect
Optionally multiply a vector by the inverse covariance matrix. Also called preconditioning. A method that does nothing is equivalent to an identity. [vect.magnitude() should return the same value as vect.dot(((Vect)vect.clone()).multiplyInverseCovariance()); This should enhance components that should be discouraged in the model and suppress components that are preferred. This operation slows convergence. This filter must be linear. For inversions, you should at least implement a scaling operation that correctly weights errors in the data versus the magnitude of the model.]

Specified by:
multiplyInverseCovariance in interface Vect

constrain

public void constrain()
Description copied from interface: Vect
Optionally apply a hard constraint (such as an inequality) to the current vector. This is used only by a non-linear optimization. This method can safely do nothing.

Specified by:
constrain in interface Vect

add

public void add(double scaleThis,
                double scaleOther,
                VectConst other)
Description copied from interface: Vect
Add a scaled version of another vector to a scaled version of this vector. [If this==other, then the result should be the same as scaling this by (scaleThis+scaleOther)]

Specified by:
add in interface Vect
Parameters:
scaleThis - Multiply this vector by this scalar before adding.
scaleOther - Multiply the other vector by this scalar before adding.
other - The other vector to be multiplied.

project

public void project(double scaleThis,
                    double scaleOther,
                    VectConst other)
Description copied from interface: Vect
Project another vector onto the space of this vector, then scale, and add to a scaled version of this vector. (Useful for perturbing one vector with a constrained subspace.) This method should give the same result as add(), if the other Vect is an instance of the same class as this Vect. This operation need not be supported for any any types other than this Vect.

Specified by:
project in interface Vect
Parameters:
scaleThis - Multiply this vector by this scalar before adding.
scaleOther - Multiply the other vector by this scalar before adding.
other - The other vector to be projected, scaled, and added.

magnitude

public double magnitude()
Description copied from interface: VectConst
This is the dot product of the vector with itself premultiplied by the inverse covariance. If the inverse covariance is an identity, then the result is just the dot product with itself. Equivalently,
      Vect vect = (Vect) this.clone();
      vect.multiplyInverseCovariance();
      return this.dot(vect);
      
But you can usually avoid the clone.

Specified by:
magnitude in interface VectConst
Returns:
magnitude of vector.

postCondition

public void postCondition()
Description copied from interface: Vect
Apply a linear filter that enhances components that should be optimized first, and suppresses components of lesser importance. Also called post-conditioning. This filter prefilters all perturbations of the model and speeds convergence on components of most importance in the model. The same result can be accomplished by Transform.inverseHessian(), but this location may be more convenient. Use this location if the conditioning is independent of the Transform and dependent on the implementation of the model. This method can safely do nothing.

Specified by:
postCondition in interface Vect