Skip to content
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

[GSoC] Added symbolic Expectation, Variance and CrossCovariance matrix #19529

Merged
merged 7 commits into from
Jun 19, 2020

Conversation

Smit-create
Copy link
Member

@Smit-create Smit-create commented Jun 11, 2020

Added symbolic Expectation, Variance and Covariance matrix

References to other Issues or PRs

References from #19299

Brief description of what is fixed or changed

Other comments

  • Add classses
  • Add docs and tests

Release Notes

  • stats
    • Added Expectation Matrix, Variance Matrix and CrossCovariance Matrix

ping @czgdp1807 @Upabjojr

@sympy-bot
Copy link

sympy-bot commented Jun 11, 2020

Hi, I am the SymPy bot (v160). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • stats
    • Added Expectation Matrix, Variance Matrix and CrossCovariance Matrix (#19529 by @Smit-create)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.7.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->
Added symbolic Expectation, Variance and Covariance matrix
#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
References from #19299 

#### Brief description of what is fixed or changed


#### Other comments
- [x] Add classses
- [x] Add docs and tests 

#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* stats
  * Added Expectation Matrix, Variance Matrix and CrossCovariance Matrix
<!-- END RELEASE NOTES -->
ping @czgdp1807  @Upabjojr

Update

The release notes on the wiki have been updated.

@sympy-bot
Copy link

sympy-bot commented Jun 11, 2020

🟠

Hi, I am the SymPy bot (v160). I've noticed that some of your commits add or delete files. Since this is sometimes done unintentionally, I wanted to alert you about it.

This is an experimental feature of SymPy Bot. If you have any feedback on it, please comment at sympy/sympy-bot#75.

The following commits add new files:

  • 21f5de8:
    • sympy/stats/symbolic_multivariate_probability.py
  • 3117bbf:
    • sympy/stats/tests/test_symbolic_multivariate.py

If these files were added/deleted on purpose, you can ignore this message.

@Upabjojr
Copy link
Contributor

There are various name possibilities to choose, from wikipedia:

  1. https://en.wikipedia.org/wiki/Covariance_matrix

covariance matrix (also known as auto-covariance matrix, dispersion matrix, variance matrix, or variance–covariance matrix)

  1. OTOH, the cross-covariance matrix: https://en.wikipedia.org/wiki/Cross-covariance_matrix

In principle, 1 and 2 are the generalizations of variance and covariance to vector random variables. There are problems with the terminology though, as the covariance matrix is the generalization of the variance (not the covariance), while the cross-covariance matrix is the generalization of the covariance.

@czgdp1807
Copy link
Member

Tests?

@Smit-create
Copy link
Member Author

I am writing them currently, and push by tonight.

@Smit-create
Copy link
Member Author

Smit-create commented Jun 12, 2020

I have added docs and tests for VarianceMatrix and CrossCovarianceMatrix. I am currently trying to resolve the following error with ExpectationMatrix.

>>> A = MatrixSymbol("A", k, k)
>>> X = RandomMatrixSymbol("X", k, 1)
>>> Expectation((Mul.fromiter([A*X]))) # correct
ExpectationMatrix(A*X)
>>> Expectation((Mul.fromiter([X])))
ExpectationMatrix(X)
>>> A*Expectation((Mul.fromiter([X]))) # this looks incorrect
A*X  # Expected as: A*ExpectationMatrix(X)

@oscarbenjamin @sylee957 Can you please have a look at this?

@czgdp1807
Copy link
Member

The problem is with doit of ExpectationMatrix,

>>> r = Expectation((Mul.fromiter([X])))
>>> r
ExpectationMatrix(X)
>>> r.doit()
X

@codecov
Copy link

codecov bot commented Jun 13, 2020

Codecov Report

Merging #19529 into master will increase coverage by 0.046%.
The diff coverage is 87.820%.

@@              Coverage Diff              @@
##            master    #19529       +/-   ##
=============================================
+ Coverage   75.621%   75.667%   +0.046%     
=============================================
  Files          652       655        +3     
  Lines       169813    170092      +279     
  Branches     40061     40110       +49     
=============================================
+ Hits        128415    128705      +290     
+ Misses       35789     35770       -19     
- Partials      5609      5617        +8     

@Smit-create
Copy link
Member Author

Smit-create commented Jun 13, 2020

The problem is with doit of ExpectationMatrix,

Opps, got it, MatMul will call doit, so for ExpecationMatrix, Expectation's doit is called, so need to fix it. Thanks!!

@czgdp1807
Copy link
Member

LGTM. Any thoughts @Upabjojr @jmig5776 ?

@Smit-create
Copy link
Member Author

ping @Upabjojr

def test_multivariate_variance():
raises(ShapeError, lambda: Variance(A))

expr = Variance(a) # type: VarianceMatrix
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe also an assert isinstance(expr, VarianceMatrix)?

@Upabjojr
Copy link
Contributor

This looks good to me.

@Upabjojr Upabjojr merged commit fb8cdf0 into sympy:master Jun 19, 2020
@Smit-create Smit-create changed the title [GSoC] Added symbolic Expectation, Variance and Covariance matrix [GSoC] Added symbolic Expectation, Variance and CrossCovariance matrix Jun 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants