Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

Support Hellinger-distance-based scoring both on SDAR 1D and 2D #330

Merged
merged 2 commits into from
Sep 3, 2016

Conversation

takuti
Copy link
Contributor

@takuti takuti commented Sep 2, 2016

What this PR includes

By keeping the last _mu and _sigma in the SDAR algorithm as _muOld and _sigmaOld, we are now able to compute the Hellinger distance between the models before/after update. Usage is demonstrated as comments in ChangeFinder1D and ChangeFinder2D.

Computation of the Hellinger distance between two (multivariate) normal distributions are implemented on MathUtils.

Are the Hellinger distances computed correctly?

Unit tests have not been implemented yet. However, I have confirmed whether it works as expected by comparing the results of Python implementation.

  • mu1: 2.25635999045
  • sigma1: 1.56789907203
  • mu2: 2.37802392246
  • sigma2: 4.5496514822

For the above parameters, the Python code returns a distance 0.0661275442145.

Here, our MathUtils.hellingerDistanes() method also works as:

MathUtils.hellingerDistance(2.25635999045, 1.56789907203, 2.37802392246, 4.5496514822);
// => almost equal to 0.0661275442145
RealVector mu1 = new ArrayRealVector(new double[] {2.25635999045});
RealMatrix sigma1 = new Array2DRowRealMatrix(new double[] {1.56789907203});
RealVector mu2 = new ArrayRealVector(new double[] {2.37802392246});
RealMatrix sigma2 = new Array2DRowRealMatrix(new double[] {4.5496514822});
MathUtils.hellingerDistance(mu1, sigma1, mu2, sigma2);
// => almost equal to 0.0661275442145

double numerator = Math.pow(sigma1, 0.25) * Math.pow(sigma2, 0.25) *
Math.exp(-0.25 * Math.pow(mu1 - mu2, 2) / sigmaSum);
double denominator = Math.sqrt(sigmaSum / 2);
return 1.d - numerator / denominator;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(denominator == 0.d) {
return 1.d;
}

@myui myui added this to the v0.4 milestone Sep 2, 2016
@myui myui self-assigned this Sep 2, 2016
@myui myui merged commit 9db88f1 into myui:feature/changefinder1d Sep 3, 2016
@myui
Copy link
Owner

myui commented Sep 3, 2016

Merged. Thanks. I'll fix some.

@takuti takuti deleted the support-hellinger-distance branch September 3, 2016 07:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants