Package wsh.opt
Class ArrayVect1
- java.lang.Object
-
- wsh.opt.ArrayVect1
-
public class ArrayVect1 extends java.lang.Object implements Vect
Implements a Vect by wrapping an array of doubles. 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.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ArrayVect1()
To be used with init()ArrayVect1(double[] data, double variance)
Construct from an array of data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(double scaleThis, double scaleOther, VectConst other)
Add a scaled version of another vector to a scaled version of this vector.ArrayVect1
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).double[]
getData()
Get the embedded dataint
getSize()
Return the size of the embedded arrayprotected void
init(double[] data, 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.java.lang.String
toString()
-
-
-
Constructor Detail
-
ArrayVect1
public ArrayVect1(double[] data, double variance)
Construct from an array of data.- Parameters:
data
- This is the data that will be manipulated.variance
- The method multiplyInverseCovariance() will divide all samples by this number. Pass a value of 1 if you do not care.
-
ArrayVect1
protected ArrayVect1()
To be used with init()
-
-
Method Detail
-
init
protected final void init(double[] data, double variance)
Construct from an array of data.- Parameters:
data
- This is the data that will be manipulated.variance
- The method multiplyInverseCovariance() will divide all samples by this number. Pass a value of 1 if you do not care.
-
getSize
public int getSize()
Return the size of the embedded array- Returns:
- size of the embedded array
-
getData
public double[] getData()
Get the embedded data- Returns:
- Same array as passed to constructore.
-
clone
public ArrayVect1 clone()
-
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.]
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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.
-
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 interfaceVect
-
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.
-
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 interfaceVect
-
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)]
-
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.
-
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.
-
-