Skip to content

Shift to the pymc current version #548

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 14 commits into from
Feb 8, 2023

Conversation

miemiekurisu
Copy link
Contributor

Update to pymc current version and add some Arviz content

Update to pymc current version and add some Arviz content
@miemiekurisu
Copy link
Contributor Author

miemiekurisu commented Aug 13, 2022

I'm reading this book again these days and find some of the contents a bit outdated even in pymc3 version.
So I plan to update it to pymc current version.
I believe that I've tested these new codes in the file well, and it works well under the pymc current version.

…于分支 master
# 您的分支与上游分支 'origin/master' 一致。
#
# 要提交的变更:
#	修改: Chapter2_MorePyMC/Ch2_MorePyMC_PyMC_current.ipynb
#
# 尚未暂存以备提交的变更:
#	修改: Chapter1_Introduction/Ch1_Introduction_PyMC3.ipynb
#
# 未跟踪的文件:
#	Chapter3_MCMC/Ch3_IntroMCMC_PyMC3_current.ipynb
#
@CamDavidsonPilon
Copy link
Owner

Great, thanks @miemiekurisu. This is pymc4, correct?

@miemiekurisu
Copy link
Contributor Author

Great, thanks @miemiekurisu. This is pymc4, correct?

Definitely, based on the pymc4. And I found some gaps between pymc4 and 3, different APIs, different usages, etc.
But I'll try my best ヾ(≧▽≦*)o

@twiecki
Copy link
Contributor

twiecki commented Aug 26, 2022

Thanks for taking this on @miemiekurisu!

@miemiekurisu
Copy link
Contributor Author

Update Chapter 5, some codes work, but I'm afraid it needs some review or check = ̄ω ̄=

@twiecki
Copy link
Contributor

twiecki commented Sep 4, 2022

@CamDavidsonPilon Can you enable reviewnb for this repo?

…ated (return 404), and modified some related code
@miemiekurisu
Copy link
Contributor Author

miemiekurisu commented Sep 7, 2022

♪(´▽`) Finished Ch1-6 and plan to check codes again.
And add some Arviz content to make it look more "pymc4". ★,°:.☆( ̄▽ ̄)/$:.°★

@twiecki
Copy link
Contributor

twiecki commented Sep 7, 2022

Once we have reviewnb added looking forward to reviewing!

@CamDavidsonPilon
Copy link
Owner

I've added reviewnb to the repo. It's my first time using it, so I'm not 100% where it's accessed by others. Can ya'll access this page?

@miemiekurisu
Copy link
Contributor Author

I've added reviewnb to the repo. It's my first time using it, so I'm not 100% where it's accessed by others. Can ya'll access this page?

Affirmative~ ヾ(•ω•`)o

@Slepetys
Copy link

Slepetys commented Sep 8, 2022

Hi @miemiekurisu Miemiekurisu,

I restarted reading Davidson-Pilon book last weekend, in parallel with Oswaldo Martin´s book, and both were written with previous versions of PyMC and I was struggling to replicate the results with the current code until I found your fork.

Thank you very much for the effort! And also for adding some Arviz steps, which since PyMC3 makes the data analysis and model development check much easier.

Running it locally or even in Colab, I realized that your running time in the sampling step, even using exactly the same sampler and settings was much faster than mine, do you have any advice on how to speed up it?

Thanks

@miemiekurisu
Copy link
Contributor Author

miemiekurisu commented Sep 9, 2022

@Slepetys Hi,glad you found it helpful q(≧▽≦q)
I'm not so sure about the speed difference, maybe it is the hardware difference?
I just use i3 12th gen to do this work. To be honest, I think it's so so slow in some cases.

I provide my hardware brief below:

OS: Ubuntu 22.04.1 LTS x86_64
Kernel: 5.15.0-46-generic
Shell: bash 5.1.16
CPU: 12th Gen Intel i3-12100 (8) @ 5.500GHz
GPU: Intel Device 4692
Memory: 6280MiB / 15744MiB

