org.apache.commons.math3.exception.NullArgumentException Java Examples

The following examples show how to use org.apache.commons.math3.exception.NullArgumentException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Math_27_Fraction_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Multiplies the value of this fraction by another, returning the
 * result in reduced form.</p>
 *
 * @param fraction  the fraction to multiply by, must not be {@code null}
 * @return a {@code Fraction} instance with the resulting values
 * @throws NullArgumentException if the fraction is {@code null}
 * @throws MathArithmeticException if the resulting numerator or denominator exceeds
 *  {@code Integer.MAX_VALUE}
 */
public Fraction multiply(Fraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (numerator == 0 || fraction.numerator == 0) {
        return ZERO;
    }
    // knuth 4.5.1
    // make sure we don't overflow unless the result *must* overflow.
    int d1 = ArithmeticUtils.gcd(numerator, fraction.denominator);
    int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator);
    return getReducedFraction
    (ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2),
            ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1));
}
 
Example #2
Source File: Math_1_Fraction_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Multiplies the value of this fraction by another, returning the
 * result in reduced form.</p>
 *
 * @param fraction  the fraction to multiply by, must not be {@code null}
 * @return a {@code Fraction} instance with the resulting values
 * @throws NullArgumentException if the fraction is {@code null}
 * @throws MathArithmeticException if the resulting numerator or denominator exceeds
 *  {@code Integer.MAX_VALUE}
 */
public Fraction multiply(Fraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (numerator == 0 || fraction.numerator == 0) {
        return ZERO;
    }
    // knuth 4.5.1
    // make sure we don't overflow unless the result *must* overflow.
    int d1 = ArithmeticUtils.gcd(numerator, fraction.denominator);
    int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator);
    return getReducedFraction
    (ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2),
            ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1));
}
 
Example #3
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Adds the value of this fraction to another, returning the result in
 * reduced form.
 * </p>
 *
 * @param fraction
 *            the {@link BigFraction} to add, must not be <code>null</code>.
 * @return a {@link BigFraction} instance with the resulting values.
 * @throws NullArgumentException if the {@link BigFraction} is {@code null}.
 */
public BigFraction add(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (ZERO.equals(fraction)) {
        return this;
    }

    BigInteger num = null;
    BigInteger den = null;

    if (denominator.equals(fraction.denominator)) {
        num = numerator.add(fraction.numerator);
        den = denominator;
    } else {
        num = (numerator.multiply(fraction.denominator)).add((fraction.numerator).multiply(denominator));
        den = denominator.multiply(fraction.denominator);
    }
    return new BigFraction(num, den);

}
 
Example #4
Source File: BigFraction_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>
 * Subtracts the value of another fraction from the value of this one,
 * returning the result in reduced form.
 * </p>
 *
 * @param fraction {@link BigFraction} to subtract, must not be {@code null}.
 * @return a {@link BigFraction} instance with the resulting values
 * @throws NullArgumentException if the {@code fraction} is {@code null}.
 */
public BigFraction subtract(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (ZERO.equals(fraction)) {
        return this;
    }

    BigInteger num = null;
    BigInteger den = null;
    if (denominator.equals(fraction.denominator)) {
        num = numerator.subtract(fraction.numerator);
        den = denominator;
    } else {
        num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator));
        den = denominator.multiply(fraction.denominator);
    }
    return new BigFraction(num, den);

}
 
Example #5
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Adds the value of this fraction to another, returning the result in
 * reduced form.
 * </p>
 *
 * @param fraction
 *            the {@link BigFraction} to add, must not be <code>null</code>.
 * @return a {@link BigFraction} instance with the resulting values.
 * @throws NullArgumentException if the {@link BigFraction} is {@code null}.
 */
public BigFraction add(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (ZERO.equals(fraction)) {
        return this;
    }

    BigInteger num = null;
    BigInteger den = null;

    if (denominator.equals(fraction.denominator)) {
        num = numerator.add(fraction.numerator);
        den = denominator;
    } else {
        num = (numerator.multiply(fraction.denominator)).add((fraction.numerator).multiply(denominator));
        den = denominator.multiply(fraction.denominator);
    }
    return new BigFraction(num, den);

}
 
