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

Symbolic dimensions allowed in MultivariateEwens #16914

Merged
merged 3 commits into from Jun 1, 2019

Conversation

Projects
None yet
5 participants
@czgdp1807
Copy link
Member

commented May 28, 2019

References to other Issues or PRs

[1] Extends #16576

Brief description of what is fixed or changed

Symbolic dimensions can now be passed to MultivariateEwens in sympy.stats.joint_rv_types.

Other comments

This is a work in progress task. There are some problems with ArrayComprehension which need to be handled, for instance, it is not possible to multiply the elements of ArrayComprehension and return an unevaluated Mul object.

Release Notes

NO ENTRY

@sympy-bot

This comment has been minimized.

Copy link

commented May 28, 2019

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

  • No release notes entry will be added for this pull request.

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. -->

#### 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://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->
[1] Extends https://github.com/sympy/sympy/pull/16576

#### Brief description of what is fixed or changed
Symbolic dimensions can now be passed to `MultivariateEwens` in `sympy.stats.joint_rv_types`.

#### Other comments
This is a work in progress task. There are some problems with `ArrayComprehension` which need to be handled, for instance, it is not possible to multiply the elements of `ArrayComprehension` and return an unevaluated `Mul` object. 

#### 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 -->
NO ENTRY
<!-- END RELEASE NOTES -->

@czgdp1807 czgdp1807 changed the title symbolic dimensions allowed [WIP][GSoC] Symbolic dimensions allowed in MultivariateEwens May 28, 2019

@czgdp1807

This comment has been minimized.

Copy link
Member Author

commented May 28, 2019

@Abdullahjavednesar Abdullahjavednesar requested a review from Upabjojr May 28, 2019

@czgdp1807 czgdp1807 changed the title [WIP][GSoC] Symbolic dimensions allowed in MultivariateEwens [WIP] Symbolic dimensions allowed in MultivariateEwens May 29, 2019

@codecov

This comment has been minimized.

Copy link

commented May 29, 2019

Codecov Report

Merging #16914 into master will increase coverage by 0.015%.
The diff coverage is 76%.

@@              Coverage Diff              @@
##            master    #16914       +/-   ##
=============================================
+ Coverage   73.941%   73.957%   +0.015%     
=============================================
  Files          620       620               
  Lines       160203    160262       +59     
  Branches     37599     37606        +7     
=============================================
+ Hits        118457    118525       +68     
+ Misses       36262     36248       -14     
- Partials      5484      5489        +5
@kangzhiq

This comment has been minimized.

Copy link
Contributor

commented May 29, 2019

>>> M = Mul.fromiter(ArrayComprehension(i, (i, 1, n)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\CodeHouse\Python\sympy\sympy\core\basic.py", line 259, in fromiter
    return cls(*tuple(args), **assumptions)
TypeError: 'ArrayComprehension' object is not iterable

So more precisely, do you mean that ArrayComprehension should be iterable?

@czgdp1807

This comment has been minimized.

Copy link
Member Author

commented May 30, 2019

@kangzhiq As you would have seen the diff, I am able to get the things done without, ArrayComprehension but the logic is separate for integer and symbolic dimensions.
Basically, ArrayComprehension should be an iterable and whenever operators like * or fromiter are used it should remain unevaluated if dimensions are symbolic and Mul, Add should also remain unevaluated.

@oscarbenjamin

This comment has been minimized.

Copy link
Contributor

commented May 30, 2019

I don't see how ArrayComprehension can remain unevaluated with * and fromiter. They both require an actual iterable and there's no way a symbolic ArrayComprehension can do that. There could be a way to construct a symbolic Product from a symbolic ArrayComprehension though.

@czgdp1807

This comment has been minimized.

Copy link
Member Author

commented May 30, 2019

There could be a way to construct a symbolic Product from a symbolic ArrayComprehension though.

I don't think we should create an ArrayComprehension to just convert it into Product, instead we can directly create the Product object and this is what I have done in the diff.

@kangzhiq

This comment has been minimized.

Copy link
Contributor

commented May 30, 2019

As far as I can understand, what you are expecting from ArrayComprehension that multiplying each term by iterating on a list of function is supposed to be handled by Product.
However, when I try to test it by using:

j, k = symbols('j, k', positive=True, integer=True)
term_2 = Product(theta**syms[j]/((j+1)**syms[j]*factorial(syms[j])),(j, 0, n - 1)).doit()
cond = Eq(Sum((k + 1)*syms[k], (k, 0, n - 1)).doit(), n)
return Piecewise((term_1 * term_2, cond), (0, True))

so that you won't need to check the type of n, it continuously raises some errors. Have you already tried it?

@czgdp1807

This comment has been minimized.

Copy link
Member Author

commented May 31, 2019

@kangzhiq I will try to unify the logic today and will update you accordingly if the things work correctly. Currently, I don't expect them to because there will be a problem of indexing the syms.

@czgdp1807 czgdp1807 changed the title [WIP] Symbolic dimensions allowed in MultivariateEwens Symbolic dimensions allowed in MultivariateEwens May 31, 2019

@czgdp1807

This comment has been minimized.

Copy link
Member Author

commented May 31, 2019

Currently, I don't expect them to because there will be a problem of indexing the syms.

This will cause a problem for symbolic n. Hence, the logic for symbolic dimensions and integer dimensions cannot be unified.
The reason is for symbolic n, in syms[j], j will be a symbol. So for combining the logic, we will be required to use IndexedBase because it allows both symbolic and integer indexes. However, I don't support it because it will not allow the use of API like, density(ed)(x, y, z). The user will be restricted to use, density(ed)(i), i is IndexedBase object which will lead to bad user experience and may cause a lot of problems. If @Upabjojr agrees to such restriction of arguments then I will make the change.

@Upabjojr

This comment has been minimized.

Copy link
Contributor

commented Jun 1, 2019

I think the code looks good. Tell me if you're OK to merge.

@czgdp1807

This comment has been minimized.

Copy link
Member Author

commented Jun 1, 2019

@Upabjojr Yes, please merge it.

@Upabjojr Upabjojr merged commit ab7dbc8 into sympy:master Jun 1, 2019

3 checks passed

codecov/project 73.957% (target 0%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
sympy-bot/release-notes The release notes look OK
Details

@czgdp1807 czgdp1807 deleted the czgdp1807:sym_dims_1 branch Jun 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.