/** {@inheritDoc} */ @Override public double getEntry(int index) throws OutOfRangeException { return v.getEntry(index); }
protected List getAlgorithmWeight(RealVector solution) throws Exception{ List<Double> weightList = new ArrayList<>(); Integer n = solution.getDimension(); for(int i=0; i<n; i++){ weightList.add(solution.getEntry(i)); } return weightList; }
/** * Change an entry at the specified index. * * @param index Index location of entry to be set. * @param increment Value to add to the vector entry. * @throws OutOfRangeException if the index is not valid. * @since 3.0 */ public void addToEntry(int index, double increment) throws OutOfRangeException { setEntry(index, getEntry(index) + increment); }
/** * Get the value of the maximum entry. * * @return the value of the maximum entry or {@code NaN} if all * entries are {@code NaN}. */ public double getMaxValue() { final int maxIndex = getMaxIndex(); return maxIndex < 0 ? Double.NaN : getEntry(maxIndex); }
/** * Get the value of the entry. * * @return the value of the entry. */ public double getValue() { return getEntry(getIndex()); }
/** * Get the value of the minimum entry. * * @return the value of the minimum entry or {@code NaN} if all * entries are {@code NaN}. */ public double getMinValue() { final int minIndex = getMinIndex(); return minIndex < 0 ? Double.NaN : getEntry(minIndex); }
/** * Construct a vector by appending one vector to another vector. * @param v1 First vector (will be put in front of the new vector). * @param v2 Second vector (will be put at back of the new vector). */ public ArrayRealVector(RealVector v1, ArrayRealVector v2) { final int l1 = v1.getDimension(); final int l2 = v2.data.length; data = new double[l1 + l2]; for (int i = 0; i < l1; ++i) { data[i] = v1.getEntry(i); } System.arraycopy(v2.data, 0, data, l1, l2); }
/** * Construct a vector by appending one vector to another vector. * @param v1 First vector (will be put in front of the new vector). * @param v2 Second vector (will be put at back of the new vector). */ public ArrayRealVector(ArrayRealVector v1, RealVector v2) { final int l1 = v1.data.length; final int l2 = v2.getDimension(); data = new double[l1 + l2]; System.arraycopy(v1.data, 0, data, 0, l1); for (int i = 0; i < l2; ++i) { data[l1 + i] = v2.getEntry(i); } }
/** * A clone of the BLAS {@code DAXPY} function, which carries out the * operation y ← a · x + y. This is for internal use only: no * dimension checks are provided. * * @param a the scalar by which {@code x} is to be multiplied * @param x the vector to be added to {@code y} * @param y the vector to be incremented */ private static void daxpy(final double a, final RealVector x, final RealVector y) { final int n = x.getDimension(); for (int i = 0; i < n; i++) { y.setEntry(i, a * x.getEntry(i) + y.getEntry(i)); } }
/** * Convert the vector to an array of {@code double}s. * The array is independent from this vector data: the elements * are copied. * * @return an array containing a copy of the vector elements. */ public double[] toArray() { int dim = getDimension(); double[] values = new double[dim]; for (int i = 0; i < dim; i++) { values[i] = getEntry(i); } return values; }
/** * Construct a vector from another vector, using a deep copy. * * @param v vector to copy. * @throws NullArgumentException if {@code v} is {@code null}. */ public ArrayRealVector(RealVector v) throws NullArgumentException { if (v == null) { throw new NullArgumentException(); } data = new double[v.getDimension()]; for (int i = 0; i < data.length; ++i) { data[i] = v.getEntry(i); } }
public float[] solveFToF(float[] b) { RealVector bVec = new ArrayRealVector(b.length); for (int i = 0; i < b.length; i++) { bVec.setEntry(i, b[i]); } RealVector resultVec = solver.solve(bVec); float[] result = new float[resultVec.getDimension()]; for (int i = 0; i < result.length; i++) { result[i] = (float) resultVec.getEntry(i); } return result; }
/** * Generic copy constructor. * * @param v Instance to copy from. */ public OpenMapRealVector(RealVector v) { virtualSize = v.getDimension(); entries = new OpenIntToDoubleHashMap(0.0); epsilon = DEFAULT_ZERO_TOLERANCE; for (int key = 0; key < virtualSize; key++) { double value = v.getEntry(key); if (!isDefaultValue(value)) { entries.put(key, value); } } }
/** {@inheritDoc} */ @Override public void setSubVector(int index, RealVector v) throws OutOfRangeException { checkIndex(index); checkIndex(index + v.getDimension() - 1); for (int i = 0; i < v.getDimension(); i++) { setEntry(i + index, v.getEntry(i)); } }
/** {@inheritDoc} */ @Override public OpenMapRealVector append(RealVector v) { if (v instanceof OpenMapRealVector) { return append((OpenMapRealVector) v); } else { final OpenMapRealVector res = new OpenMapRealVector(this, v.getDimension()); for (int i = 0; i < v.getDimension(); i++) { res.setEntry(i + virtualSize, v.getEntry(i)); } return res; } }
/** {@inheritDoc} */ @Override public void setSubVector(int index, RealVector v) throws OutOfRangeException { if (v instanceof ArrayRealVector) { setSubVector(index, ((ArrayRealVector) v).data); } else { try { for (int i = index; i < index + v.getDimension(); ++i) { data[i] = v.getEntry(i - index); } } catch (IndexOutOfBoundsException e) { checkIndex(index); checkIndex(index + v.getDimension() - 1); } } }
/** {@inheritDoc} */ public void setColumnVector(final int column, final RealVector vector) throws OutOfRangeException, MatrixDimensionMismatchException { MatrixUtils.checkColumnIndex(this, column); final int nRows = getRowDimension(); if (vector.getDimension() != nRows) { throw new MatrixDimensionMismatchException(vector.getDimension(), 1, nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, vector.getEntry(i)); } }
/** {@inheritDoc} */ public void setRowVector(final int row, final RealVector vector) throws OutOfRangeException, MatrixDimensionMismatchException { MatrixUtils.checkRowIndex(this, row); final int nCols = getColumnDimension(); if (vector.getDimension() != nCols) { throw new MatrixDimensionMismatchException(1, vector.getDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, vector.getEntry(i)); } }
/** {@inheritDoc} */ @Override public OpenMapRealVector ebeDivide(RealVector v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); OpenMapRealVector res = new OpenMapRealVector(this); /* * MATH-803: it is not sufficient to loop through non zero entries of * this only. Indeed, if this[i] = 0d and v[i] = 0d, then * this[i] / v[i] = NaN, and not 0d. */ final int n = getDimension(); for (int i = 0; i < n; i++) { res.setEntry(i, this.getEntry(i) / v.getEntry(i)); } return res; }
/** {@inheritDoc} */ @Override public OpenMapRealVector ebeMultiply(RealVector v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); OpenMapRealVector res = new OpenMapRealVector(this); Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); res.setEntry(iter.key(), iter.value() * v.getEntry(iter.key())); } return res; }