Ejemplo n.º 1
0
            'in_train_file in_test_file in_test_ans in_user_profile_file in_config out_train_file out_test_file'
        )
        exit()

    # arguments
    train_file = sys.argv[1]
    test_file = sys.argv[2]
    test_ans_file = sys.argv[3]
    user_profile_file = sys.argv[4]
    config_file = sys.argv[5]
    out_train_file = sys.argv[6]
    out_test_file = sys.argv[7]

    # read in data
    train_graph = file_io.read_graph(train_file)
    config = file_io.read_config(config_file)
    user_feature = None

    (user_feature,
     feature_name) = file_io.read_feature_column_major(user_profile_file,
                                                       config)

    #normalize features
    for column in user_feature:
        if column.type == 'numerical':
            cf.normalize_column(column)
        elif column.type == 'categorical':
            cf.convert_to_dummy_variable(column)

    test_pair = file_io.read_data(test_file)
    train_graph = update_nodes_from_test_data(train_graph, test_pair)
Ejemplo n.º 2
0
from PyQt5 import QtWidgets

from algorithms.beam_search_solver import BeamSearchSolver
from algorithms.ga_solver import GASolver
from algorithms.csp_solver import CSPSolver
from algorithms.hill_climbing_solver import HillClimbingSolver
from chessboard.chessboard_state_node import ChessboardStateNode
from ui.main_window import MainWindow
import sys

from file_io import read_config, write_config
from chessboard.chessboard_state import ChessboardState

if __name__ == '__main__':
    # pass
    initial_config = read_config('input2.txt')

    state = ChessboardState(initial_config)
    # state.print_chessboard()
    ga_solver = GASolver(n_population=8)
    final_state = ga_solver.solve()
    final_state.print_chessboard()
    print(final_state.get_attacking_count())
    print(ga_solver.get_running_time(), ga_solver.get_expanded_count(),
          ga_solver.get_cost())

    csp = CSPSolver()
    csp.solve(state)
    print("Number steps to the final solution =", csp.get_cost())
    csp.final_sol.print_chessboard()
    print("Expanded node count =", csp.get_expanded_count())
Ejemplo n.º 3
0
    if len(sys.argv) != 8:
        print('Usage:', sys.argv[0], 'in_train_file in_test_file in_test_ans in_user_profile_file in_config out_train_file out_test_file')
        exit()
    
    # arguments
    train_file = sys.argv[1]
    test_file = sys.argv[2]
    test_ans_file = sys.argv[3]
    user_profile_file = sys.argv[4]
    config_file = sys.argv[5]
    out_train_file = sys.argv[6]
    out_test_file = sys.argv[7]

    # read in data
    train_graph = file_io.read_graph(train_file)
    config = file_io.read_config(config_file)
    user_feature = None
    
    (user_feature, feature_name) = file_io.read_feature_column_major(user_profile_file, config)
    
    #normalize features
    for column in user_feature:
        if column.type == 'numerical':
            cf.normalize_column(column)
        elif column.type == 'categorical':
            cf.convert_to_dummy_variable(column)
    
    test_pair = file_io.read_data(test_file)
    train_graph = update_nodes_from_test_data(train_graph, test_pair)
    test_ans = gen_label_mapping(test_pair, file_io.read_ans(test_ans_file))
    gen_training_data(train_graph, user_feature, out_train_file)
Ejemplo n.º 4
0
 def load_file(self):
     file, _ = QFileDialog.getOpenFileName(QFileDialog(), 'Open File')
     if file:
         self.chessboard = read_config(file)
         self.refresh_chessboard()
