Skip to content

Covariance of array elements #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2020
Merged

Conversation

jvdp1
Copy link
Member

@jvdp1 jvdp1 commented Apr 12, 2020

Draft proposal for covariance of array elements opened for discussion

Related to #113

To be discussed:

  • Name: the currently proposed name is cov. But what about covariance,....?
  • API: similar to the API of variance
  • Implementation: only for arrays of rank 1 and rank 2.
  • Implementation: the API accepts only 1 array.
    An implementation to compute the covariance among 2 arrays still needs to be done.

Others:
Octave cov
Matlab cov
Julia cov
R cov
Numpy cov

cov - covariance of array elements

Description

Returns the covariance of the elements of array along dimension dim if the corresponding e
lement in mask is true.

Per default, the covariance is defined as:

 cov(array) = 1/(n-1) sum_i (array(i) - mean(array) * (array(i) - mean(array)))

where n is the number of elements.

The scaling can be changed with the logical argument corrected. If corrected is .false.,
then the sum is scaled with n, otherwise with n-1.

Syntax

result = cov(array, dim [, mask [, corrected]])

jvdp1 added 2 commits April 12, 2020 11:03
Squashed commit of the following:

commit c7d6c1d
Author: Vandenplas, Jeremie <[email protected]>
Date:   Sun Apr 12 10:18:15 2020 +0200

    covariance: addition of tests

commit 9cd7e63
Author: Vandenplas, Jeremie <[email protected]>
Date:   Sun Apr 12 00:12:41 2020 +0200

    covariance:comment

commit 958b59b
Author: Vandenplas, Jeremie <[email protected]>
Date:   Sat Apr 11 23:46:40 2020 +0200

    covariance: correct test

commit fdf4e54
Author: Vandenplas, Jeremie <[email protected]>
Date:   Sat Apr 11 22:57:23 2020 +0200

    covariance: update spec

commit c3c277f
Author: Vandenplas, Jeremie <[email protected]>
Date:   Sat Apr 11 22:35:11 2020 +0200

    covariance: support of cov for vectors

commit c60ce03
Author: Vandenplas, Jeremie <[email protected]>
Date:   Sat Apr 11 21:46:41 2020 +0200

    covariance: real + complex+integer

commit 9e3eba0
Author: Vandenplas, Jeremie <[email protected]>
Date:   Fri Apr 10 23:16:48 2020 +0200

    covariance: addition of complex

commit 340309e
Author: Vandenplas, Jeremie <[email protected]>
Date:   Fri Apr 10 22:32:17 2020 +0200

    covariance: init
@jvdp1 jvdp1 requested review from certik, ivan-pi and milancurcic April 12, 2020 10:06
@ivan-pi
Copy link
Member

ivan-pi commented Apr 13, 2020

I am fine with both cov or covariance. In case we decide to go for the long version, I would suggest renaming var to variance. They can always be renamed at import if desired, using use stdlib_stats, only: cov => covariance.

Overall a nice proposal, so I am fine with merging.

Copy link
Member

@milancurcic milancurcic left a comment

Choose a reason for hiding this comment

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

Great!

I vote for cov (is there chance of it being confused with something else? I don't think so).

@certik
Copy link
Member

certik commented Apr 13, 2020

Looks good. Yes cov seems fine, consistent with other languages.

@jvdp1 jvdp1 marked this pull request as ready for review April 13, 2020 17:47
@certik certik changed the title Covariance of array elemetns Covariance of array elements Apr 13, 2020
@jvdp1
Copy link
Member Author

jvdp1 commented Apr 17, 2020

It seems that all of you agreed with cov as name for this function.
If there are no other comments about the implementation and API, it could be merged.

Note: An implementation to compute the covariance between 2 arrays still needs to be done, but it will be for another PR.

@jvdp1
Copy link
Member Author

jvdp1 commented Apr 22, 2020

I will merge this PR. Thank you for your reviews and approvals.

@jvdp1 jvdp1 merged commit 639cf2f into fortran-lang:master Apr 22, 2020
@jvdp1 jvdp1 deleted the covariance_dev branch April 22, 2020 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants