emcee EnsembleSampler object has no attribute get_chain - python

I am having trouble accessing the values generated from emcee using the get_chain() method. My code is provided below:
import numpy as np
import emcee
def log_prob(x): return -np.sum(x**2)
p0 = np.array(np.random.randn(12, 1))
sampler = emcee.EnsembleSampler(12, 1, log_prob)
sampler.run_mcmc(p0, 1000)
samples = sampler.get_chain()
When I run this, I get the message AttributeError: 'EnsembleSampler' object has no attribute 'get_chain', and I am not sure why.
I read somewhere online that the get_chain() method was only added in a newer release of emcee, and that it needed to be downloaded from GitHub. If this is the issue, how would I download it from GitHub and ensure it still works with Anaconda (I'm new to Python/GitHub, and I'm not too familiar with how this would be done)?
Any help would be greatly appreciated! Thanks!

As you suspect, this is probably due to having installed an old version of emcee. You can check the version installed with
emcee.__version__
emcee 3 was only a release candidate (instead of an official release) for quite a long time, hence the advise from the blog post you read. It has already been released however, the post is probably nearly a year old at least. You should be able to update to latest emcee and fix your issue with pip
pip install -U emcee
or with conda (which looks like what you are using).
conda install -c conda-forge emcee
see more details on emcee installation with conda on its conda forge page

Related

Why does Importing Pennylane give out cannot import name "shape"

