Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Programs/Perceptron_OOP/Clase_perceptron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class perceptron:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Las clases por convención se declaran con Mayúsculas, esto es Perceptron


def insert_matriz(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recomendaría que no cargue elemento a elemento los datos. Esto esta bien para ejemplos tipo toy como AND y OR y XOR, pero si tengo cientos de datos? Preferible que cargue la matriz de datos X desde afuera y mas bien extraiga de la misma las filas y columnas para disponer del numero de muestras y del numero de componentes

# La mas sencilla e intuitiva
self.numero_filas=2
numero_columnas=2
matriz = []
for i in range(numero_filas):
matriz.append([])
for j in range(numero_columnas):
print("Ingrese elemento:")
matriz[i].append(input())
print(matriz)

def insert_arreglo(self):
arr = []
self.numero_filas = 2
for i in range(self.numero_filas):
print("Ingrese elemento:")
arr.append(input())
print(arr)
def learn1(self):
return learn_rate=0.1
def learn2(self):
return learn_rate=0.01
def learn3(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seguramente en esta parte Pycharm te pinta un warning, ya que este método al no utilizar self pasa a ser una funcion cualquiera y no es necesario que este dentro de la clase. Revisar

return learn_rate=0.001
def numbers_learn(self,argument):
switcher = {
0: self.learn1,
1: self.learn2,
2: self.learn3,
}
return switcher.get(argument,lambda: "Invalid")

def signo(self,net):
fsigno = [1. if elem >=0 else -1. for elem in net]
return fsigno
def paso(self,net):
fpaso = [1. if elem >= 0 else 0. for elem in net]
return fpaso
def sigmoide(self,net):
fsigmoide=1/(1+np.exp(elem) for elem in net)
return fsigmoide
def tanhip(self,net):
ftanhip=((np.exp(elem)-np.exp(-elem))/(np.exp(elem)+np.exp(-elem)) for elem in net )
return ftanhip

def funcion(self,argumento):
switcher = {
1: self.signo(),
2: self.paso(),
3: self.sigmoide(),
4: self.tanhip(),
}
# Get the function from switcher dictionary
return switcher.get(argumento, lambda: "Invalid")