Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set random seed for python/numpy/tf during nn training #236

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions nmma/em/create_svdmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ def main():
default=False,
help="Refresh the list of models available on Zenodo",
)
parser.add_argument(
"--random-seed",
type=int,
default=42,
help="random seed to set during training",
)
args = parser.parse_args()

refresh = False
Expand Down Expand Up @@ -246,6 +252,7 @@ def main():
ncpus=args.ncpus,
univariate_spline=args.use_UnivariateSpline,
univariate_spline_s=args.UnivariateSpline_s,
random_seed=args.random_seed,
)

light_curve_model = SVDLightCurveModel(
Expand Down
6 changes: 4 additions & 2 deletions nmma/em/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(
ncpus=1,
univariate_spline=False,
univariate_spline_s=2,
random_seed=42,
):

if interpolation_type not in ["sklearn_gp", "tensorflow", "api_gp"]:
Expand All @@ -82,6 +83,7 @@ def __init__(
self.ncpus = ncpus
self.univariate_spline = univariate_spline
self.univariate_spline_s = univariate_spline_s
self.random_seed = random_seed
if self.univariate_spline:
print("The grid will be interpolated to sample_time with UnivariateSpline")
else:
Expand Down Expand Up @@ -397,10 +399,10 @@ def train_tensorflow_model(self, dropout_rate=0.6):
cAmat.T,
shuffle=True,
test_size=0.1,
random_state=8581,
random_state=self.random_seed,
)

np.random.RandomState(42)
tf.keras.utils.set_random_seed(self.random_seed)
model = Sequential()
# One/few layers of wide NN approximate GP
model.add(
Expand Down
Loading