10
10
11
11
from ..base import BaseEstimator , RegressorMixin
12
12
from ..metrics .pairwise import manhattan_distances
13
- from ..utils import array2d
13
+ from ..utils import array2d , check_random_state
14
14
from . import regression_models as regression
15
15
from . import correlation_models as correlation
16
16
@@ -163,6 +163,11 @@ class GaussianProcess(BaseEstimator, RegressorMixin):
163
163
exponential distribution (log-uniform on [thetaL, thetaU]).
164
164
Default does not use random starting point (random_start = 1).
165
165
166
+ random_state: integer or numpy.RandomState, optional
167
+ The generator used to shuffle the sequence of coordinates of theta in
168
+ the Welch optimizer. If an integer is given, it fixes the seed.
169
+ Defaults to the global numpy random number generator.
170
+
166
171
Examples
167
172
--------
168
173
>>> import numpy as np
@@ -212,7 +217,7 @@ def __init__(self, regr='constant', corr='squared_exponential', beta0=None,
212
217
storage_mode = 'full' , verbose = False , theta0 = 1e-1 ,
213
218
thetaL = None , thetaU = None , optimizer = 'fmin_cobyla' ,
214
219
random_start = 1 , normalize = True ,
215
- nugget = 10. * MACHINE_EPSILON ):
220
+ nugget = 10. * MACHINE_EPSILON , random_state = None ):
216
221
217
222
self .regr = regr
218
223
self .corr = corr
@@ -226,6 +231,7 @@ def __init__(self, regr='constant', corr='squared_exponential', beta0=None,
226
231
self .nugget = nugget
227
232
self .optimizer = optimizer
228
233
self .random_start = random_start
234
+ self .random_state = random_state
229
235
230
236
# Run input checks
231
237
self ._check_params ()
@@ -250,6 +256,7 @@ def fit(self, X, y):
250
256
A fitted Gaussian Process model object awaiting data to perform
251
257
predictions.
252
258
"""
259
+ self .random_state = check_random_state (self .random_state )
253
260
254
261
# Force data to 2D numpy.array
255
262
X = array2d (np .asarray (X ))
@@ -748,7 +755,7 @@ def minus_reduced_likelihood_function(log10t):
748
755
# Iterate over all dimensions of theta allowing for anisotropy
749
756
if verbose :
750
757
print ("Now improving allowing for anisotropy..." )
751
- for i in np . random . permutation (range (theta0 .size )):
758
+ for i in self . random_state . shuffle (range (theta0 .size )):
752
759
if verbose :
753
760
print "Proceeding along dimension %d..." % (i + 1 )
754
761
self .theta0 = array2d (theta_iso )
0 commit comments