Example #6
Source File: Math_26_Fraction_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Multiplies the value of this fraction by another, returning the
 * result in reduced form.</p>
 *
 * @param fraction  the fraction to multiply by, must not be {@code null}
 * @return a {@code Fraction} instance with the resulting values
 * @throws NullArgumentException if the fraction is {@code null}
 * @throws MathArithmeticException if the resulting numerator or denominator exceeds
 *  {@code Integer.MAX_VALUE}
 */
public Fraction multiply(Fraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (numerator == 0 || fraction.numerator == 0) {
        return ZERO;
    }
    // knuth 4.5.1
    // make sure we don't overflow unless the result *must* overflow.
    int d1 = ArithmeticUtils.gcd(numerator, fraction.denominator);
    int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator);
    return getReducedFraction
    (ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2),
            ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1));
}
 
Example #7
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Subtracts the value of another fraction from the value of this one,
 * returning the result in reduced form.
 * </p>
 *
 * @param fraction {@link BigFraction} to subtract, must not be {@code null}.
 * @return a {@link BigFraction} instance with the resulting values
 * @throws NullArgumentException if the {@code fraction} is {@code null}.
 */
public BigFraction subtract(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (ZERO.equals(fraction)) {
        return this;
    }

    BigInteger num = null;
    BigInteger den = null;
    if (denominator.equals(fraction.denominator)) {
        num = numerator.subtract(fraction.numerator);
        den = denominator;
    } else {
        num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator));
        den = denominator.multiply(fraction.denominator);
    }
    return new BigFraction(num, den);

}
 
Example #8
Source File: Math_1_Fraction_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>Multiplies the value of this fraction by another, returning the
 * result in reduced form.</p>
 *
 * @param fraction  the fraction to multiply by, must not be {@code null}
 * @return a {@code Fraction} instance with the resulting values
 * @throws NullArgumentException if the fraction is {@code null}
 * @throws MathArithmeticException if the resulting numerator or denominator exceeds
 *  {@code Integer.MAX_VALUE}
 */
public Fraction multiply(Fraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (numerator == 0 || fraction.numerator == 0) {
        return ZERO;
    }
    // knuth 4.5.1
    // make sure we don't overflow unless the result *must* overflow.
    int d1 = ArithmeticUtils.gcd(numerator, fraction.denominator);
    int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator);
    return getReducedFraction
    (ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2),
            ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1));
}
 
Example #9
Source File: Math_34_ListPopulation_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a new ListPopulation instance.
 * <p>Note: the chromosomes of the specified list are added to the population.</p>
 * @param chromosomes list of chromosomes to be added to the population
 * @param populationLimit maximal size of the population
 * @throws NullArgumentException if the list of chromosomes is {@code null}
 * @throws NotPositiveException if the population limit is not a positive number (&lt; 1)
 * @throws NumberIsTooLargeException if the list of chromosomes exceeds the population limit
 */
public ListPopulation(final List<Chromosome> chromosomes, final int populationLimit) {
    if (chromosomes == null) {
        throw new NullArgumentException();
    }
    if (populationLimit <= 0) {
        throw new NotPositiveException(LocalizedFormats.POPULATION_LIMIT_NOT_POSITIVE, populationLimit);
    }
    if (chromosomes.size() > populationLimit) {
        throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                                            chromosomes.size(), populationLimit, false);
    }
    this.populationLimit = populationLimit;
    this.chromosomes = new ArrayList<Chromosome>(populationLimit);
    this.chromosomes.addAll(chromosomes);
}
 
Example #10
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Adds the value of this fraction to another, returning the result in
 * reduced form.
 * </p>
 *
 * @param fraction
 *            the {@link BigFraction} to add, must not be <code>null</code>.
 * @return a {@link BigFraction} instance with the resulting values.
 * @throws NullArgumentException if the {@link BigFraction} is {@code null}.
 */
