Beispiel #1
0
 /**
  * MAtrix difference
  *
  * @param left
  * @param right
  * @return
  */
 public static IMatrix diff(IMatrix left, IMatrix right) {
   Set<Cell<Integer, Integer, Double>> iter = left.getValueRange();
   iter.addAll(right.getValueRange());
   IMatrix g = new GuavaMatrix();
   for (Cell<Integer, Integer, Double> x : iter) {
     g.set(
         x.getRowKey(),
         x.getColumnKey(),
         left.get(x.getRowKey(), x.getColumnKey()) - right.get(x.getRowKey(), x.getColumnKey()));
   }
   return g;
 }
Beispiel #2
0
 /**
  * Matrix divide
  *
  * @param left
  * @param right
  * @return
  */
 public static IMatrix div(IMatrix left, IMatrix right) {
   IMatrix g = new GuavaMatrix();
   for (Cell<Integer, Integer, Double> l : left.getValueRange()) {
     for (Cell<Integer, Integer, Double> r : right.getValueRange()) {
       int li = l.getColumnKey();
       int ri = l.getRowKey();
       if (li == ri) {
         double lv = (Double) left.get(li, ri);
         double rv = (Double) right.get(r.getRowKey(), r.getColumnKey());
         // System.out.println(lv+" "+rv+" "+lv*rv);
         g.incr((Integer) l.getRowKey(), (Integer) r.getColumnKey(), lv / rv);
       }
     }
   }
   return g;
 }
Beispiel #3
0
 /**
  * Matrix transpose
  *
  * @param m
  * @return
  */
 public static IMatrix transpose(IMatrix m) {
   IMatrix g = new GuavaMatrix();
   for (Cell<Integer, Integer, Double> k : m.getValueRange()) {
     int li = k.getRowKey();
     int ri = k.getColumnKey();
     g.set(ri, li, m.get(li, ri));
   }
   return g;
 }
Beispiel #4
0
 /**
  * Matrix divide
  *
  * @param left
  * @param r
  * @return
  */
 public static IMatrix div(IMatrix left, double r) {
   IMatrix g = new GuavaMatrix();
   for (Cell<Integer, Integer, Double> l : left.getValueRange()) {
     int li = l.getRowKey();
     int ri = l.getColumnKey();
     g.incr(li, ri, (left.get(li, ri) / r));
   }
   return g;
 }
Beispiel #5
0
 /**
  * Matrix product
  *
  * @param left
  * @param right
  * @return
  */
 public static IMatrix prod(IMatrix left, IMatrix right) {
   IMatrix g = new GuavaMatrix();
   double size = (left.getValueRange().size() * right.getValueRange().size());
   System.out.println(size + " ~~~ ");
   double i = 0;
   for (Cell<Integer, Integer, Double> l : left.getValueRange()) {
     int li = (Integer) l.getColumnKey();
     for (Cell<Integer, Integer, Double> r : right.getValueRange()) {
       int ri = (Integer) r.getRowKey();
       if (li == ri) {
         double lv = (Double) left.get(l.getRowKey(), l.getColumnKey());
         double rv = (Double) right.get(r.getRowKey(), r.getColumnKey());
         // System.out.println(lv+" "+rv+" "+lv*rv);
         g.incr((Integer) l.getRowKey(), (Integer) r.getColumnKey(), lv * rv);
       }
       i++;
       // updateProgress((double) i / (double) size);
     }
   }
   System.out.println("Done!");
   return g;
 }