def learn(args):

    # 1. Obtengo los patrones de entrenamiento
    # inputs, outputs = fp.parse_file('terrains/terrain4.txt', -1)
    _inputs, _outputs = fp.parse_file('terrains/terrain4.txt', -1)

    inputs, outputs, _inputs_test, _outputs_test = randomTerrain(300, _inputs, _outputs)

    patterns = len(outputs)
    arquitecture = [2, args.hl1, args.hl2, 1]
    fun = args.g_fun
    ecm = args.ecm
    eta = args.eta
    alfa = args.alpha
    #los valores a,b,k en cero desactiva el eta adaptativo
    a = args.a
    b = args.b
    k = args.k

    # 2. Entreno la red
    #multilayer_perceptron(arquitecture, input, output, bias, beta, eta, error_cuad, fun, alfa, a, b, k):

    errors, epoch, out, weights = bp.train(arquitecture, inputs, outputs, -1, 0.5, eta, ecm, fun, alfa, a, b, k)
    fp.plotX1X2Z(inputs, out)
    #fp.plotOriginals(inputs,outputs)

    # 3. Obtengo los patrones de testeo
    inputs, outputs = fp.parse_file('terrains/terrain4-test-1.txt', -1)

    # 4. Testeo la red
    # out = bp.test(arquitecture, inputs, outputs, -1, 0.5, eta, fun, weights)
    out = bp.test(arquitecture, _inputs_test, _outputs_test, -1, 0.5, eta, fun, weights)
    # 5. Calculo porcentaje de aciertos y aproximaciones
    hit_p, apprx_p = percentage(outputs, out, ecm)

    print('Porcentaje de aciertos: ' + "%.2f" % round(hit_p,2) + '% - Porcentaje de aproximaciones: ' + "%.2f" % round(apprx_p,2) + '%')


    fp.plotX1X2Z(inputs, out)
    #fp.plotOriginals(inputs, outputs)

    plt.plot(range(1, epoch), errors)
    plt.xlabel('Epoca')
    plt.ylabel('Error cuadratico medio')

    plt.title('Red neuronal con arquitectura ' + str(arquitecture) + ', cantidad de patrones: ' + str(patterns) + ', funcion de activacion: ' + fun)
    plt.show()

    return
Exemple #2
0
def get_closest_store(current_location):
    store_list = parse_file('com/resources/store-locations.csv')
    closest_store = find_closest_store(current_location, store_list)

    if closest_store is None:
        sys.exit('No stores found, something went wrong')

    return closest_store
Exemple #3
0
def main(argv):
    input_files = []
    help_text = 'main.py -i <input_file>'
    try:
        opts, args = getopt.getopt(argv, "h:i:", ["ifile="])
    except getopt.GetoptError:
        print(help_text)
        sys.exit()
    if len(opts) < 1:
        print(help_text)
        sys.exit()
    for opt, arg in opts:
        if opt == "-h":
            print(help_text)
            sys.exit()
        elif opt in ("-i", "--ifile"):
            input_files.append(arg)
    if len(input_files) > 0:
        for file in input_files:
            print("Opening file" + file)
            parse_file(file)
    else:
        print(help_text)
        sys.exit()
 def insert_blocks(self, mineral_deposit, block_model, data_file):
     model = self.fetch_block_model(mineral_deposit, block_model)
     headers, amount_headers, data_map, weight_column, weight_column_index, grades_data_map = self.get_params_from_model(
         model)
     data = parse_file(data_file)
     data_array = []
     grade_units = ['tonn', 'percentage', 'oz/tonn', 'ppm']
     self.print_units(grade_units)
     my_units = self.select_options_for_units(grade_units, grades_data_map)
     for item in data:
         document = self.create_block_document(mineral_deposit, block_model,
                                               amount_headers, headers,
                                               grades_data_map, item,
                                               weight_column_index,
                                               grade_units, my_units)
         data_array.append(document)
     self.db.blocks.insert_many(data_array)
