コード例 #1
0
 def test_ssr(self):
     # if x is a N x M array, then beta must be a M x P array, then y must be a N x P array
     x = np.array([[1, 0, 4, 3, 2], [1, 1, 2, 2, 3]])
     y = np.array([[1, 1], [1, 2]])
     beta = np.array([[1, 2], [2, 3], [1, 1], [1, 2], [0, 1]])
     result = bayes_stats.ssr(x, y, beta)
     np.testing.assert_array_equal(result, 398)
コード例 #2
0
 def test_calc_rate_lin_alg_error(self):
     x = np.array([[1, 2, 3], [2, 4, 6], [4, 8, 12], [8, 16, 24]])
     y = np.array([[1, 2, 3], [0, 1, 1], [1, 1, 1], [1, 0, 1]])
     xtx = np.dot(x.T, x)  # [k x k]
     xty = np.dot(x.T, y)  # [k x 1]
     gprior = np.array([[1, 1, 1, 1], [1, 0, 1, 0], [0, 0, 1, 1],
                        [1, 0, 1, 1]])
     with self.assertRaises(np.linalg.LinAlgError):
         model_beta = bayes_stats._solve_model(xtx, xty)
         model_ssr = bayes_stats.ssr(x, y, model_beta)
         scale_param = bayes_stats._calc_ig_scale(model_beta, model_ssr,
                                                  xtx, gprior)
コード例 #3
0
    def test_calc_rate(self):
        x = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
        y = np.array([[1, 2, 3], [0, 1, 1], [1, 1, 1], [1, 0, 1]])
        xtx = np.dot(x.T, x)  # [k x k]
        xty = np.dot(x.T, y)  # [k x 1]
        gprior = np.array([[1, 1, 1, 1], [1, 0, 1, 0], [0, 0, 1, 1],
                           [1, 0, 1, 1]])

        model_beta = bayes_stats._solve_model(xtx, xty)
        model_ssr = bayes_stats.ssr(x, y, model_beta)
        scale_param = bayes_stats._calc_ig_scale(model_beta, model_ssr, xtx,
                                                 gprior)

        np.testing.assert_array_equal(
            scale_param,
            np.array([[1.5, 1.5, 2.5], [1.5, 2.5, 3.5], [2.5, 3.5, 5.5]]))
コード例 #4
0
 def test_ssr_negative(self):
     x = np.array([[0, 1, -1, -2, 1], [-1, 2, 0, -1, 1]])
     y = np.array([[2, -1], [1, 2]])
     beta = np.array([[-1, -1], [1, 2], [2, 1], [-2, 1], [1, -1]])
     result = bayes_stats.ssr(x, y, beta)
     np.testing.assert_array_equal(result, 31)
コード例 #5
0
 def test_ssr_zeros(self):
     x = np.array([[0, 0, 0, 0], [0, 0, 0, 0]])
     y = np.array([[0, 0], [0, 0]])
     beta = np.array([[0, 0], [0, 0], [0, 0], [0, 0]])
     result = bayes_stats.ssr(x, y, beta)
     np.testing.assert_array_equal(result, 0)