public BigFraction add(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (ZERO.equals(fraction)) {
        return this;
    }

    BigInteger num = null;
    BigInteger den = null;

    if (denominator.equals(fraction.denominator)) {
        num = numerator.add(fraction.numerator);
        den = denominator;
    } else {
        num = (numerator.multiply(fraction.denominator)).add((fraction.numerator).multiply(denominator));
        den = denominator.multiply(fraction.denominator);
    }
    return new BigFraction(num, den);

}
 
Example #11
Source File: BigFraction_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * <p>
 * Subtracts the value of another fraction from the value of this one,
 * returning the result in reduced form.
 * </p>
 *
 * @param fraction {@link BigFraction} to subtract, must not be {@code null}.
 * @return a {@link BigFraction} instance with the resulting values
 * @throws NullArgumentException if the {@code fraction} is {@code null}.
 */
public BigFraction subtract(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (ZERO.equals(fraction)) {
        return this;
    }

    BigInteger num = null;
    BigInteger den = null;
    if (denominator.equals(fraction.denominator)) {
        num = numerator.subtract(fraction.numerator);
        den = denominator;
    } else {
        num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator));
        den = denominator.multiply(fraction.denominator);
    }
    return new BigFraction(num, den);

}
 
Example #12
Source File: Elixir_0025_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Sets the list of chromosomes.
 * <p>Note: this method removed all existing chromosomes in the population and adds all chromosomes
 * of the specified list to the population.</p>
 * @param chromosomes the list of chromosomes
 * @throws NullArgumentException if the list of chromosomes is {@code null}
 * @throws NumberIsTooLargeException if the list of chromosomes exceeds the population limit
 * @deprecated use {@link #addChromosomes(Collection)} instead
 */
public void setChromosomes(final List<Chromosome> chromosomes) {
    if (chromosomes == null) {
        throw new NullArgumentException();
    }
    if (chromosomes.size() > populationLimit) {
        throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                                            chromosomes.size(), populationLimit, false);
    }
    this.chromosomes.clear();
    this.chromosomes.addAll(chromosomes);
}
 
Example #13
Source File: buggyMannWhitneyUTest.java    From coming with MIT License 5 votes vote down vote up
/**
 * Computes the <a
 * href="http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U"> Mann-Whitney
 * U statistic</a> comparing mean for two independent samples possibly of
 * different length.
 * <p>
 * This statistic can be used to perform a Mann-Whitney U test evaluating
 * the null hypothesis that the two independent samples has equal mean.
 * </p>
 * <p>
 * Let X<sub>i</sub> denote the i'th individual of the first sample and
 * Y<sub>j</sub> the j'th individual in the second sample. Note that the
 * samples would often have different length.
 * </p>
 * <p>
 * <strong>Preconditions</strong>:
 * <ul>
 * <li>All observations in the two samples are independent.</li>
 * <li>The observations are at least ordinal (continuous are also ordinal).</li>
 * </ul>
 * </p>
 *
 * @param x the first sample
 * @param y the second sample
 * @return Mann-Whitney U statistic (maximum of U<sup>x</sup> and U<sup>y</sup>)
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 */
public double mannWhitneyU(final double[] x, final double[] y)
    throws NullArgumentException, NoDataException {

    ensureDataConformance(x, y);

    final double[] z = concatenateSamples(x, y);
    final double[] ranks = naturalRanking.rank(z);

    double sumRankX = 0;

    /*
     * The ranks for x is in the first x.length entries in ranks because x
     * is in the first x.length entries in z
     */
    for (int i = 0; i < x.length; ++i) {
        sumRankX += ranks[i];
    }

    /*
     * U1 = R1 - (n1 * (n1 + 1)) / 2 where R1 is sum of ranks for sample 1,
     * e.g. x, n1 is the number of observations in sample 1.
     */
    final double U1 = sumRankX - (x.length * (x.length + 1)) / 2;

    /*
     * It can be shown that U1 + U2 = n1 * n2
     */
    final double U2 = x.length * y.length - U1;

    return FastMath.max(U1, U2);
}
 
