示例#1
0
    def __init__(self,
                 settings: utilities.ExperimentSettings.ExperimentSettings):
        self.__space = settings.initial_space
        self.__selector = settings.selector
        self.__networks = []
        self.__nodes = []

        self.__settings = settings

        self._test_dao = test_dao.TestDAO(db='database.db')
        self.__test_result_dao = test_result_dao.TestResultDAO(
            db='database.db')
        self.__test_model_dao = test_model_dao.TestModelDAO(db='database.db')

        self.__best_network = None

        if self.__settings.loadedNetwork == None:
            self.__best_network = self.__create_network(
                dna=settings.initial_dna)
        else:
            self.__best_network = self.__settings.loadedNetwork

        self.__actions = []

        self.__fileManager = FileManager.FileManager()

        if self.__settings.save_txt == True:
            self.__fileManager.setFileName(self.__settings.test_name)
            self.__fileManager.writeFile("")

        self.__memoryManager = MemoryManager.MemoryManager()
示例#2
0
import matplotlib.pyplot as plt
import matplotlib.ticker
import numpy as np
import matplotlib.backends.backend_pdf as pdf_manager
from DAO.database.dao import test_model_dao, test_dao, test_result_dao
import os 

testDAO = test_dao.TestDAO()
testModelDAO = test_model_dao.TestModelDAO()
testResultDAO = test_result_dao.TestResultDAO()
test_list = testDAO.findAll()

def findAccByAlaiRange(min_alai, max_alai, modelList, last_acc):

    acc = last_acc
    for model in modelList:   
        
        if model.current_alai_time >= min_alai and model.current_alai_time <= max_alai:
            acc = model.model_weight
    if acc == 0:
        acc = last_acc
    return acc

tests_to_graph = int(input("Enter the number of tests to graph: "))
selected_test_list = [] 

def convertPosition(y):

    convert = (y-0.7)*(1/0.3)

    return convert
    def __init__(self, db="database_product.db"):

        self.__testDao = test_dao.TestDAO(db)
        self.__value = None
示例#4
0
 def __init__(self, testId):
     self.__testId = testId
     self.__testDao = test_dao.TestDAO()
     self.__testResultDao = test_result_dao.TestResultDAO()
     self.__value = None
