Spaces:
Sleeping
Sleeping
Update domain_space.py
Browse files- 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 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
):
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
def create_domain_space(space_dict, inference_dict, df_path):
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
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):
|