JakeColtman / bartpy

Bayesian Additive Regression Trees For Python
https://jakecoltman.github.io/bartpy/
MIT License
219 stars 44 forks source link

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

Open ichxw opened 5 years ago

ichxw commented 5 years ago

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 commented 5 years ago

Same here.

duhd1993 commented 5 years ago

The ReadOneTrees branch seems working.

JakeColtman commented 5 years ago

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 commented 5 years ago

Same problem here !

The ReadOneTrees branch seems working.

Thank you!

WilsonAntony-171060 commented 4 years ago

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

WilsonAntony-171060 commented 4 years ago

### 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 commented 4 years ago

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

WilsonAntony-171060 commented 4 years ago

Si amigo lo resolvi. La solucion esta en que deberas instalar la libreria desde la rama que te indica el autor de la libreria

El jue., 28 de nov. de 2019 7:16 AM, b5ck1n notifications@github.com escribió:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JakeColtman/bartpy/issues/44?email_source=notifications&email_token=ANLKCFX3M3TMGU5O4TP7OWTQV6ZAPA5CNFSM4ICOR22KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFMN4HI#issuecomment-559472157, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANLKCFQEPK7IEFRYI65TU73QV6ZAPANCNFSM4ICOR22A .