hive-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maxim Bolotin (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HIVE-3455) ANSI CORR(X,Y) is incorrect
Date Wed, 12 Sep 2012 23:01:08 GMT

    [ https://issues.apache.org/jira/browse/HIVE-3455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13454461#comment-13454461
] 

Maxim Bolotin commented on HIVE-3455:
-------------------------------------

284,285c282,283
<         double xavgOld = myagg.xavg;
<         double yavgOld = myagg.yavg;
---
>         double deltaX = vx - myagg.xavg;
>         double deltaY = vy - myagg.yavg;
287,288c285,286
<         myagg.xavg += (vx - xavgOld) / myagg.count;
<         myagg.yavg += (vy - yavgOld) / myagg.count;
---
>         myagg.xavg += deltaX / ((double) myagg.count);
>         myagg.yavg += deltaY / ((double) myagg.count);
290,292c288,290
<             myagg.covar += (vx - xavgOld) * (vy - myagg.yavg);
<             myagg.xvar += (vx - xavgOld) * (vx - myagg.xavg);
<             myagg.yvar += (vy - yavgOld) * (vy - myagg.yavg);
---
>             myagg.covar += deltaX * (vy - myagg.yavg);
>             myagg.xvar += deltaX * (vx - myagg.xavg);
>             myagg.yvar += deltaY * (vy - myagg.yavg);
345,350c343,351
<           myagg.xavg = (xavgA * nA + xavgB * nB) / myagg.count;
<           myagg.yavg = (yavgA * nA + yavgB * nB) / myagg.count;
<           myagg.xvar += xvarB + (xavgA - xavgB) * (xavgA - xavgB) * myagg.count;
<           myagg.yvar += yvarB + (yavgA - yavgB) * (yavgA - yavgB) * myagg.count;
<           myagg.covar +=
<               covarB + (xavgA - xavgB) * (yavgA - yavgB) * ((double) (nA * nB) / myagg.count);
---
>           double n=myagg.count;
>           double nn=nA*nB/n;
>           double dX = xavgA-xavgB;
>           double dY = yavgA-yavgB;
>           myagg.xavg = xavgA * nA / n + xavgB * nB / n;
>           myagg.yavg = yavgA * nA / n + yavgB * nB / n;
>           myagg.xvar  += xvarB  + dX * dX * nn ;
>           myagg.yvar  += yvarB  + dY * dY * nn ;
>           myagg.covar += covarB + dX * dY * nn;

                
> ANSI CORR(X,Y) is incorrect
> ---------------------------
>
>                 Key: HIVE-3455
>                 URL: https://issues.apache.org/jira/browse/HIVE-3455
>             Project: Hive
>          Issue Type: Bug
>          Components: UDF
>    Affects Versions: 0.7.1, 0.8.0, 0.9.0
>            Reporter: Maxim Bolotin
>
> A simple test with 2 collinear vectors returns a wrong result.
> The problem is the merge of variances, file:
> http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCorrelation.java?revision=1157222&view=markup
> lines:
> 347: myagg.xvar += xvarB + (xavgA-xavgB) * (xavgA-xavgB) * myagg.count;
> 348: myagg.yvar += yvarB + (yavgA-yavgB) * (yavgA-yavgB) * myagg.count;
> the correct merge should be like this:
> 347: myagg.xvar += xvarB+(xavgA - xavgB)*(xavgA-xavgB)/myagg.count*nA*nB;
> 348: myagg.yvar += yvarB+(yavgA - yavgB)*(yavgA-yavgB)/myagg.count*nA*nB;

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message