Skip to content

Commit 2602acf

Browse files
ENH: Add private RNG normalizer (#14199)
1 parent 1710155 commit 2602acf

94 files changed

Lines changed: 827 additions & 379 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``rng`` parameters to APIs that use randomness, while retaining keyword-only ``seed`` and ``random_state`` for compatibility (:gh:`9233` by `Bruno Aristimunha`_).

examples/datasets/spm_faces_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
raw.resample(100)
3737
raw.filter(1.0, None) # high-pass
3838
reject = dict(mag=5e-12)
39-
ica = ICA(n_components=0.95, max_iter="auto", random_state=0)
39+
ica = ICA(n_components=0.95, max_iter="auto", rng=97)
4040
ica.fit(raw, reject=reject)
4141
# compute correlation scores, get bad indices sorted by score
4242
eog_epochs = create_eog_epochs(raw, ch_name="MRT31-2908", reject=reject)

examples/decoding/decoding_csp_eeg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
scores = []
8181
epochs_data = epochs.get_data(copy=False)
8282
epochs_data_train = epochs_train.get_data(copy=False)
83-
cv = ShuffleSplit(10, test_size=0.2, random_state=42)
83+
cv = ShuffleSplit(10, test_size=0.2, random_state=103)
8484
cv_split = cv.split(epochs_data_train)
8585

8686
# Assemble a classifier

examples/decoding/decoding_csp_timefreq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
LinearDiscriminantAnalysis(),
5454
)
5555
n_splits = 3 # for cross-validation, 5 is better, here we use 3 for speed
56-
cv = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=42)
56+
cv = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=191)
5757

5858
# Classification & time-frequency parameters
5959
tmin, tmax = -0.200, 2.000

examples/decoding/decoding_rsa.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@
125125
# to focus the classifier on the time interval with best SNR.
126126
clf = make_pipeline(
127127
StandardScaler(),
128-
OneVsRestClassifier(LogisticRegression(C=1)),
128+
OneVsRestClassifier(LogisticRegression(C=1, random_state=79)),
129129
)
130130
X = epochs.get_data(tmin=0.05, tmax=0.3).mean(axis=2)
131131
y = epochs.events[:, 2]
132132

133133
classes = set(y)
134-
cv = StratifiedKFold(n_splits=5, random_state=0, shuffle=True)
134+
cv = StratifiedKFold(n_splits=5, random_state=83, shuffle=True)
135135

136136
# Compute confusion matrix for each cross-validation fold
137137
y_pred = np.zeros((len(y), len(classes)))
@@ -173,7 +173,7 @@
173173
chance = 0.5
174174
# TODO VERSION: this is MDS(2, n_init=4, init='random', metric='precomputed'),
175175
# but that spelling requires scikit-learn >= 1.8
176-
summary, _ = smacof(chance - confusion, n_components=2, n_init=4, random_state=0)
176+
summary, _ = smacof(chance - confusion, n_components=2, n_init=4, random_state=89)
177177
cmap = plt.colormaps["rainbow"]
178178
colors = ["r", "b"]
179179
names = list(conds["condition"].values)

examples/decoding/decoding_spatio_temporal_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
clf = make_pipeline(
104104
StandardScaler(), # z-score normalization
105105
SelectKBest(f_classif, k=500), # select features for speed
106-
LinearModel(LogisticRegression(C=1, solver="liblinear")),
106+
LinearModel(LogisticRegression(C=1, solver="liblinear", random_state=107)),
107107
)
108108
time_decod = SlidingEstimator(clf, scoring="roc_auc")
109109

examples/decoding/decoding_spoc_CMC.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
# Classification pipeline with SPoC spatial filtering and Ridge Regression
6262
spoc = SPoC(n_components=2, log=True, reg="oas", rank="full")
63-
clf = make_pipeline(spoc, Ridge())
63+
clf = make_pipeline(spoc, Ridge(random_state=127))
6464
# Define a two fold cross-validation
6565
cv = KFold(n_splits=2, shuffle=False)
6666

examples/decoding/decoding_time_generalization_conditions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
# and test on all right visual vs auditory trials.
7070
clf = make_pipeline(
7171
StandardScaler(),
72-
LogisticRegression(solver="liblinear"), # liblinear is faster than lbfgs
72+
# liblinear is faster than lbfgs
73+
LogisticRegression(solver="liblinear", random_state=131),
7374
)
7475
time_gen = GeneralizingEstimator(clf, scoring="roc_auc", n_jobs=None, verbose=True)
7576

examples/decoding/decoding_unsupervised_spatial_filter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
##############################################################################
6565
# Transform data with PCA computed on the average ie evoked response
66-
pca = UnsupervisedSpatialFilter(PCA(30), average=False)
66+
pca = UnsupervisedSpatialFilter(PCA(30, random_state=193), average=False)
6767
pca_data = pca.fit_transform(X)
6868
ev = mne.EvokedArray(
6969
np.mean(pca_data, axis=0),
@@ -74,7 +74,9 @@
7474

7575
##############################################################################
7676
# Transform data with ICA computed on the raw epochs (no averaging)
77-
ica = UnsupervisedSpatialFilter(FastICA(30, whiten="unit-variance"), average=False)
77+
ica = UnsupervisedSpatialFilter(
78+
FastICA(30, whiten="unit-variance", random_state=197), average=False
79+
)
7880
ica_data = ica.fit_transform(X)
7981
ev1 = mne.EvokedArray(
8082
np.mean(ica_data, axis=0),

examples/decoding/decoding_xdawn_eeg.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@
8080
XdawnTransformer(n_components=n_filter),
8181
Vectorizer(),
8282
MinMaxScaler(),
83-
OneVsRestClassifier(LogisticRegression(solver="liblinear", **kwargs)),
83+
OneVsRestClassifier(
84+
LogisticRegression(solver="liblinear", random_state=157, **kwargs)
85+
),
8486
)
8587

8688
# Get the data and labels
@@ -89,7 +91,7 @@
8991
y = epochs.events[:, -1]
9092

9193
# Cross validator
92-
cv = StratifiedKFold(n_splits=10, shuffle=True, random_state=42)
94+
cv = StratifiedKFold(n_splits=10, shuffle=True, random_state=163)
9395

9496
# Do cross-validation
9597
preds = np.empty(len(y))

0 commit comments

Comments
 (0)