public void run() { for (int i = firstIdx; i < lastIdx; i++) { C.viewPart(i * size_y, size_y).assign(y, DoubleFunctions.multSecond(x.getQuick(i))); } } });
public void run() { for (int i = firstIdx; i < lastIdx; i++) { C.viewPart(i * size_y, size_y).assign(y, DoubleFunctions.multSecond(x.getQuick(i))); } } });
/** * C = A||A||..||A; Constructs a new matrix which is concatenated * <tt>repeat</tt> times. Example: * * <pre> * 0 1 * repeat(3) --> * 0 1 0 1 0 1 * * </pre> */ public DoubleMatrix1D repeat(DoubleMatrix1D A, int repeat) { int size = (int) A.size(); DoubleMatrix1D matrix = make(repeat * size); for (int i = repeat; --i >= 0;) { matrix.viewPart(size * i, size).assign(A); } return matrix; }
/** * C = A||B; Constructs a new matrix which is the concatenation of two other * matrices. Example: <tt>0 1</tt> append <tt>3 4</tt> --> <tt>0 1 3 4</tt>. */ public DoubleMatrix1D append(DoubleMatrix1D A, DoubleMatrix1D B) { // concatenate DoubleMatrix1D matrix = make((int) (A.size() + B.size())); matrix.viewPart(0, (int) A.size()).assign(A); matrix.viewPart((int) A.size(), (int) B.size()).assign(B); return matrix; }
/** * C = A||B; Constructs a new matrix which is the concatenation of two other * matrices. Example: <tt>0 1</tt> append <tt>3 4</tt> --> <tt>0 1 3 4</tt>. */ public DoubleMatrix1D append(DoubleMatrix1D A, DoubleMatrix1D B) { // concatenate DoubleMatrix1D matrix = make((int) (A.size() + B.size())); matrix.viewPart(0, (int) A.size()).assign(A); matrix.viewPart((int) A.size(), (int) B.size()).assign(B); return matrix; }
/** * Appends a value to the given matrix. * * @param x input matrix of length n * @param a value to append * @return new matrix of length n + 1 */ public static DoubleMatrix1D append(DoubleMatrix1D x, double a) { int n = (int) x.size(); DoubleMatrix1D y = DoubleFactory1D.dense.make(n + 1); y.viewPart(0, n).assign(x); y.setQuick(n, a); return y; }
/** * Appends a value to the given matrix. * * @param x input matrix of length n * @param a value to append * @return new matrix of length n + 1 */ public static DoubleMatrix1D append(DoubleMatrix1D x, double a) { int n = (int) x.size(); DoubleMatrix1D y = DoubleFactory1D.dense.make(n + 1); y.viewPart(0, n).assign(x); y.setQuick(n, a); return y; }
/** * Appends a value to the given matrix. * * @param x input matrix of length n * @param a value to append * @return new matrix of length n + 1 */ public static DoubleMatrix1D append(DoubleMatrix1D x, double a) { int n = (int) x.size(); DoubleMatrix1D y = DoubleFactory1D.dense.make(n + 1); y.viewPart(0, n).assign(x); y.setQuick(n, a); return y; }
public DoubleMatrix1D vectorize() { DoubleMatrix1D v = new SparseDoubleMatrix1D((int) size()); int length = rows * columns; for (int s = 0; s < slices; s++) { v.viewPart(s * length, length).assign(viewSlice(s).vectorize()); } return v; }
public DoubleMatrix1D vectorize() { DoubleMatrix1D v = new DenseDoubleMatrix1D((int) size()); int length = rows * columns; for (int s = 0; s < slices; s++) { v.viewPart(s * length, length).assign(viewSlice(s).vectorize()); } return v; }
public DoubleMatrix1D vectorize() { DoubleMatrix1D v = new DenseDoubleMatrix1D((int) size()); int length = rows * columns; for (int s = 0; s < slices; s++) { v.viewPart(s * length, length).assign(viewSlice(s).vectorize()); } return v; }
public DoubleMatrix1D vectorize() { DoubleMatrix1D v = new SparseDoubleMatrix1D((int) size()); int length = rows * columns; for (int s = 0; s < slices; s++) { v.viewPart(s * length, length).assign(viewSlice(s).vectorize()); } return v; }
public DoubleMatrix1D vectorize() { DoubleMatrix1D v = new DenseDoubleMatrix1D((int) size()); int length = rows * columns; for (int s = 0; s < slices; s++) { v.viewPart(s * length, length).assign(viewSlice(s).vectorize()); } return v; }
public DoubleMatrix1D vectorize() { DoubleMatrix1D v = new DenseDoubleMatrix1D((int) size()); int length = rows * columns; for (int s = 0; s < slices; s++) { v.viewPart(s * length, length).assign(viewSlice(s).vectorize()); } return v; }
/** * Constructs a matrix which is the concatenation of all given parts. Cells * are copied. */ public DoubleMatrix1D make(DoubleMatrix1D[] parts) { if (parts.length == 0) return make(0); int size = 0; for (int i = 0; i < parts.length; i++) size += parts[i].size(); DoubleMatrix1D vector = make(size); size = 0; for (int i = 0; i < parts.length; i++) { vector.viewPart(size, (int) parts[i].size()).assign(parts[i]); size += parts[i].size(); } return vector; }
/** * Constructs a matrix which is the concatenation of all given parts. Cells * are copied. */ public DoubleMatrix1D make(DoubleMatrix1D[] parts) { if (parts.length == 0) return make(0); int size = 0; for (int i = 0; i < parts.length; i++) size += parts[i].size(); DoubleMatrix1D vector = make(size); size = 0; for (int i = 0; i < parts.length; i++) { vector.viewPart(size, (int) parts[i].size()).assign(parts[i]); size += parts[i].size(); } return vector; }
private double GCVstopfun(double alpha, DoubleMatrix1D u, double[] s, double beta, int rows, int columns) { int k = s.length; double beta2 = beta * beta; DoubleMatrix1D s2 = new DenseDoubleMatrix1D(s); s2.assign(DoubleFunctions.square); double alpha2 = alpha * alpha; DoubleMatrix1D t1 = s2.copy(); t1.assign(DoubleFunctions.plus(alpha2)); t1.assign(DoubleFunctions.inv); DoubleMatrix1D t2 = t1.copy(); t2.assign(u.viewPart(0, k), DoubleFunctions.mult); t2.assign(DoubleFunctions.mult(alpha2)); double num = beta2 * (t2.aggregate(DoubleFunctions.plus, DoubleFunctions.square) + Math.pow(Math.abs(u.getQuick(k)), 2)) / columns; double den = (rows - t1.aggregate(s2, DoubleFunctions.plus, DoubleFunctions.mult)) / columns; den = den * den; return num / den; }
private double GCVstopfun(double alpha, DoubleMatrix1D u, double[] s, double beta, int rows, int columns) { int k = s.length; double beta2 = beta * beta; DoubleMatrix1D s2 = new DenseDoubleMatrix1D(s); s2.assign(DoubleFunctions.square); double alpha2 = alpha * alpha; DoubleMatrix1D t1 = s2.copy(); t1.assign(DoubleFunctions.plus(alpha2)); t1.assign(DoubleFunctions.inv); DoubleMatrix1D t2 = t1.copy(); t2.assign(u.viewPart(0, k), DoubleFunctions.mult); t2.assign(DoubleFunctions.mult(alpha2)); double num = beta2 * (t2.aggregate(DoubleFunctions.plus, DoubleFunctions.square) + Math.pow(Math.abs(u.getQuick(k)), 2)) / columns; double den = (rows - t1.aggregate(s2, DoubleFunctions.plus, DoubleFunctions.mult)) / columns; den = den * den; return num / den; }
/** * Solves A*x = b. * * @return x; a new independent matrix; solution if A is square, least * squares solution otherwise. */ public DoubleMatrix1D solve(DoubleMatrix2D A, DoubleMatrix1D b) { if (A.rows() == A.columns()) { return lu(A).solve(b); } else { DoubleMatrix1D x = b.copy(); qr(A).solve(x); return x.viewPart(0, A.columns()).copy(); } }
/** * Solves A*x = b. * * @return x; a new independent matrix; solution if A is square, least * squares solution otherwise. */ public DoubleMatrix1D solve(DoubleMatrix2D A, DoubleMatrix1D b) { if (A.rows() == A.columns()) { return lu(A).solve(b); } else { DoubleMatrix1D x = b.copy(); qr(A).solve(x); return x.viewPart(0, A.columns()).copy(); } }