Class DenseDoubleMatrix1D
- java.lang.Object
-
- cern.colt.PersistentObject
-
- cern.colt.matrix.AbstractMatrix
-
- cern.colt.matrix.AbstractMatrix1D
-
- cern.colt.matrix.tdouble.DoubleMatrix1D
-
- cern.colt.matrix.tdouble.impl.DenseDoubleMatrix1D
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class DenseDoubleMatrix1D extends DoubleMatrix1D
Dense 1-d matrix (aka vector) holding double elements. First see the package summary and javadoc tree view to get the broad picture.Implementation:
Internally holds one single contigous one-dimensional array. Note that this implementation is not synchronized.
Time complexity:
O(1) (i.e. constant time) for the basic operations get, getQuick, set, setQuick and size,
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DenseDoubleMatrix1D(double[] values)Constructs a matrix with a copy of the given values.DenseDoubleMatrix1D(int size)Constructs a matrix with a given number of cells.DenseDoubleMatrix1D(int size, double[] elements, int zero, int stride, boolean isView)Constructs a matrix with the given parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doubleaggregate(DoubleDoubleFunction aggr, DoubleFunction f)Applies a function to each cell and aggregates the results.doubleaggregate(DoubleDoubleFunction aggr, DoubleFunction f, IntArrayList indexList)Applies a function to all cells with a given indexes and aggregates the results.doubleaggregate(DoubleMatrix1D other, DoubleDoubleFunction aggr, DoubleDoubleFunction f)Applies a function to each corresponding cell of two matrices and aggregates the results.DoubleMatrix1Dassign(double value)Sets all cells to the state specified by value.DoubleMatrix1Dassign(double[] values)Sets all cells to the state specified by values.DoubleMatrix1Dassign(DoubleFunction function)Assigns the result of a function to each cell; x[i] = function(x[i]).DoubleMatrix1Dassign(DoubleMatrix1D source)Replaces all cell values of the receiver with the values of another matrix.DoubleMatrix1Dassign(DoubleMatrix1D y, DoubleDoubleFunction function)Assigns the result of a function to each cell; x[i] = function(x[i],y[i]).DoubleMatrix1Dassign(DoubleProcedure cond, double value)Assigns a value to all cells that satisfy a condition.DoubleMatrix1Dassign(DoubleProcedure cond, DoubleFunction function)Assigns the result of a function to all cells that satisfy a condition.intcardinality()Returns the number of cells having non-zero values; ignores tolerance.voiddct(boolean scale)Computes the discrete cosine transform (DCT-II) of this matrix.voiddht()Computes the discrete Hartley transform (DHT) of this matrix.voiddst(boolean scale)Computes the discrete sine transform (DST-II) of this matrix.double[]elements()Returns the elements of this matrix.voidfft()Computes the discrete Fourier transform (DFT) of this matrix.DenseDComplexMatrix1DgetFft()Returns new complex matrix which is the discrete Fourier transform (DFT) of this matrix.DenseDComplexMatrix1DgetIfft(boolean scale)Returns new complex matrix which is the inverse of the discrete Fourier (IDFT) transform of this matrix.double[]getMaxLocation()Return the maximum value of this matrix together with its locationdouble[]getMinLocation()Return the minimum value of this matrix together with its locationvoidgetNegativeValues(IntArrayList indexList, DoubleArrayList valueList)Fills the coordinates and values of cells having negative values into the specified lists.voidgetNonZeros(IntArrayList indexList, DoubleArrayList valueList)Fills the coordinates and values of cells having non-zero values into the specified lists.voidgetPositiveValues(IntArrayList indexList, DoubleArrayList valueList)Fills the coordinates and values of cells having positive values into the specified lists.doublegetQuick(int index)Returns the matrix cell value at coordinate index.voididct(boolean scale)Computes the inverse of the discrete cosine transform (DCT-III) of this matrix.voididht(boolean scale)Computes the inverse of the discrete Hartley transform (IDHT) of this matrix.voididst(boolean scale)Computes the inverse of discrete sine transform (DST-III) of this matrix.voidifft(boolean scale)Computes the inverse of the discrete Fourier transform (DFT) of this matrix.longindex(int rank)Returns the position of the element with the given relative rank within the (virtual or non-virtual) internal 1-dimensional array.DoubleMatrix1Dlike(int size)Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified size.DoubleMatrix2Dlike2D(int rows, int columns)Construct and returns a new 2-d matrix of the corresponding dynamic type, entirelly independent of the receiver.DoubleMatrix2Dreshape(int rows, int columns)Returns new DoubleMatrix2D of size rows x columns whose elements are taken column-wise from this matrix.DoubleMatrix3Dreshape(int slices, int rows, int columns)Returns new DoubleMatrix3D of size slices x rows x columns, whose elements are taken column-wise from this matrix.voidsetQuick(int index, double value)Sets the matrix cell at coordinate index to the specified value.voidswap(DoubleMatrix1D other)Swaps each element this[i] with other[i].voidtoArray(double[] values)Fills the cell values into the specified 1-dimensional array.doublezDotProduct(DoubleMatrix1D y, int from, int length)Returns the dot product of two vectors x and y, which is Sum(x[i]*y[i]).doublezSum()Returns the sum of all cells; Sum( x[i] ).-
Methods inherited from class cern.colt.matrix.tdouble.DoubleMatrix1D
assign, copy, equals, equals, get, getNonZeros, like, normalize, set, toArray, toString, viewFlip, viewPart, viewSelection, viewSelection, viewSorted, viewStrides, zDotProduct, zDotProduct
-
Methods inherited from class cern.colt.matrix.AbstractMatrix1D
checkSize, size, stride, toStringShort
-
Methods inherited from class cern.colt.matrix.AbstractMatrix
ensureCapacity, isView, trimToSize
-
Methods inherited from class cern.colt.PersistentObject
clone
-
-
-
-
Constructor Detail
-
DenseDoubleMatrix1D
public DenseDoubleMatrix1D(double[] values)
Constructs a matrix with a copy of the given values. The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.- Parameters:
values- The values to be filled into the new matrix.
-
DenseDoubleMatrix1D
public DenseDoubleMatrix1D(int size)
Constructs a matrix with a given number of cells. All entries are initially 0.- Parameters:
size- the number of cells the matrix shall have.- Throws:
java.lang.IllegalArgumentException- if size<0.
-
DenseDoubleMatrix1D
public DenseDoubleMatrix1D(int size, double[] elements, int zero, int stride, boolean isView)Constructs a matrix with the given parameters.- Parameters:
size- the number of cells the matrix shall have.elements- the cells.zero- the index of the first element.stride- the number of indexes between any two elements, i.e. index(i+1)-index(i).isView- if true then a matrix view is constructed- Throws:
java.lang.IllegalArgumentException- if size<0.
-
-
Method Detail
-
aggregate
public double aggregate(DoubleDoubleFunction aggr, DoubleFunction f)
Description copied from class:DoubleMatrix1DApplies a function to each cell and aggregates the results. Returns a value v such that v==a(size()) where a(i) == aggr( a(i-1), f(get(i)) ) and terminators are a(1) == f(get(0)), a(0)==Double.NaN.Example:
cern.jet.math.Functions F = cern.jet.math.Functions.functions; matrix = 0 1 2 3 // Sum( x[i]*x[i] ) matrix.aggregate(F.plus,F.square); --> 14For further examples, see the package doc.- Overrides:
aggregatein classDoubleMatrix1D- Parameters:
aggr- an aggregation function taking as first argument the current aggregation and as second argument the transformed current cell value.f- a function transforming the current cell value.- Returns:
- the aggregated measure.
- See Also:
DoubleFunctions
-
aggregate
public double aggregate(DoubleDoubleFunction aggr, DoubleFunction f, IntArrayList indexList)
Description copied from class:DoubleMatrix1DApplies a function to all cells with a given indexes and aggregates the results.- Overrides:
aggregatein classDoubleMatrix1D- Parameters:
aggr- an aggregation function taking as first argument the current aggregation and as second argument the transformed current cell value.f- a function transforming the current cell value.indexList- indexes.- Returns:
- the aggregated measure.
- See Also:
DoubleFunctions
-
aggregate
public double aggregate(DoubleMatrix1D other, DoubleDoubleFunction aggr, DoubleDoubleFunction f)
Description copied from class:DoubleMatrix1DApplies a function to each corresponding cell of two matrices and aggregates the results. Returns a value v such that v==a(size()) where a(i) == aggr( a(i-1), f(get(i),other.get(i)) ) and terminators are a(1) == f(get(0),other.get(0)), a(0)==Double.NaN.Example:
cern.jet.math.Functions F = cern.jet.math.Functions.functions; x = 0 1 2 3 y = 0 1 2 3 // Sum( x[i]*y[i] ) x.aggregate(y, F.plus, F.mult); --> 14 // Sum( (x[i]+y[i])ˆ2 ) x.aggregate(y, F.plus, F.chain(F.square,F.plus)); --> 56For further examples, see the package doc.- Overrides:
aggregatein classDoubleMatrix1Daggr- an aggregation function taking as first argument the current aggregation and as second argument the transformed current cell values.f- a function transforming the current cell values.- Returns:
- the aggregated measure.
- See Also:
DoubleFunctions
-
assign
public DoubleMatrix1D assign(DoubleFunction function)
Description copied from class:DoubleMatrix1DAssigns the result of a function to each cell; x[i] = function(x[i]). (Iterates downwards from [size()-1] to [0]).Example:
// change each cell to its sine matrix = 0.5 1.5 2.5 3.5 matrix.assign(cern.jet.math.Functions.sin); --> matrix == 0.479426 0.997495 0.598472 -0.350783For further examples, see the package doc.- Overrides:
assignin classDoubleMatrix1D- Parameters:
function- a function object taking as argument the current cell's value.- Returns:
- this (for convenience only).
- See Also:
DoubleFunctions
-
assign
public DoubleMatrix1D assign(DoubleProcedure cond, DoubleFunction function)
Description copied from class:DoubleMatrix1DAssigns the result of a function to all cells that satisfy a condition.- Overrides:
assignin classDoubleMatrix1D- Parameters:
cond- a condition.function- a function object.- Returns:
- this (for convenience only).
- See Also:
DoubleFunctions
-
assign
public DoubleMatrix1D assign(DoubleProcedure cond, double value)
Description copied from class:DoubleMatrix1DAssigns a value to all cells that satisfy a condition.- Overrides:
assignin classDoubleMatrix1D- Parameters:
cond- a condition.value- a value.- Returns:
- this (for convenience only).
-
assign
public DoubleMatrix1D assign(double value)
Description copied from class:DoubleMatrix1DSets all cells to the state specified by value.- Overrides:
assignin classDoubleMatrix1D- Parameters:
value- the value to be filled into the cells.- Returns:
- this (for convenience only).
-
assign
public DoubleMatrix1D assign(double[] values)
Description copied from class:DoubleMatrix1DSets all cells to the state specified by values. values is required to have the same number of cells as the receiver.The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.
- Overrides:
assignin classDoubleMatrix1D- Parameters:
values- the values to be filled into the cells.- Returns:
- this (for convenience only).
-
assign
public DoubleMatrix1D assign(DoubleMatrix1D source)
Description copied from class:DoubleMatrix1DReplaces all cell values of the receiver with the values of another matrix. Both matrices must have the same size. If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces as if using an intermediate auxiliary deep copy of other.- Overrides:
assignin classDoubleMatrix1D- Parameters:
source- the source matrix to copy from (may be identical to the receiver).- Returns:
- this (for convenience only).
-
assign
public DoubleMatrix1D assign(DoubleMatrix1D y, DoubleDoubleFunction function)
Description copied from class:DoubleMatrix1DAssigns the result of a function to each cell; x[i] = function(x[i],y[i]).Example:
// assign x[i] = x[i]<sup>y[i]</sup> m1 = 0 1 2 3; m2 = 0 2 4 6; m1.assign(m2, cern.jet.math.Functions.pow); --> m1 == 1 1 16 729For further examples, see the package doc.- Overrides:
assignin classDoubleMatrix1D- Parameters:
y- the secondary matrix to operate on.function- a function object taking as first argument the current cell's value of this, and as second argument the current cell's value of y,- Returns:
- this (for convenience only).
- See Also:
DoubleFunctions
-
cardinality
public int cardinality()
Description copied from class:DoubleMatrix1DReturns the number of cells having non-zero values; ignores tolerance.- Overrides:
cardinalityin classDoubleMatrix1D- Returns:
- the number of cells having non-zero values.
-
dct
public void dct(boolean scale)
Computes the discrete cosine transform (DCT-II) of this matrix.- Parameters:
scale- if true then scaling is performed
-
dht
public void dht()
Computes the discrete Hartley transform (DHT) of this matrix.
-
dst
public void dst(boolean scale)
Computes the discrete sine transform (DST-II) of this matrix.- Parameters:
scale- if true then scaling is performed
-
elements
public double[] elements()
Description copied from class:DoubleMatrix1DReturns the elements of this matrix.- Specified by:
elementsin classDoubleMatrix1D- Returns:
- the elements
-
fft
public void fft()
Computes the discrete Fourier transform (DFT) of this matrix. The physical layout of the output data is as follows:this[2*k] = Re[k], 0<=k<size/2 this[2*k+1] = Im[k], 0<k<size/2 this[1] = Re[size/2]
This method computes only half of the elements of the real transform. The other half satisfies the symmetry condition. If you want the full real forward transform, usegetFft. To get back the original data, useifft.
-
getFft
public DenseDComplexMatrix1D getFft()
Returns new complex matrix which is the discrete Fourier transform (DFT) of this matrix.- Returns:
- the discrete Fourier transform (DFT) of this matrix.
-
getIfft
public DenseDComplexMatrix1D getIfft(boolean scale)
Returns new complex matrix which is the inverse of the discrete Fourier (IDFT) transform of this matrix.- Returns:
- the inverse of the discrete Fourier transform (IDFT) of this matrix.
-
getNonZeros
public void getNonZeros(IntArrayList indexList, DoubleArrayList valueList)
Description copied from class:DoubleMatrix1DFills the coordinates and values of cells having non-zero values into the specified lists. Fills into the lists, starting at index 0. After this call returns the specified lists all have a new size, the number of non-zero values.In general, fill order is unspecified. This implementation fills like: for (index = 0..size()-1) do ... . However, subclasses are free to us any other order, even an order that may change over time as cell values are changed. (Of course, result lists indexes are guaranteed to correspond to the same cell).
Example:
0, 0, 8, 0, 7 --> indexList = (2,4) valueList = (8,7)In other words, get(2)==8, get(4)==7.- Overrides:
getNonZerosin classDoubleMatrix1D- Parameters:
indexList- the list to be filled with indexes, can have any size.valueList- the list to be filled with values, can have any size.
-
getPositiveValues
public void getPositiveValues(IntArrayList indexList, DoubleArrayList valueList)
Description copied from class:DoubleMatrix1DFills the coordinates and values of cells having positive values into the specified lists. Fills into the lists, starting at index 0. After this call returns the specified lists all have a new size, the number of non-zero values.- Overrides:
getPositiveValuesin classDoubleMatrix1D- Parameters:
indexList- the list to be filled with indexes, can have any size.valueList- the list to be filled with values, can have any size.
-
getNegativeValues
public void getNegativeValues(IntArrayList indexList, DoubleArrayList valueList)
Description copied from class:DoubleMatrix1DFills the coordinates and values of cells having negative values into the specified lists. Fills into the lists, starting at index 0. After this call returns the specified lists all have a new size, the number of non-zero values.- Overrides:
getNegativeValuesin classDoubleMatrix1D- Parameters:
indexList- the list to be filled with indexes, can have any size.valueList- the list to be filled with values, can have any size.
-
getMaxLocation
public double[] getMaxLocation()
Description copied from class:DoubleMatrix1DReturn the maximum value of this matrix together with its location- Overrides:
getMaxLocationin classDoubleMatrix1D- Returns:
- { maximum_value, location };
-
getMinLocation
public double[] getMinLocation()
Description copied from class:DoubleMatrix1DReturn the minimum value of this matrix together with its location- Overrides:
getMinLocationin classDoubleMatrix1D- Returns:
- { minimum_value, location };
-
getQuick
public double getQuick(int index)
Description copied from class:DoubleMatrix1DReturns the matrix cell value at coordinate index.Provided with invalid parameters this method may return invalid objects without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): index<0 || index>=size().
- Specified by:
getQuickin classDoubleMatrix1D- Parameters:
index- the index of the cell.- Returns:
- the value of the specified cell.
-
idct
public void idct(boolean scale)
Computes the inverse of the discrete cosine transform (DCT-III) of this matrix.- Parameters:
scale- if true then scaling is performed
-
idht
public void idht(boolean scale)
Computes the inverse of the discrete Hartley transform (IDHT) of this matrix.- Parameters:
scale- if true then scaling is performed
-
idst
public void idst(boolean scale)
Computes the inverse of discrete sine transform (DST-III) of this matrix.- Parameters:
scale- if true then scaling is performed
-
ifft
public void ifft(boolean scale)
Computes the inverse of the discrete Fourier transform (DFT) of this matrix. The physical layout of the input data has to be as follows:this[2*k] = Re[k], 0<=k<size/2 this[2*k+1] = Im[k], 0<k<size/2 this[1] = Re[size/2]
This method computes only half of the elements of the real transform. The other half satisfies the symmetry condition. If you want the full real inverse transform, usegetIfft.
-
like
public DoubleMatrix1D like(int size)
Description copied from class:DoubleMatrix1DConstruct and returns a new empty matrix of the same dynamic type as the receiver, having the specified size. For example, if the receiver is an instance of type DenseDoubleMatrix1D the new matrix must also be of type DenseDoubleMatrix1D, if the receiver is an instance of type SparseDoubleMatrix1D the new matrix must also be of type SparseDoubleMatrix1D, etc. In general, the new matrix should have internal parametrization as similar as possible.- Specified by:
likein classDoubleMatrix1D- Parameters:
size- the number of cell the matrix shall have.- Returns:
- a new empty matrix of the same dynamic type.
-
like2D
public DoubleMatrix2D like2D(int rows, int columns)
Description copied from class:DoubleMatrix1DConstruct and returns a new 2-d matrix of the corresponding dynamic type, entirelly independent of the receiver. For example, if the receiver is an instance of type DenseDoubleMatrix1D the new matrix must be of type DenseDoubleMatrix2D, if the receiver is an instance of type SparseDoubleMatrix1D the new matrix must be of type SparseDoubleMatrix2D, etc.- Specified by:
like2Din classDoubleMatrix1D- Parameters:
rows- the number of rows the matrix shall have.columns- the number of columns the matrix shall have.- Returns:
- a new matrix of the corresponding dynamic type.
-
reshape
public DoubleMatrix2D reshape(int rows, int columns)
Description copied from class:DoubleMatrix1DReturns new DoubleMatrix2D of size rows x columns whose elements are taken column-wise from this matrix.- Specified by:
reshapein classDoubleMatrix1D- Parameters:
rows- number of rowscolumns- number of columns- Returns:
- new 2D matrix with columns being the elements of this matrix.
-
reshape
public DoubleMatrix3D reshape(int slices, int rows, int columns)
Description copied from class:DoubleMatrix1DReturns new DoubleMatrix3D of size slices x rows x columns, whose elements are taken column-wise from this matrix.- Specified by:
reshapein classDoubleMatrix1Drows- number of rowscolumns- number of columns- Returns:
- new 2D matrix with columns being the elements of this matrix.
-
setQuick
public void setQuick(int index, double value)Description copied from class:DoubleMatrix1DSets the matrix cell at coordinate index to the specified value.Provided with invalid parameters this method may access illegal indexes without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): index<0 || index>=size().
- Specified by:
setQuickin classDoubleMatrix1D- Parameters:
index- the index of the cell.value- the value to be filled into the specified cell.
-
swap
public void swap(DoubleMatrix1D other)
Description copied from class:DoubleMatrix1DSwaps each element this[i] with other[i].- Overrides:
swapin classDoubleMatrix1D
-
toArray
public void toArray(double[] values)
Description copied from class:DoubleMatrix1DFills the cell values into the specified 1-dimensional array. The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa. After this call returns the array values has the form
for (int i=0; i < size(); i++) values[i] = get(i);- Overrides:
toArrayin classDoubleMatrix1D
-
zDotProduct
public double zDotProduct(DoubleMatrix1D y, int from, int length)
Description copied from class:DoubleMatrix1DReturns the dot product of two vectors x and y, which is Sum(x[i]*y[i]). Where x == this. Operates on cells at indexes from .. Min(size(),y.size(),from+length)-1.- Overrides:
zDotProductin classDoubleMatrix1D- Parameters:
y- the second vector.from- the first index to be considered.length- the number of cells to be considered.- Returns:
- the sum of products; zero if from<0 || length<0.
-
zSum
public double zSum()
Description copied from class:DoubleMatrix1DReturns the sum of all cells; Sum( x[i] ).- Overrides:
zSumin classDoubleMatrix1D- Returns:
- the sum.
-
index
public long index(int rank)
Description copied from class:AbstractMatrix1DReturns the position of the element with the given relative rank within the (virtual or non-virtual) internal 1-dimensional array. You may want to override this method for performance.- Overrides:
indexin classAbstractMatrix1D- Parameters:
rank- the rank of the element.
-
-
DMelt 3.0 © DataMelt by jWork.ORG