public static void convert(DMatrixRMaj src, ZMatrixRMaj dst ) { int N = src.getNumElements(); for (int i = 0,indexDst=0; i < N; i++) { dst.data[indexDst++] = src.data[i]; dst.data[indexDst++] = 0; } }
public static void convert(DMatrixRMaj src, FMatrixRMaj dst ) { int N = src.getNumElements(); for (int i = 0; i < N; i++) { dst.data[i] = (float)src.data[i]; } }
public static void convert(DMatrixRMaj src, CMatrixRMaj dst ) { int N = src.getNumElements(); for (int i = 0,indexDst=0; i < N; i++) { dst.data[indexDst++] = (float)src.data[i]; dst.data[indexDst++] = 0; } }
/** * Sets all elements equal to zero. */ public void zero() { Arrays.fill(data, 0, getNumElements(), 0.0); }
@Override public void reshape(int numRows, int numCols, boolean saveValues) { if( data.length < numRows * numCols ) { double []d = new double[ numRows*numCols ]; if( saveValues ) { System.arraycopy(data,0,d,0,getNumElements()); } this.data = d; } this.numRows = numRows; this.numCols = numCols; }
/** * Creates a new matrix which is equivalent to the provided matrix. Note that * the length of the data will be determined by the shape of the matrix. * * @param orig The matrix which is to be copied. This is not modified or saved. */ public DMatrixRMaj(DMatrixRMaj orig ) { this(orig.numRows,orig.numCols); System.arraycopy(orig.data, 0, this.data, 0, orig.getNumElements()); }
/** * <p> * Converts this matrix formated trifocal into a 27 element vector:<br> * m.data[ i*9 + j*3 + k ] = T_i(j,k) * </p> * * @param m Output: Trifocal tensor encoded in a vector */ public void convertTo( DMatrixRMaj m ) { if( m.getNumElements() != 27 ) throw new IllegalArgumentException("Input matrix/vector must have 27 elements"); for( int i = 0; i < 9; i++ ) { m.data[i] = T1.data[i]; m.data[i+9] = T2.data[i]; m.data[i+18] = T3.data[i]; } }
/** * <p> * Converts the 27 element vector into a three matrix format:<br> * T_i(j,k) = m.data[ i*9 + j*3 + k ] * </p> * * @param m Input: Trifocal tensor encoded in a vector */ public void convertFrom( DMatrixRMaj m ) { if( m.getNumElements() != 27 ) throw new IllegalArgumentException("Input matrix/vector must have 27 elements"); for( int i = 0; i < 9; i++ ) { T1.data[i] = m.data[i]; T2.data[i] = m.data[i+9]; T3.data[i] = m.data[i+18]; } }
/** * Use reference to provided mixtures */ public AssignGmm_F64(List<GaussianGmm_F64> mixture) { this.mixture = mixture; int N = mixture.get(0).mean.getNumElements(); glm = new GaussianLikelihoodManager(N,mixture); glm.precomputeAll(); }
/** * Copy constructor */ public AssignGmm_F64( AssignGmm_F64 original ) { mixture = new ArrayList<GaussianGmm_F64>(); for (int i = 0; i < original.mixture.size(); i++) { GaussianGmm_F64 o = original.mixture.get(i); mixture.add(o.copy()); } int N = mixture.get(0).mean.getNumElements(); glm = new GaussianLikelihoodManager(N,mixture); glm.precomputeAll(); }
/** * Use reference to provided mixtures */ public AssignGmm_F64(List<GaussianGmm_F64> mixture) { this.mixture = mixture; int N = mixture.get(0).mean.getNumElements(); glm = new GaussianLikelihoodManager(N,mixture); glm.precomputeAll(); }
/** * Copy constructor */ public AssignGmm_F64( AssignGmm_F64 original ) { mixture = new ArrayList<GaussianGmm_F64>(); for (int i = 0; i < original.mixture.size(); i++) { GaussianGmm_F64 o = original.mixture.get(i); mixture.add(o.copy()); } int N = mixture.get(0).mean.getNumElements(); glm = new GaussianLikelihoodManager(N,mixture); glm.precomputeAll(); }
/** * Normalizes the matrix such that the Frobenius norm is equal to one. * * @param A The matrix that is to be normalized. */ public static void normalizeF( DMatrixRMaj A ) { double val = normF(A); if( val == 0 ) return; int size = A.getNumElements(); for( int i = 0; i < size; i++) { A.div(i , val); } }
public static void inv(DMatrixRMaj mat , DMatrixRMaj inv ) { double max = Math.abs(mat.data[0]); int N = mat.getNumElements(); for( int i = 1; i < N; i++ ) { double a = Math.abs(mat.data[i]); if( a > max ) max = a; } switch( mat.numRows ) { case 2: inv2(mat,inv,1.0/max); break; case 3: inv3(mat,inv,1.0/max); break; case 4: inv4(mat,inv,1.0/max); break; case 5: inv5(mat,inv,1.0/max); break; default: throw new IllegalArgumentException("Not supported"); } }
/** * Applies the ≥ operator to each element in A. Results are stored in a boolean matrix. * * @param A Input matrix * @param value value each element is compared against * @param output (Optional) Storage for results. Can be null. Is reshaped. * @return Boolean matrix with results */ public static BMatrixRMaj elementLessThanOrEqual(DMatrixRMaj A , double value , BMatrixRMaj output ) { if( output == null ) { output = new BMatrixRMaj(A.numRows,A.numCols); } output.reshape(A.numRows, A.numCols); int N = A.getNumElements(); for (int i = 0; i < N; i++) { output.data[i] = A.data[i] <= value; } return output; }
public GaussianGmm_F64 copy() { GaussianGmm_F64 out = new GaussianGmm_F64(mean.getNumElements()); out.mean.set(mean); out.covariance.set(covariance); out.weight = weight; return out; }
public GaussianGmm_F64 copy() { GaussianGmm_F64 out = new GaussianGmm_F64(mean.getNumElements()); out.mean.set(mean); out.covariance.set(covariance); out.weight = weight; return out; }
/** * Extracts the row from a matrix. * @param a Input matrix * @param row Which row is to be extracted * @param out output. Storage for the extracted row. If null then a new vector will be returned. * @return The extracted row. */ public static DMatrixRMaj extractRow(DMatrixRMaj a , int row , DMatrixRMaj out ) { if( out == null) out = new DMatrixRMaj(1,a.numCols); else if( !MatrixFeatures_DDRM.isVector(out) || out.getNumElements() != a.numCols ) throw new MatrixDimensionException("Output must be a vector of length "+a.numCols); System.arraycopy(a.data,a.getIndex(row,0),out.data,0,a.numCols); return out; }
/** * Extracts the elements from the source matrix by their 1D index. * * @param src Source matrix. Not modified. * @param indexes array of row indexes * @param length maximum element in row array * @param dst output matrix. Must be a vector of the correct length. */ public static void extract(DMatrixRMaj src, int indexes[] , int length , DMatrixRMaj dst ) { if( !MatrixFeatures_DDRM.isVector(dst)) throw new MatrixDimensionException("Dst must be a vector"); if( length != dst.getNumElements()) throw new MatrixDimensionException("Unexpected number of elements in dst vector"); for (int i = 0; i < length; i++) { dst.data[i] = src.data[indexes[i]]; } }
/** * Creates a random vector that is inside the specified span. * * @param span The span the random vector belongs in. * @param rand RNG * @return A random vector within the specified span. */ public static DMatrixRMaj insideSpan(DMatrixRMaj[] span , double min , double max , Random rand ) { DMatrixRMaj A = new DMatrixRMaj(span.length,1); DMatrixRMaj B = new DMatrixRMaj(span[0].getNumElements(),1); for( int i = 0; i < span.length; i++ ) { B.set(span[i]); double val = rand.nextDouble()*(max-min)+min; CommonOps_DDRM.scale(val,B); CommonOps_DDRM.add(A,B,A); } return A; }