Ejemplo n.º 5
0
def main():
    # Command line args are in sys.argv[1], sys.argv[2] ..
    # sys.argv[0] is the script name itself and can be ignored
    config = 'V:/DAMAnalysis-Lori/PySolo_Data/pysolo_video.cfg'
    key = ''
    if len(sys.argv) == 2:
        directory = os.path.dirname(os.path.realpath(__file__))
        config = os.path.join(directory, 'config.ini')
        key = sys.argv[1]
    elif len(sys.argv) > 2:
        config = sys.argv[1]
        key = sys.argv[2]
    else:
        print """
        usage: python process_experiment.py [config_file] key_file

        To process trikinetics experimental data, pass a config file (containing
        relatively constant parameters) and a key file (containing both parameters
        relevant to the specific experiment as well as the genotypes and
        monitor/channel positions of flies).  If only one argument is passed, the
        default configuration is used.

        When called, these files are parsed and the raw experimental data is
        processed/aggregated into two dictionaries:
        activity_dict - a table containing the raw beam crossing events, per minute
        sleep_dict    - a table where minutes of sleep are marked with a '1'
                    (sleep is defined as 5+ consecutive minutes of 0 activity)

        After the construction of these dictionaries, plots are produced for the
        experimental metadata as well as sleep and activity for each line vs all
        controls.  Other plot types are included in the plot.y module, but not
        implemented in this script.

        The activity and sleep dictionaries are written as .xls files for later use.
        """

    # read the configuration file
    config_dict = file_io.read_config(config)

    # read the key file
    (protocol_dict, genotype_dict) = file_io.read_key(key)

    # create dataframe for DEnM data
    DEnM_df = file_io.read_DEnM_data(protocol_dict['DEnM'],
                                     config_dict['env_monitors'])

    # since loading activity monitor data is expensive, find out which
    # monitors we need first, then load the data into DAM_dict
    dam_monitors = set(item[0] for sublist in genotype_dict.itervalues()
                       for item in sublist)
    DAM_dict = {
        'M' + str(monitor): file_io.read_DAM_data(monitor,
                                                  config_dict['max_monitor'])
        for monitor in dam_monitors
    }

    # sort/collect data by genotype and create activity dict
    activity_dict = analyze.aggregate_by_genotype(genotype_dict, config_dict,
                                                  DEnM_df, DAM_dict)
    # mark and remove dead fly data so that it isn't plotted
    dead_flies = analyze.mark_dead_flies(protocol_dict, DEnM_df, activity_dict,
                                         genotype_dict)
    dead_flies_filename = key[:-4] + '_dead_flies' + '.txt'
    with open(dead_flies_filename, "a") as myfile:
        myfile.write('\n'.join(dead_flies))
    # create sleep dict from activity dict
    sleep_dict = analyze.calculate_sleep(activity_dict)

    # create subfolder for output
    f = key[:-4] + '_plots'
    try:
        os.makedirs(f)
    except OSError as exception:
        if exception.errno != errno.EEXIST:
            raise
    shutil.copy(key, f)  # copy key file to output folder
    shutil.move(dead_flies_filename,
                f)  # move dead_flies file to output folder
    os.chdir(
        f
    )  # move into the output folder, so all subsequent files will be saved there

    # plot the DEnM data, including light intensity, temperature, and relative humidity
    plot.metadata(protocol_dict, DEnM_df)

    # plot the activity and sleep of each genotype individually, with all controls
    controls = list()
    if set(protocol_dict['control_genotype']) & set(genotype_dict.keys()):
        controls = protocol_dict['control_genotype']
    for genotype in genotype_dict.keys():
        if genotype not in protocol_dict['control_genotype']:
            genotype_list = list(controls)
            genotype_list.append(genotype)
            plot.data(protocol_dict, DEnM_df, activity_dict, genotype_list,
                      'activity')
            plot.data(protocol_dict, DEnM_df, sleep_dict, genotype_list,
                      'sleep')

    # write the data to excel files
    file_io.write_data(protocol_dict, DEnM_df, activity_dict,
                       key[:-4] + '_activity.xls')
    file_io.write_data(protocol_dict, DEnM_df, sleep_dict,
                       key[:-4] + '_sleep.xls')
