%%HTML<style>div.prompt {display:none}</style>
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(color_codes=True)
%matplotlib inline
import sys
import time
import gradient_descent_with_momentum as gdt
Generamos la muestra de grado 4
grado=4
tamano=100000
x,y,coeficentes=gdt.generar_muestra(grado,tamano)
print ("Coeficientes: ",coeficentes)
plt.plot(x,y,'.')
Calcular los coeficientes que mejor se ajusten a la muestra sabiendo que es de grado 4
train_x=gdt.generar_matriz_coeficientes(x,grado)
train_y=np.reshape(y,(y.shape[0],-1))
learning_rate_inicial=1e-2
gdt.gradient_descent_with_momentum(
train_x,
train_y,
num_mini_batch=1,
learning_rate_inicial=learning_rate_inicial,
momentum=0.0)
gdt.gradient_descent_with_momentum(
train_x,
train_y,
num_mini_batch=10000,
learning_rate_inicial=learning_rate_inicial,
momentum=0.0)
gdt.gradient_descent_with_momentum(
train_x,
train_y,
num_mini_batch=10000,
learning_rate_inicial=learning_rate_inicial,
momentum=0.9)
gdt.gradient_descent_with_momentum(
train_x,
train_y,
num_mini_batch=len(train_x),
learning_rate_inicial=learning_rate_inicial,
momentum=0.9)
gdt.gradient_descent_with_momentum(
train_x,
train_y,
num_mini_batch=len(train_x),
learning_rate_inicial=1e-3, # Disminuimos la tasa de aprendizaje
momentum=0.9)