Skip to content

Commit

Permalink
Fixing bug in normalization (ORNL#82)
Browse files Browse the repository at this point in the history
* fix an indexing bug in denormalization

* add min/max loading from pkl
  • Loading branch information
pzhanggit authored Dec 20, 2021
1 parent 08df317 commit 84e70f4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 4 additions & 5 deletions hydragnn/postprocess/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

def output_denormalize(y_minmax, true_values, predicted_values):
for ihead in range(len(y_minmax)):
for isample in range(len(predicted_values[0])):
for iatom in range(len(predicted_values[ihead][0])):
ymin = y_minmax[ihead][0]
ymax = y_minmax[ihead][1]

ymin = y_minmax[ihead][0]
ymax = y_minmax[ihead][1]
for isample in range(len(predicted_values[ihead])):
for iatom in range(len(predicted_values[ihead][isample])):
predicted_values[ihead][isample][iatom] = (
predicted_values[ihead][isample][iatom] * (ymax - ymin) + ymin
)
Expand Down
3 changes: 3 additions & 0 deletions hydragnn/run_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from hydragnn.utils.config_utils import (
update_config_NN_outputs,
get_model_output_name_config,
normalize_output_config,
)
from hydragnn.utils.model import calculate_PNA_degree
from hydragnn.models.create import create_model_config
Expand Down Expand Up @@ -62,6 +63,8 @@ def _(config: dict):
)
config = update_config_NN_outputs(config, graph_size_variable)

config = normalize_output_config(config)

config["NeuralNetwork"]["Architecture"]["input_dim"] = len(
config["NeuralNetwork"]["Variables_of_interest"]["input_node_features"]
)
Expand Down
11 changes: 7 additions & 4 deletions hydragnn/utils/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ def update_config_NN_outputs(config, graph_size_variable):
def normalize_output_config(config):
var_config = config["NeuralNetwork"]["Variables_of_interest"]
if "denormalize_output" in var_config and var_config["denormalize_output"]:
if "total" in config["Dataset"]["path"].keys():
dataset_path = f"{os.environ['SERIALIZED_DATA_PATH']}/serialized_dataset/{config['Dataset']['name']}.pkl"
###loading min/max values from input data file. Only one path is needed
if list(config["Dataset"]["path"].values())[0].endswith(".pkl"):
dataset_path = list(config["Dataset"]["path"].values())[0]
else:
###used for min/max values loading below
dataset_path = f"{os.environ['SERIALIZED_DATA_PATH']}/serialized_dataset/{config['Dataset']['name']}_train.pkl"
if "total" in config["Dataset"]["path"].keys():
dataset_path = f"{os.environ['SERIALIZED_DATA_PATH']}/serialized_dataset/{config['Dataset']['name']}.pkl"
else:
dataset_path = f"{os.environ['SERIALIZED_DATA_PATH']}/serialized_dataset/{config['Dataset']['name']}_train.pkl"
var_config = update_config_minmax(dataset_path, var_config)
else:
var_config["denormalize_output"] = False
Expand Down

0 comments on commit 84e70f4

Please sign in to comment.