Pymc3 parameter estimation using custom likelihood function sampling error - theano
I try to estimate parameters with a custom complex likelihood function (with 5 parameters to be estimated) using pm.DensityDist:
with pm.Model() as model:
# Define priors for unknown model parameters
mu_1 = pm.Normal("mu_1", mu=0, sigma=10)
mu_1_prime = pm.Normal("mu_1_prime", mu=0, sigma=10)
sigma = pm.Normal("sigma", mu=1, sigma=10)
sigma_1 = pm.Normal("sigma_1", mu=1, sigma=10)
alpha = pm.Normal("alpha_1", mu=1, sigma=10)
# Define likelihood
def loglikelihood(dL_list, dt_list):
res = 0
for i in range(145):
dL = dL_list[i]
dt = dt_list[i]
U1 = U1fun(dL, dt, mu_1,sigma_1,sigma)
U2 = U2fun(dL, dt, mu_1_prime,sigma_1,sigma)
u1 = u1fun(dL, dt, mu_1,sigma_1,sigma)
u2 = u2fun(dL, dt, mu_1_prime,sigma_1,sigma)
res1 = - 0.5 * np.log(1-alpha**2) - 0.5*(u1*2 + u2**2 - 2*alpha*u1*u2) / (1-alpha**2) #Copula function pdf
res2 = - 0.5 * np.log(sigma_1**2 * dt**2 + 2 * sigma**2) - 0.5 * np.log(sigma_1**2 * dt**2 + sigma**2 * dt)
res3 = - 0.5 * (U1**2+U2**2)
res += res1 + res2 + res3
return res
likelihood = pm.DensityDist(
"loglikelihood", loglikelihood, observed = {'dL_list':dL_list, 'dt_list':dt_list})
# Sampling
step = pm.Metropolis()
trace = pm.sample(3000, step=step)
The custom likelihood function is quite complex, , and dL_list and dt_list are those input data. Other functions are like:
def normpdf(x, mu, sigma):
return 1./(sigma * pm.math.sqrt(2 * np.pi)) * pm.math.exp(-(x-mu)**2 / (2 * sigma**2))
def normcdf(x, mu, sigma):
return 1./2.*(1 + pm.math.erf((x-mu)/(sigma*pm.math.sqrt(2))))
def U1fun(dL, dt, mu_1,sigma_1,sigma):
return (dL - mu_1 * dt) / (sigma_1 * dt + pm.math.sqrt(2) * sigma)
def U2fun(dL, dt, mu_1_prime,sigma_1,sigma):
return (dL - mu_1_prime * dt) / (sigma_1 * dt + pm.math.sqrt(dt) * sigma)
def u1fun(dL, dt, mu_1,sigma_1,sigma):
return normcdf(U1fun(dL, dt, mu_1,sigma_1,sigma),0,1)
def u2fun(dL, dt, mu_1_prime,sigma_1,sigma):
return normcdf(U2fun(dL, dt, mu_1_prime,sigma_1,sigma),0,1)
But I got an error in the last row AttributeError: 'Scratchpad' object has no attribute 'ufunc' Apply node that caused the error. I don't understand the hint and tried several ways but always failed to generate sampling traces, neither find_MAP. Much appreciated if anyone could help.
AttributeError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\theano\link\vm.py in __call__(self)
312 ):
--> 313 thunk()
314 for old_s in old_storage:
~\Anaconda3\lib\site-packages\theano\graph\op.py in rval(p, i, o, n)
475 def rval(p=p, i=node_input_storage, o=node_output_storage, n=node):
--> 476 r = p(n, [x[0] for x in i], o)
477 for o in node.outputs:
~\Anaconda3\lib\site-packages\theano\tensor\elemwise.py in perform(self, node, inputs, output_storage)
819 else:
--> 820 ufunc = node.tag.ufunc
821 else:
AttributeError: 'Scratchpad' object has no attribute 'ufunc'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
<ipython-input-77-abc5c0bd756f> in <module>
13
14 # Sampling
---> 15 start = pm.find_MAP(fmin=optimize.fmin_powell)
16 step = pm.Metropolis()
17 optimizer=None
~\AppData\Roaming\Python\Python37\site-packages\pymc3\tuning\starting.py in find_MAP(start, vars, method, return_raw, include_transformed, progressbar, maxeval, model, *args, **kwargs)
104 else:
105 update_start_vals(start, model.test_point, model)
--> 106 check_start_vals(start, model)
107
108 start = Point(start, model=model)
~\AppData\Roaming\Python\Python37\site-packages\pymc3\util.py in check_start_vals(start, model)
232 )
233
--> 234 initial_eval = model.check_test_point(test_point=elem)
235
236 if not np.all(np.isfinite(initial_eval)):
~\AppData\Roaming\Python\Python37\site-packages\pymc3\model.py in check_test_point(self, test_point, round_vals)
1382
1383 return Series(
-> 1384 {RV.name: np.round(RV.logp(test_point), round_vals) for RV in self.basic_RVs},
1385 name="Log-probability of test_point",
1386 )
~\AppData\Roaming\Python\Python37\site-packages\pymc3\model.py in <dictcomp>(.0)
1382
1383 return Series(
-> 1384 {RV.name: np.round(RV.logp(test_point), round_vals) for RV in self.basic_RVs},
1385 name="Log-probability of test_point",
1386 )
~\AppData\Roaming\Python\Python37\site-packages\pymc3\model.py in __call__(self, *args, **kwargs)
1559 def __call__(self, *args, **kwargs):
1560 point = Point(model=self.model, *args, **kwargs)
-> 1561 return self.f(**point)
1562
1563
~\Anaconda3\lib\site-packages\theano\compile\function\types.py in __call__(self, *args, **kwargs)
973 outputs = (
974 self.fn()
--> 975 if output_subset is None
976 else self.fn(output_subset=output_subset)
977 )
~\Anaconda3\lib\site-packages\theano\link\vm.py in __call__(self)
315 old_s[0] = None
316 except Exception:
--> 317 raise_with_op(self.fgraph, node, thunk)
318
319
~\Anaconda3\lib\site-packages\theano\link\utils.py in raise_with_op(fgraph, node, thunk, exc_info, storage_map)
506 # Some exception need extra parameter in inputs. So forget the
507 # extra long error message in that case.
--> 508 raise exc_value.with_traceback(exc_trace)
509
510
~\Anaconda3\lib\site-packages\theano\link\vm.py in __call__(self)
311 self.thunks, self.nodes, self.post_thunk_clear
312 ):
--> 313 thunk()
314 for old_s in old_storage:
315 old_s[0] = None
~\Anaconda3\lib\site-packages\theano\graph\op.py in rval(p, i, o, n)
474 # default arguments are stored in the closure of `rval`
475 def rval(p=p, i=node_input_storage, o=node_output_storage, n=node):
--> 476 r = p(n, [x[0] for x in i], o)
477 for o in node.outputs:
478 compute_map[o][0] = True
~\Anaconda3\lib\site-packages\theano\tensor\elemwise.py in perform(self, node, inputs, output_storage)
818 ufunc = self.ufunc
819 else:
--> 820 ufunc = node.tag.ufunc
821 else:
822 ufunc = node.tag.ufunc
AttributeError: 'Scratchpad' object has no attribute 'ufunc'
Apply node that caused the error: Elemwise{add,no_inplace}(Elemwise{Composite{(i0 * (((Composite{erfc(((i0 * i1) / i2))}(i1, i2, i3) / i4) + (sqr((i0 * Composite{erfc(((i0 * i1) / i2))}(i1, i5, i3))) / i4)) - ((i0 * i6 * Composite{erfc(((i0 * i1) / i2))}(i1, i2, i3) * Composite{erfc(((i0 * i1) / i2))}(i1, i5, i3)) / i4)))}}.0, ...... Elemwise{Composite{(i0 * (((Composite{erfc(((i0 * i1) / i2))}(i1, i2, i3) / i4) + (sqr((i0 * Composite{erfc(((i0 * i1) / i2))}(i1, i5, i3))) / i4)) - ((i0 * i6 * Composite{erfc(((i0 * i1) / i2))}(i1, i2, i3) * Composite{erfc(((i0 * i1) / i2))}(i1, i5, i3)) / i4)))}}.0, Elemwise{mul,no_inplace}.0, Elemwise{Composite{(i0 * (((Composite{erfc(((i0 * i1) / i2))}(i1, i2, i3) / i4) + (sqr((i0 * Composite{erfc(((i0 * i1) / i2))}(i1, i5, i3))) / i4)) - ((i0 * i6 * Composite{erfc(((i0 * i1) / i2))}(i1, i2, i3) * Composite{erfc(((i0 * i1) / i2))}(i1, i5, i3)) / i4)))}}.0, Elemwise{mul,no_inplace}.0)
Toposort index: 442
Inputs types: [TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar)]
Inputs shapes: [(), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ()]
Inputs strides: [(), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ()]
Inputs values: [array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973), array(nan), array(0.89587973)]
Outputs clients: [[Elemwise{sub,no_inplace}(Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0)]]
HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'.
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.
Related
Simple code producing so much error report
I am trying to do MannWhitney-U test as described here. Following is my code: import Data.Vector as V import Data.Vector.Unboxed as VU import Statistics.Test.MannWhitneyU sampleA = [1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4] sampleB = [2.0, 4.0, 5.0, 5.0, 3.0, 4.0, 5.0, 6] main = do putStrLn "\nResult of mannWhitneyUtest: " print (mannWhitneyUtest SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB) ) However, the error is much longer than above code: [1 of 1] Compiling Main ( rnmann.hs, rnmann.o ) rnmann.hs:6:12: error: • Ambiguous type variable ‘t0’ arising from the literal ‘1.0’ prevents the constraint ‘(Fractional t0)’ from being solved. Relevant bindings include sampleA :: [t0] (bound at rnmann.hs:6:1) Probable fix: use a type annotation to specify what ‘t0’ should be. These potential instances exist: instance Fractional Double -- Defined in ‘GHC.Float’ instance Fractional Float -- Defined in ‘GHC.Float’ ...plus four instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the expression: 1.0 In the expression: [1.0, 2.0, 3.0, 4.0, ....] In an equation for ‘sampleA’: sampleA = [1.0, 2.0, 3.0, ....] rnmann.hs:6:47: error: • Ambiguous type variable ‘t0’ arising from the literal ‘4’ prevents the constraint ‘(Num t0)’ from being solved. Relevant bindings include sampleA :: [t0] (bound at rnmann.hs:6:1) Probable fix: use a type annotation to specify what ‘t0’ should be. These potential instances exist: instance Num Integer -- Defined in ‘GHC.Num’ instance Num Double -- Defined in ‘GHC.Float’ instance Num Float -- Defined in ‘GHC.Float’ ...plus two others ...plus 13 instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the expression: 4 In the expression: [1.0, 2.0, 3.0, 4.0, ....] In an equation for ‘sampleA’: sampleA = [1.0, 2.0, 3.0, ....] rnmann.hs:7:12: error: • Ambiguous type variable ‘t0’ arising from the literal ‘2.0’ prevents the constraint ‘(Fractional t0)’ from being solved. Relevant bindings include sampleB :: [t0] (bound at rnmann.hs:7:1) Probable fix: use a type annotation to specify what ‘t0’ should be. These potential instances exist: instance Fractional Double -- Defined in ‘GHC.Float’ instance Fractional Float -- Defined in ‘GHC.Float’ ...plus four instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the expression: 2.0 In the expression: [2.0, 4.0, 5.0, 5.0, ....] In an equation for ‘sampleB’: sampleB = [2.0, 4.0, 5.0, ....] rnmann.hs:7:47: error: • Ambiguous type variable ‘t0’ arising from the literal ‘6’ prevents the constraint ‘(Num t0)’ from being solved. Relevant bindings include sampleB :: [t0] (bound at rnmann.hs:7:1) Probable fix: use a type annotation to specify what ‘t0’ should be. These potential instances exist: instance Num Integer -- Defined in ‘GHC.Num’ instance Num Double -- Defined in ‘GHC.Float’ instance Num Float -- Defined in ‘GHC.Float’ ...plus two others ...plus 13 instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the expression: 6 In the expression: [2.0, 4.0, 5.0, 5.0, ....] In an equation for ‘sampleB’: sampleB = [2.0, 4.0, 5.0, ....] rnmann.hs:11:16: error: • Ambiguous type variable ‘t0’ arising from a use of ‘mannWhitneyUtest’ prevents the constraint ‘(Ord t0)’ from being solved. Probable fix: use a type annotation to specify what ‘t0’ should be. These potential instances exist: instance Ord Ordering -- Defined in ‘GHC.Classes’ instance Ord Integer -- Defined in ‘integer-gmp-1.0.0.1:GHC.Integer.Type’ instance Ord PositionTest -- Defined in ‘Statistics.Test.Types’ ...plus 26 others ...plus 25 instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the first argument of ‘print’, namely ‘(mannWhitneyUtest SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB))’ In a stmt of a 'do' block: print (mannWhitneyUtest SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB)) In the expression: do { putStrLn "\n\ \Result of mannWhitneyUtest: "; print (mannWhitneyUtest SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB)) } rnmann.hs:11:47: error: • No instance for (Fractional (Statistics.Types.PValue Double)) arising from the literal ‘0.05’ • In the second argument of ‘mannWhitneyUtest’, namely ‘0.05’ In the first argument of ‘print’, namely ‘(mannWhitneyUtest SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB))’ In a stmt of a 'do' block: print (mannWhitneyUtest SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB)) rnmann.hs:11:75: error: • Ambiguous type variable ‘t0’ arising from a use of ‘VU.fromList’ prevents the constraint ‘(Unbox t0)’ from being solved. Probable fix: use a type annotation to specify what ‘t0’ should be. These potential instances exist: instance Unbox () -- Defined in ‘Data.Vector.Unboxed.Base’ instance (Unbox a, Unbox b) => Unbox (a, b) -- Defined in ‘Data.Vector.Unboxed.Base’ instance (Unbox a, Unbox b, Unbox c) => Unbox (a, b, c) -- Defined in ‘Data.Vector.Unboxed.Base’ ...plus 9 others ...plus 16 instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the fourth argument of ‘mannWhitneyUtest’, namely ‘(VU.fromList sampleB)’ In the first argument of ‘print’, namely ‘(mannWhitneyUtest SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB))’ In a stmt of a 'do' block: print (mannWhitneyUtest SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB)) I think the key problem is how to mention 0.05 as the Pvalue. Thanks for your help.
Here's the super relevant bits of the error report. Ambiguous type variable ‘t0’ arising from the literal ‘4’ Probable fix: use a type annotation to specify what ‘t0’ should be. Is it an Int, Double, Float? The compiler can't tell since 2 it is ambiguous. Adding a type signature ought to fix things. sampleA :: [Double]
You can not use 0.05 as PValue, you can use the mkPValue :: (Ord a, Num a) => a -> PValue a to construct a PValue: import Statistics.Types(mkPValue) main = do putStrLn "\nResult of mannWhitneyUtest: " print $ mannWhitneyUtest SamplesDiffer (mkPValue 0.05) (VU.fromList sampleA) (VU.fromList sampleB) This prints as result: Result of mannWhitneyUtest: Just Significant
WReq simple post request - results in error of No instance for (FormValue v0) arising from a use of ‘:=’
I'm trying to code something to do a few requests to a json API. I have this function : apiLogin = do r <- post "https://url:port/somewhere" ["user" := "some_name", "password" := "test"] putStrLn $ cs $ r ^. responseBody Here are the errors I'm getting : Api.hs:12:96: No instance for (FormValue v0) arising from a use of ‘:=’ The type variable ‘v0’ is ambiguous Note: there are several potential instances: instance FormValue a => FormValue (Maybe a) -- Defined in ‘Network.Wreq.Types’ instance FormValue GHC.Int.Int16 -- Defined in ‘Network.Wreq.Types’ instance FormValue GHC.Int.Int32 -- Defined in ‘Network.Wreq.Types’ ...plus 18 others In the expression: "user" := "some_name" In the second argument of ‘post’, namely ‘["user" := "some_name", "password" := "test"]’ In a stmt of a 'do' block: r <- post "https://url:port/somewhere/g" ["user" := "some_name", "password" := "test"] Api.hs:12:99: No instance for (Data.String.IsString v0) arising from the literal ‘"some_name"’ The type variable ‘v0’ is ambiguous Note: there are several potential instances: instance Data.String.IsString http-client-0.4.29:Network.HTTP.Client.Types.Request -- Defined in ‘http-client-0.4.29:Network.HTTP.Client.Request’ instance Data.String.IsString http-client-0.4.29:Network.HTTP.Client.Types.RequestBody -- Defined in ‘http-client-0.4.29:Network.HTTP.Client.Types’ instance (a ~ Data.ByteString.Internal.ByteString) => Data.String.IsString (attoparsec-0.13.0.2:Data.Attoparsec.ByteString.Internal.Parser a) -- Defined in ‘Data.Attoparsec.ByteString.Char8’ ...plus 11 others In the second argument of ‘(:=)’, namely ‘"some_name"’ In the expression: "user" := "some_name" In the second argument of ‘post’, namely ‘["user" := "some_name", "password" := "test"]’ Api.hs:12:122: No instance for (FormValue v1) arising from a use of ‘:=’ The type variable ‘v1’ is ambiguous Note: there are several potential instances: instance FormValue a => FormValue (Maybe a) -- Defined in ‘Network.Wreq.Types’ instance FormValue GHC.Int.Int16 -- Defined in ‘Network.Wreq.Types’ instance FormValue GHC.Int.Int32 -- Defined in ‘Network.Wreq.Types’ ...plus 18 others In the expression: "password" := "test" In the second argument of ‘post’, namely ‘["user" := "some_name", "password" := "test"]’ In a stmt of a 'do' block: r <- post "https://url:port/somewhere/g" ["user" := "some_name", "password" := "test"] Api.hs:12:125: No instance for (Data.String.IsString v1) arising from the literal ‘"test"’ The type variable ‘v1’ is ambiguous Note: there are several potential instances: instance Data.String.IsString http-client-0.4.29:Network.HTTP.Client.Types.Request -- Defined in ‘http-client-0.4.29:Network.HTTP.Client.Request’ instance Data.String.IsString http-client-0.4.29:Network.HTTP.Client.Types.RequestBody -- Defined in ‘http-client-0.4.29:Network.HTTP.Client.Types’ instance (a ~ Data.ByteString.Internal.ByteString) => Data.String.IsString (attoparsec-0.13.0.2:Data.Attoparsec.ByteString.Internal.Parser a) -- Defined in ‘Data.Attoparsec.ByteString.Char8’ ...plus 11 others In the second argument of ‘(:=)’, namely ‘"test"’ In the expression: "password" := "test" In the second argument of ‘post’, namely ‘["user" := "some_name", "password" := "test"]’ I have no idea what I'm doing wrong, I'm trying to do the same thing they show in the doc (http://www.serpentine.com/wreq/tutorial.html uploading data via post) except not in ghci. I am using Overloaded strings. Could someone explain what those error means ?
The error is because of ambiguity against the function :=. If you specify that both name and values are ByteString, the code will run. I'm not sure why it resolves ambiguity in GHCI but not in standalone code, though.
how to print a formula like "1+(3-2)" in haskell?
how do i solve this problem in haskell? " A machine selects an integral number ( more than or equal to one and less than or equal to N) with equal probability at one operation. Find the excepted probability in which the median of three integral number selected by three times operation with the machine above is K. (K is also integral number) " first i tried this and got this error: main = do n <- getLine k <- getLine print 1+(n-1)+(n-1)*(n-2)/n^3 q4.hs:7:18: Couldn't match type ‘[Char]’ with ‘IO ()’ Expected type: IO () Actual type: String In the first argument of ‘(-)’, namely ‘n’ In the second argument of ‘(+)’, namely ‘(n - 1)’ q4.hs:7:24: Couldn't match type ‘[Char]’ with ‘IO ()’ Expected type: IO () Actual type: String In the first argument of ‘(-)’, namely ‘n’ In the first argument of ‘(*)’, namely ‘(n - 1)’ q4.hs:7:30: Couldn't match type ‘[Char]’ with ‘IO ()’ Expected type: IO () Actual type: String In the first argument of ‘(-)’, namely ‘n’ In the second argument of ‘(*)’, namely ‘(n - 2)’ q4.hs:7:35: Couldn't match type ‘[Char]’ with ‘IO ()’ Expected type: IO () Actual type: String In the first argument of ‘(^)’, namely ‘n’ In the second argument of ‘(/)’, namely ‘n ^ 3’ how do i solve this problem? sorry i'm very new to haskell(and english too.) thank you.
The first level of problems can be solved by adding parentheses to group the argument to print (or by using $): main = do n <- getLine k <- getLine print (1+(n-1)+(n-1)*(n-2)/n^3) -- OR print $ 1+(n-1)+(n-1)*(n-2)/n^3 The next level of problems is that n is a String, but you're hoping for it to be some kind of number. You can fix this by using readLn instead of getLine and specifying what type you want to use; for example: main = do n <- readLn :: IO Double k <- getLine print $ 1+(n-1)+(n-1)*(n-2)/n^3
Is there a way to make GHC provide the type class constraints of typed holes?
Current behavior Prelude> show _ <interactive>:7:6: Found hole ‘_’ with type: a0 Where: ‘a0’ is an ambiguous type variable Relevant bindings include it :: String (bound at <interactive>:7:1) In the first argument of ‘show’, namely ‘_’ In the expression: show _ In an equation for ‘it’: it = show _ Desired behavior It would be nice if GHC would also tell me that the typed hole has the Show type class constraint. Misc GHC Version 7.8.1
This is now fixed in GHC 8.0 thanks to #DominiqueDevriese's GHC ticket. Due to extended type defaulting, this isn't immediately obvious in GHCi. With your example, > show _ <interactive>:7:6: error: • Found hole: _h :: () Or perhaps ‘_h’ is mis-spelled, or not in scope • In the first argument of ‘show’, namely ‘_h’ In the expression: show _h In an equation for ‘it’: it = show _h • Relevant bindings include it :: String (bound at <interactive>:7:1) the type of the hole is defaulted to (). This is apparently the desired behavior, though there's an argument to be made that extended defaulting shouldn't apply to holes (as a common use for them is to get the compiler to tell you the inferred type). Nevertheless, if you compile with GHC or disable extended default rules in GHCi (via :set -XNoExtendedDefaultRules), we see the result of the improvements: <interactive>:3:1: error: • Ambiguous type variable ‘a0’ arising from a use of ‘show’ prevents the constraint ‘(Show a0)’ from being solved. Probable fix: use a type annotation to specify what ‘a0’ should be. These potential instances exist: instance Show Ordering -- Defined in ‘GHC.Show’ instance Show Integer -- Defined in ‘GHC.Show’ instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’ ...plus 22 others ...plus 11 instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the expression: show _ In an equation for ‘it’: it = show _ <interactive>:3:6: error: • Found hole: _ :: a0 Where: ‘a0’ is an ambiguous type variable • In the first argument of ‘show’, namely ‘_’ In the expression: show _ In an equation for ‘it’: it = show _ • Relevant bindings include it :: String (bound at <interactive>:3:1)
No currently its not possible.But it may be added to GHC as per the speculations.
Try it :: _ => _ in GHC 8.8+.
type error in func declaration
I do: Prelude> "sone" ++ "otehr" "soneotehr" But such code: addOneToElement :: [a] -> [a] addOneToElement element = element ++ "next" main = do let s = addOneToElement("some") putStrLn s produces this output: all_possible_combinations.hs:22:37: Couldn't match expected type `a' against inferred type `Char' `a' is a rigid type variable bound by the type signature for `addOneToElement' at all_possible_combinations.hs:21:20 Expected type: [a] Inferred type: [Char] In the second argument of `(++)', namely `"next"' In the expression: element ++ "next" Why I get this error and how I can fix it?
Your type signature should be: addOneToElement :: [Char] -> [Char] (Or more simply, addOneToElement :: String -> String) The "a" in your type signature is a wildcard - it can match anything. However you are trying to concatenate a list of Char to a list of anything - and there is no way to do that.
Why are you using a type variable here anyway? The only type that can match is Char, since the second operand of (++) is fixed to [Char] ("next").