I am trying to import Pennylane in jupyter notebook. I installed it using Ubuntu.
import pennylane as cents
However, it is spewing out this:
ImportError: cannot import name 'shape'
I found two reasons online. One is that python needs to be at version less than 3.7[https://github.com/PennyLaneAI/pennylane/issues/1922]. To solve this I used pip install -U jupyter. Another reason is that Pennylane might be at a version earlier enough that it had a bug[https://discuss.pennylane.ai/t/importerror-cannot-import-name-shape/1383]. I installed Pennylane to the latest version I could find, 0.25. I did pip install pennylane==0.25 But it still does not work
Could someone please explain this to me?

Pytorch installation could not find a version that satisfies the requirement

When i tried to install Pytorch in the way they suggest on their website:
pip install torch===1.7.0 torchvision===0.8.1 torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
this is the error that appear:
ERROR: Could not find a version that satisfies the requirement torch===1.7.0 (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)
ERROR: No matching distribution found for torch===1.7.0
How can i solve it?
Just wanted to start out by letting all the mac, linux, and python 3.8.x- users here know that adding "https://" to the command does not solve the problem: Proof that it doesn't help or solve anything
Here's why: OP, you probably have python 3.9 installed on your machine. Unfortunately, Python 3.9 is not yet supported by Pytorch. Install python 3.8.6 instead, that's the latest version that's currently supported. You'll find similar problems trying to install packages like sklearn or tensorflow as well.
So here's the answer: either wait, or uninstall python and roll back to python 3.8.6
Sorry it couldn't be a better one.
I have had the same issue and solved it by looking at the packages list. E.g.:
cpu/torch-1.10.1-cp36-none-macosx_10_9_x86_64.whl
cpu/torch-1.10.1-cp37-none-macosx_10_9_x86_64.whl
cpu/torch-1.10.1-cp38-none-macosx_10_9_x86_64.whl
cpu/torch-1.10.1-cp38-none-macosx_11_0_arm64.whl
cpu/torch-1.10.1-cp39-none-macosx_10_9_x86_64.whl
cpu/torch-1.10.1-cp39-none-macosx_11_0_arm64.whl
Since I have macOS 11 running, I had to make sure to have python 3.8 or 3.9 (as the package was not yet available for python 3.10 by end of December 2021)
Once I've set up my environment with python 3.9 the installation instructions provided by pytorch worked for me:
pip install torch torchvision torchaudio
You are most probably missing the -f https://download.pytorch.org/whl/torch_stable.html at the end.
Make sure you include the whole line in your terminal. Even a missing l (from the .html) from the rest of the link causes you to see the error. something that may not show itself easily at first!
So make sure all bits are there! i.e. use the full link with all the bells and whistles, make sure nothing is omitted.
Update:
Looking at your comment, you are missing the https://, using this exact command as yours, I get the same error as yours as it treats it as a path thus issuing the error :
Url 'download.pytorch.org/whl/torch_stable.html' is ignored. It is
either a non-existing path or lacks a specific scheme.
which further proves the point I made earlier!

Error import with 'shamilton_filter_log' from 'statsmodels.tsa.regime_switching._hamilton_filter'

I tried to compile MarkovSwitching.py from statsmodels (link description here) in python, but I have the follwoing error,
ImportError: cannot import name 'shamilton_filter_log' from 'statsmodels.tsa.regime_switching._hamilton_filter' (C:\Users\myuser\Anaconda3\lib\site-packages\statsmodels\tsa\regime_switching\_hamilton_filter.cp37-win_amd64.pyd)
And I don't kown how solve this. Furthermore, I upgrade the statsmodels using '' pip install statsmodels --upgrade'', but doesn't work.
I don't know how to solve this problem, any help is welcome!
Thanks!
It's very hard to tell from your description what might be going wrong, since there could be many problems with your setup.
It looks like maybe you have installed Statsmodels v0.10 via Conda or pip and have then downloaded the development version of markov_switching.py. The development version has new functions that v0.10 does not have, and this is my guess about why you are getting the error.
You might try installing the release candidate of v0.11, using: pip install statsmodels==0.11.0rc1.

Encountering Import Error DLL load failed constantly

I have been trying to intall scikit-learn and pytorch using their respective commands given in the docs:
The commands for installing PyTorch are:
1) pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp37-cp37m-win_amd64.whl
2) pip3 install torchvision
The command for installing scikit-learn is:
pip install -U scikit-learn
Some background:
I am using Windows 8.1, Python 3.7.2. My pip is updated. I have also installed Anaconda for solving this using conda, but had zero luck!(Also, here I am running into 'conda' unrecognized error which is another story). Here are the paths my PATH variable holds.
PATH
C:\Users\satya\Anaconda3;
C:\Users\satya\Anaconda3\Library\mingw-w64\bin;
C:\Users\satya\Anaconda3\Library\usr\bin;
C:\Users\satya\Anaconda3\Library\bin;
C:\Users\satya\Anaconda3\Scripts;
C:\Users\satya\AppData\Local\Programs\Python\Python37\Scripts\;
C:\Users\satya\AppData\Local\Programs\Python\Python37\; C:\Users\satya\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.7
The Actual Problem:
The same commands for installation given above work perfectly fine on my other Windows 10, but, for my Windows 8.1 it gives this error which has become a real PITA
Import Error: DLL load failed The specified module could not be found
When I import sklearn or import torch I get the exact same error. All the time.
Back Story:
I have searched almost all the related questions I could find on Stackoverflow and Github for 6+ hours to help me solve this problem. But, none of the answers have helped till now and some haven't had an "understandable" answer. Maybe, its just a small fix, but now, I am choosing to post a question on SO.
My Question Again:
Can someone please help out and try to explain what I am missing out here? I really want to fix this error for good(and want to be in a position to fix it if I encounter it again). An elaborate answer would really help understand easily.
Thank You!
Please check your python build number with the following command.
conda list python
Python 3.7.2 with build number h8c8aaf0_2 has a solved issue.
If this is the case, an update will do.
conda update python

Wrong scikit-learn version installed?

I encountered the same
ValueError: scoring must return a number, got [...] (<class 'numpy.core.memmap.memmap'>) instead.
error as discussed in Q34857870.
Based on answers to this question, and my own research, I believe this issue to be fixed in scikit-learn version 0.17.1, though I'm still encountering it. Then I noticed something strange.
conda lists the right version.
$ conda list scikit-learn
packages in environment:
scikit-learn 0.17.1 np111py27_0
My Jupyter notebook gives the right version:
%load_ext watermark
%watermark scikit-learn
scikit-learn 0.17.1
But I get a different version when I check the version within my code:
import sklearn
print(sklearn.__version__)
0.17
I wouldn't think anything of this, except I'm still seeing a bug in 0.17 that should have been fixed in 0.17.1, so I'm wondering whether I'm using the wrong version somehow.
I'm wondering if it is somehow connected to Q30666685.
You probably have multiple versions of scikit learn installed. You can see where it is installed by using
print(sklearn.__file__)
and then simply delete that. In case if you are still having version troubles work within a virtual environment.

Categories