From b709df5840921d2e7b437f50f39ffe51957f7391 Mon Sep 17 00:00:00 2001 From: Silviu Marian Udrescu Date: Sat, 20 Jun 2020 04:36:49 -0400 Subject: [PATCH] Add files via upload --- Code/RPN_to_pytorch.py | 4 ++++ Code/S_final_gd.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Code/RPN_to_pytorch.py b/Code/RPN_to_pytorch.py index 8e696bf..fb3b971 100644 --- a/Code/RPN_to_pytorch.py +++ b/Code/RPN_to_pytorch.py @@ -109,6 +109,10 @@ def RPN_to_pytorch(pathdir,filename, math_expr, lr = 1e-2, N_epochs = 500): trainable_parameters[j] -= lr * trainable_parameters[j].grad trainable_parameters[j].grad.zero_() + for nan_i in range(len(trainable_parameters)): + if torch.isnan(trainable_parameters[nan_i])==True or abs(trainable_parameters[nan_i])>1e7: + return 1000000, 10000000, "1" + ii = -1 for parm in unsnapped_param_dict: if ii == -1: diff --git a/Code/S_final_gd.py b/Code/S_final_gd.py index 3597634..d73def2 100644 --- a/Code/S_final_gd.py +++ b/Code/S_final_gd.py @@ -119,7 +119,11 @@ def final_gd(pathdir,filename, math_expr, lr = 1e-2, N_epochs = 5000): for j in range(N_params-1): trainable_parameters[j] -= lr/10 * trainable_parameters[j].grad trainable_parameters[j].grad.zero_() - + + for nan_i in range(len(trainable_parameters)): + if torch.isnan(trainable_parameters[nan_i])==True or abs(trainable_parameters[nan_i])>1e7: + return 1000000, 10000000, "1" + # get the updated symbolic regression ii = -1 for parm in unsnapped_param_dict: