/** * Sets all cells to the state specified by <tt>value</tt>. * @param value the value to be filled into the cells. * @return <tt>this</tt> (for convenience only). */ public DoubleMatrix1D assign(double value) { for (int i=size; --i >= 0;) { setQuick(i,value); } return this; } /**
/** * Sets all cells to the state specified by <tt>value</tt>. * @param value the value to be filled into the cells. * @return <tt>this</tt> (for convenience only). */ public DoubleMatrix1D assign(double value) { for (int i=size; --i >= 0;) { setQuick(i,value); } return this; } /**
/** * Sets the matrix cell at coordinate <tt>index</tt> to the specified value. * * <p>Provided with invalid parameters this method may access illegal indexes without throwing any exception. * <b>You should only use this method when you are absolutely sure that the coordinate is within bounds.</b> * Precondition (unchecked): <tt>index<0 || index>=size()</tt>. * * @param index the index of the cell. * @param value the value to be filled into the specified cell. */ public void setQuick(int index, double value) { content.setQuick(index, value); } /**
/** * Sets the matrix cell at coordinate <tt>index</tt> to the specified value. * * <p>Provided with invalid parameters this method may access illegal indexes without throwing any exception. * <b>You should only use this method when you are absolutely sure that the coordinate is within bounds.</b> * Precondition (unchecked): <tt>index<0 || index>=size()</tt>. * * @param index the index of the cell. * @param value the value to be filled into the specified cell. */ public void setQuick(int index, double value) { content.setQuick(index, value); } /**
/** * Sets the matrix cell at coordinate <tt>index</tt> to the specified value. * * @param index the index of the cell. * @param value the value to be filled into the specified cell. * @throws IndexOutOfBoundsException if <tt>index<0 || index>=size()</tt>. */ public void set(int index, double value) { if (index<0 || index>=size) checkIndex(index); setQuick(index,value); } /**
/** * Sets the matrix cell at coordinate <tt>index</tt> to the specified value. * * @param index the index of the cell. * @param value the value to be filled into the specified cell. * @throws IndexOutOfBoundsException if <tt>index<0 || index>=size()</tt>. */ public void set(int index, double value) { if (index<0 || index>=size) checkIndex(index); setQuick(index,value); } /**
/** Constructs a matrix with cells having descending values. For debugging purposes. Example: <tt>2 1 0</tt> */ public DoubleMatrix1D descending(int size) { DoubleMatrix1D matrix = make(size); int v = 0; for (int i=size; --i >= 0;) { matrix.setQuick(i, v++); } return matrix; } /**
/** Constructs a matrix with cells having descending values. For debugging purposes. Example: <tt>2 1 0</tt> */ public DoubleMatrix1D descending(int size) { DoubleMatrix1D matrix = make(size); int v = 0; for (int i=size; --i >= 0;) { matrix.setQuick(i, v++); } return matrix; } /**
/** Swaps each element <tt>this[i]</tt> with <tt>other[i]</tt>. @throws IllegalArgumentException if <tt>size() != other.size()</tt>. */ public void swap(DoubleMatrix1D other) { checkSize(other); for (int i=size; --i >= 0; ) { double tmp = getQuick(i); setQuick(i, other.getQuick(i)); other.setQuick(i, tmp); } return; } /**
@Override public double apply(int i, int j, double Aij) { ret.setQuick(j, ret.getQuick(j) + Aij * a.getQuick(i)); return Aij; } });
@Override public double apply(int i, int j, double Aij) { double vi = 0; vi += Aij * b.getQuick(j); ret.setQuick(i, ret.getQuick(i) + beta * vi); return Aij; } });
@Override public double apply(int i, int j, double Aij) { ret.setQuick(i, ret.getQuick(i) + Aij * a.getQuick(j)); return Aij; } });
/** * Returns v = c * v1. * Useful in avoiding the need of the copy() in the colt api. */ public static final DoubleMatrix1D scalarMult(DoubleMatrix1D v1, double c){ DoubleMatrix1D ret = DoubleFactory1D.dense.make(v1.size()); for(int i=0; i<ret.size(); i++){ ret.setQuick(i, c * v1.getQuick(i)); } return ret; }
/** * Matrix-vector multiplication with diagonal matrix. * @param diagonalM diagonal matrix M, in the form of a vector of its diagonal elements * @param vector * @return M.x */ public static final DoubleMatrix1D diagonalMatrixMult(DoubleMatrix1D diagonalM, DoubleMatrix1D vector){ int n = diagonalM.size(); DoubleMatrix1D ret = DoubleFactory1D.dense.make(n); for(int i=0; i<n; i++){ ret.setQuick(i, diagonalM.getQuick(i) * vector.getQuick(i)); } return ret; }
/** * {@inheritDoc} */ @Override protected DoubleMatrix1D gradFiStepX(DoubleMatrix1D stepX){ DoubleMatrix1D ret = F1.make(getMieq()); for(int i=0; i<originalProblem.getDim(); i++){ ret.setQuick( i, - stepX.getQuick(i) - stepX.getQuick(getDim()-1)); ret.setQuick(originalProblem.getDim()+i, stepX.getQuick(i) - stepX.getQuick(getDim()-1)); } //counts for the new upper bound on s ret.setQuick(getMieq()-1, stepX.getQuick(getDim()-1)); return ret; }
/** * @see "Convex Optimization, p. 610" */ private DoubleMatrix1D rCent(DoubleMatrix1D fiX, DoubleMatrix1D L, double t) { DoubleMatrix1D ret = F1.make(L.size()); for(int i=0; i<ret.size(); i++){ ret.setQuick(i, -L.getQuick(i)*fiX.getQuick(i) - 1. / t); } return ret; } }
/** * @see "Convex Optimization, p. 610" */ private DoubleMatrix1D rCent(DoubleMatrix1D fiX, DoubleMatrix1D L, double t) { DoubleMatrix1D ret = F1.make(L.size()); for(int i=0; i<ret.size(); i++){ ret.setQuick(i, -L.getQuick(i)*fiX.getQuick(i) - 1. / t); } return ret; }
/** * Returns v = v1 + c*v2. * Useful in avoiding the need of the copy() in the colt api. */ public static final DoubleMatrix1D add(DoubleMatrix1D v1, DoubleMatrix1D v2, double c){ if(v1.size()!=v2.size()){ throw new IllegalArgumentException("wrong vectors dimensions"); } DoubleMatrix1D ret = DoubleFactory1D.dense.make(v1.size()); for(int i=0; i<ret.size(); i++){ ret.setQuick(i, v1.getQuick(i) + c*v2.getQuick(i)); } return ret; }
/** * Calculates the second term of the first row of (11.55) "Convex Optimization". * @see "Convex Optimization, 11.55" */ protected DoubleMatrix1D gradSum(double t, DoubleMatrix1D fiX) { DoubleMatrix1D gradSum = F1.make(getDim()); for(int i=0; i<dim; i++){ double d = 0; d += 1. / (t * fiX.getQuick(i)); d += -1. / (t * fiX.getQuick(getDim() + i)); gradSum.setQuick(i, d); } return gradSum; }