@@ -545,9 +545,7 @@ def get_inputs_from_apply_node_outputs(outputs):
545
545
# I am assuming there will always only be 1 Apply parent node in this context
546
546
return parents [0 ].inputs
547
547
548
- def test_pymc_params_match_rv_ones (
549
- self , pymc_params , expected_aesara_params , pymc_dist , decimal = 6
550
- ):
548
+ def _pymc_params_match_rv_ones (self , pymc_params , expected_aesara_params , pymc_dist , decimal = 6 ):
551
549
pymc_dist_output = pymc_dist .dist (** dict (pymc_params ))
552
550
aesera_dist_inputs = self .get_inputs_from_apply_node_outputs (pymc_dist_output )[3 :]
553
551
assert len (expected_aesara_params ) == len (aesera_dist_inputs )
@@ -558,52 +556,88 @@ def test_pymc_params_match_rv_ones(
558
556
559
557
def test_normal (self ):
560
558
params = [("mu" , 5.0 ), ("sigma" , 10.0 )]
561
- self .test_pymc_params_match_rv_ones (params , params , pm .Normal )
559
+ self ._pymc_params_match_rv_ones (params , params , pm .Normal )
562
560
563
561
def test_uniform (self ):
564
562
params = [("lower" , 0.5 ), ("upper" , 1.5 )]
565
- self .test_pymc_params_match_rv_ones (params , params , pm .Uniform )
563
+ self ._pymc_params_match_rv_ones (params , params , pm .Uniform )
566
564
567
565
def test_half_normal (self ):
568
566
params , expected_aesara_params = [("sigma" , 10.0 )], [("mean" , 0 ), ("sigma" , 10.0 )]
569
- self .test_pymc_params_match_rv_ones (params , expected_aesara_params , pm .HalfNormal )
567
+ self ._pymc_params_match_rv_ones (params , expected_aesara_params , pm .HalfNormal )
570
568
571
569
def test_beta_alpha_beta (self ):
572
570
params = [("alpha" , 2.0 ), ("beta" , 5.0 )]
573
- self .test_pymc_params_match_rv_ones (params , params , pm .Beta )
571
+ self ._pymc_params_match_rv_ones (params , params , pm .Beta )
574
572
575
573
def test_beta_mu_sigma (self ):
576
574
params = [("mu" , 2.0 ), ("sigma" , 5.0 )]
577
575
expected_alpha , expected_beta = pm .Beta .get_alpha_beta (mu = params [0 ][1 ], sigma = params [1 ][1 ])
578
576
expected_params = [("alpha" , expected_alpha ), ("beta" , expected_beta )]
579
- self .test_pymc_params_match_rv_ones (params , expected_params , pm .Beta )
577
+ self ._pymc_params_match_rv_ones (params , expected_params , pm .Beta )
580
578
581
579
@pytest .mark .skip (reason = "Expected to fail due to bug" )
582
580
def test_exponential (self ):
583
581
params = [("lam" , 10.0 )]
584
582
expected_params = [("lam" , 1 / params [0 ][1 ])]
585
- self .test_pymc_params_match_rv_ones (params , expected_params , pm .Exponential )
583
+ self ._pymc_params_match_rv_ones (params , expected_params , pm .Exponential )
586
584
587
585
def test_cauchy (self ):
588
586
params = [("alpha" , 2.0 ), ("beta" , 5.0 )]
589
- self .test_pymc_params_match_rv_ones (params , params , pm .Cauchy )
587
+ self ._pymc_params_match_rv_ones (params , params , pm .Cauchy )
590
588
591
589
def test_half_cauchy (self ):
592
590
params = [("alpha" , 2.0 ), ("beta" , 5.0 )]
593
- self .test_pymc_params_match_rv_ones (params , params , pm .HalfCauchy )
591
+ self ._pymc_params_match_rv_ones (params , params , pm .HalfCauchy )
594
592
595
593
@pytest .mark .skip (reason = "Expected to fail due to bug" )
596
594
def test_gamma_alpha_beta (self ):
597
595
params = [("alpha" , 2.0 ), ("beta" , 5.0 )]
598
596
expected_params = [("alpha" , params [0 ][1 ]), ("beta" , 1 / params [1 ][1 ])]
599
- self .test_pymc_params_match_rv_ones (params , expected_params , pm .Gamma )
597
+ self ._pymc_params_match_rv_ones (params , expected_params , pm .Gamma )
600
598
601
599
@pytest .mark .skip (reason = "Expected to fail due to bug" )
602
600
def test_gamma_mu_sigma (self ):
603
601
params = [("mu" , 2.0 ), ("sigma" , 5.0 )]
604
602
expected_alpha , expected_beta = pm .Gamma .get_alpha_beta (mu = params [0 ][1 ], sigma = params [1 ][1 ])
605
603
expected_params = [("alpha" , expected_alpha ), ("beta" , 1 / expected_beta )]
606
- self .test_pymc_params_match_rv_ones (params , expected_params , pm .Gamma )
604
+ self ._pymc_params_match_rv_ones (params , expected_params , pm .Gamma )
605
+
606
+ def test_inverse_gamma_alpha_beta (self ):
607
+ params = [("alpha" , 2.0 ), ("beta" , 5.0 )]
608
+ self ._pymc_params_match_rv_ones (params , params , pm .InverseGamma )
609
+
610
+ def test_inverse_gamma_mu_sigma (self ):
611
+ params = [("mu" , 2.0 ), ("sigma" , 5.0 )]
612
+ expected_alpha , expected_beta = pm .InverseGamma ._get_alpha_beta (
613
+ mu = params [0 ][1 ], sigma = params [1 ][1 ], alpha = None , beta = None
614
+ )
615
+ expected_params = [("alpha" , expected_alpha ), ("beta" , expected_beta )]
616
+ self ._pymc_params_match_rv_ones (params , expected_params , pm .InverseGamma )
617
+
618
+ def test_binomial (self ):
619
+ params = [("n" , 100 ), ("p" , 0.33 )]
620
+ self ._pymc_params_match_rv_ones (params , params , pm .Binomial )
621
+
622
+ def test_negative_binomial (self ):
623
+ params = [("n" , 100 ), ("p" , 0.33 )]
624
+ self ._pymc_params_match_rv_ones (params , params , pm .NegativeBinomial )
625
+
626
+ def test_negative_binomial_mu_sigma (self ):
627
+ params = [("mu" , 5.0 ), ("alpha" , 8.0 )]
628
+ expected_n , expected_p = pm .NegativeBinomial .get_n_p (
629
+ mu = params [0 ][1 ], alpha = params [1 ][1 ], n = None , p = None
630
+ )
631
+ expected_params = [("n" , expected_n ), ("p" , expected_p )]
632
+ self ._pymc_params_match_rv_ones (params , expected_params , pm .NegativeBinomial )
633
+
634
+ def test_bernoulli (self ):
635
+ params = [("p" , 0.33 )]
636
+ self ._pymc_params_match_rv_ones (params , params , pm .Bernoulli )
637
+
638
+ def test_poisson (self ):
639
+ params = [("mu" , 4 )]
640
+ self ._pymc_params_match_rv_ones (params , params , pm .Poisson )
607
641
608
642
609
643
class TestScalarParameterSamples (SeededTest ):
@@ -701,13 +735,6 @@ def ref_rand(size, nu, mu, lam):
701
735
702
736
pymc3_random (pm .StudentT , {"nu" : Rplus , "mu" : R , "lam" : Rplus }, ref_rand = ref_rand )
703
737
704
- @pytest .mark .skip (reason = "This test is covered by Aesara" )
705
- def test_inverse_gamma (self ):
706
- def ref_rand (size , alpha , beta ):
707
- return st .invgamma .rvs (a = alpha , scale = beta , size = size )
708
-
709
- pymc3_random (pm .InverseGamma , {"alpha" : Rplus , "beta" : Rplus }, ref_rand = ref_rand )
710
-
711
738
@pytest .mark .xfail (reason = "This distribution has not been refactored for v4" )
712
739
def test_pareto (self ):
713
740
def ref_rand (size , alpha , m ):
@@ -754,10 +781,6 @@ def test_half_flat(self):
754
781
with pytest .raises (ValueError ):
755
782
f .random (1 )
756
783
757
- @pytest .mark .skip (reason = "This test is covered by Aesara" )
758
- def test_binomial (self ):
759
- pymc3_random_discrete (pm .Binomial , {"n" : Nat , "p" : Unit }, ref_rand = st .binom .rvs )
760
-
761
784
@pytest .mark .xfail (reason = "This distribution has not been refactored for v4" )
762
785
@pytest .mark .xfail (
763
786
sys .platform .startswith ("win" ),
@@ -771,29 +794,6 @@ def test_beta_binomial(self):
771
794
def _beta_bin (self , n , alpha , beta , size = None ):
772
795
return st .binom .rvs (n , st .beta .rvs (a = alpha , b = beta , size = size ))
773
796
774
- @pytest .mark .skip (reason = "This test is covered by Aesara" )
775
- def test_bernoulli (self ):
776
- pymc3_random_discrete (
777
- pm .Bernoulli , {"p" : Unit }, ref_rand = lambda size , p = None : st .bernoulli .rvs (p , size = size )
778
- )
779
-
780
- @pytest .mark .skip (reason = "This test is covered by Aesara" )
781
- def test_poisson (self ):
782
- pymc3_random_discrete (pm .Poisson , {"mu" : Rplusbig }, size = 500 , ref_rand = st .poisson .rvs )
783
-
784
- @pytest .mark .skip (reason = "This test is covered by Aesara" )
785
- def test_negative_binomial (self ):
786
- def ref_rand (size , alpha , mu ):
787
- return st .nbinom .rvs (alpha , alpha / (mu + alpha ), size = size )
788
-
789
- pymc3_random_discrete (
790
- pm .NegativeBinomial ,
791
- {"mu" : Rplusbig , "alpha" : Rplusbig },
792
- size = 100 ,
793
- fails = 50 ,
794
- ref_rand = ref_rand ,
795
- )
796
-
797
797
@pytest .mark .xfail (reason = "This distribution has not been refactored for v4" )
798
798
def test_geometric (self ):
799
799
pymc3_random_discrete (pm .Geometric , {"p" : Unit }, size = 500 , fails = 50 , ref_rand = nr .geometric )
0 commit comments