Example #14
Source File: MathArrays_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Throws DimensionMismatchException if the input array is not rectangular.
 *
 * @param in array to be tested
 * @throws NullArgumentException if input array is null
 * @throws DimensionMismatchException if input array is not rectangular
 * @since 3.1
 */
public static void checkRectangular(final long[][] in)
    throws NullArgumentException, DimensionMismatchException {
    MathUtils.checkNotNull(in);
    for (int i = 1; i < in.length; i++) {
        if (in[i].length != in[0].length) {
            throw new DimensionMismatchException(
                    LocalizedFormats.DIFFERENT_ROWS_LENGTHS,
                    in[i].length, in[0].length);
        }
    }
}
 
Example #15
Source File: BigFraction_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * <p>
 * Multiplies the value of this fraction by another, returning the result in
 * reduced form.
 * </p>
 *
 * @param fraction Fraction to multiply by, must not be {@code null}.
 * @return a {@link BigFraction} instance with the resulting values.
 * @throws NullArgumentException if {@code fraction} is {@code null}.
 */
public BigFraction multiply(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (numerator.equals(BigInteger.ZERO) ||
        fraction.numerator.equals(BigInteger.ZERO)) {
        return ZERO;
    }
    return new BigFraction(numerator.multiply(fraction.numerator),
                           denominator.multiply(fraction.denominator));
}
 
Example #16
Source File: patchedMannWhitneyUTest.java    From coming with MIT License 5 votes vote down vote up
/**
 * Computes the <a
 * href="http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U"> Mann-Whitney
 * U statistic</a> comparing mean for two independent samples possibly of
 * different length.
 * <p>
 * This statistic can be used to perform a Mann-Whitney U test evaluating
 * the null hypothesis that the two independent samples has equal mean.
 * </p>
 * <p>
 * Let X<sub>i</sub> denote the i'th individual of the first sample and
 * Y<sub>j</sub> the j'th individual in the second sample. Note that the
 * samples would often have different length.
 * </p>
 * <p>
 * <strong>Preconditions</strong>:
 * <ul>
 * <li>All observations in the two samples are independent.</li>
 * <li>The observations are at least ordinal (continuous are also ordinal).</li>
 * </ul>
 * </p>
 *
 * @param x the first sample
 * @param y the second sample
 * @return Mann-Whitney U statistic (maximum of U<sup>x</sup> and U<sup>y</sup>)
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 */
public double mannWhitneyU(final double[] x, final double[] y)
    throws NullArgumentException, NoDataException {

    ensureDataConformance(x, y);

    final double[] z = concatenateSamples(x, y);
    final double[] ranks = naturalRanking.rank(z);

    double sumRankX = 0;

    /*
     * The ranks for x is in the first x.length entries in ranks because x
     * is in the first x.length entries in z
     */
    for (int i = 0; i < x.length; ++i) {
        sumRankX += ranks[i];
    }

    /*
     * U1 = R1 - (n1 * (n1 + 1)) / 2 where R1 is sum of ranks for sample 1,
     * e.g. x, n1 is the number of observations in sample 1.
     */
    final double U1 = sumRankX - (x.length * (x.length + 1)) / 2;

    /*
     * It can be shown that U1 + U2 = n1 * n2
     */
    final double U2 = x.length * y.length - U1;

    return FastMath.max(U1, U2);
}
 
