/** * Create a discrete real-valued distribution using the given random number generator * and probability mass function enumeration. * * @param rng random number generator. * @param singletons array of random variable values. * @param probabilities array of probabilities. * @throws DimensionMismatchException if * {@code singletons.length != probabilities.length} * @throws NotPositiveException if any of the probabilities are negative. * @throws NotFiniteNumberException if any of the probabilities are infinite. * @throws NotANumberException if any of the probabilities are NaN. * @throws MathArithmeticException all of the probabilities are 0. */ public EnumeratedRealDistribution(final RandomGenerator rng, final double[] singletons, final double[] probabilities) throws DimensionMismatchException, NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException { super(rng); innerDistribution = new EnumeratedDistribution<Double>( rng, createDistribution(singletons, probabilities)); }
/** * Create a discrete real-valued distribution from the input data. Values are assigned * mass based on their frequency. * * @param rng random number generator used for sampling * @param data input dataset * @since 3.6 */ public EnumeratedRealDistribution(final RandomGenerator rng, final double[] data) { super(rng); final Map<Double, Integer> dataMap = new HashMap<Double, Integer>(); for (double value : data) { Integer count = dataMap.get(value); if (count == null) { count = 0; } dataMap.put(value, ++count); } final int massPoints = dataMap.size(); final double denom = data.length; final double[] values = new double[massPoints]; final double[] probabilities = new double[massPoints]; int index = 0; for (Entry<Double, Integer> entry : dataMap.entrySet()) { values[index] = entry.getKey(); probabilities[index] = entry.getValue().intValue() / denom; index++; } innerDistribution = new EnumeratedDistribution<Double>(rng, createDistribution(values, probabilities)); }
/** * Create a discrete real-valued distribution using the given random number generator * and probability mass function enumeration. * * @param rng random number generator. * @param singletons array of random variable values. * @param probabilities array of probabilities. * @throws DimensionMismatchException if * {@code singletons.length != probabilities.length} * @throws NotPositiveException if any of the probabilities are negative. * @throws NotFiniteNumberException if any of the probabilities are infinite. * @throws NotANumberException if any of the probabilities are NaN. * @throws MathArithmeticException all of the probabilities are 0. */ public EnumeratedRealDistribution(final RandomGenerator rng, final double[] singletons, final double[] probabilities) throws DimensionMismatchException, NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException { super(rng); innerDistribution = new EnumeratedDistribution<Double>( rng, createDistribution(singletons, probabilities)); }
/** * Create a discrete real-valued distribution using the given random number generator * and probability mass function enumeration. * * @param rng random number generator. * @param singletons array of random variable values. * @param probabilities array of probabilities. * @throws DimensionMismatchException if * {@code singletons.length != probabilities.length} * @throws NotPositiveException if any of the probabilities are negative. * @throws NotFiniteNumberException if any of the probabilities are infinite. * @throws NotANumberException if any of the probabilities are NaN. * @throws MathArithmeticException all of the probabilities are 0. */ public EnumeratedRealDistribution(final RandomGenerator rng, final double[] singletons, final double[] probabilities) throws DimensionMismatchException, NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException { super(rng); innerDistribution = new EnumeratedDistribution<Double>( rng, createDistribution(singletons, probabilities)); }
/** * Create a discrete real-valued distribution from the input data. Values are assigned * mass based on their frequency. * * @param rng random number generator used for sampling * @param data input dataset * @since 3.6 */ public EnumeratedRealDistribution(final RandomGenerator rng, final double[] data) { super(rng); final Map<Double, Integer> dataMap = new HashMap<Double, Integer>(); for (double value : data) { Integer count = dataMap.get(value); if (count == null) { count = 0; } dataMap.put(value, ++count); } final int massPoints = dataMap.size(); final double denom = data.length; final double[] values = new double[massPoints]; final double[] probabilities = new double[massPoints]; int index = 0; for (Entry<Double, Integer> entry : dataMap.entrySet()) { values[index] = entry.getKey(); probabilities[index] = entry.getValue().intValue() / denom; index++; } innerDistribution = new EnumeratedDistribution<Double>(rng, createDistribution(values, probabilities)); }
/** * Create a discrete real-valued distribution from the input data. Values are assigned * mass based on their frequency. * * @param rng random number generator used for sampling * @param data input dataset * @since 3.6 */ public EnumeratedRealDistribution(final RandomGenerator rng, final double[] data) { super(rng); final Map<Double, Integer> dataMap = new HashMap<Double, Integer>(); for (double value : data) { Integer count = dataMap.get(value); if (count == null) { count = 0; } dataMap.put(value, ++count); } final int massPoints = dataMap.size(); final double denom = data.length; final double[] values = new double[massPoints]; final double[] probabilities = new double[massPoints]; int index = 0; for (Entry<Double, Integer> entry : dataMap.entrySet()) { values[index] = entry.getKey(); probabilities[index] = entry.getValue().intValue() / denom; index++; } innerDistribution = new EnumeratedDistribution<Double>(rng, createDistribution(values, probabilities)); }