@@ -87,10 +87,13 @@ def full(self, X, Xs):
87
87
88
88
def _slice (self , X , Xs ):
89
89
if self .input_dim != X .shape [- 1 ]:
90
- warnings .warn (f"Only { self .input_dim } column(s) out of { X .shape [- 1 ]} are"
91
- " being used to compute the covariance function. If this"
92
- " is not intended, increase 'input_dim' parameter to"
93
- " the number of columns to use. Ignore otherwise." , UserWarning )
90
+ warnings .warn (
91
+ f"Only { self .input_dim } column(s) out of { X .shape [- 1 ]} are"
92
+ " being used to compute the covariance function. If this"
93
+ " is not intended, increase 'input_dim' parameter to"
94
+ " the number of columns to use. Ignore otherwise." ,
95
+ UserWarning ,
96
+ )
94
97
X = tt .as_tensor_variable (X [:, self .active_dims ])
95
98
if Xs is not None :
96
99
Xs = tt .as_tensor_variable (Xs [:, self .active_dims ])
@@ -109,9 +112,9 @@ def __rmul__(self, other):
109
112
return self .__mul__ (other )
110
113
111
114
def __pow__ (self , other ):
112
- if (
113
- isinstance (other , theano .compile .SharedVariable ) and
114
- other .get_value ().squeeze ().shape == ()
115
+ if (
116
+ isinstance (other , theano .compile .SharedVariable )
117
+ and other .get_value ().squeeze ().shape == ()
115
118
):
116
119
other = tt .squeeze (other )
117
120
return Exponentiated (self , other )
@@ -123,7 +126,6 @@ def __pow__(self, other):
123
126
124
127
raise ValueError ("A covariance function can only be exponentiated by a scalar value" )
125
128
126
-
127
129
def __array_wrap__ (self , result ):
128
130
"""
129
131
Required to allow radd/rmul by numpy arrays.
@@ -132,7 +134,9 @@ def __array_wrap__(self, result):
132
134
if len (result .shape ) <= 1 :
133
135
result = result .reshape (1 , 1 )
134
136
elif len (result .shape ) > 2 :
135
- raise ValueError (f"cannot combine a covariance function with array of shape { result .shape } " )
137
+ raise ValueError (
138
+ f"cannot combine a covariance function with array of shape { result .shape } "
139
+ )
136
140
r , c = result .shape
137
141
A = np .zeros ((r , c ))
138
142
for i in range (r ):
@@ -149,11 +153,7 @@ def __array_wrap__(self, result):
149
153
class Combination (Covariance ):
150
154
def __init__ (self , factor_list ):
151
155
input_dim = max (
152
- [
153
- factor .input_dim
154
- for factor in factor_list
155
- if isinstance (factor , Covariance )
156
- ]
156
+ [factor .input_dim for factor in factor_list if isinstance (factor , Covariance )]
157
157
)
158
158
super ().__init__ (input_dim = input_dim )
159
159
self .factor_list = []
@@ -205,10 +205,7 @@ class Exponentiated(Covariance):
205
205
def __init__ (self , kernel , power ):
206
206
self .kernel = kernel
207
207
self .power = power
208
- super ().__init__ (
209
- input_dim = self .kernel .input_dim ,
210
- active_dims = self .kernel .active_dims
211
- )
208
+ super ().__init__ (input_dim = self .kernel .input_dim , active_dims = self .kernel .active_dims )
212
209
213
210
def __call__ (self , X , Xs = None , diag = False ):
214
211
return self .kernel (X , Xs , diag = diag ) ** self .power
@@ -247,9 +244,7 @@ def _split(self, X, Xs):
247
244
248
245
def __call__ (self , X , Xs = None , diag = False ):
249
246
X_split , Xs_split = self ._split (X , Xs )
250
- covs = [
251
- cov (x , xs , diag ) for cov , x , xs in zip (self .factor_list , X_split , Xs_split )
252
- ]
247
+ covs = [cov (x , xs , diag ) for cov , x , xs in zip (self .factor_list , X_split , Xs_split )]
253
248
return reduce (mul , covs )
254
249
255
250
@@ -431,9 +426,7 @@ class Matern52(Stationary):
431
426
def full (self , X , Xs = None ):
432
427
X , Xs = self ._slice (X , Xs )
433
428
r = self .euclidean_dist (X , Xs )
434
- return (1.0 + np .sqrt (5.0 ) * r + 5.0 / 3.0 * tt .square (r )) * tt .exp (
435
- - 1.0 * np .sqrt (5.0 ) * r
436
- )
429
+ return (1.0 + np .sqrt (5.0 ) * r + 5.0 / 3.0 * tt .square (r )) * tt .exp (- 1.0 * np .sqrt (5.0 ) * r )
437
430
438
431
439
432
class Matern32 (Stationary ):
@@ -605,14 +598,10 @@ def __init__(self, input_dim, lengthscale_func, args=None, active_dims=None):
605
598
super ().__init__ (input_dim , active_dims )
606
599
if active_dims is not None :
607
600
if len (active_dims ) > 1 :
608
- raise NotImplementedError (
609
- ("Higher dimensional inputs " , "are untested" )
610
- )
601
+ raise NotImplementedError (("Higher dimensional inputs " , "are untested" ))
611
602
else :
612
603
if input_dim != 1 :
613
- raise NotImplementedError (
614
- ("Higher dimensional inputs " , "are untested" )
615
- )
604
+ raise NotImplementedError (("Higher dimensional inputs " , "are untested" ))
616
605
if not callable (lengthscale_func ):
617
606
raise TypeError ("lengthscale_func must be callable" )
618
607
self .lfunc = handle_args (lengthscale_func , args )
@@ -642,9 +631,7 @@ def full(self, X, Xs=None):
642
631
r2 = self .square_dist (X , Xs )
643
632
rx2 = tt .reshape (tt .square (rx ), (- 1 , 1 ))
644
633
rz2 = tt .reshape (tt .square (rz ), (1 , - 1 ))
645
- return tt .sqrt ((2.0 * tt .outer (rx , rz )) / (rx2 + rz2 )) * tt .exp (
646
- - 1.0 * r2 / (rx2 + rz2 )
647
- )
634
+ return tt .sqrt ((2.0 * tt .outer (rx , rz )) / (rx2 + rz2 )) * tt .exp (- 1.0 * r2 / (rx2 + rz2 ))
648
635
649
636
def diag (self , X ):
650
637
return tt .alloc (1.0 , X .shape [0 ])
@@ -734,19 +721,15 @@ def __init__(self, input_dim, W=None, kappa=None, B=None, active_dims=None):
734
721
raise ValueError ("Coregion requires exactly one dimension to be active" )
735
722
make_B = W is not None or kappa is not None
736
723
if make_B and B is not None :
737
- raise ValueError (
738
- "Exactly one of (W, kappa) and B must be provided to Coregion"
739
- )
724
+ raise ValueError ("Exactly one of (W, kappa) and B must be provided to Coregion" )
740
725
if make_B :
741
726
self .W = tt .as_tensor_variable (W )
742
727
self .kappa = tt .as_tensor_variable (kappa )
743
728
self .B = tt .dot (self .W , self .W .T ) + tt .diag (self .kappa )
744
729
elif B is not None :
745
730
self .B = tt .as_tensor_variable (B )
746
731
else :
747
- raise ValueError (
748
- "Exactly one of (W, kappa) and B must be provided to Coregion"
749
- )
732
+ raise ValueError ("Exactly one of (W, kappa) and B must be provided to Coregion" )
750
733
751
734
def full (self , X , Xs = None ):
752
735
X , Xs = self ._slice (X , Xs )
0 commit comments