You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Benjamin McCann (JIRA)" <ji...@apache.org> on 2011/03/11 06:52:59 UTC

[jira] Created: (MATH-545) Feature Request: RealVector cosine

Feature Request: RealVector cosine
----------------------------------

                 Key: MATH-545
                 URL: https://issues.apache.org/jira/browse/MATH-545
             Project: Commons Math
          Issue Type: New Feature
            Reporter: Benjamin McCann


I'd like a method to compute the cosine similarity between vectors.
http://en.wikipedia.org/wiki/Cosine_similarity

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Resolved: (MATH-545) Feature Request: RealVector cosine

Posted by "Gilles (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-545?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gilles resolved MATH-545.
-------------------------

       Resolution: Fixed
    Fix Version/s: 3.0

Method "cosine" added in "RealVector" interface (revision 1082442).


> Feature Request: RealVector cosine
> ----------------------------------
>
>                 Key: MATH-545
>                 URL: https://issues.apache.org/jira/browse/MATH-545
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Benjamin McCann
>            Assignee: Gilles
>             Fix For: 3.0
>
>
> I'd like a method to compute the cosine similarity between vectors.
> http://en.wikipedia.org/wiki/Cosine_similarity

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Issue Comment Edited: (MATH-545) Feature Request: RealVector cosine

Posted by "Benjamin McCann (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-545?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13005517#comment-13005517 ] 

Benjamin McCann edited comment on MATH-545 at 3/11/11 6:36 AM:
---------------------------------------------------------------

I guess it's pretty simple, but it still might be nice as a convenience method:
{noformat} 
  public double cosine(double[] a1, double[] a2) {
    ArrayRealVector v1 = new ArrayRealVector(a1);
    ArrayRealVector v2 = new ArrayRealVector(a2);
    return v1.dotProduct(v2) / (v1.getNorm() * v2.getNorm());
  }
{noformat}

      was (Author: bmccann):
    I guess it's pretty simple, but it still might be nice as a convenience method:

    public double cosine(double[] a1, double[] a2) {
      ArrayRealVector v1 = new ArrayRealVector(a1);
      ArrayRealVector v2 = new ArrayRealVector(a2);
      return v1.dotProduct(v2) / (v1.getNorm() * v2.getNorm());
    }
  
> Feature Request: RealVector cosine
> ----------------------------------
>
>                 Key: MATH-545
>                 URL: https://issues.apache.org/jira/browse/MATH-545
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Benjamin McCann
>
> I'd like a method to compute the cosine similarity between vectors.
> http://en.wikipedia.org/wiki/Cosine_similarity

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Issue Comment Edited: (MATH-545) Feature Request: RealVector cosine

Posted by "Benjamin McCann (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-545?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13005517#comment-13005517 ] 

Benjamin McCann edited comment on MATH-545 at 3/11/11 6:33 AM:
---------------------------------------------------------------

I guess it's pretty simple, but it still might be nice as a convenience method:

    public double cosine(double[] a1, double[] a2) {
      ArrayRealVector v1 = new ArrayRealVector(a1);
      ArrayRealVector v2 = new ArrayRealVector(a2);
      return v1.dotProduct(v2) / (v1.getNorm() * v2.getNorm());
    }

      was (Author: bmccann):
    I guess it's pretty simple, but it still might be nice as a convenience method:
  public double cosine(double[] a1, double[] a2) {
    ArrayRealVector v1 = new ArrayRealVector(a1);
    ArrayRealVector v2 = new ArrayRealVector(a2);
    return v1.dotProduct(v2) / (v1.getNorm() * v2.getNorm());
  }
  
> Feature Request: RealVector cosine
> ----------------------------------
>
>                 Key: MATH-545
>                 URL: https://issues.apache.org/jira/browse/MATH-545
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Benjamin McCann
>
> I'd like a method to compute the cosine similarity between vectors.
> http://en.wikipedia.org/wiki/Cosine_similarity

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Commented: (MATH-545) Feature Request: RealVector cosine

Posted by "Gilles (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-545?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13005609#comment-13005609 ] 

Gilles commented on MATH-545:
-----------------------------

Shall we add "cosine" to the "RealVector" interface?

And the implementation would go in "AbstractRealVector":
{noformat}
public double cosine(RealVector v) {
  final double norm = getNorm();
  final double vNorm = v.getNorm();
  if (norm == 0 || vNorm == 0) {
      throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
  }
  return dotProduct(v) / (norm * vNorm);
}
{noformat}


> Feature Request: RealVector cosine
> ----------------------------------
>
>                 Key: MATH-545
>                 URL: https://issues.apache.org/jira/browse/MATH-545
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Benjamin McCann
>
> I'd like a method to compute the cosine similarity between vectors.
> http://en.wikipedia.org/wiki/Cosine_similarity

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Commented: (MATH-545) Feature Request: RealVector cosine

Posted by "Benjamin McCann (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-545?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13005517#comment-13005517 ] 

Benjamin McCann commented on MATH-545:
--------------------------------------

I guess it's pretty simple, but it still might be nice as a convenience method:
  public double cosine(double[] a1, double[] a2) {
    ArrayRealVector v1 = new ArrayRealVector(a1);
    ArrayRealVector v2 = new ArrayRealVector(a2);
    return v1.dotProduct(v2) / (v1.getNorm() * v2.getNorm());
  }

> Feature Request: RealVector cosine
> ----------------------------------
>
>                 Key: MATH-545
>                 URL: https://issues.apache.org/jira/browse/MATH-545
>             Project: Commons Math
>          Issue Type: New Feature
>            Reporter: Benjamin McCann
>
> I'd like a method to compute the cosine similarity between vectors.
> http://en.wikipedia.org/wiki/Cosine_similarity

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira