# -*- coding: utf-8 -*-
"""
Created on Wed Nov 24 15:44:12 2021

@author: virgi
"""

import tensorflow as tf
import matplotlib.pyplot as plt
from fonction_activation import *

from Creation_donnee import *
import numpy as np

n=20
#création de la base de donnéé
X,Y=creation_sin(-15,-8,n,1,)
X2,Y2=creation_sin(10,18,n,1,)
X=np.concatenate([X,X2])
Y=np.concatenate([Y,Y2])

n=10000
Xv,Yv=creation_sin(-20,20,n,1)


model_ReLU=tf.keras.models.Sequential()


model_ReLU.add(tf.keras.Input(shape=(1,)))

model_ReLU.add(tf.keras.layers.Dense(64, activation='relu'))
model_ReLU.add(tf.keras.layers.Dense(64, activation='relu'))
model_ReLU.add(tf.keras.layers.Dense(64, activation='relu'))
model_ReLU.add(tf.keras.layers.Dense(64, activation='relu'))
model_ReLU.add(tf.keras.layers.Dense(64, activation='relu'))


model_ReLU.add(tf.keras.layers.Dense(1))

# Choix de la méthode d'optimisation
opti=tf.keras.optimizers.Adam()
# Compilation du graphe et choix de la fonction de coût
model_ReLU.compile(opti, loss='mse', metrics=['accuracy'])

model_ReLU.summary()



model_ReLU.fit(X, Y, batch_size=1, epochs=10, shuffle='True',validation_data=(Xv, Yv))



model_snake=tf.keras.models.Sequential()

model_snake.add(tf.keras.Input(shape=(1,)))

model_snake.add(tf.keras.layers.Dense(64, activation=snake))
model_snake.add(tf.keras.layers.Dense(64, activation=snake))
model_snake.add(tf.keras.layers.Dense(64, activation=snake))
model_snake.add(tf.keras.layers.Dense(64, activation=snake))
model_snake.add(tf.keras.layers.Dense(64, activation=snake))


model_snake.add(tf.keras.layers.Dense(1))

opti=tf.keras.optimizers.Adam()

model_snake.compile(opti, loss='mse', metrics=['accuracy'])


model_snake.summary()

model_snake.fit(X, Y, batch_size=1, epochs=10, shuffle='True',validation_data=(Xv, Yv))









Y_predis_snake=model_snake.predict(X)
Y_predis_validation_snake=model_snake.predict(Xv)

Y_predis_ReLU=model_ReLU.predict(X)
Y_predis_validation_ReLU=model_ReLU.predict(Xv)





plt.figure()
plt.plot(X,Y,'x',label='donnée')
plt.plot(Xv,Yv,label="validation")
plt.plot(X,Y_predis_ReLU,'o',label='prediction sur les donné')
plt.plot(Xv,Y_predis_validation_ReLU,label='prediction sur la validation')
plt.legend()
plt.show()

plt.figure()
plt.plot(X,Y,'x',label='donnée')
plt.plot(Xv,Yv,label="validation")
plt.plot(X,Y_predis_snake,'o',label='prediction sur les donné avec snake comme activation')
plt.plot(Xv,Y_predis_validation_snake,label='prediction sur la validation avec snake comme activation')
plt.legend()
plt.show()

