AiSc 8

Pasted Nov 4, 2026, 3:49 PM1 file29 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/ai8
untitled
import numpy as np

# Define binary patterns using bipolar values (-1 and 1)
pattern_A = np.array([1, 1, -1, -1])

# Training Phase: Hebbian Learning Rule
W = np.outer(pattern_A, pattern_A)
np.fill_diagonal(W, 0)


def recall(test_pattern, weights, steps=5):
    state = np.array(test_pattern)

    for _ in range(steps):
        # Calculate activation and apply threshold
        raw_activation = np.dot(weights, state)
        state = np.where(raw_activation >= 0, 1, -1)

    return state


# Test data: Introduce noise
noisy_input = np.array([1, 1, -1, 1])

recovered_output = recall(noisy_input, W)

print("Stored Pattern (Memory):", pattern_A)
print("Noisy Input Provided:   ", noisy_input)
print("Recovered Memory Output:", recovered_output)

748 chars · codepastes.com