org.carrot2.util.MathUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of carrot2-core Show documentation
Show all versions of carrot2-core Show documentation
Carrot2 Text Clustering Library
/*
* 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);
}
}