Result of a VectorFn eval or the accumulation structure for a LinearContribution @author johnmount
| 7 | * |
| 8 | */ |
| 9 | public class VEval { |
| 10 | public double[] x; |
| 11 | public double fx; |
| 12 | public double[] gx; |
| 13 | public double[][] hx; |
| 14 | |
| 15 | public VEval(final double[] x, final boolean wantGrad, final boolean wantHessian) { |
| 16 | final int dim = x.length; |
| 17 | this.x = new double[dim]; |
| 18 | fx = 0.0; |
| 19 | if(wantGrad) { |
| 20 | gx = new double[dim]; |
| 21 | } else { |
| 22 | gx = null; |
| 23 | } |
| 24 | if(wantHessian) { |
| 25 | hx = new double[dim][dim]; |
| 26 | } else { |
| 27 | hx = null; |
| 28 | } |
| 29 | for(int i=0;i<dim;++i) { |
| 30 | this.x[i] = x[i]; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | protected VEval() { |
| 35 | x = null; |
| 36 | fx = 0.0; |
| 37 | gx = null; |
| 38 | hx = null; |
| 39 | } |
| 40 | |
| 41 | public String toString() { |
| 42 | return "VEval:\n\tx\t" + LinUtil.toString(x) + "\n\tfx\t" + fx + "\n\tgx\t" + LinUtil.toString(gx) + "\n\thx\t" + LinUtil.toString(hx) + "\n"; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | * slow operation |
| 48 | * assumes the two x's are the same |
| 49 | * @param o |
| 50 | */ |
| 51 | public void add(final VEval o) { |
| 52 | final int dim = x.length; |
| 53 | fx += o.fx; |
| 54 | if(gx!=null) { |
| 55 | for(int i=0;i<dim;++i) { |
| 56 | gx[i] += o.gx[i]; |
| 57 | } |
| 58 | } |
| 59 | if(hx!=null) { |
| 60 | for(int i=0;i<dim;++i) { |
| 61 | for(int j=0;j<dim;++j) { |
| 62 | hx[i][j] += o.hx[i][j]; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
nothing calls this directly
no outgoing calls
no test coverage detected