|
|
import numpy as np |
|
|
import pandas as pd |
|
|
|
|
|
np.random.seed(42) |
|
|
epsilon = 1e-8 |
|
|
|
|
|
class Dataset: |
|
|
def __init__(self, mat_name='FRP'): |
|
|
filename = './Data/240_simulations_DS.xlsx' |
|
|
self.df = pd.read_excel(filename, sheet_name=mat_name, header=1) |
|
|
|
|
|
self.input_columns = [ |
|
|
'Gate Location', |
|
|
'Matrix', |
|
|
'Fiber Type', |
|
|
'Fiber wt%(Volume Fractions)', |
|
|
|
|
|
'Packing Pressure (MPa)', |
|
|
'Packing Time (s)', |
|
|
'Mold Temperature (°C)', |
|
|
'Injection Speed (cm^3/s)' |
|
|
] |
|
|
self.output_columns = ['Alpha_angle_deg(ABS)', 'Beta_angle_deg(ABS)', 'Gamma_angle_deg(ABS)'] |
|
|
|
|
|
self.material_map = {'PA6': 0, 'PP': 1} |
|
|
self.fiber_map = {'CF': 0, 'GF': 1} |
|
|
self.combination_map = {'PA6-CF-10': 0, 'PA6-CF-15': 1, 'PA6-CF-30': 2, 'PA6-CF-40': 3, |
|
|
'PA6-GF-15': 4, 'PA6-GF-30': 5, 'PA6-GF-40': 6, 'PA6-GF-50': 7, |
|
|
'PP-CF-10': 8, 'PP-CF-15': 9, 'PP-CF-30': 10, 'PP-CF-40': 11, |
|
|
'PP-GF-15': 12, 'PP-GF-30': 13, 'PP-GF-40': 14, 'PP-GF-50': 15} |
|
|
self.df['Matrix'] = self.df['Matrix'].map(self.material_map) |
|
|
self.df['Fiber Type'] = self.df['Fiber Type'].map(self.fiber_map) |
|
|
self.df['Fiber-Matrix Combination'] = self.df['Fiber-Matrix Combination'].map(self.combination_map) |
|
|
self.df['Fiber wt%(Volume Fractions)'] = self.df['Fiber wt%(Volume Fractions)'] / 100.0 |
|
|
|
|
|
self.input_mean = self.df[self.input_columns].mean().to_numpy(dtype=np.float32) |
|
|
self.input_std = self.df[self.input_columns].std().to_numpy(dtype=np.float32) + epsilon |
|
|
self.output_mean = self.df[self.output_columns].mean().to_numpy(dtype=np.float32) |
|
|
self.output_std = self.df[self.output_columns].std().to_numpy(dtype=np.float32) + epsilon |
|
|
|
|
|
|
|
|
def get_input(self, normalize=False): |
|
|
data = self.df[self.input_columns].to_numpy(dtype=np.float32) |
|
|
if normalize: |
|
|
data = self.normalize_input(data) |
|
|
return data |
|
|
|
|
|
|
|
|
def get_output(self, normalize=False): |
|
|
data = self.df[self.output_columns].to_numpy(dtype=np.float32) |
|
|
if normalize: |
|
|
data = self.normalize_output(data) |
|
|
return data |
|
|
|
|
|
def __str__(self): |
|
|
return str(self.df.head()) |
|
|
|
|
|
def normalize_input(self, input_data): |
|
|
return (input_data - self.input_mean) / self.input_std |
|
|
|
|
|
def normalize_output(self, output_data): |
|
|
return (output_data - self.output_mean) / self.output_std |
|
|
|
|
|
def denormalize_input(self, normalized_input): |
|
|
return normalized_input * self.input_std + self.input_mean |
|
|
|
|
|
def denormalize_output(self, normalized_output): |
|
|
return normalized_output * self.output_std + self.output_mean |
|
|
|
|
|
if __name__ == "__main__": |
|
|
dataset = Dataset() |
|
|
|
|
|
|
|
|
input_data = dataset.get_input(normalize=False) |
|
|
output_data = dataset.get_output(normalize=False) |
|
|
|
|
|
print("Input shape:", input_data.shape) |
|
|
print("Output shape:", output_data.shape) |