<jupyter_start><jupyter_text>Gráficas de funciones de activación en Keras<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow.keras as keras



def plot_activation(figure,nrows, ncols, index,x,y,nombre):
    
    axis = figure.add_subplot(nrows, ncols, index)

    axis.plot(x, y,color="#0056B8") 

    axis.set_title(nombre, fontsize=20,pad=0,color="#003B80")
    axis.set_facecolor("#F0F7FF")
    axis.grid(b=True, which='major', axis='both',color="#FFFFFF",linewidth=3)
    axis.grid(b=True, which='minor', axis='both',color="#FFFFFF",linewidth=1)

figure=plt.figure(figsize=(25,10))
figure.subplots_adjust(wspace=2, hspace=0.2)

x=np.linspace(-10,10,50)
y=tf.keras.activations.sigmoid(x).numpy()
plot_activation(figure,2,16,(1,4),x,y,"sigmoid")

x=np.linspace(-10,10,50)
y=tf.keras.activations.tanh(x).numpy()
plot_activation(figure,2,16,(5,8),x,y,"tanh")

x=np.linspace(-10,10,50)
y=tf.keras.activations.softsign(x).numpy()
plot_activation(figure,2,16,(9,12),x,y,"softsign")

x=np.linspace(-10,10,50)
y=tf.keras.activations.relu(x,alpha=0.1).numpy()
plot_activation(figure,2,16,(13,16),x,y,"relu α=0.1")

x=np.linspace(-10,10,50)
y=tf.keras.activations.softplus(x).numpy()
plot_activation(figure,2,16,(17,20),x,y,"softplus")

x=np.linspace(-10,10,50)
y=tf.keras.activations.selu(x).numpy()
plot_activation(figure,2,16,(21,24),x,y,"selu")

x=np.linspace(-10,10,50)
y=tf.keras.activations.elu(x,alpha=2).numpy()
plot_activation(figure,2,16,(25,28),x,y,"elu α=2")

x=np.linspace(-10,10,50)
y=tf.keras.activations.exponential(x).numpy()
plot_activation(figure,2,16,(29,33),x,y,"exponential")

figure.savefig("funciones_activacion.png",facecolor="#FFFFFF",bbox_inches='tight')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup