Package cern.colt.function

Examples of cern.colt.function.DoubleDoubleFunction


System.out.println(otherMatrix1D);
// Sum(Math.PI * Math.log(otherMatrix1D[i] / matrix[i]))
System.out.println(matrix.aggregate(otherMatrix1D, F.plus, F.chain(F.mult(Math.PI),F.chain(F.log,F.swapArgs(F.div)))));
// or, perhaps less error prone and more readable:
System.out.println(matrix.aggregate(otherMatrix1D, F.plus,
   new DoubleDoubleFunction() {
    public double apply(double a, double b) { return Math.PI*Math.log(b/a); }
   }
)
);

View Full Code Here


* @param g a unary function.
* @param h a unary function.
* @return the binary function <tt>f( g(a), h(b) )</tt>.
*/
public static DoubleDoubleFunction chain(final DoubleDoubleFunction f, final DoubleFunction g, final DoubleFunction h) {
  return new DoubleDoubleFunction() {
    public final double apply(double a, double b) { return f.apply(g.apply(a), h.apply(b)); }
  };
}
View Full Code Here

* @param g a unary function.
* @param h a binary function.
* @return the unary function <tt>g( h(a,b) )</tt>.
*/
public static DoubleDoubleFunction chain(final DoubleFunction g, final DoubleDoubleFunction h) {
  return new DoubleDoubleFunction() {
    public final double apply(double a, double b) { return g.apply(h.apply(a,b)); }
  };
}
View Full Code Here

  cern.jet.math.Functions F = cern.jet.math.Functions.functions;
  double a = 0.5;
  double b = 0.2;
  double v = Math.sin(a) + Math.pow(Math.cos(b),2);
  System.out.println(v);
  DoubleDoubleFunction f = F.chain(F.plus,F.sin,F.chain(F.square,F.cos));
  //DoubleDoubleFunction f = F.chain(plus,sin,F.chain(square,cos));
  System.out.println(f.apply(a,b));
  DoubleDoubleFunction g = new DoubleDoubleFunction() {
    public final double apply(double x, double y) { return Math.sin(x) + Math.pow(Math.cos(y),2); }
  };
  System.out.println(g.apply(a,b));
  DoubleFunction m = F.plus(3);
  DoubleFunction n = F.plus(4);
  System.out.println(m.apply(0));
  System.out.println(n.apply(0));
}
View Full Code Here

  //double v = Math.sin(a) + Math.pow(Math.cos(b),2);
  //double v = a + b;
  System.out.println(v);
 
  //DoubleDoubleFunction f = F.chain(F.plus,F.identity,F.identity);
  DoubleDoubleFunction f = F.chain(F.abs,F.chain(F.plus,F.sin,F.chain(F.square,F.cos)));
  //DoubleDoubleFunction f = F.chain(F.plus,F.sin,F.chain(F.square,F.cos));
  //DoubleDoubleFunction f = F.plus;
 
  System.out.println(f.apply(a,b));
  DoubleDoubleFunction g = new DoubleDoubleFunction() {
    public final double apply(double x, double y) { return Math.abs(Math.sin(x) + Math.pow(Math.cos(y),2)); }
    //public final double apply(double x, double y) { return x+y; }
  };
  System.out.println(g.apply(a,b));

  // emptyLoop
  cern.colt.Timer emptyLoop = new cern.colt.Timer().start();
  a = 0; b = 0;
  double sum = 0;
  for (int i=size; --i >= 0; ) {
    sum += a;
    a++;
    b++;
  }
  emptyLoop.stop().display();
  System.out.println("empty sum="+sum);
 
  cern.colt.Timer timer = new cern.colt.Timer().start();
  a = 0; b = 0;
  sum = 0;
  for (int i=size; --i >= 0; ) {
    sum += Math.abs(Math.sin(a) + Math.pow(Math.cos(b),2));
    //sum += a + b;
    a++; b++;
  }
  timer.stop().display();
  System.out.println("evals / sec = "+size / timer.minus(emptyLoop).seconds());
  System.out.println("sum="+sum);

  timer.reset().start();
  a = 0; b = 0;
  sum = 0;
  for (int i=size; --i >= 0; ) {
    sum += f.apply(a,b);
    a++; b++;
  }
  timer.stop().display();
  System.out.println("evals / sec = "+size / timer.minus(emptyLoop).seconds());
  System.out.println("sum="+sum);
   
  timer.reset().start();
  a = 0; b = 0;
  sum = 0;
  for (int i=size; --i >= 0; ) {
    sum += g.apply(a,b);
    a++; b++;
  }
  timer.stop().display();
  System.out.println("evals / sec = "+size / timer.minus(emptyLoop).seconds());
  System.out.println("sum="+sum);
View Full Code Here

*
* @param function a function taking operands in the form <tt>function.apply(a,b)</tt>.
* @return the binary function <tt>function(b,a)</tt>.
*/
public static DoubleDoubleFunction swapArgs(final DoubleDoubleFunction function) {
  return new DoubleDoubleFunction() {
    public final double apply(double a, double b) { return function.apply(b,a); }
  };
}
View Full Code Here

System.out.println(otherMatrix1D);
// Sum(Math.PI * Math.log(otherMatrix1D[i] / matrix[i]))
System.out.println(matrix.aggregate(otherMatrix1D, F.plus, F.chain(F.mult(Math.PI),F.chain(F.log,F.swapArgs(F.div)))));
// or, perhaps less error prone and more readable:
System.out.println(matrix.aggregate(otherMatrix1D, F.plus,
   new DoubleDoubleFunction() {
    public double apply(double a, double b) { return Math.PI*Math.log(b/a); }
   }
)
);

View Full Code Here

* @param g a unary function.
* @param h a unary function.
* @return the binary function <tt>f( g(a), h(b) )</tt>.
*/
public static DoubleDoubleFunction chain(final DoubleDoubleFunction f, final DoubleFunction g, final DoubleFunction h) {
  return new DoubleDoubleFunction() {
    public final double apply(double a, double b) { return f.apply(g.apply(a), h.apply(b)); }
  };
}
View Full Code Here

* @param g a unary function.
* @param h a binary function.
* @return the unary function <tt>g( h(a,b) )</tt>.
*/
public static DoubleDoubleFunction chain(final DoubleFunction g, final DoubleDoubleFunction h) {
  return new DoubleDoubleFunction() {
    public final double apply(double a, double b) { return g.apply(h.apply(a,b)); }
  };
}
View Full Code Here

  cern.jet.math.Functions F = cern.jet.math.Functions.functions;
  double a = 0.5;
  double b = 0.2;
  double v = Math.sin(a) + Math.pow(Math.cos(b),2);
  System.out.println(v);
  DoubleDoubleFunction f = F.chain(F.plus,F.sin,F.chain(F.square,F.cos));
  //DoubleDoubleFunction f = F.chain(plus,sin,F.chain(square,cos));
  System.out.println(f.apply(a,b));
  DoubleDoubleFunction g = new DoubleDoubleFunction() {
    public final double apply(double x, double y) { return Math.sin(x) + Math.pow(Math.cos(y),2); }
  };
  System.out.println(g.apply(a,b));
  DoubleFunction m = F.plus(3);
  DoubleFunction n = F.plus(4);
  System.out.println(m.apply(0));
  System.out.println(n.apply(0));
}
View Full Code Here

TOP

Related Classes of cern.colt.function.DoubleDoubleFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.