@@ -2085,19 +2085,39 @@ def check_draws_match_expected(self):
2085
2085
class TestICAR (BaseTestDistributionRandom ):
2086
2086
pymc_dist = pm .ICAR
2087
2087
pymc_dist_params = {"W" : np .array ([[0 , 1 , 1 ], [1 , 0 , 1 ], [1 , 1 , 0 ]]), "sigma" : 2 }
2088
- expected_rv_op_params = {"W" : np .array ([[0 , 1 , 1 ], [1 , 0 , 1 ], [1 , 1 , 0 ]]), "sigma" : 2 }
2089
- sizes_to_check = [None , (1 ), (2 ), (2 , 2 )]
2090
- sizes_expected = [(3 ,), (3 ), (6 ), (12 )]
2091
- checks_to_run = [
2092
- "check_pymc_params_match_rv_op" ,
2093
- "check_rv_size" ,
2094
- ]
2088
+ expected_rv_op_params = {
2089
+ "W" : np .array ([[0 , 1 , 1 ], [1 , 0 , 1 ], [1 , 1 , 0 ]]),
2090
+ "node1" : np .array ([1 , 2 , 2 ]),
2091
+ "node2" : np .array ([0 , 0 , 1 ]),
2092
+ "N" : 3 ,
2093
+ "sigma" : 2 ,
2094
+ "zero_sum_strength" : 0.001 ,
2095
+ }
2096
+ checks_to_run = ["check_pymc_params_match_rv_op" ]
2097
+
2098
+ def test_icar_logp (self ):
2099
+ W = np .array ([[0 , 1 , 0 , 1 ], [1 , 0 , 1 , 0 ], [0 , 1 , 0 , 1 ], [1 , 0 , 1 , 0 ]])
2100
+
2101
+ with pm .Model () as m :
2102
+ RV = pm .ICAR ("phi" , W = W )
2103
+
2104
+ assert pt .isclose (
2105
+ pm .logp (RV , np .array ([0.01 , - 0.03 , 0.02 , 0.00 ])).eval (), np .array (4.60022238 )
2106
+ ).eval (), "logp inaccuracy"
2107
+
2108
+ def test_icar_rng_fn (self ):
2109
+ W = np .array ([[0 , 1 , 0 , 1 ], [1 , 0 , 1 , 0 ], [0 , 1 , 0 , 1 ], [1 , 0 , 1 , 0 ]])
2110
+
2111
+ RV = pm .ICAR .dist (W = W )
2112
+
2113
+ with pytest .raises (NotImplementedError , match = "Cannot sample from ICAR prior" ):
2114
+ pm .draw (RV )
2095
2115
2096
2116
@pytest .mark .parametrize (
2097
2117
"W,msg" ,
2098
2118
[
2099
2119
(np .array ([0 , 1 , 0 , 0 ]), "W must be matrix with ndim=2" ),
2100
- (np .array ([[0 , 1 , 0 , 0 ], [1 , 0 , 0 , 1 ], [1 , 0 , 0 , 1 ]]), "W must be a symmetric matrix" ),
2120
+ (np .array ([[0 , 1 , 0 , 0 ], [1 , 0 , 0 , 1 ], [1 , 0 , 0 , 1 ]]), "W must be a square matrix" ),
2101
2121
(
2102
2122
np .array ([[0 , 1 , 0 , 0 ], [1 , 0 , 0 , 1 ], [1 , 0 , 0 , 1 ], [0 , 1 , 1 , 0 ]]),
2103
2123
"W must be a symmetric matrix" ,
@@ -2108,29 +2128,11 @@ class TestICAR(BaseTestDistributionRandom):
2108
2128
),
2109
2129
],
2110
2130
)
2111
- def test_icar_matrix_checks (W , msg ):
2131
+ def test_icar_matrix_checks (self , W , msg ):
2112
2132
with pytest .raises (ValueError , match = msg ):
2113
2133
with pm .Model ():
2114
2134
pm .ICAR ("phi" , W = W )
2115
2135
2116
- def test_icar_logp ():
2117
- W = np .array ([[0 , 1 , 0 , 1 ], [1 , 0 , 1 , 0 ], [0 , 1 , 0 , 1 ], [1 , 0 , 1 , 0 ]])
2118
-
2119
- with pm .Model () as m :
2120
- RV = pm .ICAR ("phi" , W = W )
2121
-
2122
- assert pt .isclose (
2123
- pm .logp (RV , np .array ([0.01 , - 0.03 , 0.02 , 0.00 ])).eval (), np .array (4.60022238 )
2124
- ).eval (), "logp inaccuracy"
2125
-
2126
- def test_icar_rng_fn ():
2127
- W = np .array ([[0 , 1 , 0 , 1 ], [1 , 0 , 1 , 0 ], [0 , 1 , 0 , 1 ], [1 , 0 , 1 , 0 ]])
2128
-
2129
- RV = pm .ICAR .dist (W = W )
2130
-
2131
- with pytest .raises (NotImplementedError , match = "Cannot sample from ICAR prior" ):
2132
- pm .draw (RV )
2133
-
2134
2136
2135
2137
@pytest .mark .parametrize ("sparse" , [True , False ])
2136
2138
def test_car_rng_fn (sparse ):
0 commit comments