/** * Computes the sensitivity of the Smith-Wilson curve function to weights parameters at a x value. * <p> * The {@code nodes} must be sorted in ascending order. * * @param x the x value * @param alpha the alpha parameter * @param nodes the nodes * @return the value */ public DoubleArray parameterSensitivity(double x, double alpha, DoubleArray nodes) { int size = nodes.size(); double[] res = new double[size]; double expOmega = Math.exp(-omega * x); int bound = x < nodes.get(0) ? 0 : FunctionUtils.getLowerBoundIndex(nodes, x) + 1; for (int i = 0; i < bound; ++i) { res[i] = expOmega * wilsonFunctionLeft(x, alpha, nodes.get(i)); } for (int i = bound; i < size; ++i) { res[i] = expOmega * wilsonFunctionRight(x, alpha, nodes.get(i)); } return DoubleArray.ofUnsafe(res); }
/** * Evaluates the Smith-Wilson curve function at a x value. * <p> * The {@code nodes} must be sorted in ascending order and coherent to {@code weights}. * * @param x the x value * @param alpha the alpha parameter * @param nodes the nodes * @param weights the weights * @return the value */ public double value(double x, double alpha, DoubleArray nodes, DoubleArray weights) { int size = nodes.size(); ArgChecker.isTrue(size == weights.size(), "nodes and weights must be the same size"); double res = 1d; int bound = x < nodes.get(0) ? 0 : FunctionUtils.getLowerBoundIndex(nodes, x) + 1; for (int i = 0; i < bound; ++i) { res += weights.get(i) * wilsonFunctionLeft(x, alpha, nodes.get(i)); } for (int i = bound; i < size; ++i) { res += weights.get(i) * wilsonFunctionRight(x, alpha, nodes.get(i)); } res *= Math.exp(-omega * x); return res; }