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

Extending scope of queries for DiscreteMarkovChain #17083

Merged
merged 8 commits into from Jul 5, 2019

Conversation

Projects
None yet
4 participants
@czgdp1807
Copy link
Member

commented Jun 24, 2019

References

Phase 2 initialisation
[1.1] https://czgdp1807.github.io/week_4/

Use cases and problems
[2.1] https://www.probabilitycourse.com/chapter11/11_2_7_solved_probs.php - 7616f24
[2.2] Or Conditions - 1919621
[2.3] Ne Conditions - 1129f0a
[2.4] Conditions similar to Eq(X[2], 1) & Eq(X[2], 2) - 691d47c

Brief description of what is fixed or changed

I have updated the sympy.stats.stochastic_process_types.py to handle some miscellaneous queries. I will update the references [2.x] with each commit, covering a case which was uncovered before.
This is a part of the plan for phase 2 as can be seen in [1.1]. This continues the work done in phase 1.

Other comments

ping @Upabjojr @sidhantnagpal
As, in future more cases will be covered and may be it can become difficult to review, I have provided the link to the commit(for ease) associated with each extra case I cover.
Please let me know of better approaches if you have any to share. Thanks.

Release Notes

  • stats
    • DiscreteMarkovChain is now able to handle complex queries.
@sympy-bot

This comment has been minimized.

Copy link

commented Jun 24, 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.

Your release notes are in good order.

Here is what the release notes will look like:

  • stats
    • DiscreteMarkovChain is now able to handle complex queries. (#17083 by @czgdp1807)

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

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
<!-- 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. -->
**Phase 2 initialisation**
[1.1] https://czgdp1807.github.io/week_4/

**Use cases and problems**
 [2.1] https://www.probabilitycourse.com/chapter11/11_2_7_solved_probs.php - https://github.com/sympy/sympy/commit/7616f244394367fd89519548340cfdd7b8e9b244
[2.2] `Or` Conditions - https://github.com/sympy/sympy/pull/17083/commits/19196217d75c016daa4f1758f76da3d47bb0c9ef
[2.3] `Ne` Conditions - https://github.com/sympy/sympy/pull/17083/commits/1129f0a2ffb1b922bf45b1be44cde7a8c455f534
[2.4] Conditions similar to `Eq(X[2], 1) & Eq(X[2], 2)` - https://github.com/sympy/sympy/pull/17083/commits/691d47c46d743ebdcf973ce097f1749452498d4a

#### Brief description of what is fixed or changed
I have updated the `sympy.stats.stochastic_process_types.py` to handle some miscellaneous queries. I will update the references [2.x] with each commit, covering a case which was uncovered before.
This is a part of the plan for phase 2 as can be seen in [1.1]. This continues the work done in phase 1.

#### Other comments
ping @Upabjojr @sidhantnagpal 
As, in future more cases will be covered and may be it can become difficult to review, I have provided the link to the commit(for ease) associated with each extra case I cover.
Please let me know of better approaches if you have any to share. Thanks.

#### 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
   * `DiscreteMarkovChain` is now able to handle complex queries.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@codecov

This comment has been minimized.

Copy link

commented Jun 25, 2019

Codecov Report

Merging #17083 into master will increase coverage by 0.078%.
The diff coverage is 85.454%.

@@              Coverage Diff              @@
##            master    #17083       +/-   ##
=============================================
+ Coverage   74.435%   74.513%   +0.078%     
=============================================
  Files          622       623        +1     
  Lines       161085    161421      +336     
  Branches     37811     37890       +79     
=============================================
+ Hits        119904    120281      +377     
+ Misses       35861     35804       -57     
- Partials      5320      5336       +16
@czgdp1807

This comment has been minimized.

Copy link
Member Author

commented Jul 2, 2019

The work on probability queries is complete. It is capable of handling a variety of queries. We can make changes to include rare queries according to the response received from the users.
Now, I will focus on extending expectation queries.

@czgdp1807

This comment has been minimized.

Copy link
Member Author

commented Jul 3, 2019

From my side the work on DiscreteMarkovChain is complete(changes can be made in future as per response received from the user base). Please provide reviews, so that this can be merged and I can proceed towards adding ContinuousMarkovChain. Thanks.

@czgdp1807 czgdp1807 changed the title [WIP] Extending scope of queries for DiscreteMarkovChain Extending scope of queries for DiscreteMarkovChain Jul 3, 2019

@sidhantnagpal

This comment has been minimized.

Copy link
Member

commented Jul 3, 2019

Good start. This patch deserves a release notes entry.

@czgdp1807

This comment has been minimized.

Copy link
Member Author

commented Jul 3, 2019

Sure, I will add one.

Show resolved Hide resolved sympy/stats/stochastic_process_types.py Outdated
Show resolved Hide resolved sympy/stats/stochastic_process_types.py Outdated
@Upabjojr

This comment has been minimized.

Copy link
Contributor

commented Jul 3, 2019

@czgdp1807 you are implementing rules to handle specific relational expressions. Have you given a thought on whether some generic algorithms like SAT-solvers can be generalized to be used here?

(This is just a curiosity, no request to implement anything as it's probably extremely hard).

@czgdp1807

This comment has been minimized.

Copy link
Member Author

commented Jul 4, 2019

Have you given a thought on whether some generic algorithms like SAT-solvers can be generalized to be used here?

One way is to convert the condition into set using c.as_set() and then back to relationals, using, c.as_set().as_relational(idx), But as_set doesn't work for multivariate expressions and hence it will fail for some queries. Therefore, I had to work in the way I did.
Though, the current algorithm can handle a variety of queries. I have implemented the logic for basic operators like, And, Or, Ne, Eq and most complex queries will be a combination of these. I have as_set().as_relational(idx) in And, Or and hence, allow us to handle a lot of cases with ease. The point of not including, Nand, Nor, etc. is that it doesn't hold any meaning to pass such inputs, we can directly pass them as And, Or. In fact, And, Or are just a way to transform mathematical problems into API and these are the most intuitive operators to do so.
Regarding, expectation, it has a generic implementation, and will handle maximum inputs. Though some will be invalid, like, E(X[1], X[1] > 1), because there isn't any information about the past and Markov process require that, so it doesn't hold any meaning.

czgdp1807 added some commits Jul 4, 2019

@Upabjojr Upabjojr merged commit 0e4975f into sympy:master Jul 5, 2019

3 checks passed

codecov/project 74.513% (target 0%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
sympy-bot/release-notes The release notes look OK
Details
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.