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

UnboundLocalError: local variable 'mutation' referenced before assignment #44

Open
ichxw opened this issue Jul 12, 2019 · 8 comments
Open

Comments

@ichxw
Copy link

ichxw commented Jul 12, 2019

Hi Jake,
When running example code as beflow:
`import numpy as np
import pandas as pd

from matplotlib import pyplot as plt

from bartpy.sklearnmodel import SklearnModel

x = np.random.normal(0, 0.5, size=1000)
X = pd.DataFrame({"x": x})
y = 2 * x + 4 * np.power(x, 3)
plt.scatter(x, y)

model = SklearnModel(n_jobs=1)

model.fit(X, y)
plt.scatter(x, model.predict())
plt.scatter(x, y)`

I got the following error:
0%| | 0/200 [00:00<?, ?it/s]Starting burn
Traceback (most recent call last):

File "", line 15, in
model.fit(X, y)

File ".../BART/bartpy-master/bartpy-master/bartpy/sklearnmodel.py", line 134, in fit
self.extract = Parallel(n_jobs=self.n_jobs)(self.f_delayed_chains(X, y))

File ".../anaconda3/lib/python3.6/site-packages/joblib/parallel.py", line 921, in call
if self.dispatch_one_batch(iterator):

File ".../anaconda3/lib/python3.6/site-packages/joblib/parallel.py", line 759, in dispatch_one_batch
self._dispatch(tasks)

File ".../anaconda3/lib/python3.6/site-packages/joblib/parallel.py", line 716, in _dispatch
job = self._backend.apply_async(batch, callback=cb)

File ".../anaconda3/lib/python3.6/site-packages/joblib/_parallel_backends.py", line 182, in apply_async
result = ImmediateResult(func)

File ".../anaconda3/lib/python3.6/site-packages/joblib/_parallel_backends.py", line 549, in init
self.results = batch()

File ".../anaconda3/lib/python3.6/site-packages/joblib/parallel.py", line 225, in call
for func, args, kwargs in self.items]

File ".../anaconda3/lib/python3.6/site-packages/joblib/parallel.py", line 225, in
for func, args, kwargs in self.items]

File ".../BART/bartpy-master/bartpy-master/bartpy/sklearnmodel.py", line 31, in run_chain
model.store_acceptance_trace)

File ".../BART/bartpy-master/bartpy-master/bartpy/samplers/modelsampler.py", line 43, in samples
self.step(model, trace_logger)

File ".../BART/bartpy-master/bartpy-master/bartpy/samplers/modelsampler.py", line 26, in step
result = step()

File ".../BART/bartpy-master/bartpy-master/bartpy/samplers/schedule.py", line 48, in
yield "Tree", lambda: self.tree_sampler.step(model, tree)

File ".../BART/bartpy-master/bartpy-master/bartpy/samplers/unconstrainedtree/treemutation.py", line 47, in step
mutation = self.sample(model, tree)

File ".../BART/bartpy-master/bartpy-master/bartpy/samplers/unconstrainedtree/treemutation.py", line 40, in sample
ratio = self.likihood_ratio.log_probability_ratio(model, tree, proposal)

File ".../BART/bartpy-master/bartpy-master/bartpy/samplers/treemutation.py", line 80, in log_probability_ratio
return self.log_transition_ratio(tree, mutation) + self.log_likihood_ratio(model, tree, mutation) + self.log_tree_ratio(model, tree, mutation)

File ".../BART/bartpy-master/bartpy-master/bartpy/samplers/unconstrainedtree/likihoodratio.py", line 69, in log_likihood_ratio
#mutation: GrowMutation = mutation

UnboundLocalError: local variable 'mutation' referenced before assignment

Do you know where the problem is? Thank you.
xiangwei

@duhd1993
Copy link

Same here.

@duhd1993
Copy link

The ReadOneTrees branch seems working.

@JakeColtman
Copy link
Owner

Hi, Thanks for trying it out and raising an issue :) I'd pretty strongly recommend working off the ReadOneTrees branch rather than master. I'm going to do some final checks and then merge the changes back in.

@CoteDave
Copy link

CoteDave commented Jul 23, 2019

Same problem here !

The ReadOneTrees branch seems working.

Thank you!

@WilsonAntony-171060
Copy link

como se una la rama ReadOneTrees alguien me ayuda porfavor, tengo el mismo problema de: "local variable 'mutation' referenced before assignment"

@WilsonAntony-171060
Copy link

### ESTO ME SALTA AL EJECUTARLO
0%| | 0/200 [00:00<?, ?it/s]Traceback (most recent call last):

File "", line 1, in
runfile('/home/antony/Python/Datos Panel Solar Validado/Bart_3.py', wdir='/home/antony/Python/Datos Panel Solar Validado')

File "/home/antony/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile
execfile(filename, namespace)

File "/home/antony/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "/home/antony/Python/Datos Panel Solar Validado/Bart_3.py", line 23, in
model.fit(X, y)

File "/home/antony/anaconda3/lib/python3.7/site-packages/bartpy/sklearnmodel.py", line 134, in fit
self.extract = Parallel(n_jobs=self.n_jobs)(self.f_delayed_chains(X, y))

File "/home/antony/anaconda3/lib/python3.7/site-packages/joblib/parallel.py", line 934, in call
self.retrieve()

File "/home/antony/anaconda3/lib/python3.7/site-packages/joblib/parallel.py", line 833, in retrieve
self._output.extend(job.get(timeout=self.timeout))

File "/home/antony/anaconda3/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 521, in wrap_future_result
return future.result(timeout=timeout)

File "/home/antony/anaconda3/lib/python3.7/concurrent/futures/_base.py", line 432, in result
return self.__get_result()

File "/home/antony/anaconda3/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception

@b5ck1n
Copy link

b5ck1n commented Nov 28, 2019

Hi, I got the same problem, have you solved it?

@WilsonAntony-171060
Copy link

WilsonAntony-171060 commented Dec 2, 2019 via email

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

6 participants