bndl commited on
Commit
6ff4a05
·
1 Parent(s): 54e032e

Update domain_space.py

Browse files
Files changed (1) hide show
  1. domain_space.py +117 -116
domain_space.py CHANGED
@@ -3,129 +3,130 @@ import pandas as pd
3
  import os
4
  import matplotlib.pyplot as plt
5
 
6
- from utils import unpickle_file, scale_numerical_w_missing
 
7
  import plotly.express as px
8
  from gradio_utils import load_theme
9
- from alloy_data_preprocessing import add_physics_features
10
- from inference_model_main import predict_all_results
11
  import plotly.graph_objects as go
12
  import yaml
13
  import numpy as np
14
 
15
 
16
- def run_predictions(
17
- df,
18
- scaler_inputs_path,
19
- main_model_path,
20
- main_input_cols_order,
21
- intermediate_model_path,
22
- intermediate_results_columns,
23
- ):
24
- """
25
- Scale the data and runs the predictions on the intermediate columns and the final properties
26
- """
27
- scaler_inputs = unpickle_file(scaler_inputs_path)
28
- df_p = add_physics_features(df)
29
- df_scaled = scale_numerical_w_missing(df_p, scaler_inputs.feature_names_in_, scaler_inputs)
30
-
31
- y_pred, uncertainty = predict_all_results(
32
- df_scaled,
33
- main_model_path,
34
- main_input_cols_order,
35
- scaler_targets_main=None,
36
- intermediate_model_path=intermediate_model_path,
37
- intermediate_results_columns=intermediate_results_columns,
38
- return_uncertainty=True,
39
- uncertainty_type="weighted",
40
- )
41
-
42
- return y_pred, uncertainty
43
-
44
-
45
- def create_domain_space(space_dict, inference_dict, df_path):
46
- """
47
- Create the dataframe containing the pre-computed values for the uncertainty
48
- """
49
- input_cols = ["%C", "%Co", "%Cr", "%V", "%Mo", "%W", "Temperature_C"]
50
-
51
- c = space_dict["%C"]["value"]
52
- co = space_dict["%Co"]["value"]
53
- cr = space_dict["%Cr"]["value"]
54
- v = space_dict["%V"]["value"]
55
- mo = space_dict["%Mo"]["value"]
56
- w = space_dict["%W"]["value"]
57
- temp = 538
58
- space_list = [
59
- [ic, ico, icr, iv, imo, iw, temp]
60
- for ic in np.arange(
61
- space_dict["%C"]["min"], space_dict["%C"]["max"] + space_dict["%C"]["step"], space_dict["%C"]["step"]
62
- )
63
- for ico in np.arange(
64
- space_dict["%Co"]["min"], space_dict["%Co"]["max"] + space_dict["%Co"]["step"], space_dict["%Co"]["step"]
65
- )
66
- for icr in np.arange(
67
- space_dict["%Cr"]["min"], space_dict["%Cr"]["max"] + space_dict["%Cr"]["step"], space_dict["%Cr"]["step"]
68
- )
69
- for iv in np.arange(
70
- space_dict["%V"]["min"], space_dict["%V"]["max"] + space_dict["%V"]["step"], space_dict["%V"]["step"]
71
- )
72
- for imo in np.arange(
73
- space_dict["%Mo"]["min"], space_dict["%Mo"]["max"] + space_dict["%Mo"]["step"], space_dict["%Mo"]["step"]
74
- )
75
- for iw in np.arange(
76
- space_dict["%W"]["min"], space_dict["%W"]["max"] + space_dict["%W"]["step"], space_dict["%W"]["step"]
77
- )
78
- ]
79
-
80
- df_synth = pd.DataFrame(space_list, columns=input_cols)
81
-
82
- print("Uncertainty space will be computed on:")
83
- print(df_synth.shape)
84
-
85
- model_path = inference_dict["final_prediction"]["model_path"]
86
- print("Model used:", model_path)
87
- scaler_inputs_intermediate = inference_dict["scaler_inputs_path"]
88
- intermediate_cols = [
89
- "%C matrice",
90
- "%Co matrice",
91
- "%Cr matrice",
92
- "%V matrice",
93
- "%Mo matrice",
94
- "%W matrice",
95
- "M6C",
96
- "M23C6",
97
- "FCCA1#2",
98
- "M2C",
99
- "MC - SHP",
100
- "MC ETA",
101
- ]
102
- scaler_inputs_main = unpickle_file(inference_dict["final_prediction"]["scaler_inputs_path"])
103
- intermediate_model_path_dict = inference_dict["multiple_model_path"]
104
-
105
- y_pred, uncertainty = run_predictions(
106
- df_synth,
107
- scaler_inputs_intermediate,
108
- model_path,
109
- scaler_inputs_main.feature_names_in_,
110
- intermediate_model_path_dict,
111
- intermediate_cols,
112
- )
113
- df_synth_pred = df_synth.copy()
114
- df_synth_pred["y_pred"] = y_pred
115
- df_synth_pred["uncertainty_not_scaled"] = uncertainty
116
- min_uncertainty, max_uncertainty = (
117
- df_synth_pred["uncertainty_not_scaled"].min(),
118
- df_synth_pred["uncertainty_not_scaled"].max(),
119
- )
120
- df_synth_pred["uncertainty"] = (df_synth_pred["uncertainty_not_scaled"] - min_uncertainty) / (
121
- max_uncertainty - min_uncertainty
122
- )
123
- print("Domain space created")
124
-
125
- print("-----------------------------")
126
- print("Saving dataframe at", df_path)
127
- df_synth_pred.to_csv(df_path, sep=";", index=False)
128
- return df_synth_pred
129
 
