test_Bayesian.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:F_UNCLE 作者: fraserphysics 项目源码 文件源码
def test_hessian(self):
        """Tests hessian calculation
        """

        indep = np.arange(10)
        resp_mat = np.array([(1.02 * 2 * indep)**2 + 1 * indep -
                             (2 * indep)**2 - indep,
                             (2 * indep)**2 + 1.02 * indep -
                             (2 * indep)**2 - indep])
        inp_mat = np.array([[0.02 * 2, 0], [0, 0.02]])
        init_sens = np.linalg.lstsq(inp_mat, resp_mat)[0].T

        resp_mat = np.array([(1.02**2 * 2 * indep)**2 + indep -
                             (1.02 * 2 * indep)**2 - indep,
                             (1.02 * 2 * indep)**2 + 1.02 * indep -
                             (1.02 * 2 * indep)**2 - indep])
        inp_mat = np.array([[0.02 * 1.02 * 2, 0], [0, 0.02]])
        step1_sens = np.linalg.lstsq(inp_mat, resp_mat)[0].T

        resp_mat = np.array([(1.02 * 2 * indep)**2 + 1.02 * indep -
                             (2 * indep)**2 - 1.02 * indep,
                             (2 * indep)**2 + 1.02**2 * indep -
                             (2 * indep)**2 - 1.02 * indep])
        inp_mat = np.array([[0.02 * 2, 0], [0, 0.02 * 1.02]])
        step2_sens = np.linalg.lstsq(inp_mat, resp_mat)[0].T

        true_hess = np.zeros((2, 10, 2))
        true_hess[0, :, :] = (step1_sens - init_sens) / (0.02 * 2.0)

        true_hess[1, :, :] = (step2_sens - init_sens) / (0.02 * 1.0)

        hessian = self.bayes.get_hessian()
        npt.assert_array_almost_equal(hessian['simple'], true_hess,
                                      decimal=8,
                                      err_msg='Hessian not as predicted')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号