Class for slow loosely coupled summation of VectorFns. designed usage: summing two unrelated functions (like data score and regularization penalty) @author johnmount
| 11 | * |
| 12 | */ |
| 13 | public class SumFn implements VectorFn { |
| 14 | private final Iterable<VectorFn> underlying; |
| 15 | private final int dim; |
| 16 | |
| 17 | public SumFn(final Iterable<VectorFn> underlying) { |
| 18 | this.underlying = underlying; |
| 19 | dim = underlying.iterator().next().dim(); |
| 20 | } |
| 21 | |
| 22 | @Override |
| 23 | public int dim() { |
| 24 | return dim; |
| 25 | } |
| 26 | |
| 27 | @Override |
| 28 | public VEval eval(final double[] x, final boolean wantGrad, final boolean wantHessian) { |
| 29 | final VEval r = new VEval(x,wantGrad,wantHessian); |
| 30 | for(final VectorFn fi: underlying) { |
| 31 | final VEval vi = fi.eval(x,wantGrad,wantHessian); |
| 32 | r.add(vi); |
| 33 | } |
| 34 | return r; |
| 35 | } |
| 36 | |
| 37 | } |
nothing calls this directly
no outgoing calls
no test coverage detected