/** * Performs a change of variable so that the integration can be performed * on an arbitrary interval {@code [a, b]}. * It is assumed that the natural interval is {@code [-1, 1]}. * * @param rule Original points and weights. * @param a Lower bound of the integration interval. * @param b Lower bound of the integration interval. * @return the points and weights adapted to the new interval. */ private static Pair<double[], double[]> transform(Pair<double[], double[]> rule, double a, double b) { final double[] points = rule.getFirst(); final double[] weights = rule.getSecond(); // Scaling final double scale = (b - a) / 2; final double shift = a + scale; for (int i = 0; i < points.length; i++) { points[i] = points[i] * scale + shift; weights[i] *= scale; } return new Pair<double[], double[]>(points, weights); } }
/** * Creates an integrator from the given pair of points (first element of * the pair) and weights (second element of the pair. * * @param pointsAndWeights Integration points and corresponding weights. * @throws NonMonotonicSequenceException if the {@code points} are not * sorted in increasing order. * * @see #SymmetricGaussIntegrator(double[], double[]) */ public SymmetricGaussIntegrator(Pair<double[], double[]> pointsAndWeights) throws NonMonotonicSequenceException { this(pointsAndWeights.getFirst(), pointsAndWeights.getSecond()); }
public SequentialDistribution(Integer start, Integer end, List<Object> enumeratedValues) { // just pass in some bogus probability mass function, we won't be using it super(Collections.singletonList(new Pair<Object, Double>(null, 1.0))); this.start = start; this.end = end; this.enumeratedValues = enumeratedValues; if (enumeratedValues == null) { counter = start; } else { counter = 0; } }
public EnumeratedTreeDistribution(final List<Pair<T, Double>> pmf) { super(pmf); // build the interval tree probabilityRanges = new TreeMap<Double, Integer>(); normalizedPmf = this.getPmf(); double cumulativep = 0.0; for (int i = 0; i < normalizedPmf.size(); i++) { probabilityRanges.put(cumulativep, i); Pair<T, Double> pair = normalizedPmf.get(i); cumulativep += pair.getSecond(); } }
@Override public T sample() { final double randomValue = random.nextDouble(); Integer valueIndex = probabilityRanges.floorEntry(randomValue).getValue(); return normalizedPmf.get(valueIndex).getFirst(); } }
/** * Gets a reference to the value of the objective function. * * @return a reference to the internal array storing the value of * the objective function. */ public double[] getValueRef() { return super.getValue(); }
/** * Creates an integrator from the given pair of points (first element of * the pair) and weights (second element of the pair. * * @param pointsAndWeights Integration points and corresponding weights. * @throws NonMonotonicSequenceException if the {@code points} are not * sorted in increasing order. * * @see #GaussIntegrator(double[], double[]) */ public GaussIntegrator(Pair<double[], double[]> pointsAndWeights) throws NonMonotonicSequenceException { this(pointsAndWeights.getFirst(), pointsAndWeights.getSecond()); }
/** * Convenience factory method that calls the * {@link #Pair(Object, Object) constructor}. * * @param <K> the key type * @param <V> the value type * @param k First element of the pair. * @param v Second element of the pair. * @return a new {@code Pair} containing {@code k} and {@code v}. * @since 3.3 */ public static <K, V> Pair<K, V> create(K k, V v) { return new Pair<K, V>(k, v); } }
@SuppressWarnings("unchecked") private void addCredentialToSubject(Subject subject, Map<String, String> credentials) { try { for (Pair<String, Credentials> cred : getCredentials(credentials)) { subject.getPrivateCredentials().add(cred.getSecond()); LOG.info("Credentials added to the subject."); } } catch (Exception e) { LOG.error("Failed to initialize and get UserGroupInformation.", e); } }
/** * Gets a reference to the value of the objective function. * * @return a reference to the internal array storing the value of * the objective function. */ public double[] getValueRef() { return super.getValue(); }
/** * Converts the from the actual {@code Number} type to {@code double} * * @param <T> Type of the number used to represent the points and * weights of the quadrature rules. * @param rule Points and weights. * @return points and weights as {@code double}s. */ private static <T extends Number> Pair<double[], double[]> convertToDouble(Pair<T[], T[]> rule) { final T[] pT = rule.getFirst(); final T[] wT = rule.getSecond(); final int len = pT.length; final double[] pD = new double[len]; final double[] wD = new double[len]; for (int i = 0; i < len; i++) { pD[i] = pT[i].doubleValue(); wD[i] = wT[i].doubleValue(); } return new Pair<double[], double[]>(pD, wD); } }
public Builder addServlet(String endpoint, Class<? extends HttpServlet> servlet) { servlets.add(new Pair<String, Class<? extends HttpServlet>>(endpoint, servlet)); return this; } }