コード例 #1
0
 /** {@inheritDoc} */
 public OpenMapRealVector subtract(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   OpenMapRealVector res = new OpenMapRealVector(this);
   for (int i = 0; i < v.length; i++) {
     if (entries.containsKey(i)) {
       res.setEntry(i, entries.get(i) - v[i]);
     } else {
       res.setEntry(i, -v[i]);
     }
   }
   return res;
 }
コード例 #2
0
 /**
  * Optimized method to add two OpenMapRealVectors.
  *
  * @param v Vector to add with
  * @return The sum of <code>this</code> with <code>v</code>
  * @throws IllegalArgumentException If the dimensions don't match
  */
 public OpenMapRealVector add(OpenMapRealVector v) throws IllegalArgumentException {
   checkVectorDimensions(v.getDimension());
   OpenMapRealVector res = (OpenMapRealVector) copy();
   Iterator iter = v.getEntries().iterator();
   while (iter.hasNext()) {
     iter.advance();
     int key = iter.key();
     if (entries.containsKey(key)) {
       res.setEntry(key, entries.get(key) + iter.value());
     } else {
       res.setEntry(key, iter.value());
     }
   }
   return res;
 }
コード例 #3
0
 /** {@inheritDoc} */
 public OpenMapRealVector append(double[] a) {
   OpenMapRealVector res = new OpenMapRealVector(this, a.length);
   for (int i = 0; i < a.length; i++) {
     res.setEntry(i + virtualSize, a[i]);
   }
   return res;
 }
コード例 #4
0
 /** {@inheritDoc} */
 public void setSubVector(int index, double[] v) throws MatrixIndexException {
   checkIndex(index);
   checkIndex(index + v.length - 1);
   for (int i = 0; i < v.length; i++) {
     setEntry(i + index, v[i]);
   }
 }
コード例 #5
0
 /** {@inheritDoc} */
 public OpenMapRealVector add(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   OpenMapRealVector res = new OpenMapRealVector(getDimension());
   for (int i = 0; i < v.length; i++) {
     res.setEntry(i, v[i] + getEntry(i));
   }
   return res;
 }
コード例 #6
0
 /**
  * Optimized method to append a OpenMapRealVector.
  *
  * @param v vector to append
  * @return The result of appending <code>v</code> to self
  */
 public OpenMapRealVector append(OpenMapRealVector v) {
   OpenMapRealVector res = new OpenMapRealVector(this, v.getDimension());
   Iterator iter = v.entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     res.setEntry(iter.key() + virtualSize, iter.value());
   }
   return res;
 }
コード例 #7
0
 /** {@inheritDoc} */
 public OpenMapRealVector ebeMultiply(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   OpenMapRealVector res = new OpenMapRealVector(this);
   Iterator iter = res.entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     res.setEntry(iter.key(), iter.value() * v[iter.key()]);
   }
   return res;
 }
コード例 #8
0
 /** {@inheritDoc} */
 public OpenMapRealVector ebeDivide(RealVector v) throws IllegalArgumentException {
   checkVectorDimensions(v.getDimension());
   OpenMapRealVector res = new OpenMapRealVector(this);
   Iterator iter = res.entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     res.setEntry(iter.key(), iter.value() / v.getEntry(iter.key()));
   }
   return res;
 }
コード例 #9
0
 /** {@inheritDoc} */
 public OpenMapRealVector getSubVector(int index, int n) throws MatrixIndexException {
   checkIndex(index);
   checkIndex(index + n - 1);
   OpenMapRealVector res = new OpenMapRealVector(n);
   int end = index + n;
   Iterator iter = entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     int key = iter.key();
     if (key >= index && key < end) {
       res.setEntry(key - index, iter.value());
     }
   }
   return res;
 }
コード例 #10
0
 /** {@inheritDoc} */
 public OpenMapRealVector mapLogToSelf() {
   for (int i = 0; i < virtualSize; i++) {
     setEntry(i, Math.log(getEntry(i)));
   }
   return this;
 }
コード例 #11
0
 /** {@inheritDoc} */
 public OpenMapRealVector mapInvToSelf() {
   for (int i = 0; i < virtualSize; i++) {
     setEntry(i, 1.0 / getEntry(i));
   }
   return this;
 }
コード例 #12
0
 /** {@inheritDoc} */
 public OpenMapRealVector mapAddToSelf(double d) {
   for (int i = 0; i < virtualSize; i++) {
     setEntry(i, getEntry(i) + d);
   }
   return this;
 }
コード例 #13
0
 /** {@inheritDoc} */
 public OpenMapRealVector append(double d) {
   OpenMapRealVector res = new OpenMapRealVector(this, 1);
   res.setEntry(virtualSize, d);
   return res;
 }
コード例 #14
0
 /** {@inheritDoc} */
 public void set(double value) {
   for (int i = 0; i < virtualSize; i++) {
     setEntry(i, value);
   }
 }