# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
import keras
import pandas as pd
import os
import tensorflow as tf
from keras.callbacks import ModelCheckpoint, EarlyStopping
from keras.models import Sequential, Model
from keras.layers import Dense, InputLayer, Input
import keras.backend as K

from sklearn.model_selection import KFold
from sklearn.model_selection import train_test_split


def custom_loss(layer):
    def loss(y_true,y_pred):
        return K.mean(K.mean(K.square(y_pred - y_true)) + K.square(layer), axis=-1)
    return loss

model = Sequential()
model.add(Dense(3))
model.add(Dense(16, activation='relu'))
model.add(Dense(32, activation='relu'))
model.add(Dense(16, activation='relu'))
model.add(Dense(4))

# inputs = Input(shape=(3,))
# layer1 = Dense(16, activation='relu')(inputs)
# layer2 = Dense(32, activation='relu')(layer1)
# predictions = Dense(4)(layer2)
# model = Model(inputs=inputs, outputs=predictions)

# f = custom_loss(inputs)
model.compile(loss='mse', optimizer='SGD', metrics=['mse'])


# +
dir_path = '../../../experiments_prokhn/controllers/mined'
data = []
for file_name in [i for i in os.listdir(dir_path) if '.csv' in i]:
    _data = pd.read_csv(os.path.join(dir_path, file_name), sep=';', engine='python')
    _data.columns = ['delta1', 'delta2', 'delta3', 'v1', 'v2', 'v3', 'v4']
    data.append(_data)
data = pd.concat(data, axis=0)

columns = [column for column in data.columns if 'delta' in column]
x = data[columns].values
y = data.drop(columns, axis=1).values
model.fit(x, y, batch_size=64, epochs=1, validation_split=0.2, shuffle=True, 
              callbacks=[ModelCheckpoint('model.hd5', save_best_only=True), 
                         EarlyStopping(monitor='val_loss', min_delta=0.0001, patience=20)])
# print(y)
# print(x)
# -

import numpy as np
model.predict(np.array([[1, 1, 1]]))

print(x)



StarcoderdataJupyterScriptsDedupFiltered