File size: 3,146 Bytes
6977ea8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
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)
        # normalize data
        self.input_columns = [
            'Gate Location', 
            'Matrix', 
            'Fiber Type', 
            'Fiber wt%(Volume Fractions)', 
            # 'Fiber-Matrix Combination',
            '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()
    
    # Example usage
    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)