130
 
131
  def load_domain_space(df_path):
 
3
  import os
4
  import matplotlib.pyplot as plt
5
 
6
+ # from utils import unpickle_file, scale_numerical_w_missing
7
+ from utils import unpickle_file
8
  import plotly.express as px
9
  from gradio_utils import load_theme
10
+ # from alloy_data_preprocessing import add_physics_features
11
+ # from inference_model_main import predict_all_results
12
  import plotly.graph_objects as go
13
  import yaml
14
  import numpy as np
15
 
16
 
17
+ # def run_predictions(
18
+ # df,
19
+ # scaler_inputs_path,
20
+ # main_model_path,
21
+ # main_input_cols_order,
22
+ # intermediate_model_path,
23
+ # intermediate_results_columns,
24
+ # ):
25
+ # """
26
+ # Scale the data and runs the predictions on the intermediate columns and the final properties
27
+ # """
28
+ # scaler_inputs = unpickle_file(scaler_inputs_path)
29
+ # df_p = add_physics_features(df)
30
+ # df_scaled = scale_numerical_w_missing(df_p, scaler_inputs.feature_names_in_, scaler_inputs)
31
+
32
+ # y_pred, uncertainty = predict_all_results(
33
+ # df_scaled,
34
+ # main_model_path,
35
+ # main_input_cols_order,
36
+ # scaler_targets_main=None,
37
+ # intermediate_model_path=intermediate_model_path,
38
+ # intermediate_results_columns=intermediate_results_columns,
39
+ # return_uncertainty=True,
40
+ # uncertainty_type="weighted",
41
+ # )
42
+
43
+ # return y_pred, uncertainty
44
+
45
+
46
+ # def create_domain_space(space_dict, inference_dict, df_path):
47
+ # """
48
+ # Create the dataframe containing the pre-computed values for the uncertainty
49
+ # """
50
+ # input_cols = ["%C", "%Co", "%Cr", "%V", "%Mo", "%W", "Temperature_C"]
51
+
52
+ # c = space_dict["%C"]["value"]
53
+ # co = space_dict["%Co"]["value"]
54
+ # cr = space_dict["%Cr"]["value"]
55
+ # v = space_dict["%V"]["value"]
56
+ # mo = space_dict["%Mo"]["value"]
57
+ # w = space_dict["%W"]["value"]
58
+ # temp = 538
59
+ # space_list = [
60
+ # [ic, ico, icr, iv, imo, iw, temp]
61
+ # for ic in np.arange(
62
+ # space_dict["%C"]["min"], space_dict["%C"]["max"] + space_dict["%C"]["step"], space_dict["%C"]["step"]
63
+ # )
64
+ # for ico in np.arange(
65
+ # space_dict["%Co"]["min"], space_dict["%Co"]["max"] + space_dict["%Co"]["step"], space_dict["%Co"]["step"]
66
+ # )
67
+ # for icr in np.arange(
68
+ # space_dict["%Cr"]["min"], space_dict["%Cr"]["max"] + space_dict["%Cr"]["step"], space_dict["%Cr"]["step"]
69
+ # )
70
+ # for iv in np.arange(
71
+ # space_dict["%V"]["min"], space_dict["%V"]["max"] + space_dict["%V"]["step"], space_dict["%V"]["step"]
72
+ # )
73
+ # for imo in np.arange(
74
+ # space_dict["%Mo"]["min"], space_dict["%Mo"]["max"] + space_dict["%Mo"]["step"], space_dict["%Mo"]["step"]
75
+ # )
76
+ # for iw in np.arange(
77
+ # space_dict["%W"]["min"], space_dict["%W"]["max"] + space_dict["%W"]["step"], space_dict["%W"]["step"]
78
+ # )
79
+ # ]
80
+
81
+ # df_synth = pd.DataFrame(space_list, columns=input_cols)
82
+
83
+ # print("Uncertainty space will be computed on:")
84
+ # print(df_synth.shape)
85
+
86
+ # model_path = inference_dict["final_prediction"]["model_path"]
87
+ # print("Model used:", model_path)
88
+ # scaler_inputs_intermediate = inference_dict["scaler_inputs_path"]
89
+ # intermediate_cols = [
90
+ # "%C matrice",
91
+ # "%Co matrice",
92
+ # "%Cr matrice",
93
+ # "%V matrice",
94
+ # "%Mo matrice",
95
+ # "%W matrice",
96
+ # "M6C",
97
+ # "M23C6",
98
+ # "FCCA1#2",
99
+ # "M2C",
100
+ # "MC - SHP",
101
+ # "MC ETA",
102
+ # ]
103
+ # scaler_inputs_main = unpickle_file(inference_dict["final_prediction"]["scaler_inputs_path"])
104
+ # intermediate_model_path_dict = inference_dict["multiple_model_path"]
105
+
106
+ # y_pred, uncertainty = run_predictions(
107
+ # df_synth,
108
+ # scaler_inputs_intermediate,
109
+ # model_path,
110
+ # scaler_inputs_main.feature_names_in_,
111
+ # intermediate_model_path_dict,
112
+ # intermediate_cols,
113
+ # )
114
+ # df_synth_pred = df_synth.copy()
115
+ # df_synth_pred["y_pred"] = y_pred
116
+ # df_synth_pred["uncertainty_not_scaled"] = uncertainty
117
+ # min_uncertainty, max_uncertainty = (
118
+ # df_synth_pred["uncertainty_not_scaled"].min(),
119
+ # df_synth_pred["uncertainty_not_scaled"].max(),
120
+ # )
121
+ # df_synth_pred["uncertainty"] = (df_synth_pred["uncertainty_not_scaled"] - min_uncertainty) / (
122
+ # max_uncertainty - min_uncertainty
123
+ # )
124
+ # print("Domain space created")
125
+
126
+ # print("-----------------------------")
127
+ # print("Saving dataframe at", df_path)
128
+ # df_synth_pred.to_csv(df_path, sep=";", index=False)
129
+ # return df_synth_pred
130
 
131
 
132
  def load_domain_space(df_path):