// create matrix A double[][] matValues = new double[n][n]; ... // initialize values of the matrix Matrix A = new DenseMatrix(matValues); // create vector x double[] vecValues = new double[n]; ... // initialize values of the vector Vector x = new DenseVector(vecValues); // create vector y to store result of multiplication Vector y = new DenseVector(n); // perform multiplication A.mult(x, y);
public Vector solve(Matrix A, Vector b, Vector x) throws IterativeSolverNotConvergedException { checkSizes(A, b, x); double alpha = 0, beta = 0, c = 0, d = 0; A.multAdd(-1, x, r.set(b)); c = (eigmax - eigmin) / 2.0; d = (eigmax + eigmin) / 2.0; for (iter.setFirst(); !iter.converged(r, x); iter.next()) { M.apply(r, z); if (iter.isFirst()) { p.set(z); alpha = 2.0 / d; } else { beta = (alpha * c) / 2.0; beta *= beta; alpha = 1.0 / (d - beta); p.scale(beta).add(z); } A.mult(p, q); x.add(alpha, p); r.add(-alpha, q); } return x; }
/** * Computes standard deviation for given instance, without transforming target * back into original space. */ protected double computeStdDev(Instance inst, Vector k) throws Exception { double kappa = m_actualKernel.eval(-1, -1, inst) + m_deltaSquared; double s = m_L.mult(k, new DenseVector(k.size())).dot(k); double sigma = m_delta; if (kappa > s) { sigma = Math.sqrt(kappa - s); } return sigma; }
public Vector solve(Matrix A, Vector b, Vector x) throws IterativeSolverNotConvergedException { checkSizes(A, b, x); double alpha = 0, beta = 0, c = 0, d = 0; A.multAdd(-1, x, r.set(b)); c = (eigmax - eigmin) / 2.0; d = (eigmax + eigmin) / 2.0; for (iter.setFirst(); !iter.converged(r, x); iter.next()) { M.apply(r, z); if (iter.isFirst()) { p.set(z); alpha = 2.0 / d; } else { beta = (alpha * c) / 2.0; beta *= beta; alpha = 1.0 / (d - beta); p.scale(beta).add(z); } A.mult(p, q); x.add(alpha, p); r.add(-alpha, q); } return x; }
/** * Computes standard deviation for given instance, without transforming target * back into original space. */ protected double computeStdDev(Instance inst, Vector k) throws Exception { double kappa = m_actualKernel.eval(-1, -1, inst) + m_deltaSquared; double s = m_L.mult(k, new DenseVector(k.size())).dot(k); double sigma = m_delta; if (kappa > s) { sigma = Math.sqrt(kappa - s); } return sigma; }
public Vector solve(Matrix A, Vector b, Vector x) throws IterativeSolverNotConvergedException { checkSizes(A, b, x); double alpha = 0, beta = 0, rho = 0, rho_1 = 0; A.multAdd(-1, x, r.set(b)); for (iter.setFirst(); !iter.converged(r, x); iter.next()) { M.apply(r, z); rho = r.dot(z); if (iter.isFirst()) p.set(z); else { beta = rho / rho_1; p.scale(beta).add(z); } A.mult(p, q); alpha = rho / p.dot(q); x.add(alpha, p); r.add(-alpha, q); rho_1 = rho; } return x; }
private void av(double[] work, int input_offset, int output_offset) { DenseVector w = new DenseVector(work, false); Vector x = new DenseVectorSub(w, input_offset, matrix.numColumns()); Vector y = new DenseVectorSub(w, output_offset, matrix.numColumns()); matrix.mult(x, y); } }
public Vector solve(Matrix A, Vector b, Vector x) throws IterativeSolverNotConvergedException { checkSizes(A, b, x); double alpha = 0, beta = 0, rho = 0, rho_1 = 0; A.multAdd(-1, x, r.set(b)); for (iter.setFirst(); !iter.converged(r, x); iter.next()) { M.apply(r, z); rho = r.dot(z); if (iter.isFirst()) p.set(z); else { beta = rho / rho_1; p.scale(beta).add(z); } A.mult(p, q); alpha = rho / p.dot(q); x.add(alpha, p); r.add(-alpha, q); rho_1 = rho; } return x; }
private void av(double[] work, int input_offset, int output_offset) { DenseVector w = new DenseVector(work, false); Vector x = new DenseVectorSub(w, input_offset, matrix.numColumns()); Vector y = new DenseVectorSub(w, output_offset, matrix.numColumns()); matrix.mult(x, y); } }
A.mult(p, q); A.transMult(ptilde, qtilde);
/** * Internal function call that stores the result of a matrix multiply * into the given destinationMatrix. * * @param multiplicationMatrix * matrix to postmultiply this by * @param destinationMatrix * matrix to store the matrix multiplication result, must have * rows == this.getNumRows and columns == * multiplicationMatrix.getNumColumns */ protected void timesInto( final AbstractMTJMatrix multiplicationMatrix, AbstractMTJMatrix destinationMatrix) { int M = this.getNumRows(); int N = multiplicationMatrix.getNumColumns(); if ((M != destinationMatrix.getNumRows()) || (N != destinationMatrix.getNumColumns())) { throw new DimensionalityMismatchException( "Multiplication dimensions do not agree."); } this.internalMatrix.mult( multiplicationMatrix.internalMatrix, destinationMatrix.internalMatrix); }
/** * Internal function call that stores the result of a matrix multiply * into the given destinationMatrix. * * @param multiplicationMatrix * matrix to postmultiply this by * @param destinationMatrix * matrix to store the matrix multiplication result, must have * rows == this.getNumRows and columns == * multiplicationMatrix.getNumColumns */ protected void timesInto( final AbstractMTJMatrix multiplicationMatrix, AbstractMTJMatrix destinationMatrix) { int M = this.getNumRows(); int N = multiplicationMatrix.getNumColumns(); if ((M != destinationMatrix.getNumRows()) || (N != destinationMatrix.getNumColumns())) { throw new DimensionalityMismatchException( "Multiplication dimensions do not agree."); } this.internalMatrix.mult( multiplicationMatrix.internalMatrix, destinationMatrix.internalMatrix); }
/** * Internal function call that stores the result of a matrix multiply * into the given destinationMatrix. * * @param multiplicationMatrix * matrix to postmultiply this by * @param destinationMatrix * matrix to store the matrix multiplication result, must have * rows == this.getNumRows and columns == * multiplicationMatrix.getNumColumns */ protected void timesInto( final AbstractMTJMatrix multiplicationMatrix, AbstractMTJMatrix destinationMatrix) { int M = this.getNumRows(); int N = multiplicationMatrix.getNumColumns(); if ((M != destinationMatrix.getNumRows()) || (N != destinationMatrix.getNumColumns())) { throw new DimensionalityMismatchException( "Multiplication dimensions do not agree."); } this.internalMatrix.mult( multiplicationMatrix.internalMatrix, destinationMatrix.internalMatrix); }
/** * Internal function call that stores the result of a matrix multiply * into the given destinationVector. * * @param multiplicationVector * vector to postmultiply this by * @param destinationVector * vector to store the matrix multiplication result, must have * dimensionality == this.getNumRows */ protected void timesInto( final AbstractMTJVector multiplicationVector, AbstractMTJVector destinationVector) { int M = this.getNumRows(); if (M != destinationVector.getDimensionality()) { throw new DimensionalityMismatchException( M, destinationVector.getDimensionality()); } this.internalMatrix.mult( multiplicationVector.getInternalVector(), destinationVector.getInternalVector()); }
/** * Internal function call that stores the result of a matrix multiply * into the given destinationVector. * * @param multiplicationVector * vector to postmultiply this by * @param destinationVector * vector to store the matrix multiplication result, must have * dimensionality == this.getNumRows */ protected void timesInto( final AbstractMTJVector multiplicationVector, AbstractMTJVector destinationVector) { int M = this.getNumRows(); if (M != destinationVector.getDimensionality()) { throw new DimensionalityMismatchException( M, destinationVector.getDimensionality()); } this.internalMatrix.mult( multiplicationVector.getInternalVector(), destinationVector.getInternalVector()); }
public Assignment sample (Randoms r) { // generate from standard normal double[] vals = new double [mean.size ()]; for (int k = 0; k < vals.length; k++) { vals[k] = r.nextGaussian (); } // and transform Vector Z = new DenseVector (vals, false); DenseVector result = new DenseVector (vals.length); variance.mult (Z, result); result = (DenseVector) result.add (mean); return new Assignment (vars.toVariableArray (), result.getData ()); }
public Assignment sample (Randoms r) { // generate from standard normal double[] vals = new double [mean.size ()]; for (int k = 0; k < vals.length; k++) { vals[k] = r.nextGaussian (); } // and transform Vector Z = new DenseVector (vals, false); DenseVector result = new DenseVector (vals.length); variance.mult (Z, result); result = (DenseVector) result.add (mean); return new Assignment (vars.toVariableArray (), result.getData ()); }
public Assignment sample (Randoms r) { // generate from standard normal double[] vals = new double [mean.size ()]; for (int k = 0; k < vals.length; k++) { vals[k] = r.nextGaussian (); } // and transform Vector Z = new DenseVector (vals, false); DenseVector result = new DenseVector (vals.length); variance.mult (Z, result); result = (DenseVector) result.add (mean); return new Assignment (vars.toVariableArray (), result.getData ()); }
/** * Internal function call that stores the result of a matrix multiply * into the given destinationVector. * * @param multiplicationVector * vector to postmultiply this by * @param destinationVector * vector to store the matrix multiplication result, must have * dimensionality == this.getNumRows */ protected void timesInto( final AbstractMTJVector multiplicationVector, AbstractMTJVector destinationVector) { int M = this.getNumRows(); if (M != destinationVector.getDimensionality()) { throw new DimensionalityMismatchException( M, destinationVector.getDimensionality()); } this.internalMatrix.mult( multiplicationVector.getInternalVector(), destinationVector.getInternalVector()); }
/** * Takes a batch of data and transforms it. * * @param instances the data to process * @return the processed instances * @throws Exception is thrown if a problem occurs */ @Override protected Instances process(Instances instances) throws Exception { Instances transformed = getOutputFormat(); for (Instance inst : instances) { Vector newInst = m_WeightingMatrix.mult(instanceToVector(inst), new DenseVector(m_WeightingMatrix.numRows())); double[] newVals = new double[m_WeightingMatrix.numRows() + 1]; for (int i = 0; i < m_WeightingMatrix.numRows(); i++) { newVals[i] = newInst.get(i); } newVals[transformed.classIndex()] = inst.classValue(); transformed.add(new DenseInstance(inst.weight(), newVals)); } return transformed; }