def main():
    # Command line args are in sys.argv[1], sys.argv[2] ..
    # sys.argv[0] is the script name itself and can be ignored
    config = ''
    key = ''
    if len(sys.argv) == 2:
        directory = os.path.dirname(os.path.realpath(__file__))
        config = os.path.join(directory, 'config.ini')
        key = sys.argv[1]
    elif len(sys.argv) > 2:
        config = sys.argv[1]
        key = sys.argv[2]
    else:
        print """
        usage: python process_experiment.py [config_file] key_file

        To process trikinetics experimental data, pass a config file (containing
        relatively constant parameters) and a key file (containing both parameters
        relevant to the specific experiment as well as the genotypes and
        monitor/channel positions of flies).  If only one argument is passed, the
        default configuration is used.

        When called, these files are parsed and the raw experimental data is
        processed/aggregated into two dictionaries:
        activity_dict - a table containing the raw beam crossing events, per minute
        sleep_dict    - a table where minutes of sleep are marked with a '1'
                    (sleep is defined as 5+ consecutive minutes of 0 activity)

        After the construction of these dictionaries, plots are produced for the
        experimental metadata as well as sleep and activity for each line vs all
        controls.  Other plot types are included in the plot.y module, but not
        implemented in this script.

        The activity and sleep dictionaries are written as .xls files for later use.
        """

    # read the configuration file
    config_dict = file_io.read_config(config)

    # read the key file
    (protocol_dict, genotype_dict) = file_io.read_key(key)

    # create dataframe for DEnM data
    DEnM_df = file_io.read_DEnM_data(protocol_dict['DEnM'], config_dict['env_monitors'])

    # since loading activity monitor data is expensive, find out which
    # monitors we need first, then load the data into DAM_dict
    dam_monitors = set(item[0] for sublist in genotype_dict.itervalues() for item in sublist)
    DAM_dict = {'M' + str(monitor): file_io.read_DAM_data(monitor, config_dict['max_monitor']) for monitor in dam_monitors}

    # sort/collect data by genotype and create activity dict
    activity_dict = analyze.aggregate_by_genotype(genotype_dict, config_dict, DEnM_df, DAM_dict)
    # mark and remove dead fly data so that it isn't plotted
    dead_flies = analyze.mark_dead_flies(protocol_dict, DEnM_df, activity_dict, genotype_dict)
    dead_flies_filename = key[:-4] + '_dead_flies' + '.txt'
    with open(dead_flies_filename, "a") as myfile:
        myfile.write('\n'.join(dead_flies))
    # create sleep dict from activity dict
    sleep_dict = analyze.calculate_sleep(activity_dict)

    # create subfolder for output
    f = key[:-4] + '_plots'
    try:
        os.makedirs(f)
    except OSError as exception:
        if exception.errno != errno.EEXIST:
            raise
    shutil.copy(key, f) # copy key file to output folder
    shutil.move(dead_flies_filename, f) # move dead_flies file to output folder
    os.chdir(f) # move into the output folder, so all subsequent files will be saved there

    # plot the DEnM data, including light intensity, temperature, and relative humidity
    plot.metadata(protocol_dict, DEnM_df)

    # plot the activity and sleep of each genotype individually, with all controls
    controls = list()
    if set(protocol_dict['control_genotype']) & set(genotype_dict.keys()):
        controls = protocol_dict['control_genotype']
    for genotype in genotype_dict.keys():
        if genotype not in protocol_dict['control_genotype']:
            genotype_list = list(controls)
            genotype_list.append(genotype)
            plot.data(protocol_dict, DEnM_df, activity_dict, genotype_list, 'activity')
            plot.data(protocol_dict, DEnM_df, sleep_dict, genotype_list, 'sleep')

    # write the data to excel files
    file_io.write_data(protocol_dict, DEnM_df, activity_dict, key[:-4] + '_activity.xls')
    file_io.write_data(protocol_dict, DEnM_df, sleep_dict, key[:-4] + '_sleep.xls')
Ejemplo n.º 7
0
def get_config_if_exist():
    if file_io.config_file_exist():
        config = file_io.read_config()
        return config
Ejemplo n.º 8
0
def init_config():
    logger.info("Read config file --- Start")
    config = read_config()
    logger.info("Read config file --- Complete")

    return config