Example #17
Source File: MathArrays_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Calculates the <a href="http://en.wikipedia.org/wiki/Convolution">
 * convolution</a> between two sequences.
 * The solution is obtained via straightforward computation of the
 * convolution sum (and not via FFT).
 * Whenever the computation needs an element that would be located
 * at an index outside the input arrays, the value is assumed to be
 * zero.
 *
 * @param x First sequence.
 * Typically, this sequence will represent an input signal to a system.
 * @param h Second sequence.
 * Typically, this sequence will represent the impulse response of the
 * system.
 * @return the convolution of {@code x} and {@code h}.
 * This array's length will be {@code x.length + h.length - 1}.
 * @throws NullArgumentException if either {@code x} or {@code h} is
 * {@code null}.
 * @throws NoDataException if either {@code x} or {@code h} is empty.
 *
 * @since 3.3
 */
public static double[] convolve(double[] x, double[] h)
    throws NullArgumentException,
           NoDataException {
    MathUtils.checkNotNull(x);
    MathUtils.checkNotNull(h);

    final int xLen = x.length;
    final int hLen = h.length;

    if (xLen == 0 || hLen == 0) {
        throw new NoDataException();
    }

    // initialize the output array
    final int totalLength = xLen + hLen - 1;
    final double[] y = new double[totalLength];

    // straightforward implementation of the convolution sum
    for (int n = 0; n < totalLength; n++) {
        double yn = 0;
        int k = FastMath.max(0, n + 1 - xLen);
        int j = n - k;
        while (k < hLen && j >= 0) {
            yn += x[j--] * h[k++];
        }
        y[n] = yn;
    }

    return y;
}
 
Example #18
Source File: Math_3_MathArrays_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Throws DimensionMismatchException if the input array is not rectangular.
 *
 * @param in array to be tested
 * @throws NullArgumentException if input array is null
 * @throws DimensionMismatchException if input array is not rectangular
 * @since 3.1
 */
public static void checkRectangular(final long[][] in)
    throws NullArgumentException, DimensionMismatchException {
    MathUtils.checkNotNull(in);
    for (int i = 1; i < in.length; i++) {
        if (in[i].length != in[0].length) {
            throw new DimensionMismatchException(
                    LocalizedFormats.DIFFERENT_ROWS_LENGTHS,
                    in[i].length, in[0].length);
        }
    }
}
 
Example #19
Source File: Math_34_ListPopulation_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Sets the list of chromosomes.
 * <p>Note: this method removed all existing chromosomes in the population and adds all chromosomes
 * of the specified list to the population.</p>
 * @param chromosomes the list of chromosomes
 * @throws NullArgumentException if the list of chromosomes is {@code null}
 * @throws NumberIsTooLargeException if the list of chromosomes exceeds the population limit
 * @deprecated use {@link #addChromosomes(Collection)} instead
 */
public void setChromosomes(final List<Chromosome> chromosomes) {
    if (chromosomes == null) {
        throw new NullArgumentException();
    }
    if (chromosomes.size() > populationLimit) {
        throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                                            chromosomes.size(), populationLimit, false);
    }
    this.chromosomes.clear();
    this.chromosomes.addAll(chromosomes);
}
 
Example #20
Source File: Math_30_MannWhitneyUTest_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Ensures that the provided arrays fulfills the assumptions.
 *
 * @param x first sample
 * @param y second sample
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 */
private void ensureDataConformance(final double[] x, final double[] y)
    throws NullArgumentException, NoDataException {

    if (x == null ||
        y == null) {
        throw new NullArgumentException();
    }
    if (x.length == 0 ||
        y.length == 0) {
        throw new NoDataException();
    }
}
 
Example #21
Source File: Math_3_MathArrays_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Calculates the <a href="http://en.wikipedia.org/wiki/Convolution">
 * convolution</a> between two sequences.
 * The solution is obtained via straightforward computation of the
 * convolution sum (and not via FFT).
 * Whenever the computation needs an element that would be located
 * at an index outside the input arrays, the value is assumed to be
 * zero.
 *
 * @param x First sequence.
 * Typically, this sequence will represent an input signal to a system.
 * @param h Second sequence.
 * Typically, this sequence will represent the impulse response of the
 * system.
 * @return the convolution of {@code x} and {@code h}.
 * This array's length will be {@code x.length + h.length - 1}.
 * @throws NullArgumentException if either {@code x} or {@code h} is
 * {@code null}.
 * @throws NoDataException if either {@code x} or {@code h} is empty.
 *
 * @since 3.3
 */
