juliet icon indicating copy to clipboard operation
juliet copied to clipboard

Unable to evaluate RV model including custom linear model

Open ThomasGWilson opened this issue 3 years ago • 6 comments

Hi Nestor,

I have been trying to use Juliet to fit a rv model to data including custom linear basis vectors. I have proceeded following the "incorporating linear models" tutorial (https://juliet.readthedocs.io/en/latest/tutorials/linearmodels.html), but of course changing relevant data and priors. Loading in the data works well and running dataset.fit() apparently works, however when I run results.rv.evaluate() with the instrument and return components arguments set I get the following error:

---------------------------------------------------------------------------
~/anaconda3/envs/py3.6/lib/python3.6/site-packages/juliet/fit.py in evaluate_model(self, instrument, parameter_values, resampling, nresampling, etresampling, all_samples, nsamples, return_samples, t, GPregressors, LMregressors, return_err, alpha, return_components, evaluate_transit)
   2007                                               nsamples = nsamples, return_samples = return_samples, t = t, GPregressors = GPregressors, \
   2008                                               LMregressors = LMregressors, return_err = return_err, return_components = return_components, alpha = alpha, \
-> 2009                                               evaluate_transit = evaluate_transit)
   2010             if return_samples:
   2011                 if return_err:

~/anaconda3/envs/py3.6/lib/python3.6/site-packages/juliet/fit.py in evaluate_model(self, instrument, parameter_values, resampling, nresampling, etresampling, all_samples, nsamples, return_samples, t, GPregressors, LMregressors, return_err, alpha, return_components, evaluate_transit)
   1791                                     self.lm_arguments[instrument] = LMregressors
   1792                                 # Generate RV model:
-> 1793                                 self.generate_rv_model(current_parameter_values, evaluate_global_errors = False)
   1794 
   1795 

~/anaconda3/envs/py3.6/lib/python3.6/site-packages/juliet/fit.py in generate_rv_model(self, parameter_values, evaluate_global_errors)
   1431                 self.model[instrument]['LM'] = np.zeros(self.ndatapoints_per_instrument[instrument])
   1432                 for i in range(self.lm_n[instrument]):
-> 1433                     self.model[instrument]['LM'] += parameter_values['theta'+str(i)+'_'+instrument]*self.lm_arguments[instrument][:,i]
   1434                 self.model[instrument]['deterministic'] += self.model[instrument]['LM']
   1435             # If the model under consideration is a global model, populate the global model dictionary:

TypeError: 'NoneType' object is not subscriptable

After some digging into the code, self.lm_arguments[instrument][:,i] seems to be the culprit, however I am not sure why it is not being populated, so any help would be welcome.

Cheers,

Tom

ThomasGWilson avatar Nov 06 '20 19:11 ThomasGWilson

Hi @ThomasGWilson,

I'll have to look at this to see what is going on, but in the meantime if it is a simple linear model, perhaps you can evaluate it on your own? I just won't have time to look at any of this before November 24th sadly :-(.

Cheers, Néstor

nespinoza avatar Nov 10 '20 04:11 nespinoza

Hi @nespinoza,

I was just wondering if you've had a chance to look into this? Unfortunately, I have been unable to get results.rv.evaluate() or results.rv.evaluate_model() to work, and get the same error as before even though dataset.fit() completes and produces responsible posterior values and corner plot.

Cheers, Tom

ThomasGWilson avatar Dec 15 '20 16:12 ThomasGWilson

I am also having this issue. Any workaround?

LucaNap avatar Sep 20 '21 16:09 LucaNap

I would like for folks to double check if this has been solved in recent versions. @LucaNap, @ThomasGWilson --- if you manage to find time (and the scripts), please let me know!

Also a working example would be ideal if issues is still there.

N.

nespinoza avatar Nov 15 '23 19:11 nespinoza

Hi Nestor,

I just recently encountered this same issue. I was running juliet version 2.1.2 and I had the same problem as reported by Tom.

I updated to the newest juliet version 2.2.4 and now I get a different error, see below. Unlike before, the fit no longer runs because theta_iname is missing. Please let me know if there is a way to fix this.

Thanks, Amy

Traceback (most recent call last):
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/dynesty/dynesty.py", line 910, in __call__
    return self.func(np.asarray(x).copy(), *self.args, **self.kwargs)
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/juliet/fit.py", line 1361, in loglike
    self.rv.generate(self.posteriors)
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/juliet/fit.py", line 2178, in generate_rv_model
    self.theta_iname[str(i)+instrument]] * self.lm_arguments[instrument][:, i]
AttributeError: 'model' object has no attribute 'theta_iname'
Traceback (most recent call last):
  File "hd5806_juliet_harps-n.py", line 123, in <module>
    results = dataset.fit(n_live_points = 300, sampler='dynesty', nthreads=4) #, ta=2500)
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/juliet/fit.py", line 892, in fit
    return fit(self, **kwargs)
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/juliet/fit.py", line 1716, in __init__
    self.data.nparams, **d_args)
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/dynesty/dynesty.py", line 686, in __new__
    use_pool_ptform=use_pool.get('prior_transform', True))
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/dynesty/dynamicsampler.py", line 438, in _initialize_live_points
    cur_live_logl = loglikelihood.map(np.asarray(cur_live_v))
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/dynesty/utils.py", line 172, in map
    LoglOutput(_, self.blob) for _ in map(self.loglikelihood, pars)
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/dynesty/utils.py", line 172, in <listcomp>
    LoglOutput(_, self.blob) for _ in map(self.loglikelihood, pars)
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/dynesty/dynesty.py", line 910, in __call__
    return self.func(np.asarray(x).copy(), *self.args, **self.kwargs)
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/juliet/fit.py", line 1361, in loglike
    self.rv.generate(self.posteriors)
  File "/opt/anaconda3/envs/juliet_v2.2.4/lib/python3.7/site-packages/juliet/fit.py", line 2178, in generate_rv_model
    self.theta_iname[str(i)+instrument]] * self.lm_arguments[instrument][:, i]
AttributeError: 'model' object has no attribute 'theta_iname'

altuson avatar Feb 16 '24 11:02 altuson

Hi @altuson --- could you share your prior.dat file? Ideally if you could share your fit I could try this locally to see what's going on. If you can't post it here, send it to my e-mail ([email protected]) and I'll take a look at it.

Thanks!

N.

nespinoza avatar Feb 16 '24 18:02 nespinoza