@Override public default Surface withPerturbation(ParameterPerturbation perturbation) { return (Surface) ParameterizedData.super.withPerturbation(perturbation); }
@Override public default Curve withPerturbation(ParameterPerturbation perturbation) { return (Curve) ParameterizedData.super.withPerturbation(perturbation); }
/** * Applies a perturbation to the specified underlying. * <p> * This should be invoked once for each of the underlying instances. * It is intended to be used to pass the result of each invocation to the * constructor of the combined instance. * * @param <R> the type of the underlying * @param underlyingIndex the index of the underlying instance * @param underlyingType the type of the parameterized data at the specified index * @param perturbation the perturbation to apply * @return a parameterized data instance based on this with the specified perturbation applied */ public <R extends ParameterizedData> R underlyingWithPerturbation( int underlyingIndex, Class<R> underlyingType, ParameterPerturbation perturbation) { ParameterizedData underlying = underlyings[underlyingIndex]; // perturb using a derived perturbation that adjusts the index int adjustment = lookup[underlyingIndex]; ParameterizedData perturbed = underlying.withPerturbation( (idx, value, meta) -> perturbation.perturbParameter(idx + adjustment, value, meta)); return underlyingType.cast(perturbed); }
private ParameterizedData applyShifts(int scenarioIndex, ParameterizedData prams) { return prams.withPerturbation((index, value, meta) -> { double shiftAmount = shiftForNode(scenarioIndex, meta); return shiftType.applyShift(value, shiftAmount); }); }
public void test_withPerturbation() { assertSame(CURVE.withPerturbation((i, v, m) -> v), CURVE); assertEquals(CURVE.withPerturbation((i, v, m) -> v + 2d).getParameter(0), 3d); }