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

Unable to read command --ndim #13

Open
yashi0195 opened this issue Jul 14, 2022 · 10 comments
Open

Unable to read command --ndim #13

yashi0195 opened this issue Jul 14, 2022 · 10 comments

Comments

@yashi0195
Copy link

Hi,

I am trying to run the code using the command:

python lcdm-dataset1-evidence.py plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE --ndim 6

where 'lcdm......py' is my input file. ( just a copy of MCEveidence with a different name for trying.)

Somehow the code is not able to read the number of parameters from the command --ndim or -np as the output is as follows,

INFO:lcdm-dataset1-evidence.py.params_info():1219 getting params info from COSMOMC file plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE.ranges
INFO:lcdm-dataset1-evidence.py.get_prior_volume():1325 getting prior volume using cosmomc *.ranges or montepython log.param outputs
INFO:lcdm-dataset1-evidence.py.get_prior_volume():1326 prior_volume=1.0
INFO:lcdm-dataset1-evidence.py.get_prior_volume():1327 Number of params to use: ndim=0
Using file: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE
INFO:lcdm-dataset1-evidence.py.setup():146 Loading chain from plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE
INFO:lcdm-dataset1-evidence.py.read_list_to_array():567 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_3.txt
INFO:lcdm-dataset1-evidence.py.read_list_to_array():567 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_1.txt
INFO:lcdm-dataset1-evidence.py.read_list_to_array():567 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_2.txt
INFO:lcdm-dataset1-evidence.py.read_list_to_array():567 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_4.txt
INFO:lcdm-dataset1-evidence.py.init():785 chain array dimensions: [37411] x 0 =
INFO:lcdm-dataset1-evidence.py.get_covariance():863 Estimating covariance matrix using all chains
INFO:lcdm-dataset1-evidence.py.get_covariance():867 covariance matrix estimated using nsample=37411
INFO:lcdm-dataset1-evidence.py.get_samples():914 getting samples for partition s1: nsamples=37411
Traceback (most recent call last):
File "lcdm-dataset1-evidence.py", line 1476, in
mce.evidence()
File "lcdm-dataset1-evidence.py", line 1104, in evidence
nbrs = NearestNeighbors(n_neighbors=kmax+1,metric='euclidean',leaf_size=20,
File "/home/yashi/anaconda3/lib/python3.8/site-packages/sklearn/neighbors/_base.py", line 1173, in fit
return self._fit(X)
File "/home/yashi/anaconda3/lib/python3.8/site-packages/sklearn/neighbors/_base.py", line 401, in _fit
X = self._validate_data(X, accept_sparse='csr')
File "/home/yashi/anaconda3/lib/python3.8/site-packages/sklearn/base.py", line 420, in _validate_data
X = check_array(X, **check_params)
File "/home/yashi/anaconda3/lib/python3.8/site-packages/sklearn/utils/validation.py", line 72, in inner_f
return f(**kwargs)
File "/home/yashi/anaconda3/lib/python3.8/site-packages/sklearn/utils/validation.py", line 658, in check_array
raise ValueError("Found array with %d feature(s) (shape=%s) while"
ValueError: Found array with 0 feature(s) (shape=(37411, 0)) while a minimum of 1 is required.

Please help me understand what is going wrong.

@skroon
Copy link

skroon commented Jul 14, 2022

Hi.

Your line numbers for the output don't match the print statements in the current code, so presumably you have either made some local changes to the code, or don't have the most recent version. Can you please try with the same code as the most recent version? The code is also tested on Python 3.5.2, so if you can check on that version if using the updated code doesn't work, that would be helpful.

@yashi0195
Copy link
Author

Hi,

Thanks for your prompt reply. For a check, I did a run again with the original MCEvidence.py file (git cloning the master branch for the code). This time I am using python version 2.7. One change that I made in the .py file is in line 1216. Because on running command,

python MCEvidence.py ../../mcevidence/MCEvidence/plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE --ndim 6

I got,

INFO:MCEvidence.py.params_info():1215 getting params info from COSMOMC file ../../mcevidence/MCEvidence/plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE.ranges
MCEvidence.py:1216: VisibleDeprecationWarning: Reading unicode strings without specifying the encoding argument is deprecated. Set the encoding, use None for the system default.
par=np.genfromtxt(fname+'.ranges',dtype=None,names=('name','min','max'))#,unpack=True)
Traceback (most recent call last):
File "MCEvidence.py", line 1439, in
prior_volume = get_prior_volume(args,cosmo=cosmo)
File "MCEvidence.py", line 1315, in get_prior_volume
parMC=params_info(args.root_name, **kwargs)
File "MCEvidence.py", line 1225, in params_info
if not np.isclose(pmax,pmin) and pcond:
File "/home/yashi/anaconda3/envs/py2/lib/python2.7/site-packages/numpy/core/numeric.py", line 2521, in isclose
xfin = isfinite(x)
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

I changed in line 1216, dtype=None to dtype=float. (was trying to resolve this error)

After this change, the error is the same as I mentioned before, even with python2.

INFO:MCEvidence.py.params_info():1215 getting params info from COSMOMC file ../../mcevidence/MCEvidence/plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE.ranges
INFO:MCEvidence.py.get_prior_volume():1319 getting prior volume using cosmomc *.ranges or montepython log.param outputs
INFO:MCEvidence.py.get_prior_volume():1320 prior_volume=1.0
INFO:MCEvidence.py.get_prior_volume():1321 Number of params to use: ndim=0

Using file: ../../mcevidence/MCEvidence/plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE
INFO:MCEvidence.py.setup():142 Loading chain from ../../mcevidence/MCEvidence/plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE
INFO:MCEvidence.py.load_from_file():595 loading files: ../../mcevidence/MCEvidence/plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_?.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: ../../mcevidence/MCEvidence/plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_3.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: ../../mcevidence/MCEvidence/plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_1.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: ../../mcevidence/MCEvidence/plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_2.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: ../../mcevidence/MCEvidence/plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_4.txt
INFO:MCEvidence.py.init():781 chain array dimensions: [37411] x 0 =
INFO:MCEvidence.py.get_covariance():859 Estimating covariance matrix using all chains
INFO:MCEvidence.py.get_covariance():863 covariance matrix estimated using nsample=37411
INFO:MCEvidence.py.get_samples():910 getting samples for partition s1: nsamples=37411
Traceback (most recent call last):
File "MCEvidence.py", line 1470, in
mce.evidence()
File "MCEvidence.py", line 1101, in evidence
algorithm='auto',n_jobs=nproc).fit(samples)
File "/home/yashi/anaconda3/envs/py2/lib/python2.7/site-packages/sklearn/neighbors/base.py", line 929, in fit
return self._fit(X)
File "/home/yashi/anaconda3/envs/py2/lib/python2.7/site-packages/sklearn/neighbors/base.py", line 209, in _fit
X = check_array(X, accept_sparse='csr')
File "/home/yashi/anaconda3/envs/py2/lib/python2.7/site-packages/sklearn/utils/validation.py", line 590, in check_array
context))
ValueError: Found array with 0 feature(s) (shape=(37411, 0)) while a minimum of 1 is required.

Please see if any other information is required.

Thanks!

@skroon
Copy link

skroon commented Jul 15, 2022

Can you try running the code with the option "-vb 2" and attaching the output and the .ranges file you are using? The code seems to replace the ndim argument with the number of parameter names in the cosmomc ranges file.

@yashi0195
Copy link
Author

Hi,

after using the command: python MCEvidence.py -vb 2 plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE --ndim 6

I get,

INFO:MCEvidence.py.params_info():1215 getting params info from COSMOMC file plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE.ranges
{'ndim': 0, 'name': [], 'min': [], 'max': [], 'nr_of_params': 0, 'volume': 1.0, 'range': [], 'str': ''}
INFO:MCEvidence.py.get_prior_volume():1319 getting prior volume using cosmomc *.ranges or montepython log.param outputs
INFO:MCEvidence.py.get_prior_volume():1320 prior_volume=1.0
INFO:MCEvidence.py.get_prior_volume():1321 Number of params to use: ndim=0

Using file: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE
DEBUG:MCEvidence.py.init():705 Using chain: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE
INFO:MCEvidence.py.setup():142 Loading chain from plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE
DEBUG:MCEvidence.py.load_from_file():570 Loading file assuming CosmoMC columns order: weight loglike param1 param2 ...
INFO:MCEvidence.py.load_from_file():595 loading files: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_?.txt
DEBUG:MCEvidence.py.load_from_file():600 Reading from files: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_3.txt, plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_1.txt, plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_2.txt, plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_4.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_3.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_1.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_2.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_4.txt
DEBUG:MCEvidence.py.chains2samples():195 Chain2Sample: nchain=4
DEBUG:MCEvidence.py.init():771 using ndim=0
partition s1.shape (37411, 87)
INFO:MCEvidence.py.init():781 chain array dimensions: [37411] x 0 =
DEBUG:MCEvidence.py.evidence():1022 log prior volume: 0.0
DEBUG:MCEvidence.py.evidence():1029 covtype=all
INFO:MCEvidence.py.get_covariance():859 Estimating covariance matrix using all chains
DEBUG:MCEvidence.py.arrays():395 extracting arrays for sample partition:
DEBUG:MCEvidence.py.arrays():395 extracting arrays for sample partition:
INFO:MCEvidence.py.get_covariance():863 covariance matrix estimated using nsample=37411
DEBUG:MCEvidence.py.arrays():395 extracting arrays for sample partition:
INFO:MCEvidence.py.get_samples():910 getting samples for partition s1: nsamples=37411
Traceback (most recent call last):
File "MCEvidence.py", line 1470, in
mce.evidence()
File "MCEvidence.py", line 1101, in evidence
algorithm='auto',n_jobs=nproc).fit(samples)
File "/home/yashi/anaconda3/envs/py2/lib/python2.7/site-packages/sklearn/neighbors/base.py", line 929, in fit
return self._fit(X)
File "/home/yashi/anaconda3/envs/py2/lib/python2.7/site-packages/sklearn/neighbors/base.py", line 209, in _fit
X = check_array(X, accept_sparse='csr')
File "/home/yashi/anaconda3/envs/py2/lib/python2.7/site-packages/sklearn/utils/validation.py", line 590, in check_array
context))
ValueError: Found array with 0 feature(s) (shape=(37411, 0)) while a minimum of 1 is required.

@skroon
Copy link

skroon commented Jul 18, 2022

There seems to be a problem processing the .ranges file - this is its output after processing the file:
{'ndim': 0, 'name': [], 'min': [], 'max': [], 'nr_of_params': 0, 'volume': 1.0, 'range': [], 'str': ''}

Can you attach the .ranges file in a reply on this issue?

@yashi0195
Copy link
Author

Hi,

Please find attached the .ranges file. I have converted it into a .txt format to attach here.
base_plikHM_TT_lowl_lowE.ranges.txt

@skroon
Copy link

skroon commented Jul 18, 2022

The issue seems to be the N's in the .range files - the code for reading them in fails. Since unbounded ranges lead to unbounded volumes and hence a zero volume prior, I'm not sure that this tool is appropriate for your task unless you specify an upper bound in the .ranges file for these parameters? (@yabebalFantaye : Should we add some kind of warning or error, or do you have some other feedback?)

@yashi0195
Copy link
Author

Hi,

Thanks for giving time to this issue.

I removed those parameters with unbounded ranges in the .ranges file and rerun the command, yet I got the same error as in the previous case.
I doubt that it may be related to the change I made in line 1216 of the code, where I changed dtype=None to dtype=float. But without this change, the code was not working (giving another error, which I also mentioned in my second comment on this issue). Please see if this can be related to the present error.

Also, I tried to run the code using python terminal, with two lines command as:

from MCEvidence import MCEvidence
MLEbase= MCEvidence('plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE',ndim=6).evidence()

in which case I get an output as,

INFO:MCEvidence.py.setup():142 Loading chain from plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE
INFO:MCEvidence.py.load_from_file():595 loading files: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_?.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_3.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_1.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_2.txt
INFO:MCEvidence.py.read_list_to_array():563 loading: plikHM_TT_lowl_lowE/base_plikHM_TT_lowl_lowE_4.txt
INFO:MCEvidence.py.init():781 chain array dimensions: [37411] x 6 =
INFO:MCEvidence.py.get_covariance():859 Estimating covariance matrix using all chains
INFO:MCEvidence.py.get_covariance():863 covariance matrix estimated using nsample=37411
INFO:MCEvidence.py.get_samples():910 getting samples for partition s1: nsamples=37411
INFO:MCEvidence.py.evidence():1163 ln(B)[k=1] = -627.5906231903703
INFO:MCEvidence.py.evidence():1163 ln(B)[k=2] = -627.4490723146458
INFO:MCEvidence.py.evidence():1163 ln(B)[k=3] = -627.3855217868755
INFO:MCEvidence.py.evidence():1163 ln(B)[k=4] = -627.3377810034593

But it seems here .ranges file is not called!

Since I wanted to use this code for a setup where I have a few extra parameters(for a particular inflation model) to be introduced as cosmological parameters and calculate the evidence for such a model, I am not sure how this can be done using python terminal. The instructions to work with the MCEvidence.py file were somewhat clear through the 'help' option.

@skroon
Copy link

skroon commented Jul 18, 2022 via email

@yashi0195
Copy link
Author

Hi,

Thanks a lot! The issue is now resolved after using the "encoding=None" command and keeping dtype=None in line 1216 in MCEvidence.py.

One thing I would like to add is that even in this case, if the '.ranges' file has unbound ranges (those N's that you pointed out in previous comments), the code does not run. I have to remove those lines manually from the .ranges file, after which only I got the output. So my suggestion would be to display a warning message (or maybe include it in the instructions in README.md) to the user to ensure that the '.ranges' file does not have unbounded entities. It would be helpful.

But, thanks a lot for your help and efforts :)

Regards,
Yashi

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

No branches or pull requests

2 participants