Skip to content

2D Projection prediction#

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

Loading the data#

doe = pd.read_csv('../data/doe.csv')
data = pd.read_csv('../data/projection.csv')
data.drop(data[data.doe_id == 1000].index, inplace=True)
data.drop(data[data.doe_id == 247].index, inplace=True)
from mesh_predictor import ProjectionPredictor

reg = ProjectionPredictor()
reg.load_data(
    doe = doe,
    data = data,
    index='doe_id',
    process_parameters = [
        'Blechdicke', 
        'Niederhalterkraft', 
        'Ziehspalt', 
        'Einlegeposition', 
        'Ziehtiefe',
        'Rp0',
    ],
    categorical = [
        'Ziehspalt', 
        'Ziehtiefe',
    ],
    position = ['xp', 'yp'],
    output = ['deviation', 'thickness'],
    validation_split=0.1,
    validation_method='leaveoneout'
)
reg.save_config("../models/projection.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]
    - Stempel_ID : categorical [2, 3]
Input variables:
    - xp : numerical, [ -22.66964 / 170.8974 ] 
    - yp : numerical, [ -152.0864 / 137.1274 ] 
Output variable(s):
    - deviation : numerical, [ -25.10696155974797 / 6.331377221700899 ]
    - thickness : numerical, [ 0.8450137 / 1.689039 ]

Inputs (10477680, 12)
Outputs (10477680, 2)
Total number of experiments: 879
Total number of samples: 10477680
Number of training samples: 9440640
Number of test samples: 1037040
Number of experiments in the test set: 87

config = {
    'batch_size': 4096*16,
    'max_epochs': 5,
    'layers': [256, 256, 256, 256, 256],
    'dropout': 0.0,
    'learning_rate': 0.001
}

reg.custom_model(save_path='../models/best_projection_model', config=config, verbose=True)
reg.training_summary()
reg.load_network('../models/best_projection_model')
x, y = reg.predict({
        'Blechdicke': 1.01, 
        'Niederhalterkraft': 410.0, 
        'Ziehspalt': 2.4, 
        'Einlegeposition': -5, 
        'Ziehtiefe': 30,
        'Stempel_ID': 3,
    }, 
    shape=(1000, 1000))

plt.figure()
plt.imshow(y[0, :, :].T)
plt.colorbar()
plt.figure()
plt.imshow(y[1, :, :].T)
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x318748c70>
idx = np.random.choice(1000) + 1
print("Doe_ID", idx)
reg.compare(idx)
Doe_ID 758

%matplotlib inline
plt.rcParams['figure.dpi'] = 150

def viz(x, y):

    plt.figure()
    plt.imshow(y[0, :, :].T)
    plt.colorbar()
    plt.figure()
    plt.imshow(y[1, :, :].T)
    plt.colorbar()

reg.interactive(function=viz, positions=(1000, 1000))