protected Pair<Double, double[]> calculate(double[] x) {
   for (ObjectiveItemDifferentiableFunction<I> itemFn : itemFns) {
     itemFn.setWeights(x);
   }
   List<Mapper> mappers = getMappers();
   AsynchronousMapper.doMapping(items, mappers);
   double objVal = 0.0;
   double[] grad = new double[dimension()];
   for (Mapper mapper : mappers) {
     objVal += mapper.objVal;
     DoubleArrays.addInPlace(grad, mapper.localGrad);
   }
   if (regularizer != null) {
     objVal += regularizer.update(x, grad, 1.0);
   }
   return Pair.newPair(objVal, grad);
 }
 public void map(I elem) {
   objVal += itemFn.update(elem, localGrad);
 }
 Mapper(ObjectiveItemDifferentiableFunction<I> itemFn) {
   this.itemFn = itemFn;
   this.objVal = 0.0;
   this.localGrad = new double[itemFn.dimension()];
 }