예제 #1
0
from cmatrix import ConvolutionMatrix

from nnet import NNet
from verbosePrint import vprint
import verbosePrint

np.random.seed(1)

batch_size = 128
iterations = 300

cm = ConvolutionMatrix(rows=9, cols=16, shapes=((28, 28), (3, 3)))
hLen = cm.outputLength()
nn = NNet(sizes=[784, hLen, 10], batch_size=batch_size)
nn.replaceLayer(0, cm)
nn.setActivations(['tanh', 'softmax'])
nn.setMaskPr({1: 2})
nn.setAlpha(2)
nn.scale(0.01, 0)
nn.scale(0.1, 1)

# vprint(0, nn, quit=True)
# params = (test_images, test_labels)
# nn.checkup(*params)
for j in range(0, iterations + 1):
    correct_cnt = 0
    for i in range(int(len(images) / batch_size)):
        batch_start, batch_end = ((i * batch_size), ((i + 1) * batch_size))
        prediction = nn.learn(images[batch_start:batch_end],
                              labels[batch_start:batch_end])
        # vprint(i, nn, suffix='a', quit=True)
예제 #2
0
    [0, 0],
]

inputTraining = inputData
targetTraining = targetData

# nn = NNet(sizes=[5, 3], bias=True)
nn = NNet(sizes=[6, 12, 2], bias=True)
# nn = NNet([[[-0.829638, 0.164111, 0.398885],
#             [-0.603684, -0.603331, -0.819179],
#             [-0.080592, -0.386044, -0.931615],
#             [0.762514, -0.142887, -0.737862],
#             [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]
예제 #3
0
from netExamples.lecture.p3of5 import inputData
from netExamples.lecture.p3of5 import inputTraining
# from lecture.p3of5 import inputData as inputTraining
from netExamples.lecture.p3of5 import atLeast as targetData
from netExamples.lecture.p3of5 import atLeastTraining as targetTraining
# from lecture.p3of5 import atLeast as targetTraining

# nn = NNet(sizes=[5, 3], bias=True)
nn = NNet(
    [[[-0.829638, 0.164111, 0.398885], [-0.603684, -0.603331, -0.819179],
      [-0.080592, -0.386044, -0.931615], [0.762514, -0.142887, -0.737862],
      [0.175430, 0.790112, -0.267367], [-0.732674, -0.825474, 0.232357]]],
    bias=True)
# ]])
nn.setActivations(['linear'])
nn.setVerbose([])

nn.checkup(inputData, targetData)

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

cycles = 80
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]
예제 #4
0
파일: find010.py 프로젝트: WmHHooper/tennis
    [0, 1, 0],
    [0, 1, 0],
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 1],
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 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]
예제 #5
0
from netExamples.lecture.sosb \
    import inputData, inputTraining, targetData, targetTraining

from nnet import NNet
from verbosePrint import vprint
import verbosePrint

nn = NNet(sizes=[12, 22, 4], bias=True)
nn.setActivations(['tanh', 'sigmoid'])

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

cycles = 20
report = max(1, cycles / 10)
checkupParams = (inputData, targetData, inputTraining, 25)

if cycles > 0:
    nn.checkup(*checkupParams)
    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
예제 #6
0
from netExamples.lecture.sosb \
    import inputData, inputTraining, targetData, targetTraining
from cmatrix import ConvolutionMatrix

from nnet import NNet
from verbosePrint import vprint
import verbosePrint

nn = NNet(sizes=[12, 40, 4], bias=True)
cm = ConvolutionMatrix(rows=3, cols=4, bias=True, shapes=((1, 12), (1, 3)))
nn.replaceLayer(0, cm)
nn.setActivations(['softMax', 'sigmoid'])

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

cycles = 100
report = max(1, cycles / 10)
checkupParams = (inputData, targetData, inputTraining, 25)

if cycles > 0:
    nn.checkup(*checkupParams)
    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)
예제 #7
0
                error += np.sum((test_labels[i:i + 1] - layer_2) ** 2)
                correct_cnt += int(np.argmax(layer_2) == \
                                   np.argmax(test_labels[i:i + 1]))
            sys.stdout.write(
                " Test-Err:" + str(error / float(len(test_images)))[0:5]
                + " Test-Acc:" + str(correct_cnt / float(len(test_images)))
            )
            print()

if demo == 82:
    np.random.seed(1)

    iterations = 351

    nn = NNet(sizes=[784, 40, 10])
    nn.setActivations(['brelu', 'linear'])
    nn.setAlpha(0.005)
    nn.scale(0.1)

    nn.fire(images[0:1])
    vprint(0, nn)

    for j in range(iterations):
        error, correct_cnt = (0.0, 0)
        for i in range(len(images)):
            vprint(i, nn, quit=True)
            prediction = nn.learn(images[i:i+1], labels[i:i+1])
            vprint(i, nn, suffix='b', quit=True)

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