@Override public double add(int idx, double val) { return v.add(idx, val); }
@Override public int add(int idx, int val) { return v.add(idx, val); }
@Override public <M extends Number> void add(Vector<M> vector) { v.add(vector); }
@Override public <M extends Number> void add(Matrix<M> matrix) { assert (m == matrix.rows()); assert (n == matrix.cols()); if (matrix instanceof SparseMatrix) { final Vector<M>[] arr2 = ((SparseMatrix<M>) matrix).arr; for (int i = 0; i < m; i++) { if (arr[i] != null && arr2 != null) { arr[i].add(arr2[i]); } else if (arr2 != null) { arr[i] = using.make(n, defaultValue); arr[i].add(arr2[i]); } } } else { for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { row(i).add(j, matrix.doubleValue(i, j)); } } } }
@Override public <M extends Number> Matrix<N> product(Matrix<M> B) { if (this.cols() != B.rows()) { throw new IllegalArgumentException("Matrix dimensions not suitable for product"); } if (defaultValue != 0.0 || (B instanceof SparseMatrix && ((SparseMatrix) B).defaultValue != 0.0)) { throw new UnsupportedOperationException(); } Vector<N>[] res = new Vector[this.rows()]; for (int i = 0; i < this.rows(); i++) { res[i] = using.make(B.cols(), 0.0); for (int j : this.arr[i].keySet()) { final Vector<M> r = B.row(j); for (int k : r.keySet()) { res[i].add(k, this.arr[i].doubleValue(j) * B.doubleValue(j, k)); } } } return new SparseMatrix<N>(this.rows(), res, using); }
public BetaLMImpl(File data) throws IOException { final ParallelReader pr = ParallelReader.fromFile(data); this.W = pr.W(); this.x = pr.x; this.mu = new RealVector(this.W); this.mu_f = new RealVector(this.W); this.sumMu2 = initMu(x, this.W); if (method == Method.DF_DICE || method == Method.DF_JACCARD) { df = new RealVector(this.W); this.dfSp = null; for (int j = 0; j < x.length; j++) { for (int w : x[j][0].keySet()) { df.add(w, 1); } } for (int w = 0; w < this.W; w++) { df.divide(w,x.length); } } else { df = null; dfSp = null; } }