public static double[] convolve(double[] x, double[] h)
    throws NullArgumentException,
           NoDataException {
    MathUtils.checkNotNull(x);
    MathUtils.checkNotNull(h);

    final int xLen = x.length;
    final int hLen = h.length;

    if (xLen == 0 || hLen == 0) {
        throw new NoDataException();
    }

    // initialize the output array
    final int totalLength = xLen + hLen - 1;
    final double[] y = new double[totalLength];

    // straightforward implementation of the convolution sum
    for (int n = 0; n < totalLength; n++) {
        double yn = 0;
        int k = FastMath.max(0, n + 1 - xLen);
        int j = n - k;
        while (k < hLen && j >= 0) {
            yn += x[j--] * h[k++];
        }
        y[n] = yn;
    }

    return y;
}
 
Example #22
Source File: patchedMannWhitneyUTest.java    From coming with MIT License 5 votes vote down vote up
/**
 * Ensures that the provided arrays fulfills the assumptions.
 *
 * @param x first sample
 * @param y second sample
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 */
private void ensureDataConformance(final double[] x, final double[] y)
    throws NullArgumentException, NoDataException {

    if (x == null ||
        y == null) {
        throw new NullArgumentException();
    }
    if (x.length == 0 ||
        y.length == 0) {
        throw new NoDataException();
    }
}
 
Example #23
Source File: Elixir_0022_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Ensures that the provided arrays fulfills the assumptions.
 *
 * @param x first sample
 * @param y second sample
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 */
private void ensureDataConformance(final double[] x, final double[] y)
    throws NullArgumentException, NoDataException {

    if (x == null ||
        y == null) {
        throw new NullArgumentException();
    }
    if (x.length == 0 ||
        y.length == 0) {
        throw new NoDataException();
    }
}
 
Example #24
Source File: 1_BigFraction.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Multiplies the value of this fraction by another, returning the result in
 * reduced form.
 * </p>
 *
 * @param fraction Fraction to multiply by, must not be {@code null}.
 * @return a {@link BigFraction} instance with the resulting values.
 * @throws NullArgumentException if {@code fraction} is {@code null}.
 */
public BigFraction multiply(final BigFraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (numerator.equals(BigInteger.ZERO) ||
        fraction.numerator.equals(BigInteger.ZERO)) {
        return ZERO;
    }
    return new BigFraction(numerator.multiply(fraction.numerator),
                           denominator.multiply(fraction.denominator));
}
 
Example #25
Source File: Math_30_MannWhitneyUTest_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Ensures that the provided arrays fulfills the assumptions.
 *
 * @param x first sample
 * @param y second sample
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 */
private void ensureDataConformance(final double[] x, final double[] y)
    throws NullArgumentException, NoDataException {

    if (x == null ||
        y == null) {
        throw new NullArgumentException();
    }
    if (x.length == 0 ||
        y.length == 0) {
        throw new NoDataException();
    }
}
 
Example #26
Source File: Elixir_0022_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Ensures that the provided arrays fulfills the assumptions.
 *
 * @param x first sample
 * @param y second sample
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 */
private void ensureDataConformance(final double[] x, final double[] y)
    throws NullArgumentException, NoDataException {

    if (x == null ||
        y == null) {
        throw new NullArgumentException();
    }
    if (x.length == 0 ||
        y.length == 0) {
        throw new NoDataException();
    }
}
 
Example #27
Source File: Math_26_Fraction_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * <p>Divide the value of this fraction by another.</p>
 *
 * @param fraction  the fraction to divide by, must not be {@code null}
 * @return a {@code Fraction} instance with the resulting values
 * @throws IllegalArgumentException if the fraction is {@code null}
 * @throws MathArithmeticException if the fraction to divide by is zero
 * @throws MathArithmeticException if the resulting numerator or denominator exceeds
 *  {@code Integer.MAX_VALUE}
 */
