def config_and_test(index):
    global file_name, DSTR, add_strat_nn, writer, scan_spec
    # checks if we have any more params to scan
    if index < len(params):
        # gets the current param, for instance epochs: [100,200,300] 100 200 and 300 are param
        for param in scan_spec[params[index]]:
            # metaprogramming stuff, just sets the param value, e.g. epoch = 100, then recurses down to the next index
            exec (params[index] + '=' + str(param))
            config_and_test(index + 1)
    else:
        print settings.strategies
        # this part is broken, it should print what the current params are but I can't get it to work
        print settings.scan_spec
        # the file name is the current time
        file_name = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
        full_name = os.path.join(os.path.join(os.path.dirname(__file__), 'test_csv'), file_name + '.csv')

        with open(full_name, 'wb') as csvfile:
            # initialize the writer, DSTR, neural network for each config we want to test
            writer = csv.writer(csvfile)
            writer.writerow(['Output Format Version', '20150807'])
            DSTR = Distribution()
            ADD.main()
            add_strat_nn = counting_network()
            test(settings.n_problems)
def exec_strategy():
    global writer
    global strat_list
    ADD.PPA()
    # try getting a random number from a list above the confidence criterion
    retrieval = add_strat_nn.guess(ADD.ADDEND.ad1, ADD.ADDEND.ad2, 0, 13)
    SOLUTION = 0
    if retrieval is not None:
        #trp(1, "Used Retrieval")
        SOLUTION = retrieval
        writer.writerow(["used","retrieval", ADD.ADDEND.ad1, ADD.ADDEND.ad2, SOLUTION])
    else:
        # retrieval failed, so we get try to get a strategy from above the confidence criterion and use hands to add
        strat_num = add_strat_nn.guess(ADD.ADDEND.ad1, ADD.ADDEND.ad2, 13, 13 + len(settings.strategies))
        if strat_num is None:
            strat_num = randint(0, len(settings.strategies) - 1)
        else:
            strat_num -= 13
        SOLUTION = ADD.exec_strategy(settings.strategies[strat_num])
        # !!! WWW WARNING: This gets displayed even if Dynamic
        # Retrieval was used. You have to Analyze this distinction out
        # of the log at the end by seeing that a DR message appeared!
        writer.writerow(["used",settings.strategies[strat_num], ADD.ADDEND.ad1, ADD.ADDEND.ad2, SOLUTION])
        # update the neural networks based on if the strategy worked or not
        add_strat_nn.update(ADD.ADDEND.ad1, ADD.ADDEND.ad2, SOLUTION, 13 + strat_num, 13, 13 + len(settings.strategies))
    add_strat_nn.update(ADD.ADDEND.ad1, ADD.ADDEND.ad2, SOLUTION, ADD.ADDEND.ad1 + ADD.ADDEND.ad2, 0, 13)
    add_strat_nn.fit(add_strat_nn.X, add_strat_nn.y, settings.learning_rate, settings.epoch)
    add_strat_nn.update_y()
    # add method here to get what strategy is used

    return [ADD.ADDEND.ad1, ADD.ADDEND.ad2, SOLUTION]
Пример #3
0
 def testFloats(self):
     for x in xrange(-10, 10):
         for y in xrange(-10, 10):
             x = x / 10.0
             y = y / 10.0
             p = ADD.add(x, y)
             self.failUnless(p == x + y, 'Float multiplication faild')
Пример #4
0
 def compute_filamentarity(self):
     if self.nodata:
         return
     if args.verbose:
         print("-------------------> Computing Additional Parameters!")
     self.filamentarity = ADD.filamentarity(self.segmap)
     if args.verbose:
         print("Computed Filamentarity            :\t F=%.3f"%(self.filamentarity))
         print("-------------------> Done computing Filamentarity!")
Пример #5
0
import ADD


def add(a, b, c, d):
    return a + b + c + d


print ADD.add(1, 2)
print add(1, 2, 3, 4)
#print a.add(1,2)
Пример #6
0
 def testIntergers(self):
     for x in xrange(-10, 10):
         for y in xrange(-10, 10):
             p = ADD.add(x, y)
             self.failUnless(p == x + y, 'Inter multiplication faild')