Exemplo n.º 1
0
def average():
    # Raises one number to the power of another number

    random.seed(time.time())

    power_train = TrainingData()
    power_test = TrainingData()

    for i in range(100):
        a = random.random()
        b = random.random()
        power_train.append(DataPoint([a, b], [(a + b) / 2]))

        a = random.random()
        b = random.random()
        power_test.append(DataPoint([a, b], [(a + b) / 2]))

    return power_train, power_test
Exemplo n.º 2
0
def adding():
    # Adds two random numbers together

    random.seed(time.time())

    adder = TrainingData()
    adder_testing = TrainingData()

    for i in range(100):
        a = random.random()
        b = random.random()
        adder.append(DataPoint([a, b], [a + b]))

        a = random.random()
        b = random.random()
        adder_testing.append(DataPoint([a, b], [a + b]))

    # return a tuple of the training data and testing data
    return adder, adder_testing
Exemplo n.º 3
0
def subtract():
    # Subtracts two random numbers

    random.seed(time.time())

    subtract_train = TrainingData()
    subtract_test = TrainingData()

    for i in range(100):
        a = random.random()
        b = random.random()
        subtract_train.append(DataPoint([a, b], [a - b]))

        a = random.random()
        b = random.random()
        subtract_test.append(DataPoint([a, b], [a - b]))

    # return a tuple of the training data and testing data
    return subtract_train, subtract_test
Exemplo n.º 4
0
from Network import Network
from TrainingData import TrainingData, DataPoint

print("Creating network.")
net = Network([2, 8, 8, 4])

training_data = TrainingData()
#                     Inputs: 0 and 1  Expected outputs:and, or, nand, xor
training_data.append(DataPoint([0, 0], [0, 0, 1, 0]))
training_data.append(DataPoint([0, 1], [0, 1, 1, 1]))
training_data.append(DataPoint([1, 0], [0, 1, 1, 1]))
training_data.append(DataPoint([1, 1], [1, 1, 0, 0]))

print("Training network...")

current_error = net.train_network_gen_alg(training_data.get_inputs(), training_data.get_expected())
print("Current network error: " + str(current_error))
i = 0
while current_error[1] > 0.001:  # * len(training_data[1]) * len(training_data[1][0]):
    i += 1
    prev_error = current_error
    current_error = net.train_network_gen_alg(training_data.get_inputs(), training_data.get_expected())
    if i == 1:
        print()
        print("100 more iterations...")
        print("Current network error: " + str(current_error[0]))
        print("Current max error: " + str(current_error[1]))
        print("Temperature: " + str(net.temperature))
        i = 0

for data_input in training_data.get_inputs():
Exemplo n.º 5
0
def decoder():
    # Makes a binary decoder of size size

    decoder_training = TrainingData()
    decoder_testing = TrainingData()

    decoder_training.append(DataPoint([0.0],
                                      [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]))
    decoder_training.append(DataPoint([0.1],
                                      [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]))
    decoder_training.append(DataPoint([0.2],
                                      [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]))
    decoder_training.append(DataPoint([0.3],
                                      [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]))
    decoder_training.append(DataPoint([0.4],
                                      [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]))
    decoder_training.append(DataPoint([0.5],
                                      [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]))
    decoder_training.append(DataPoint([0.6],
                                      [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]))
    decoder_training.append(DataPoint([0.7],
                                      [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]))
    decoder_training.append(DataPoint([0.8],
                                      [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]))
    decoder_training.append(DataPoint([0.9],
                                      [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]))
    decoder_training.append(DataPoint([1.0],
                                      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]))

    return decoder_training, decoder_testing
Exemplo n.º 6
0
def and_or_nand_xor():
    truth_table = TrainingData()
    truth_table_testing = TrainingData()
    ##Inputs: 0 and 1  Expected outputs:and, or, nand, xor
    truth_table.append(DataPoint([0, 0, 0, 0], [0, 0, 1, 0]))
    truth_table.append(DataPoint([0, 0, 0, 1], [0, 1, 1, 1]))
    truth_table.append(DataPoint([0, 0, 1, 0], [0, 1, 1, 1]))
    truth_table.append(DataPoint([0, 0, 1, 1], [0, 1, 1, 0]))
    truth_table.append(DataPoint([0, 1, 0, 0], [0, 1, 1, 1]))
    truth_table.append(DataPoint([0, 1, 0, 1], [0, 1, 1, 0]))
    truth_table.append(DataPoint([0, 1, 1, 0], [0, 1, 1, 0]))
    truth_table.append(DataPoint([0, 1, 1, 1], [0, 1, 1, 1]))
    truth_table.append(DataPoint([1, 0, 0, 0], [0, 1, 1, 1]))
    truth_table.append(DataPoint([1, 0, 0, 1], [0, 1, 1, 0]))
    truth_table.append(DataPoint([1, 0, 1, 0], [0, 1, 1, 0]))
    truth_table.append(DataPoint([1, 0, 1, 1], [0, 1, 1, 1]))
    truth_table.append(DataPoint([1, 1, 0, 0], [0, 1, 1, 0]))
    truth_table.append(DataPoint([1, 1, 0, 1], [0, 1, 1, 1]))
    truth_table.append(DataPoint([1, 1, 1, 0], [0, 1, 1, 1]))
    truth_table.append(DataPoint([1, 1, 1, 1], [1, 1, 0, 0]))

    return truth_table, truth_table_testing
Exemplo n.º 7
0
learnAdd.update()

# network2 = network1.getReverse()
# network2.display()

#============================================#


##############################################
# Training Data #
#===============#

truth_table = TrainingData()
truth_table_testing = TrainingData()
##Inputs: 0 and 1  Expected outputs:and, or, nand, xor
truth_table.append(DataPoint([0, 0, 0, 0], [0, 0, 1, 0]))
truth_table.append(DataPoint([0, 0, 0, 1], [0, 1, 1, 1]))
truth_table.append(DataPoint([0, 0, 1, 0], [0, 1, 1, 1]))
truth_table.append(DataPoint([0, 0, 1, 1], [0, 1, 1, 0]))
truth_table.append(DataPoint([0, 1, 0, 0], [0, 1, 1, 1]))
truth_table.append(DataPoint([0, 1, 0, 1], [0, 1, 1, 0]))
truth_table.append(DataPoint([0, 1, 1, 0], [0, 1, 1, 0]))
truth_table.append(DataPoint([0, 1, 1, 1], [0, 1, 1, 1]))
truth_table.append(DataPoint([1, 0, 0, 0], [0, 1, 1, 1]))
truth_table.append(DataPoint([1, 0, 0, 1], [0, 1, 1, 0]))
truth_table.append(DataPoint([1, 0, 1, 0], [0, 1, 1, 0]))
truth_table.append(DataPoint([1, 0, 1, 1], [0, 1, 1, 1]))
truth_table.append(DataPoint([1, 1, 0, 0], [0, 1, 1, 0]))
truth_table.append(DataPoint([1, 1, 0, 1], [0, 1, 1, 1]))
truth_table.append(DataPoint([1, 1, 1, 0], [0, 1, 1, 1]))
truth_table.append(DataPoint([1, 1, 1, 1], [1, 1, 0, 0]))