public Fraction divide(Fraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (fraction.numerator == 0) {
        throw new MathArithmeticException(LocalizedFormats.ZERO_FRACTION_TO_DIVIDE_BY,
                                          fraction.numerator, fraction.denominator);
    }
    return multiply(fraction.reciprocal());
}
 
Example #28
Source File: Math_34_ListPopulation_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Sets the list of chromosomes.
 * <p>Note: this method removed all existing chromosomes in the population and adds all chromosomes
 * of the specified list to the population.</p>
 * @param chromosomes the list of chromosomes
 * @throws NullArgumentException if the list of chromosomes is {@code null}
 * @throws NumberIsTooLargeException if the list of chromosomes exceeds the population limit
 * @deprecated use {@link #addChromosomes(Collection)} instead
 */
public void setChromosomes(final List<Chromosome> chromosomes) {
    if (chromosomes == null) {
        throw new NullArgumentException();
    }
    if (chromosomes.size() > populationLimit) {
        throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                                            chromosomes.size(), populationLimit, false);
    }
    this.chromosomes.clear();
    this.chromosomes.addAll(chromosomes);
}
 
Example #29
Source File: Elixir_0025_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Sets the list of chromosomes.
 * <p>Note: this method removed all existing chromosomes in the population and adds all chromosomes
 * of the specified list to the population.</p>
 * @param chromosomes the list of chromosomes
 * @throws NullArgumentException if the list of chromosomes is {@code null}
 * @throws NumberIsTooLargeException if the list of chromosomes exceeds the population limit
 * @deprecated use {@link #addChromosomes(Collection)} instead
 */
public void setChromosomes(final List<Chromosome> chromosomes) {
    if (chromosomes == null) {
        throw new NullArgumentException();
    }
    if (chromosomes.size() > populationLimit) {
        throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                                            chromosomes.size(), populationLimit, false);
    }
    this.chromosomes.clear();
    this.chromosomes.addAll(chromosomes);
}
 
Example #30
Source File: Elixir_0022_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Computes the <a
 * href="http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U"> Mann-Whitney
 * U statistic</a> comparing mean for two independent samples possibly of
 * different length.
 * <p>
 * This statistic can be used to perform a Mann-Whitney U test evaluating
 * the null hypothesis that the two independent samples has equal mean.
 * </p>
 * <p>
 * Let X<sub>i</sub> denote the i'th individual of the first sample and
 * Y<sub>j</sub> the j'th individual in the second sample. Note that the
 * samples would often have different length.
 * </p>
 * <p>
 * <strong>Preconditions</strong>:
 * <ul>
 * <li>All observations in the two samples are independent.</li>
 * <li>The observations are at least ordinal (continuous are also ordinal).</li>
 * </ul>
 * </p>
 *
 * @param x the first sample
 * @param y the second sample
 * @return Mann-Whitney U statistic (maximum of U<sup>x</sup> and U<sup>y</sup>)
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 */
public double mannWhitneyU(final double[] x, final double[] y)
    throws NullArgumentException, NoDataException {

    ensureDataConformance(x, y);

    final double[] z = concatenateSamples(x, y);
    final double[] ranks = naturalRanking.rank(z);

    double sumRankX = 0;

    /*
     * The ranks for x is in the first x.length entries in ranks because x
     * is in the first x.length entries in z
     */
    for (int i = 0; i < x.length; ++i) {
        sumRankX += ranks[i];
    }

    /*
     * U1 = R1 - (n1 * (n1 + 1)) / 2 where R1 is sum of ranks for sample 1,
     * e.g. x, n1 is the number of observations in sample 1.
     */
    final double U1 = sumRankX - (x.length * (x.length + 1)) / 2;

    /*
     * It can be shown that U1 + U2 = n1 * n2
     */
    final double U2 = x.length * y.length - U1;

    return FastMath.max(U1, U2);
}