on pymc version '2.3.6' in Python 3.5
I am trying to suppress the progress update given when running the MCMC:
observation = pymc.Poisson('obs', lambda_, value= count_data, observed= True)
model = pymc.Model([observation, lambda_1, lambda_2, kappa])
mcmc = pymc.MCMC(model)
mcmc.sample(20000, 1000, 1)
Any idea how i could do this?
Thanks!
it seems that the value for verbose that does that is -1. I would use the following more explicit syntax:
mcmc.sample(iter=20000, lenght=1000, verbose=-1)
Alternatively:
mcmc.sample(iter=20000, lenght=1000, progress_bar=0)
Cheers,
A.
PS: you can look yourself in the source code of installation_directory/pymc/MCMC.py.
The installation directory can be found using:
pymc.__file__
According to the docs here, the sampler is called like that:
sample(iter, length, verbose, ...)
This would mean, that your are explicitly activating verbose with your 3rd argument:
mcmc.sample(20000, 1000, 1) # Make the third argument a zero
Sadly i can't test it at the moment, but this should be a good first step (if i read the docs correctly).
Related
I'm working on a project on GitHub that was made with Python 2.7 (https://github.com/AIM-Harvard/DeepCAC)
I've made most relevant changes as to update it to Python 3.7, but I'm fixed on an error message regarding simpleITK.
Error message:
TypeError: Execute() takes 2 positional arguments but 10 were given
It stems from this code:
res_filter = sitk.ResampleImageFilter()
----> img_sitk = res_filter.Execute(img_sitk, curated_size, sitk.Transform(), method, img_sitk.GetOrigin(), curated_spacing, img_sitk.GetDirection(), 0, img_sitk.GetPixelIDValue())
According to the simpleITK document on switching from 1.x to 2.x (version that is available with python 3.7) it should be done like this (https://simpleitk.readthedocs.io/en/master/migrationGuide2.0.html#filter-s-execute-method) but I can't quite grasp it.
Can someone help out?
Thanks
It looks like you're trying to use the procedural version, Resample, not the class version, ResampleImageFilter.
You can see the documentation for the Resample function here:
https://simpleitk.org/doxygen/latest/html/namespaceitk_1_1simple.html#aadbb243c10d1aedea8e955e8beda4df0
You want to the second version of Resample. So your code would look like this:
img_sitk = sitk.Resample(img_sitk, curated_size, sitk.Transform(), method, img_sitk.GetOrigin(), curated_spacing, img_sitk.GetDirection(), 0, img_sitk.GetPixelIDValue())
If you want to use the ResampleImageFilter, you would set all the parameters using the filter's various Set methods, and then just call the Execute method with the input image as the only parameter.
Long time listener, first time caller here.
I'm relatively new to Python, but not totally hopeless. The code below works as long as I omit the full_output option.
from scipy import optimize
res = optimize.newton(calcdelta, currentstartcost, full_output=True)
But when full_output is included (either True or False), it spits out the following error:
TypeError: newton() got an unexpected keyword argument 'full_output'
It's not the end of the world, but any help would be appreciated!
Thanks.
Looks like I just needed to update. I had to update statsmodels as well, as whatever version I was using would not work after updating scipy. I had assumed everything would be current since I just started using Python a few months ago, but I guess not.
Thanks to jakub for pointing me in the right direction
I have a simple LinearModel with two sparse and two real-valued features. I trained it and now I want to export it with the export_savedmodel. Referencing few sources I came up with something along the lines of:
feature_spec = create_feature_spec_for_parsing(
[
real_valued_column_1, real_valued_column_2,
sparse_column_1, sparce_column_2
]
)
input_receiver_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
my_estimator.export_savedmodel('my_model/', serving_input_fn=input_receiver_fn)
where:
real_valued_column_1 = tf.contrib.layers.real_valued_column(
'avg_consumption_h')
sparse_column_1 = tf.contrib.layers.sparse_column_with_integerized_feature("sparse_1", bucket_size=24)
Unfortunately I get ValueError: A default input_alternative must be provided. on export_savedmodel. I digged in a little into the codebase of tensorflow and it seems that build_parsing_serving_input_receiver_fn always returns ServingInputReceiver but the method that extracts input_alternatives always creates them empty if serving_input_fn passed to export_savedmodel is not of the type InputFnOps.
Is build_parsing_serving_input_receiver_fn somehow deprecated, something is wrong in the process of extraction of input_alternative, or maybe I'm misunderstanding process completely and doing something wrong?
I'm using python 3.6 with tensorflow 1.2, my model is a simple tf.contrib.learn.LinearRegressor.
You can try the following
from tensorflow.contrib.learn.python.learn.utils.input_fn_utils import build_parsing_serving_input_fn
input_receiver_fn = build_parsing_serving_input_fn(feature_spec)
I am succeding fiiting a function with iminuit in python but I can't get rid of the message even with "print_level =-1" or "print_level =0".
Here is the minimalist code I use:
from iminuit import Minuit
m = Minuit(chi2, alpha=1., beta=0., print_level=-1)
it returns:
creatFitsFile.py:430: InitialParamWarning: errordef is not given. Default to 1.
m = Minuit(chi2, alpha=1., beta=0., print_level=-1)
creatFitsFile.py:430: InitialParamWarning: Parameter alpha is floating but does not have initial step size. Assume 1.
I just want it to be quiet because I fit inside a loop with ~170.000 set of data.
Thank you
Try setting pedantic=False in the parameter list.
Example -
from iminuit import Minuit
m = Minuit(chi2, pedantic=False, alpha=1., beta=0., print_level=-1)
From the documentation -
pedantic: warns about parameters that do not have initial value or initial error/stepsize set.
From the warnings in your console, seems like it is these warnings that are getting logged, most probably setting pedantic=False should fix it.
I wanted to store the different integration steps taken by the solver itself when I call it :
solver1.integrate(t_end)
So I did a while loop and enabled the step option setting its value to True:
while solver1.successful() and solver1.t < t0+dt:
solver1.integrate(t_end,step=True)
time.append(solver1.t)
Then I plot y, the result of integration and here comes my issue. I have instabilities which appear in a located area :
I thought it was because of the loop or something like that so I checked the result removing the step :
while solver1.successful() and solver1.t < t0+dt:
solver1.integrate(t_end)
And surprise ... I have the correct result :
It's a quite weird situation ... I'd be grateful if someone of your guys could help me with this issue.
EDIT :
To set the solver I do :
solver1 = ode(y_dot,jac).set_integrator('vode',with_jacobian=True)
solver1.set_initial_value(x0,t0)
And I store the result using .append()
When you set step=True you are indirectly giving the vode._integrator.runner (a Fortran subroutine) an instruction to use itask=2, and the default is itask=1. You can get more details about this runner doing:
r._integrator.runner?
In SciPy 0.12.0 documentation you will not find an explanation about what is going on for the different itask=1 or itask=2, but you can find it here:
ITASK = An index specifying the task to be performed.
! Input only. ITASK has the following values and meanings.
! 1 means normal computation of output values of y(t) at
! t = TOUT(by overshooting and interpolating).
! 2 means take one step only and return.
! 3 means stop at the first internal mesh point at or
! beyond t = TOUT and return.
! 4 means normal computation of output values of y(t) at
! t = TOUT but without overshooting t = TCRIT.
! TCRIT must be input as RUSER(1). TCRIT may be equal to
! or beyond TOUT, but not behind it in the direction of
! integration. This option is useful if the problem
! has a singularity at or beyond t = TCRIT.
! 5 means take one step, without passing TCRIT, and return.
! TCRIT must be input as RUSER(1).