示例#5
0
def run(status):
    loaded_network = bool(input("any input to run loaded network"))
    print("Loaded network: ", loaded_network)
    status.Transfer = tran.TransferRemote(status, 'remote2local.txt',
                                          'local2remote.txt')
    #status.Transfer.readLoad()
    print(f'status.settings is {status.settings}')

    create_objects(status, loaded_network)
    print('The value of typos after loading is')
    print(status.typos)
    print("objects created")
    status.print_DNA()
    status.Transfer.un_load()
    status.Transfer.write()
    k = 0

    test_id = 0
    testDao = test_dao.TestDAO()
    testResultDao = test_result_dao.TestResultDAO()
    testModelDao = test_model_dao.TestModelDAO()
    print("cuda=", status.cuda)

    print("max layers: ", status.max_layer_conv2d)

    settings = status.settings

    if loaded_network == False:
        network = nw.Network(
            status.Center,
            cuda_flag=settings.cuda,
            momentum=settings.momentum,
            weight_decay=settings.weight_decay,
            enable_activation=settings.enable_activation,
            enable_track_stats=settings.enable_track_stats,
            dropout_value=settings.dropout_value,
            dropout_function=settings.dropout_function,
            enable_last_activation=settings.enable_last_activation,
            version=settings.version,
            eps_batchnorm=settings.eps_batchorm)

        print("starting pre-training")

        print("iterations per epoch = ", status.iterations_per_epoch)
        dt_array = status.Alai.get_increments(20 * status.iterations_per_epoch)

        if status.save2database == True:
            test_id = testDao.insert(testName=status.experiment_name,
                                     dt=status.dt_Max,
                                     dt_min=status.dt_min,
                                     batch_size=status.S,
                                     max_layers=status.max_layer_conv2d,
                                     max_filters=status.max_filter,
                                     max_filter_dense=status.max_filter_dense,
                                     max_kernel_dense=status.max_kernel_dense,
                                     max_pool_layer=status.max_pool_layer,
                                     max_parents=status.max_parents)

        network.training_custom_dt(dataGenerator=status.Data_gen,
                                   dt_array=dt_array,
                                   ricap=settings.ricap,
                                   evalLoss=settings.evalLoss)

    else:

        path = os.path.join("saved_models", "product_database",
                            "7_test_final_experiment_model_6044")
        network = NetworkStorage.load_network(fileName=None,
                                              settings=settings,
                                              path=path)
        network.generate_accuracy(status.Data_gen)
        acc = network.get_accuracy()
        print("Acc loaded network: ", acc)
        print("Alai time loaded: ", status.Alai.computeTime())
        L_1 = status.Alai.computeTime() // status.save_space_period
        L_2 = status.Alai.computeTime() // status.save_net_period
        print("L_1= ", L_1)
        print("L_2= ", L_2)
        time.sleep(2)

        if status.save2database == True:
            test_id = testDao.insert(testName=status.experiment_name,
                                     dt=status.dt_Max,
                                     dt_min=status.dt_min,
                                     batch_size=status.S,
                                     max_layers=status.max_layer_conv2d,
                                     max_filters=status.max_filter,
                                     max_filter_dense=status.max_filter_dense,
                                     max_kernel_dense=status.max_kernel_dense,
                                     max_pool_layer=status.max_pool_layer,
                                     max_parents=status.max_parents)

    status.stream.add_node(network.dna)
    status.stream.link_node(network.dna, network)

    if status.save2database == True and loaded_network == False:
        dna_graph = status.Dynamics.phase_space.DNA_graph
        testResultDao.insert(idTest=test_id,
                             iteration=0,
                             dna_graph=dna_graph,
                             current_alai_time=status.Alai.computeTime(),
                             reset_count=status.Alai.reset_count)

        save_model(status, 0, testModelDao, test_id, TrainingType.PRE_TRAINING)

    #update(status)
    while False:
        update(status)
        status.Transfer.un_load()
        status.Transfer.write()
        transfer = status.Transfer.status_transfer
        k = k + 1
        pass

    L_1 = 1
    L_2 = 1
    save_17_layers = True
    save_18_layers = True
    save_19_layers = True
    save_24_layers = True
    save_25_layers = True
    save_26_layers = True
    save_27_layers = True
    save_30_layers = True
    save_33_layers = True
    save_36_layers = True
    save_39_layers = True
    save_42_layers = True
    save_45_layers = True
    save_48_layers = True
    save_51_layers = True

    if loaded_network == True:
        save_6_layers = False
        save_17_layers = False
        save_18_layers = False
        save_19_layers = False
        L_1 = status.Alai.computeTime() // status.save_space_period
        L_2 = status.Alai.computeTime() // status.save_net_period

    while k < status.max_iter:
        #\begin{with gui}
        #status.Transfer.readLoad()
        #\end{with gui}
        #\begin{wituhout gui}
        status.active = True
        #\end{without gui}
        if status.active:
            update(status)
            print(f'The iteration number is: {k}')
            #if k % 20 == 0:
            #    status.print_accuracy()
            #status.print_energy()
            status.print_predicted_actions()
            if status.Alai:
                status.Alai.update()
            #status.print_particles()
            #status.print_particles()
            #status.print_max_particles()
            #print(status.typos)
            #status.print_signal()
            #status.print_difussion_filed()
    #        print_nets(status)
    #        time.sleep(0.5)0

            center_dna = status.Dynamics.phase_space.center()
            layers_count = 0
            if center_dna is not None:
                layers_count = countLayers(center_dna)

            print("current layers: ", layers_count)
            if status.save2database == True:

                if status.Alai.computeTime() >= L_1 * status.save_space_period:
                    print("saving space: ", L_1)
                    L_1 += 1
                    dna_graph = status.Dynamics.phase_space.DNA_graph
                    testResultDao.insert(
                        idTest=test_id,
                        iteration=k + 1,
                        dna_graph=dna_graph,
                        current_alai_time=status.Alai.computeTime(),
                        reset_count=status.Alai.reset_count)

                if status.Alai.computeTime() >= L_2 * status.save_net_period:
                    print("saving model: ", L_2)
                    L_2 += 1
                    save_model(status, k + 1, testModelDao, test_id,
                               TrainingType.MUTATION)

                if layers_count >= 17 and save_17_layers == True:
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)
                    save_17_layers = False

                elif layers_count >= 18 and save_18_layers == True:
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)
                    save_18_layers = False

                elif layers_count >= 19 and save_19_layers == True:
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)
                    save_19_layers = False

                elif layers_count >= 24 and save_24_layers == True:
                    save_24_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 25 and save_25_layers == True:
                    save_25_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 26 and save_26_layers == True:
                    save_26_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 27 and save_27_layers == True:
                    save_27_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 30 and save_30_layers == True:
                    save_30_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 33 and save_33_layers == True:
                    save_33_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 36 and save_36_layers == True:
                    save_36_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 39 and save_39_layers == True:
                    save_39_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 42 and save_42_layers == True:
                    save_42_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 45 and save_45_layers == True:
                    save_45_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 48 and save_48_layers == True:
                    save_48_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                elif layers_count >= 51 and save_51_layers == True:
                    save_51_layers = False
                    save_checkpoint(status, testResultDao, layers_count,
                                    test_id, testModelDao, k)

                if layers_count >= 39:
                    print("STOPPED MAX LAYERS: ", layers_count)
                    break
        else:
            #print('inactive')
            pass
        k = k + 1