Exemple #5
0
def get_game_file_stats(filename):
    game, winner = file_parser.parse_file(filename)
    game = _normalize_game(game)
    num_turns = len(game)
    final_board = game[num_turns -1]
    
    stats_teamA = {}
    stats_teamB = {}
    
    stats_teamA['wins'] = 0
    stats_teamA['looses'] = 0
    stats_teamA['draws'] = 0
    stats_teamA['turns_winning'] = 0
    stats_teamA['turns_losing'] = 0
    stats_teamB['wins'] = 0
    stats_teamB['looses'] = 0
    stats_teamB['draws'] = 0
    stats_teamB['turns_winning'] = 0
    stats_teamB['turns_losing'] = 0
    
    if winner == 1:
        stats_teamA['wins'] = 1
        stats_teamB['looses'] = 1
        stats_teamA['turns_winning'] = num_turns
        stats_teamB['turns_losing'] = num_turns
    elif winner == -1:
        stats_teamA['looses'] = 1
        stats_teamB['wins'] = 1
        stats_teamA['turns_losing'] = num_turns
        stats_teamB['turns_winning'] = num_turns
    else:
        stats_teamA['draws'] = 1
        stats_teamB['draws'] = 1
    
    stats_teamA['num_pieces'], stats_teamB['num_pieces'] = _count_pieces(final_board)
    stats_teamA['val_pieces'], stats_teamB['val_pieces'] = _count_values(final_board)
    
    stats_teamA['max_death'], stats_teamB['max_death'] = _check_death(6, game)
    
    return (stats_teamA, stats_teamB)
Exemple #6
0
def load_sentries(world, level):
    # load all the sentries for a given level from the file
    file_name = SENTRY_FILE
    print(file_parser.parse_file(SENTRY_FILE))

    with open(file_name, 'r') as file:
        lines = file.readlines()  # read the whole file into a string array
    i = 0

    while i < len(lines):
        while i < len(lines) and lines[
                i][:-1] != SENTRY_START:  # look for the start of a sentry definition
            i += 1
        if i < len(lines):
            all_sentries = []
            name = lines[i + 1][:-1]  # strip trailing CRLF
            sentry_level = eval(lines[i + 2])
            position = eval(lines[i + 3])
            display_program = []
            if sentry_level == level:  # only create the sentries for this game level
                s = Sentry(world, position, name)
                all_sentries.append(s)
            i += 3  # skip on to next sentry
    return all_sentries
Exemple #7
0
import file_parser
import search
import GUI

def search_word(word):
    return search.do_search(word)

if __name__ == "__main__":

    file_parser.parse_file("test-data.txt")
#    docsList=[]
#    app.run(host="localhost")
  
    GUI.vp_start_gui()    
Exemple #8
0
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
from celluloid import Camera
from file_parser import parse_file

if __name__ == '__main__':
    N, L, t_max, x_values, y_values = parse_file("../CIMOutput.txt")
    camera = Camera(plt.figure())
    for i in range(t_max):
        show_x = x_values[i]
        show_y = y_values[i]
        plt.scatter(x=show_x, y=show_y, c="black", marker='.', s=15)
        camera.snap()
    anim = camera.animate(blit=True)
    anim.save('scatter.gif')
Exemple #9
0
header_file_name = header_folder+'/'+class_name + '.h'
cpp_file_name = cpp_folder+'/'+class_name + '.cpp'
test_file_name = ''
if namespace_name != 'GUI':
	test_file_name = test_folder+'/'+class_name + 'Test.cpp'
	
#define template names
header_template = ''
cpp_template = ''
if is_factory:
	header_template = 'FactoryHTemplate.txt'
	cpp_template = 'FactoryCPPTemplate.txt'
	dictionary['FactoryType'] = factory_type
	dictionary['FACTORYTYPE'] = factory_type.upper()
	dictionary['factorytype'] = factory_type.lower()
elif is_singleton:
	header_template = 'SingletonHTemplate.txt'
	cpp_template = 'SingletonCPPTemplate.txt'
elif is_algorithm:
	header_template = 'AlgorithmHTemplate.txt'
	cpp_template = 'AlgorithmCPPTemplate.txt'
else:
	header_template = 'ClassHTemplate.txt'
	cpp_template = 'ClassCPPTemplate.txt'

parse_file(template_dir + header_template,root + header_file_name,dictionary)
parse_file(template_dir + cpp_template,root + cpp_file_name,dictionary)
if len(test_file_name) > 0:
	parse_file(template_dir + 'ClassTestTemplate.txt',root + test_file_name,dictionary)