#### Function Maximisation

``````from scipy.optimize import minimize
from scipy.stats import lognorm, norm
import numpy as np

np.random.seed(123)
obs = np.random.normal(loc=20, scale=3, size=20)

# Log-Posterior optimisation objectiv
def objective(params, y):
mu = params[0]
sigma = params[1]
llikelihood = np.sum(np.log(norm.pdf(y, mu, sigma)))
lpost = llikelihood + np.log(norm.pdf(mu, 0, 100)) + np.log(lognorm.pdf(sigma, loc= 0, s = 4))
return -1*lpost

starting_mu = 0
starting_sigma = 1
optim_res = minimize(fun = objective, x0=(starting_mu, starting_sigma), args=(obs))
``````

``````dert2@ma0phd201803:~\$ python laplace_approx.py
laplace_approx.py:12: RuntimeWarning: divide by zero encountered in log
lpost = llikelihood + np.log(norm.pdf(mu, 0, 100)) + np.log(lognorm.pdf(sigma, loc= 0, s = 4))
laplace_approx.py:12: RuntimeWarning: divide by zero encountered in log
lpost = llikelihood + np.log(norm.pdf(mu, 0, 100)) + np.log(lognorm.pdf(sigma, loc= 0, s = 4))
laplace_approx.py:12: RuntimeWarning: divide by zero encountered in log
lpost = llikelihood + np.log(norm.pdf(mu, 0, 100)) + np.log(lognorm.pdf(sigma, loc= 0, s = 4))
/opt/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py:83:     RuntimeWarning: invalid value encountered in reduce
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
``````
1 个回复

1 最大化功能

2 根据功能最大化

3 如何最大化功能？

2019-04-12 15:25:43 1 59   pulp
4 最大化功能：什么方法？

5 Python：功能最大化

2017-04-28 18:40:51 1 112   scipy
6 使用Tensorflow最大化奖励功能

7 通过两个参数最大化功能

8 pyqt关闭双击最大化功能

9 在PDDL中最大化功能

2016-06-23 12:13:01 1 376   pddl
10 Powerpoint VBA 最大化功能区