Neurona McCulloch–Pitts¶

In [ ]:
import numpy as np

class MPNeuron:
    def _init_(self):
        self.threshold = None
        
    def model(self, x):
        # input: [1, 0, 1, 0] [x1, x2, xn...]
        z = sum(x)
        return ( z >= self.threshold)
    
    def predict(self, X):
        # input : [[1, 0, 1, 0], [1, 0, 1, 1]]
        Y = []
        for x in X:
            result = self.model(x)
            Y.append(result)
        return np.array(Y)
In [ ]:
# Creamos una instancia de la neurona
mp_neuron = MPNeuron()
In [ ]:
# Establecemos un umbral
mp_neuron.threshold = 2
In [ ]:
# Evaluamos diferentes casos de uso
mp_neuron.predict([[0, 1, 0, 0], [1, 1, 0, 1], [1, 1, 1, 1]])

Ejemplo practico encuesta:¶

In [ ]:
def mcCulloch_pitts(inputs, threshold):
    return 1 if sum(inputs) >= threshold else 0
In [ ]:
# Datos de la encuesta
encuestas = [
    [1, 1, 0],  # Cliente 1
    [0, 1, 0],  # Cliente 2
    [1, 1, 1],  # Cliente 3
    [0, 0, 1],  # Cliente 4
]
In [ ]:
# Para considerar que el cliente está satisfecho, al menos 2 respuestas deben ser 'Sí' (1).
threshold = 2
for i, respuestas in enumerate(encuestas, start=1):
    resultado = mcCulloch_pitts(respuestas, threshold)
    print(f"Cliente {i}: {'Satisfecho' if resultado == 1 else 'No satisfecho'}")