@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:45Z
----------------------------------------------------------------

This should be replaced by parameter.initval.


miemiekurisu commented on 2022-11-08T09:05:14Z
----------------------------------------------------------------

Yeah, you're right, and in fact I've noticed this initval and test_value problem when I upgrade it to pymc4.

According to this URL: pymc-devs/pymc#562 (comment)

test_val is a misusing, initval parameter should be used.

I try to keep the original content as much as possible at first, so I used the

aesara.config.compute_test_value = 'warn' 

to keep compatibility.

Maybe I should add some brif comments to explain this problem to previous version readers?

@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:45Z
----------------------------------------------------------------

Here as well. There is no more test_value.


@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:46Z
----------------------------------------------------------------

import aesara.tensor as at


@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:47Z
----------------------------------------------------------------

replace theano -> aesara everywhere.


@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:47Z
----------------------------------------------------------------

again usage of test_value.


@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:48Z
----------------------------------------------------------------

esara.config.compute_test_value = 'off'  you can probably remove this.


@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:52Z
----------------------------------------------------------------

PyMC4 -> PyMC 4


@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:53Z
----------------------------------------------------------------

Unfortunately this chapter is quite out-of-date, but since we're just porting here it's oK.


miemiekurisu commented on 2022-12-03T12:10:02Z
----------------------------------------------------------------

LOL

@@ -0,0 +1,1487 @@
{
Copy link
Contributor

@twiecki twiecki Sep 30, 2022

Choose a reason for hiding this comment

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

I don't think you have to pass tune, and does it reuqire that many samples?


Reply via ReviewNB

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite sure about the sample size,

because according to the PYMC2 and PYMC3 version, it samples one chain on 20000 samples and burned the 1/4 of 20000 (5000).

I try to keep the code minimal modified with PYMC2 and PYMC3 version, maybe "15000 sample/ one chain/5000 tune" is more appropriate?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can also just leave it.

@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:55Z
----------------------------------------------------------------

I thought the syntax to pm.Potential has changed and you need to pass pm.Potential(logp=logp).Which version of PyMC 4 is this?


miemiekurisu commented on 2022-12-29T03:49:45Z
----------------------------------------------------------------

PYMC4 version is 4.1.5, let me check the API again

miemiekurisu commented on 2022-12-29T04:24:35Z
----------------------------------------------------------------

Accroding to the last version here: pymc/model.py at main · pymc-devs/pymc (github.com)

def Potential(name, var, model=None):
	    """Add an arbitrary factor potential to the model likelihood
    Parameters
    ----------
    name: str
    var: PyTensor variables

    Returns
    -------
    var: var, with name attribute
    """

@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:56Z
----------------------------------------------------------------

Try with just pm.sample().


@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:57Z
----------------------------------------------------------------

PyMC3 -> PyMC


@review-notebook-app
Copy link

review-notebook-app bot commented Sep 30, 2022

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:57Z
----------------------------------------------------------------

T -> at


@review-notebook-app
Copy link

View / edit / reply to this conversation on ReviewNB

twiecki commented on 2022-09-30T13:18:58Z
----------------------------------------------------------------

Maybe add a note that Wishart is discouraged these days and that people should use LKJ.


@twiecki
Copy link
Contributor

twiecki commented Sep 30, 2022

@miemiekurisu Sorry this took a while but your port looks really good. There are some minor things, mainly about the usage of test_values but those should be easy to fix.

@review-notebook-app
Copy link

review-notebook-app bot commented Oct 18, 2022

View / edit / reply to this conversation on ReviewNB

aaronsl-hku commented on 2022-10-18T07:06:09Z
----------------------------------------------------------------

LaTeX failed to render for me. Maybe good idea to wrap it with $$?


miemiekurisu commented on 2022-12-03T11:29:05Z
----------------------------------------------------------------

That's strange, I think it's a front end or page css problem. Sometimes I got this problem too, and it works properly after I refresh the notebook page serviral times.

twiecki commented on 2022-12-29T10:30:57Z
----------------------------------------------------------------

ReviewNB often fails but then it displays fine.

@review-notebook-app
Copy link

review-notebook-app bot commented Oct 18, 2022

View / edit / reply to this conversation on ReviewNB

aaronsl-hku commented on 2022-10-18T07:06:10Z
----------------------------------------------------------------

Line #4.        trace = pm.sample(25000, step=step)

PyMC has kwarg tune now for burning in. I suggest:

  trace = pm.sample(25000, step=step, tune=2500)

and remove the slicing in the next cell.



miemiekurisu commented on 2022-12-03T11:32:25Z
----------------------------------------------------------------

Ur right, I noticed the kwarg at the next chapters, and also left some comments.

At first, I trid to keep the original contents as much as possible. :)

