/** Constructs a diagonal block matrix from the given parts. The concatenation has the form <pre> A 0 0 0 B 0 0 0 C </pre> from the given parts. Cells are copied. */ public DoubleMatrix2D composeDiagonal(DoubleMatrix2D A, DoubleMatrix2D B, DoubleMatrix2D C) { DoubleMatrix2D diag = make(A.rows()+B.rows()+C.rows(), A.columns()+B.columns()+C.columns()); diag.viewPart(0,0,A.rows(),A.columns()).assign(A); diag.viewPart(A.rows(),A.columns(),B.rows(),B.columns()).assign(B); diag.viewPart(A.rows()+B.rows(),A.columns()+B.columns(),C.rows(),C.columns()).assign(C); return diag; } /**
public void apply(cern.colt.Timer timer) { int rows=B.rows(); int columns=B.columns(); //for (int row=rows; --row >= 0; ) { // for (int column=columns; --column >= 0; ) { for (int row=0; row < rows; row++) { for (int column=0; column < columns; column++) { A.setQuick(row,column, B.getQuick(row,column)); } } } };
public void init() { A.assign(0); int seed = 123456; current = 4*seed+1; density = A.cardinality() / (double) A.size(); } public void apply(cern.colt.Timer timer) {
private DoubleMatrix2D scale(DoubleMatrix2D x, boolean scale) { for (int j = 0; j < x.columns(); j++) { DoubleArrayList u = new DoubleArrayList(x.viewColumn(j).toArray()); double mean = Descriptive.mean(u); for (int i = 0; i < x.rows(); i++) { x.set(i, j, x.get(i, j) - mean); } if (scale) { double rms = rms(x.viewColumn(j)); for (int i = 0; i < x.rows(); i++) { x.set(i, j, x.get(i, j) / rms); } } } return x; }
public static DoubleMatrix1D flatten(DoubleMatrix2D m){ DoubleMatrix1D[] colArray = new DoubleMatrix1D[m.columns()]; for(int i = 0; i < m.columns(); i++){ colArray[i] = m.viewColumn(i); } return DoubleFactory1D.dense.make(colArray); }
/** * <tt>A = A<sup>B</sup> <=> A[row,col] = Math.pow(A[row,col], B[row,col])</tt>. * @param A the matrix to modify. * @param B the matrix to stay unaffected. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D pow(DoubleMatrix2D A, DoubleMatrix2D B) { return A.assign(B,F.pow); } }
@Override public double apply(int i, int j, double gij) { standardA.set(i, standardS + j, gij); return gij; } });
private DoubleMatrix2D decompPCA (SingularValueDecomposition svd) { DoubleMatrix2D D = svd.getS (); // Calculer la racine carree des valeurs propres for (int i = 0; i < D.rows(); ++i) { lambda[i] = D.getQuick (i, i); D.setQuick (i, i, Math.sqrt (D.getQuick (i, i))); } DoubleMatrix2D P = svd.getV(); return P.zMult (D, null); }
public double getQuick(int row, int column) { return content.get(column,row); } public void setQuick(int row, int column, double value) {
@Override public double[][] hessian(double[] X) { DoubleMatrix1D x = F1.make(X); DoubleMatrix2D hessF0X = getHessF0(x); double[][] hessX = barrierFunction.hessian(X); if(hessX == FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER){ return hessF0X.assign(Mult.mult(tIter)).toArray(); }else{ DoubleMatrix2D phiHess = F2.make(hessX); return hessF0X.assign(Mult.mult(tIter)).assign(phiHess, Functions.plus).toArray(); } }
/** * checks if yDat is zero indexed and converts to 1 index. zscores x */ private void fixData(){ double ymin = StatUtils.min(flatten(yDat).toArray()); if(ymin < 0 || ymin > 1) throw new IllegalArgumentException("Discrete data must be either zero or one indexed. Found min index: " + ymin); if(ymin==0){ yDat.assign(Functions.plus(1.0)); } //z-score columns of X for(int i = 0; i < p; i++){ xDat.viewColumn(i).assign(StatUtils.standardizeData(xDat.viewColumn(i).toArray())); } }
/** * Constructs and returns a deep copy of the receiver. * <p> * <b>Note that the returned matrix is an independent deep copy.</b> * The returned matrix is not backed by this matrix, so changes in the returned matrix are not reflected in this matrix, and vice-versa. * * @return a deep copy of the receiver. */ public DoubleMatrix2D copy() { return like().assign(this); } /**
/** * Returns the parameter * <SPAN CLASS="MATH"><I><B>Σ</B></I></SPAN> of this object. * */ public double[][] getSigma() { return sigma.toArray(); }