ni-phy / year4-project

0 stars 0 forks source link

Custom mean function - pymc3 #5

Closed asf1418 closed 3 years ago

asf1418 commented 4 years ago

@grd349

grd349 commented 4 years ago

Hi Henry,

Here is a trick for a custom mean function. So you can write any type of mean function n pymc3 if you take the mean function out of the Gaussian Process framework. For example, when trying to predict y. You build your model in standard pymc3 to predict some values y'. You then calculate the residual (y - y') and it is tis that is put onto the Gaussian Process framework. Does that make sense.

It does mean you have to work a little bit harder to make predictions using this method (you must predict the mean separately and add it to the GP variance) but it means less work in Theano.

Questions?

asf1418 commented 4 years ago

Hey Guy,

Thanks for the response. I dont think I understand what you've said here. Would you be able to show an example and maybe I can get a better understanding?

grd349 commented 4 years ago

Hi @asf1418,

Here is an example using a neural network (built elsewhere) as a mean function for a single variable.

First we construct the mean function predictions using the deterministic function (you don't have to use deterministic).

obs_prop = pm.Deterministic('obs_prop', nn(T.stacklists(slist)))

Then we take the residual of the proposed value and the observed value

y = obs_prop[:, 2] - obs_[:, 2]

Then we build the GP:

'cov_func = 1.0 * pm.gp.cov.ExpQuad(1, ls=30)'
'gp = pm.gp.Marginal(cov_func=cov_func)`
`y_ = gp.marginal_likelihood("y_", X=X, y=y, noise=obs_unc[:, 2])`

Does that make more sense? We are just running the GP on the residuals only - the mean function is treated seperately.

asf1418 commented 4 years ago

Okay, Im still not totally sure I understand whats going on. I think itll be best if we discuss it in our meeting?

grd349 commented 4 years ago

OK Henry. When are we meeting?

On Wed, 11 Nov 2020 at 12:29, Henry notifications@github.com wrote:

Okay, Im still not totally sure I understand whats going on. I think itll be best if we discuss it in our meeting?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ni-phy/year4-project/issues/5#issuecomment-725396486, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADQZOCPRZNWVIRUJPIPUWSDSPJ7T3ANCNFSM4TKDZVSQ .

-- ​Dr Guy R. Davies PI - ERC CartographY Project ​Senior Lecturer in Astrophysics​ School of Physics and Astronomy The University of Birmingham Edgbaston Birmingham B15 2TT

Tel +44 (0) 121 414 4597 ​G.R.Davies@bham.ac.uk​ grd349@gmail.com davies@bison.ph.bham.ac.u davies@bison.ph.bham.ac.ukk davies@bison.ph.bham.ac.uk

The contents of this e-mail may be privileged and are confidential. It may not be disclosed, used, or copied in any way by anyone other than the addressee. If received in error please notify the sender then delete it from your system. Should you communicate with the sender by e-mail, you consent to The University of Birmingham monitoring and reading any such correspondence.

asf1418 commented 4 years ago

I forgot to make a note of it. I think it was either 13:00 or 13:30 today, Nikolas isnt sure either. Do either of these times work for you?

grd349 commented 4 years ago

13:30 it is! See you in 45 minutes :)

On Wed, 11 Nov 2020, 12:42 Henry, notifications@github.com wrote:

I forgot to make a note of it. I think it was either 13:00 or 13:30 today, Nikolas isnt sure either. Do either of these times work for you?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ni-phy/year4-project/issues/5#issuecomment-725401970, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADQZOCOZB2JR6HBO45APB2TSPKBEPANCNFSM4TKDZVSQ .

asf1418 commented 4 years ago

Hey @grd349,

I have implemented a new mean function. The plots I am generating look really nice (I think) image image image image

However I am a little bit confused about my GP hyper parameters. With the new function should we expect the values of the length scale to vary? I have found that when I call find_map it likes to predict really high values for the length scales (if I dont cap it, l1 = 150, l2 =50) whereas before the new mean function these values were far smaller (l1 =11, l2 = 0.5).

Im not sure why this is happening, but changing the lengthscale now makes very little difference to the residual and predictions - data plots. Any ideas?

grd349 commented 4 years ago

Hi @asf1418

That looks great. I think we should try a different data set! I'll dig out a data set I have that was generated using stellar models rather than these simple relations I used to generate the current data set. That might have some impact on the length scale. Probably not worth worrying too much about the length scales for just one data set - we need more tests.

In the mean time, you could make your own 'fake' data to run tests on and see how you code responds to different inputs! Perhaps use a function you define yourself (so not t^0.5 * ( A (B - V - 0.4)^B)) rather something else that looks a little bit like it. Does that make any sense?

asf1418 commented 3 years ago

Hey @grd349

Ive had some success fitting to some similar looking data and I also used the 1d version to check one of my problem sheets, both worked very well.

Would you be able to send over the next data set?

grd349 commented 3 years ago

I will get that new data set sorted for you! ASAP.

grd349 commented 3 years ago

I have added new data for you into the repo. The data is simulated data to which I have added noise to only the rotation period. You get values for temperature, mass, age, and rotation period (units: K, M_sol, Gyr, Days). The uncertainty on the each rotation period is 1 day. There are two different files and each file has a data set that was generated my a different model of rotational evolution.

Questions? :)

asf1418 commented 3 years ago

Thank you very much for the new data. One question, what is the first column of data2.csv?

grd349 commented 3 years ago

Oh it's index - I meant to remove it. Just ignore it.

On Tue, 17 Nov 2020, 18:56 Henry, notifications@github.com wrote:

Thank you very much for the new data. One question, what is the first column of data2.csv?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ni-phy/year4-project/issues/5#issuecomment-729132861, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADQZOCN7NOE4QETMPTJUVTDSQLBOXANCNFSM4TKDZVSQ .