/** * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver. * For example, if the receiver is an instance of type <tt>DenseDoubleMatrix2D</tt> the new matrix must be of type <tt>DenseDoubleMatrix1D</tt>, * if the receiver is an instance of type <tt>SparseDoubleMatrix2D</tt> the new matrix must be of type <tt>SparseDoubleMatrix1D</tt>, etc. * * @param size the number of cells the matrix shall have. * @return a new matrix of the corresponding dynamic type. */ public DoubleMatrix1D like1D(int size) { return new DenseDoubleMatrix1D(size); } /**
/** * Increase the size of the random vectors by a given number of dimensions * * @param byNumberOfDims The number of dimensions to increase. */ public void updateRandomVectors(int byNumberOfDims) { if (byNumberOfDims <= 0) { return; } for (int bckt = 0; bckt < partialL; bckt++) { for (int i = 0; i < k; i++) { DenseDoubleMatrix1D oldVect = bucketRandVectors.get(bckt)[i]; DenseDoubleMatrix1D biggerVect = new DenseDoubleMatrix1D(oldVect.size() + byNumberOfDims); //copy each value of old Vect to new bigger one int w; for (w = 0; w < oldVect.size(); w++) { biggerVect.set(w, oldVect.get(w)); } //for the remaining dimensions put gaussian values //since w==oldVect.size for (int index = 0; index < byNumberOfDims; index++) { biggerVect.set(w + index, r.nextGaussian()); } bucketRandVectors.get(bckt)[i] = biggerVect; } } }
/** * Constructs a matrix with a copy of the given values. * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. * * @param values The values to be filled into the new matrix. */ public DenseDoubleMatrix1D(double[] values) { this(values.length); assign(values); } /**
/** * Create random vector of given dimensions. using norm1 vector. * @param dimensions * @return A normal unit vector */ private DenseDoubleMatrix1D createRandomVector(int dims) { DenseDoubleMatrix1D randomVect = new DenseDoubleMatrix1D(dims); // Random r = new Random(); double norm = 0, g; int i; for (i = 0; i < dims; i++) { g = r.nextGaussian(); randomVect.setQuick(i, g); norm += Math.abs(g); } for (i = 0; i < dims; i++) { randomVect.setQuick(i, (randomVect.getQuick(i) / norm)); } return randomVect; }
public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, boolean transposeA) { if (transposeA) return viewDice().zMult(y,z,alpha,beta,false); if (z==null) z = new DenseDoubleMatrix1D(this.rows); if (!(y instanceof DenseDoubleMatrix1D && z instanceof DenseDoubleMatrix1D)) return super.zMult(y,z,alpha,beta,transposeA); int indexY = yy.index(0); int indexZ = zz.index(0);
checkSize(other); if (isNoView && other.isNoView) { // quickest System.arraycopy(other.elements, 0, this.elements, 0, this.elements.length); return this; if (haveSharedCells(other)) { DoubleMatrix1D c = other.copy(); if (! (c instanceof DenseDoubleMatrix1D)) { // should not happen return super.assign(source); int ys = other.stride; int index = index(0); int otherIndex = other.index(0); for (int k=size; --k >= 0; ) { elems[index] = otherElems[otherIndex];
/** * Sets all cells to the state specified by <tt>values</tt>. * <tt>values</tt> is required to have the same number of cells as the receiver. * <p> * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. * * @param values the values to be filled into the cells. * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>values.length != size()</tt>. */ public DoubleMatrix1D assign(double[] values) { if (isNoView) { if (values.length != size) throw new IllegalArgumentException("Must have same number of cells: length="+values.length+"size()="+size()); System.arraycopy(values, 0, this.elements, 0, values.length); } else { super.assign(values); } return this; } /**
public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, boolean transposeA) { if (transposeA) return viewDice().zMult(y,z,alpha,beta,false); if (z==null) z = new DenseDoubleMatrix1D(this.rows); if (!(y instanceof DenseDoubleMatrix1D && z instanceof DenseDoubleMatrix1D)) return super.zMult(y,z,alpha,beta,transposeA); int indexY = yy.index(0); int indexZ = zz.index(0);
checkSize(other); if (isNoView && other.isNoView) { // quickest System.arraycopy(other.elements, 0, this.elements, 0, this.elements.length); return this; if (haveSharedCells(other)) { DoubleMatrix1D c = other.copy(); if (! (c instanceof DenseDoubleMatrix1D)) { // should not happen return super.assign(source); int ys = other.stride; int index = index(0); int otherIndex = other.index(0); for (int k=size; --k >= 0; ) { elems[index] = otherElems[otherIndex];
/** * Sets all cells to the state specified by <tt>values</tt>. * <tt>values</tt> is required to have the same number of cells as the receiver. * <p> * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. * * @param values the values to be filled into the cells. * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>values.length != size()</tt>. */ public DoubleMatrix1D assign(double[] values) { if (isNoView) { if (values.length != size) throw new IllegalArgumentException("Must have same number of cells: length="+values.length+"size()="+size()); System.arraycopy(values, 0, this.elements, 0, values.length); } else { super.assign(values); } return this; } /**
/** * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver. * For example, if the receiver is an instance of type <tt>DenseDoubleMatrix2D</tt> the new matrix must be of type <tt>DenseDoubleMatrix1D</tt>, * if the receiver is an instance of type <tt>SparseDoubleMatrix2D</tt> the new matrix must be of type <tt>SparseDoubleMatrix1D</tt>, etc. * * @param size the number of cells the matrix shall have. * @return a new matrix of the corresponding dynamic type. */ public DoubleMatrix1D like1D(int size) { return new DenseDoubleMatrix1D(size); } /**
/** * Constructs a matrix with a copy of the given values. * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. * * @param values The values to be filled into the new matrix. */ public DenseDoubleMatrix1D(double[] values) { this(values.length); assign(values); } /**
/** * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified size. * For example, if the receiver is an instance of type <tt>DenseDoubleMatrix1D</tt> the new matrix must also be of type <tt>DenseDoubleMatrix1D</tt>, * if the receiver is an instance of type <tt>SparseDoubleMatrix1D</tt> the new matrix must also be of type <tt>SparseDoubleMatrix1D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @param size the number of cell the matrix shall have. * @return a new empty matrix of the same dynamic type. */ public DoubleMatrix1D like(int size) { return new DenseDoubleMatrix1D(size); } /**
/** * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver. * For example, if the receiver is an instance of type <tt>DenseDoubleMatrix2D</tt> the new matrix must be of type <tt>DenseDoubleMatrix1D</tt>, * if the receiver is an instance of type <tt>SparseDoubleMatrix2D</tt> the new matrix must be of type <tt>SparseDoubleMatrix1D</tt>, etc. * * @param size the number of cells the matrix shall have. * @return a new matrix of the corresponding dynamic type. */ public DoubleMatrix1D like1D(int size) { return new DenseDoubleMatrix1D(size); } /**
public void initialize() { disp = new DenseDoubleMatrix1D(2); distance = 0; visited = false; }
/** * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver. * For example, if the receiver is an instance of type <tt>DenseDoubleMatrix2D</tt> the new matrix must be of type <tt>DenseDoubleMatrix1D</tt>, * if the receiver is an instance of type <tt>SparseDoubleMatrix2D</tt> the new matrix must be of type <tt>SparseDoubleMatrix1D</tt>, etc. * * @param size the number of cells the matrix shall have. * @return a new matrix of the corresponding dynamic type. */ public DoubleMatrix1D like1D(int size) { return new DenseDoubleMatrix1D(size); } /**