示例#6
0
def run(status):
    status.Transfer = tran.TransferRemote(status, 'remote2local.txt',
                                          'local2remote.txt')
    #status.Transfer.readLoad()
    create_objects(status)
    print('The value of typos after loading is')
    print(status.typos)
    print("objects created")
    status.print_DNA()
    status.Transfer.un_load()
    status.Transfer.write()
    k = 0
    #update(status)
    test_id = 0
    testDao = test_dao.TestDAO()
    testResultDao = test_result_dao.TestResultDAO()
    testModelDao = test_model_dao.TestModelDAO()

    if status.save2database == True:
        test_id = testDao.insert(testName=status.experiment_name,
                                 periodSave=status.save_space_period,
                                 dt=status.dt_Max,
                                 total=status.max_iter,
                                 periodCenter=1)

    while False:
        update(status)
        status.Transfer.un_load()
        status.Transfer.write()
        transfer = status.Transfer.status_transfer
        k = k + 1
        pass
    while k < status.max_iter:
        #\begin{with gui}
        #status.Transfer.readLoad()
        #\end{with gui}
        #\begin{wituhout gui}
        status.active = True
        #\end{without gui}
        if status.active:
            update(status)
            print(f'The iteration number is: {k}')
            #status.print_energy()
            status.print_predicted_actions()
            if status.Alai:
                status.Alai.update()

            if status.save2database == True:

                if k % status.save_space_period == status.save_space_period - 1:
                    dna_graph = status.Dynamics.phase_space.DNA_graph
                    testResultDao.insert(idTest=test_id,
                                         iteration=k + 1,
                                         dna_graph=dna_graph)

                if k % status.save_net_period == status.save_net_period - 1:
                    save_model(status, k + 1, testModelDao, test_id)
            #status.print_particles()
            #status.print_particles()
            #status.print_max_particles()
            #print(status.typos)
            #status.print_signal()
            #status.print_difussion_filed()
    #        print_nets(status)
    #        time.sleep(0.5)
        else:
            #print('inactive')
            pass
        k = k + 1