@miemiekurisu
Copy link
Contributor Author

@miemiekurisu Sorry this took a while but your port looks really good. There are some minor things, mainly about the usage of test_values but those should be easy to fix.

Sorry for not getting back to you sooner, I'm tied up with a company project whole Oct. (/▽\)
Luckily, the project will be done at the middle of Nov.
I'll fix these review problms ASAP. (/ω\)

Copy link
Contributor Author

Yeah, you're right, and infact I've noticed this initval and test_value problem when I upgrade it to pymc4.

Accroding to this URL: pymc-devs/pymc#562 (comment)

test_val is a misusing, initval parameter should be used.

I try to keep the orignal content as much as possible at first, so I used the

aesara.config.compute_test_value = 'warn' 

to keep compatibility.

Maybe I should add some brif comments to explain this problem to previous version readers?


View entire conversation on ReviewNB

@twiecki
Copy link
Contributor

twiecki commented Nov 8, 2022

Maybe I should add some brif comments to explain this problem to previous version readers?

Yes, I think that'd be helpful.

Copy link
Contributor Author

Got it.


View entire conversation on ReviewNB

Copy link
Contributor Author

That's strange, I think it's a front end or page css problem. Sometimes I got this problem too, and it works properly after I refresh the notebook page serviral times.


View entire conversation on ReviewNB

Copy link
Contributor Author

Ur right, I noticed the kwarg at the next chapters, and also left some comments.


View entire conversation on ReviewNB

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Contributor Author

LOL


View entire conversation on ReviewNB

Copy link
Contributor Author

PYMC4 version is 4.1.5, let me check the API again


View entire conversation on ReviewNB

Copy link
Contributor Author

Accroding to the last version here: pymc/model.py at main · pymc-devs/pymc (github.com)

def Potential(name, var, model=None):
	    """Add an arbitrary factor potential to the model likelihood
    Parameters
    ----------
    name: str
    var: PyTensor variables

    Returns
    -------
    var: var, with name attribute
    """

View entire conversation on ReviewNB

Copy link
Contributor

twiecki commented Dec 29, 2022

ReviewNB often fails but then it displays fine.


View entire conversation on ReviewNB

@twiecki
Copy link
Contributor

twiecki commented Dec 30, 2022

Accroding to the last version here: pymc/model.py at main · pymc-devs/pymc (github.com)

OK, I was confused. Looks good then!

@twiecki
Copy link
Contributor

twiecki commented Dec 30, 2022

What are the next steps here? would be great to get this merged.

@miemiekurisu
Copy link
Contributor Author

What are the next steps here? would be great to get this merged.

Sorry for not getting back to you sooner ...... again 〒▽〒
I believe I had checked and solved most ReviewNB problems.
I think it's ready to be merged (/≧▽≦)/

@twiecki
Copy link
Contributor

twiecki commented Feb 3, 2023

@miemiekurisu Great -- thanks!

@CamDavidsonPilon Want to merge?

@CamDavidsonPilon CamDavidsonPilon merged commit 90683f8 into CamDavidsonPilon:master Feb 8, 2023
@CamDavidsonPilon
Copy link
Owner

I've been pretty absent from this discussion, but thank you @miemiekurisu and @twiecki for shepherding this in!

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