All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.carrot2.util.MathUtils Maven / Gradle / Ivy

There is a newer version: 4.6.0
Show newest version

/*
 * Carrot2 project.
 *
 * Copyright (C) 2002-2018, Dawid Weiss, Stanisław Osiński.
 * All rights reserved.
 *
 * Refer to the full license file "carrot2.LICENSE"
 * in the root folder of the repository checkout or at:
 * http://www.carrot2.org/carrot2.LICENSE
 */

package org.carrot2.util;

/**
 * Some simple mathematical computation utility methods.
 */
public final class MathUtils
{
    private MathUtils()
    {
    }

    /**
     * Returns the harmonic mean of v1 and v2, giving both
     * arguments equal weight.
     */
    public static double harmonicMean(double v1, double v2)
    {
        return harmonicMean(v1, v2, 1, 1);
    }

    /**
     * Returns the harmonic mean of v1 and v2, weighting them by
     * w1 and w2, respectively.
     */
    public static double harmonicMean(double v1, double v2, double w1, double w2)
    {
        return (w1 + w2) / (w1 / v1 + w2 / v2);
    }

    /**
     * Returns the arithmetic mean of v1 and v2, weighting them
     * by w1 and w2, respectively.
     */
    public static double arithmeticMean(double v1, double v2, double w1, double w2)
    {
        return (v1 * w1 + v2 * w2) / (w1 + w2);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy