/** * Gets the value of the parameter at the specified index. * <p> * This gets the parameter from the correct instance. * * @param parameterIndex the zero-based index of the parameter to get * @return the value of the parameter * @throws IndexOutOfBoundsException if the index is invalid */ public double getParameter(int parameterIndex) { int underlyingIndex = findUnderlyingIndex(parameterIndex); int adjustment = lookup[underlyingIndex]; return underlyings[underlyingIndex].getParameter(parameterIndex - adjustment); }
/** * Returns a perturbed copy of the data. * <p> * The perturbation instance will be invoked once for each parameter in this instance, * returning the perturbed value for that parameter. The result of this method is a * new instance that is based on those perturbed values. * <p> * This instance is immutable and unaffected by this method call. * * @param perturbation the perturbation to apply * @return a parameterized data instance based on this with the specified perturbation applied */ public default ParameterizedData withPerturbation(ParameterPerturbation perturbation) { ParameterizedData result = this; for (int i = 0; i < getParameterCount(); i++) { double currentValue = getParameter(i); double perturbedValue = perturbation.perturbParameter(i, currentValue, getParameterMetadata(i)); // compare using Double.doubleToLongBits() result = JodaBeanUtils.equal(currentValue, perturbedValue) ? result : result.withParameter(i, perturbedValue); } return result; }
public void test_withPerturbation() { assertSame(CURVE.withPerturbation((i, v, m) -> v), CURVE); assertEquals(CURVE.withPerturbation((i, v, m) -> v + 2d).getParameter(0), 3d); }