def estimate_theta(self, samples):
'''
Estimates the theta parameters from the given samples.
Parameters
----------
samples : array_like
n-by-2 matrix of samples where n is the number of samples.
'''
if self.theta is not None:
bnds = self.theta_bounds()
def cost(theta):
'''
Calculates the cost of a given `theta` parameter.
'''
self.theta = np.asarray(theta)
vals = self.logpdf(samples)
# For optimization, filter out inifinity values
return -np.sum(vals[np.isfinite(vals)])
result = minimize(cost, self.theta, method='TNC', bounds=bnds)
self.theta = result.x
评论列表
文章目录