Created
October 5, 2021 15:24
-
-
Save germankatz/fba768a53f2937d3b455beac0d158362 to your computer and use it in GitHub Desktop.
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
import numpy as np | |
from math import dist | |
dimRed = [10, 10] # 10x10 | |
etapas = [750, 1000, 3000] | |
n = 0 # Contador de etapas | |
epoca = 0 # Contador de epoca | |
corriendo = True | |
def tasa_apren(epoca, n, etp): | |
if n == 0: | |
return 0.9 | |
if n == 1: | |
return (0.01 - 0.9) * epoca / etp[1] | |
return 0.01 | |
def entorno(epoca, n, etp): # o vecindad | |
if n == 0: | |
return 0.9 | |
if n == 1: | |
return (0.01 - 0.9) * epoca / etp[1] | |
return 0.01 | |
x = [[1, 1], [2, 2]] | |
while epoca < etapas[n] and corriendo: | |
# Genero mis pesos | |
w = np.random.randint(0, 2, dimRed) | |
# Recorro cada uno de mis pesos y me fijo cual es el mas cercano | |
minSuma = w.max() | |
minIndex = np.unravel_index(np.argmax(w, axis=None), w.shape) | |
for i, neurona in np.ndenumerate(w): # neurona tiene el valor, i tiene forma (0,0), (0,1), ... | |
sumaDistancias = 0 # Suma distancias | |
for j, entrada in np.ndenumerate(x): # entrada tiene el valor, j tiene forma (0,0), (0,1), ... | |
sumaDistancias = sumaDistancias + dist(entrada, neurona) | |
sumaDistancias = sumaDistancias / len(x.flat) # Promedio de distancias | |
if sumaDistancias < minSuma: | |
minSuma = sumaDistancias | |
minIndex = i | |
epoca = epoca + 1 | |
if epoca == etapas[n]: | |
n = n + 1 # Voy a la siguiente etapa | |
if n > 3: | |
corriendo = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment