Example #1
0
def run_sim(trials, memory_states):
    for memory_state in memory_states:
        # initialise memory.
        memory = buildNetwork.initializeMemorySet()
        # load a sym file.
        symProps = load_sym(memory_state)
        # interpret the sym file.
        mysym = buildNetwork.interpretSymfile(symProps)
        # build the network object with memory.
        memory = basicRunDORA.dataTypes.memorySet()
        memory = buildNetwork.buildTheNetwork(mysym[0], memory)
        network = basicRunDORA.runDORA(memory, parameters)
        # run trials of each kind ('whole', 'feature', 'relation').
        correct_w = 0
        correct_f = 0
        correct_r = 0
        start_POs = 0
        tally = 0
        for i in range(trials):
            # run a 'whole' trial.
            tally, was_correct = run_trial(network, start_POs, tally,
                                           correct_w, 'whole')
            correct_w += was_correct
            # run a 'feature' trial.
            tally, was_correct = run_trial(network, start_POs, tally,
                                           correct_w, 'feature')
            correct_f += was_correct
            # run a 'relation' trial.
            tally, was_correct = run_trial(network, start_POs, tally,
                                           correct_w, 'relation')
            correct_r += was_correct
        print(tally, '\n', correct_w, '\n', correct_f, '\n', correct_r, '\n',
              '\n\n\n')
Example #2
0
def init_network(parameters):
    reload(buildNetwork)
    reload(basicRunDORA)
    fileName = parameters['filename']
    f = open(fileName, 'r')
    simType = ''
    d = {'simType': simType}
    f.seek(0)
    exec(f.readline())
    if simType == 'sym_file':
        symstring = ''
        for line in f:
            symstring += line
        exec(symstring)
    # initialise memory
    memory = buildNetwork.initializeMemorySet()
    # interpret sym file
    mysym = buildNetwork.interpretSymfile(symProps)
    # build the network
    memory = basicRunDORA.dataTypes.memorySet()
    memory = buildNetwork.buildTheNetwork(mysym[0], memory)
    network = basicRunDORA.runDORA(memory, parameters)
    memory = basicRunDORA.update_memory_with_levels(memory)
    # run cycles
    # initialise mapping adjacency matrix:
    mapping_adj = np.zeros((len(network.memory.Ps), len(network.memory.Ps)))
    return [network, memory, mapping_adj]
Example #3
0
def run_NBsim(trials, memory_states):
    last_POs = 0
    last_RBs = 0
    last_Ps = 0
    for memory_state in memory_states:
        # initialise memory.
        memory = buildNetwork.initializeMemorySet()
        # load a sym file.
        symProps = load_sym(memory_state)
        # interpret the sym file.
        mysym = buildNetwork.interpretSymfile(symProps)
        # build the network object with memory.
        memory = basicRunDORA.dataTypes.memorySet()
        memory = buildNetwork.buildTheNetwork(mysym[0], memory)
        network = basicRunDORA.runDORA(memory, parameters)
        # find which reps were learned since the last simulation.
        new_POs = len(network.memory.POs) - last_POs
        new_RBs = len(network.memory.RBs) - last_RBs
        new_Ps = len(network.memory.Ps) - last_Ps
        last_POs = len(network.memory.POs)
        last_RBs = len(network.memory.RBs)
        last_Ps = len(network.memory.Ps)
        start_POs = len(network.memory.POs) - new_POs
        start_RBs = len(network.memory.RBs) - new_RBs
        start_Ps = len(network.memory.Ps) - new_Ps
        new_objs, new_preds, new_rels = count_reps(memory, start_POs,
                                                   start_RBs, start_Ps)
        print(new_POs, new_RBs, new_Ps)
        print(len(new_objs), len(new_preds), len(new_rels))
        # run 1000 trials.
        tally = {'P': 0, 'RB': 0, 'PO': 0}
        correct = 0
        for i in range(trials):
            tally, was_correct = run_NBtrial(network, start_POs, tally,
                                             correct)
            correct += was_correct
        print(tally, '\n', correct, '\n\n\n')
Example #4
0
f.seek(0)  # to get to the beginning of the file.
exec(f.readline())
if simType == 'sym_file':
    symstring = ''
    for line in f:
        symstring += line
    do_run = True
    try:
        exec symstring
    except:
        do_run = False
        print '\nSorry, you have a badly formated sym file. \nI will return to the MainMenu.'

memory = buildNetwork.initializeMemorySet()
# interpret the sym file.
mysym = buildNetwork.interpretSymfile(symProps)
print 'Sym file loaded!'
# build the network object with memory.
memory = basicRunDORA.dataTypes.memorySet()
memory = buildNetwork.buildTheNetwork(mysym[0], memory)
network = basicRunDORA.runDORA(memory, parameters)


def clear_mem():
    network.memory = basicRunDORA.clearDriverSet(network.memory)
    network.memory = basicRunDORA.clearRecipientSet(network.memory)


clear_mem()
network.memory = basicRunDORA.findDriverRecipient(network.memory)
network.do_retrieval()