Skip to content

Commit

Permalink
Added fit in 1D
Browse files Browse the repository at this point in the history
  • Loading branch information
Danilo Enoque Ferreira De Lima committed Oct 25, 2018
1 parent 93e7e6c commit 080a82d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions getmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def mpdf(x, args):
mean = args['mean']
LT = args['LT']
LNP = args['LNP']
if len(x.shape) == 1:
if LT == 0:
A = x
elif len(x.shape) == 1:
A = np.concatenate( (mean[:LT,0], x), axis = 0)
else:
A = np.concatenate((np.tile(mean[:LT,:], (1,x.shape[1])),x), axis = 0)
Expand Down Expand Up @@ -143,7 +145,11 @@ def jac(self, points):
return result_diff/result

print("value", value.shape)
pdf = GKDE(value)
LT = trace.shape[0]
LNP = len(nuistrace)
print("LT",LT)
print("LNP", LNP)
pdf = GKDE(value[LT:,:])


#pdf = stats.gaussian_kde(value,bw_method='scott')
Expand All @@ -157,11 +163,7 @@ def jac(self, points):
#print ('bounds ',bounds)

# keep those first LT variables fixed in the mean
LT = trace.shape[0]
LNP = len(nuistrace)
print("LT",LT)
print("LNP", LNP)
args = {'pdf': pdf, 'LT': LT, 'LNP': LNP, 'mean': S}
args = {'pdf': pdf, 'LT': 0, 'LNP': LNP, 'mean': S}
print("Start minimization with %s = %s" % (str(S), mpdf(S[LT:,:], args)[0]))
#print("Start minimization with %s = %f" % (str(S), mpdf(S, args)))
#print("Start minimization with dS %s" % (str(dS)))
Expand All @@ -173,7 +175,7 @@ def jac(self, points):

#res = optimize.minimize(mpdf, S, args = args, jac = True, bounds = bounds, method='L-BFGS-B', options={'ftol':10e-20,'gtol':10e-18,'maxiter': 500, 'disp': True})
# ROOT uses gtol (it calls it EDM) 1e-3
res = optimize.minimize(mpdf, np.zeros( (LNP, 1), dtype = np.float64 ), args = args, jac = False, method='L-BFGS-B', options={'maxiter': 200, 'disp': True})
res = optimize.minimize(mpdf, np.zeros( (LNP, 1), dtype = np.float64 ), args = args, jac = False, method='L-BFGS-B', options={'maxiter': 200, 'disp': True, 'ftol': 0, 'gtol': 0})
print('===================')
print(res)
print('===================')
Expand All @@ -187,9 +189,10 @@ def jac(self, points):

fig = plt.figure( figsize = (10, 6) )
x = np.reshape(np.linspace(-2, 2, 100), (1, -1) )
A = np.concatenate((np.tile(S[:LT,:], (1,x.shape[1])),x), axis = 0)
#A = np.concatenate((np.tile(S[:LT,:], (1,x.shape[1])),x), axis = 0)
A = x
print(A.shape)
y = np.reshape(np.exp(pdf.logpdf(A)+np.log(1e20)), (1, -1) )
y = np.reshape(np.exp(pdf.logpdf(A)), (1, -1) )
x = np.reshape(x, (-1))
y = np.reshape(y, (-1))
print(x, y)
Expand Down

0 comments on commit 080a82d

Please sign in to comment.