This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generar_matriz_coeficientes(datos:np.array, grado:int=1): | |
matriz_coeficientes = np.ones((len(datos), grado), dtype=np.float32) | |
for elevado in range(1, grado): | |
matriz_coeficientes[:, elevado] = np.power(datos, elevado) | |
return matriz_coeficientes | |
>>>generar_matriz_coeficientes(np.array([3,2]),grado=3) | |
Out[5]: | |
array([[ 1., 3., 9.], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with grafo_gradiente_descendente.as_default(): | |
# Entrada de los datos | |
datos_entrada = tf.placeholder(dtype=tf.float32,shape=train_x.shape) | |
datos_salida = tf.placeholder(dtype=tf.float32,shape=train_y.shape) | |
# Inicilizacion de la variable | |
pesos = tf.Variable(tf.zeros([datos_entrada.get_shape()[1], 1])) | |
# Definimos funcion coste |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_x = ... | |
train_y = ... | |
def get_minibatches(x_train,y_train,indices): | |
for idx in indices: | |
yield x_train[idx],y_train[idx] | |
with tf.Session(graph=grafo_gradiente_descendente) as sesion_SGD: | |
tf.initialize_all_variables().run() | |
for _ in range(iteraciones_maximas): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_x = ... | |
train_y = ... | |
with tf.Session(graph=grafo_gradiente_descendente) as sesion_SG: | |
tf.initialize_all_variables().run() | |
for iteracion in range(iteraciones_maximas): | |
_,p,e_ite= sesion_SG.run([optimizador,pesos,ecm],feed_dict={datos_entrada:train_x,datos_salida:train_y}) | |
... |
NewerOlder