Example #1
0
def main():
    text = t.poemToProse(t.getText('texts/wiki1.txt'))
    words = t.textToWords(text)
    # print(len(words))
    uniq = frequencyVector(m.getNouns(words))
    print(uniq[0], uniq[1])
    matrix = matchMatrix(uniq[0], t.textToSenteces(text))
    #print(np.linalg.det(matrix))
    # print(np.linalg.svd(matrix)[2][8])
    # print(matrix[2].sum())
    #print(np.linalg.det(matrix_shit))
    # print(np.linalg.det(matrix - np.identity(matrix.shape[0])))
    # print(np.linalg.eigvals(matrix_shit))
    hopfield = Hopfield(matrix, uniq[1])
    hopfield.train()

    # print(hopfield.result)

    print(showResults(hopfield.result, uniq[0]))
Example #2
0
    dim = width * height

    for _ in range(count):
        f.readline()  # skip empty line
        x = np.empty((height, width))
        #print('x shape ', x.shape)
        for r in range(height):
            x[r, :] = np.array(list(f.readline().strip())) == '#'

        patterns.append(2 * x.flatten() -
                        1)  # flatten to 1D vector, rescale {0,1} -> {-1,+1}

util_setup(width, height)

model = Hopfield(dim)
model.train(patterns)


def flip_positions(input, positions):
    flipped = 0
    new_noise = input.copy()
    for pos in positions:
        new_noise[pos] = -new_noise[pos]
        flipped += 1
    return new_noise


def discrete_noise_correction(input):
    all_inputs = []
    for noise_amount in [0, 7, 14, 21]:
        positions = []