Пример #1
0
#             [0.175430, 0.790112, -0.267367],
#             [-0.732674, -0.825474, 0.232357]]], bias=True)
# ]])
nn.setActivations(['relu', 'linear'])
nn.setVerbose([])

nn.checkup(inputData, targetData)

verbosePrint.vIteration = -1
verbosePrint.stage = ''

cycles = 1000
report = cycles / 10

for iteration in range(cycles + 1):
    vprint(iteration, '~~~~~~~~~~~ Iteration %d ~~~~~~~~~~~' % iteration)
    combinedError = 0
    for row_index in range(len(targetTraining)):
        datain = inputTraining[row_index:row_index + 1]
        goal_prediction = targetTraining[row_index:row_index + 1]
        prediction = nn.fire(datain)
        # print('Prediction:' + str(prediction))
        vprint(iteration, nn)

        error = (goal_prediction - prediction)**2
        combinedError += error

        nn.learn(datain, goal_prediction)

    if iteration % report == 0:
        print('Iteration: %d Error: %s' % (iteration, str(combinedError)))
Пример #2
0
        nn.learn(datain, goal)

if demo == 6:
    nn = NNet([[[0.5], [0.48], [-0.7]]])
    nn.setAlpha(0.1)

    streetlights = np.array([[1, 0, 1], [0, 1, 1], [0, 0, 1], [1, 1, 1],
                             [0, 1, 1], [1, 0, 1]])

    walk_vs_stop = np.array([[0, 1, 0, 1, 1, 0]]).T

    datain = streetlights[0]  # [1,0,1]
    goal_prediction = walk_vs_stop[0]  # equals 0... i.e. "stop"

    for iteration in range(40):
        vprint(iteration, '~~~~~~~~~~~ Iteration %d ~~~~~~~~~~~' % iteration)
        error_for_all_lights = 0
        for row_index in range(len(walk_vs_stop)):
            datain = streetlights[row_index:row_index + 1]
            goal_prediction = walk_vs_stop[row_index:row_index + 1]
            prediction = nn.fire(datain)
            # print('Prediction:' + str(prediction))
            vprint(iteration, nn)

            error = (goal_prediction - prediction)**2
            error_for_all_lights += error

            nn.learn(datain, goal_prediction)

        print("Error:" + str(error_for_all_lights))
        vprint(iteration, '')
Пример #3
0
    [0, 0, 0],
]

nn = NNet(sizes=[5, 3], bias=True)
nn.setActivations(['sigmoid'])

verbosePrint.vIteration = -1
verbosePrint.stage = ''

nn.checkup(inputData, targetData)

cycles = 40
report = cycles/10

for iteration in range(cycles + 1):
    vprint(iteration, '~~~~~~~~~~~ Iteration %d ~~~~~~~~~~~' % iteration)
    combinedError = 0
    for row_index in range(len(targetData)):
        datain = inputData[row_index:row_index + 1]
        goal_prediction = targetData[row_index:row_index + 1]
        prediction = nn.fire(datain)
        # print('Prediction:' + str(prediction))
        vprint(iteration, 'Goal:\n%s' % str(goal_prediction))
        vprint(iteration, nn)

        error = (goal_prediction - prediction) ** 2
        combinedError += error

        nn.learn(datain, goal_prediction)

    if iteration % report == 0:
Пример #4
0
            layer_0 = images[i:i + 1]
            layer_1 = relu(np.dot(layer_0, weights_0_1))
            layer_2 = np.dot(layer_1, weights_1_2)

            error += np.sum((labels[i:i + 1] - layer_2) ** 2)
            correct_cnt += int(np.argmax(layer_2) == \
                               np.argmax(labels[i:i + 1]))

            layer_2_delta = (labels[i:i + 1] - layer_2)
            deriv = relu2deriv(layer_1)
            layer_1_delta = layer_2_delta.dot(weights_1_2.T) \
                            * deriv
            l1_dot_l2d = layer_1.T.dot(layer_2_delta)
            weights_1_2 += alpha * l1_dot_l2d
            l0_dot_l1d = layer_0.T.dot(layer_1_delta)
            vprint(i, 'L0 * L1d: %s' % l0_dot_l1d,
                   quit=True, suffix='a')
            weights_0_1 += alpha * l0_dot_l1d

            vprintnn(i, quit=True, suffix='b')

            sys.stdout.write("\r I:" + str(j) + \
                         " Train-Err:" + str(error / float(len(images)))[0:5] + \
                         " Train-Acc:" + str(correct_cnt / float(len(images))))

        if (j % 10 == 0 or j == iterations - 1):
            error, correct_cnt = (0.0, 0)

            for i in range(len(test_images)):
                layer_0 = test_images[i:i + 1]
                layer_1 = relu(np.dot(layer_0, weights_0_1))
                layer_2 = np.dot(layer_1, weights_1_2)