private DenseVector asDense(Vector aVec) { if (aVec instanceof DenseVector) { return (DenseVector) aVec; } else { return new DenseVector(aVec); } }
/** * Creates a new instance of DenseVector * @param values The array of values to give the vector */ protected DenseVector( double... values) { this( new no.uib.cipr.matrix.DenseVector( values ) ); }
/** * Creates a new instance of DenseVector * @param values The array of values to give the vector */ protected DenseVector( double... values) { this( new no.uib.cipr.matrix.DenseVector( values ) ); }
@Override public DenseVector copy() { return new DenseVector(this); }
private Vector randvec(int nvec, double d) { double[] ret = new double[nvec]; for (int i = 0; i < ret.length; i++) { ret[i] = d * r.nextDouble(); } return new DenseVector(ret); }
@Override public DenseVector copy() { double[] data = Arrays.copyOfRange(wrapped.getData(), offset, offset + size); return new DenseVector(data, false); } }
/** * Creates a random vector. Numbers are drawn from a uniform distribution * between 0 and 1 * * @param size * Size of the vector */ public static Vector random(int size) { return random(new DenseVector(size)); }
/** * Creates a random vector. Numbers are drawn from a uniform distribution * between 0 and 1 * * @param size * Size of the vector */ public static Vector random(int size) { return random(new DenseVector(size)); }
/** * Copy constructor * @param vector Vector to copy */ protected DenseVector( AbstractMTJVector vector ) { this( new no.uib.cipr.matrix.DenseVector( vector.getInternalVector() ) ); }
@Override public Double apply(IndependentPair<double[], double[]> in) { double[] first = in.firstObject(); double[] second = in.secondObject(); return new DenseVector(first,false).dot(new DenseVector(second,false)); }
/** * Returns the log of the density value for the given vector. * * @param valuePassed input vector * @return log density based on given distribution */ @Override public double logDensity(double[] valuePassed) { // calculate mean subtractions Vector x = new DenseVector(valuePassed); return lnconstant - 0.5 * x.dot(covarianceInverse.mult(x.add(-1.0, mean), new DenseVector(x.size()))); }
/** * Computes the mean vector * @param matrix the data (assumed to contain at least one row) * @param weights the observation weights, normalized to sum to 1. * @return the weighted mean */ private DenseVector weightedMean(double[][] matrix, DenseVector weights) { return (DenseVector)new DenseMatrix(matrix).transMult(weights, new DenseVector(matrix[0].length)); }
protected DenseVector createPreferenceVector(int tokenSize, double d) { DenseVector biasVector = new DenseVector(tokenSize); double value = 1.0; for (int i = 0; i < biasVector.size(); i++) { biasVector.set(i, value); } return biasVector; }
public Vector[] getPlane() { Vector[] allInclusive = new GramSchmidtProcess().apply(new DenseVector(direction).getData()); Vector[] ret = new Vector[allInclusive.length - 1]; for (int i = 0; i < ret.length; i++) { ret[i] = allInclusive[i+1]; } return ret; }
public static DenseVector getColumn(Matrix m, int j) { DenseVector v = new DenseVector(m.numRows()); for (int i = 0; i < v.size(); i++) { v.set(i, m.get(i, j)); } return v; }
protected Vector getDegreeVector(int tokenSize, FlexCompColMatrix adjacentMatrix) { Vector degreeVector = new DenseVector(tokenSize); for (int i = 0; i < adjacentMatrix.numColumns(); i++) { SparseVector col = adjacentMatrix.getColumn(i); double sum = 0; for (VectorEntry entry : col) { sum += entry.get(); } degreeVector.set(i, sum); } return degreeVector; }
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); } }
double[] feedforward(double[] input) { final DenseVector iv = new DenseVector(input, false); final DenseVector a1 = sigmoid(w1.multAdd(iv, b1.copy())); final DenseVector a2 = sigmoid(w2.multAdd(a1, b2.copy())); return a2.getData(); }
double[] feedforward(double[] input) { final DenseVector iv = new DenseVector(input, false); final DenseVector a1 = sigmoid(w1.multAdd(iv, b1.copy())); final DenseVector a2 = sigmoid(w2.multAdd(a1, b2.copy())); return a2.getData(); }
double[][] getLayerActivations(double[] input) { final DenseVector iv = new DenseVector(input, false); final DenseVector a1 = sigmoid(w1.multAdd(iv, b1.copy())); final DenseVector a2 = sigmoid(w2.multAdd(a1, b2.copy())); return new double[][] { a1.getData(), a2.getData() }; }