27
27
28
28
from pymc3 .tests import models
29
29
from pymc3 .tests .helpers import not_raises
30
- from pymc3 .theanof import change_flags , intX
30
+ from pymc3 .theanof import intX
31
31
from pymc3 .variational import flows , opvi
32
32
from pymc3 .variational .approximations import (
33
33
Empirical ,
@@ -533,17 +533,20 @@ def test_scale_cost_to_minibatch_works(aux_total_size):
533
533
sigma = 1.0
534
534
y_obs = np .array ([1.6 , 1.4 ])
535
535
beta = len (y_obs ) / float (aux_total_size )
536
- post_mu = np .array ([1.88 ], dtype = theano .config .floatX )
537
- post_sigma = np .array ([1 ], dtype = theano .config .floatX )
538
536
539
537
# TODO: theano_config
540
538
# with pm.Model(theano_config=dict(floatX='float64')):
541
539
# did not not work as expected
542
540
# there were some numeric problems, so float64 is forced
543
- with pm .theanof .change_flags (floatX = "float64" , warn_float64 = "ignore" ):
541
+ with theano .config .change_flags (floatX = "float64" , warn_float64 = "ignore" ):
542
+
543
+ assert theano .config .floatX == "float64"
544
+ assert theano .config .warn_float64 == "ignore"
545
+
546
+ post_mu = np .array ([1.88 ], dtype = theano .config .floatX )
547
+ post_sigma = np .array ([1 ], dtype = theano .config .floatX )
548
+
544
549
with pm .Model ():
545
- assert theano .config .floatX == "float64"
546
- assert theano .config .warn_float64 == "ignore"
547
550
mu = pm .Normal ("mu" , mu = mu0 , sigma = sigma )
548
551
pm .Normal ("y" , mu = mu , sigma = 1 , observed = y_obs , total_size = aux_total_size )
549
552
# Create variational gradient tensor
@@ -552,7 +555,7 @@ def test_scale_cost_to_minibatch_works(aux_total_size):
552
555
mean_field_1 .shared_params ["mu" ].set_value (post_mu )
553
556
mean_field_1 .shared_params ["rho" ].set_value (np .log (np .exp (post_sigma ) - 1 ))
554
557
555
- with pm . theanof .change_flags (compute_test_value = "off" ):
558
+ with theano . config .change_flags (compute_test_value = "off" ):
556
559
elbo_via_total_size_scaled = - pm .operators .KL (mean_field_1 )()(10000 )
557
560
558
561
with pm .Model ():
@@ -566,7 +569,7 @@ def test_scale_cost_to_minibatch_works(aux_total_size):
566
569
mean_field_2 .shared_params ["mu" ].set_value (post_mu )
567
570
mean_field_2 .shared_params ["rho" ].set_value (np .log (np .exp (post_sigma ) - 1 ))
568
571
569
- with pm . theanof .change_flags (compute_test_value = "off" ):
572
+ with theano . config .change_flags (compute_test_value = "off" ):
570
573
elbo_via_total_size_unscaled = - pm .operators .KL (mean_field_2 )()(10000 )
571
574
572
575
np .testing .assert_allclose (
@@ -583,9 +586,12 @@ def test_elbo_beta_kl(aux_total_size):
583
586
sigma = 1.0
584
587
y_obs = np .array ([1.6 , 1.4 ])
585
588
beta = len (y_obs ) / float (aux_total_size )
586
- post_mu = np .array ([1.88 ], dtype = theano .config .floatX )
587
- post_sigma = np .array ([1 ], dtype = theano .config .floatX )
588
- with pm .theanof .change_flags (floatX = "float64" , warn_float64 = "ignore" ):
589
+
590
+ with theano .config .change_flags (floatX = "float64" , warn_float64 = "ignore" ):
591
+
592
+ post_mu = np .array ([1.88 ], dtype = theano .config .floatX )
593
+ post_sigma = np .array ([1 ], dtype = theano .config .floatX )
594
+
589
595
with pm .Model ():
590
596
mu = pm .Normal ("mu" , mu = mu0 , sigma = sigma )
591
597
pm .Normal ("y" , mu = mu , sigma = 1 , observed = y_obs , total_size = aux_total_size )
@@ -595,7 +601,7 @@ def test_elbo_beta_kl(aux_total_size):
595
601
mean_field_1 .shared_params ["mu" ].set_value (post_mu )
596
602
mean_field_1 .shared_params ["rho" ].set_value (np .log (np .exp (post_sigma ) - 1 ))
597
603
598
- with pm . theanof .change_flags (compute_test_value = "off" ):
604
+ with theano . config .change_flags (compute_test_value = "off" ):
599
605
elbo_via_total_size_scaled = - pm .operators .KL (mean_field_1 )()(10000 )
600
606
601
607
with pm .Model ():
@@ -606,7 +612,7 @@ def test_elbo_beta_kl(aux_total_size):
606
612
mean_field_3 .shared_params ["mu" ].set_value (post_mu )
607
613
mean_field_3 .shared_params ["rho" ].set_value (np .log (np .exp (post_sigma ) - 1 ))
608
614
609
- with pm . theanof .change_flags (compute_test_value = "off" ):
615
+ with theano . config .change_flags (compute_test_value = "off" ):
610
616
elbo_via_beta_kl = - pm .operators .KL (mean_field_3 , beta = beta )()(10000 )
611
617
612
618
np .testing .assert_allclose (
@@ -1014,7 +1020,7 @@ def init_(**kw):
1014
1020
def test_flow_det (flow_spec ):
1015
1021
z0 = tt .arange (0 , 20 ).astype ("float32" )
1016
1022
flow = flow_spec (dim = 20 , z0 = z0 .dimshuffle ("x" , 0 ))
1017
- with change_flags (compute_test_value = "off" ):
1023
+ with theano . config . change_flags (compute_test_value = "off" ):
1018
1024
z1 = flow .forward .flatten ()
1019
1025
J = tt .jacobian (z1 , z0 )
1020
1026
logJdet = tt .log (tt .abs_ (tt .nlinalg .det (J )))
@@ -1030,7 +1036,7 @@ def test_flow_det_local(flow_spec):
1030
1036
params [k ] = np .random .randn (1 , * shp ).astype ("float32" )
1031
1037
flow = flow_spec (dim = 12 , z0 = z0 .reshape ((1 , 1 , 12 )), ** params )
1032
1038
assert flow .batched
1033
- with change_flags (compute_test_value = "off" ):
1039
+ with theano . config . change_flags (compute_test_value = "off" ):
1034
1040
z1 = flow .forward .flatten ()
1035
1041
J = tt .jacobian (z1 , z0 )
1036
1042
logJdet = tt .log (tt .abs_ (tt .nlinalg .det (J )))
0 commit comments