Skip to content

3D Prediction#

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['figure.dpi'] = 120

from mesh_predictor import MeshPredictor
doe = pd.read_csv('../data/doe.csv')
data = pd.read_csv('../data/zt_all_raw.csv')
data.drop(data[data.doe_id == 1000].index, inplace=True)
data.drop(data[data.doe_id == 247].index, inplace=True)
reg = MeshPredictor()
reg.load_data(
    doe = doe,
    data = data,
    index='doe_id',
    process_parameters = [
        'Blechdicke', 
        'Niederhalterkraft', 
        'Ziehspalt', 
        'Einlegeposition', 
        'Ziehtiefe',
        'Rp0',
    ],
    categorical = [
        'Ziehspalt', 
        'Ziehtiefe',
    ],
    position = ['x', 'y', 'z'],
    output = ['deviation', 'thickness'],
    validation_split=0.1,
    validation_method='leaveoneout'
)
reg.save_config("../models/3d_deviation.pkl")
reg.data_summary()
Data summary
------------------------------------------------------------

Process parameters:
    - Blechdicke : numerical [ 0.99  ...  1.48 ]
    - Niederhalterkraft : numerical [ 10  ...  500 ]
    - Ziehspalt : categorical [1.6, 2.4]
    - Einlegeposition : numerical [ -5  ...  5 ]
    - Ziehtiefe : categorical [30, 50, 70]
    - Rp0 : numerical [ 133.18263199999998  ...  296.5565 ]
Input variables:
    - x : numerical, [ 0.6284683333330582 / 192.3881 ] 
    - y : numerical, [ -119.922 / 94.40363333333332 ] 
    - z : numerical, [ -73.0 / 0.0 ] 
Output variable(s):
    - deviation : numerical, [ -3.4451234340667702 / 8.456118583679201 ]
    - thickness : numerical, [ 0.8401499390602108 / 1.7142115831375102 ]

Inputs (25043148, 12)
Outputs (25043148, 2)
Total number of experiments: 879
Total number of samples: 25043148
Number of training samples: 22538833
Number of test samples: 2504315

config = {
    'batch_size': 2048*16,
    'max_epochs': 20,
    'layers': [256, 256, 256, 256, 256],
    'dropout': 0.0,
    'learning_rate': 0.001,
    'activation': 'lrelu'
}

reg.custom_model(save_path='../models/current_3d_model', config=config, verbose=True)
reg.training_summary()
reg.load_network('../models/current_3d_model')
idx = np.random.choice(data['doe_id'].unique()) 
print("Doe_ID", idx)
p, t, y = reg.compare(idx)
Doe_ID 368

geometry_50 = pd.read_csv('../data/geometry_zt50.csv')

parameters = {
    'Blechdicke': 1.01, 
    'Niederhalterkraft': 410.0, 
    'Ziehspalt': 2.4, 
    'Einlegeposition': 0, 
    'Stempel_ID': 3,
    'Ziehtiefe': 50,
    'E': 191.37245,
    'Rp0': 138.22696,
    'Rp50': 449.528189,
}

positions = geometry_50[['x', 'y', 'z']].to_numpy()
df = reg.predict(parameters, positions, as_df=True)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
p = ax.scatter(positions[:, 0], positions[:, -2], positions[:, -1], 
    c=df['thickness'], 
    cmap='seismic') 
fig.colorbar(p, ax=ax)
<matplotlib.colorbar.Colorbar at 0x147a557f0>
%matplotlib inline
plt.rcParams['figure.dpi'] = 120

positions_zt30 = pd.read_csv('../data/geometry_zt30.csv')[['x', 'y', 'z']].to_numpy()
positions_zt50 = pd.read_csv('../data/geometry_zt50.csv')[['x', 'y', 'z']].to_numpy()
positions_zt70 = pd.read_csv('../data/geometry_zt70.csv')[['x', 'y', 'z']].to_numpy()

reg.interactive(positions_zt30)