DualLoop / src / run_experiments.py
run_experiments.py
Raw
#
#     dualloop
#
#        File:  run_experiments.py
#
#     Authors: Deleted for purposes of anonymity
#
#     Proprietor: Deleted for purposes of anonymity --- PROPRIETARY INFORMATION
#
# The software and its source code contain valuable trade secrets and shall be maintained in
# confidence and treated as confidential information. The software may only be used for
# evaluation and/or testing purposes, unless otherwise explicitly stated in the terms of a
# license agreement or nondisclosure agreement with the proprietor of the software.
# Any unauthorized publication, transfer to third parties, or duplication of the object or
# source code---either totally or in part---is strictly prohibited.
#
#     Copyright (c) 2019 Proprietor: Deleted for purposes of anonymity
#     All Rights Reserved.
#
# THE PROPRIETOR DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE AND THE WARRANTY AGAINST LATENT
# DEFECTS, WITH RESPECT TO THE PROGRAM AND ANY ACCOMPANYING DOCUMENTATION.
#
# NO LIABILITY FOR CONSEQUENTIAL DAMAGES:
# IN NO EVENT SHALL THE PROPRIETOR OR ANY OF ITS SUBSIDIARIES BE
# LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES
# FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF INFORMATION, OR
# OTHER PECUNIARY LOSS AND INDIRECT, CONSEQUENTIAL, INCIDENTAL,
# ECONOMIC OR PUNITIVE DAMAGES) ARISING OUT OF THE USE OF OR INABILITY
# TO USE THIS PROGRAM, EVEN IF the proprietor HAS BEEN ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGES.
#
# For purposes of anonymity, the identity of the proprietor is not given herewith.
# The identity of the proprietor will be given once the review of the
# conference submission is completed.
#
# THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
#

import json
import os
import resource
import subprocess
import sys

import pandas as pd
import pickle

import dualloop as dual_loops

def read_config(config_file):
    with open(config_file, 'r') as f:
        config = json.load(f)
    return config

def run_evaluation_case(cfg, dataset_name, method_name):
    my_dataset_df = pd.read_csv('./data/csv/' + dataset_name + '_matrix.csv')

    lfs_set = cfg['lfs_set']
    tunable_lfs = cfg['tunable_lf_set']
    feature_set = cfg['feature_set']
    methods = cfg['methods']
    method_config = methods[method_name]

    epochs = 100
    balance = [0.9, 0.1]

    total_size = len(my_dataset_df)
    num_iteration = total_size

    # num_iteration = int(total_size * 0.2)   # explore only the first 20% of the dataset
    # if num_iteration > 2000:
    #     num_iteration = 2000

    if dataset_name.startswith('conference-'):
        batch_size = 10
        interval_slow_loop = 20
    elif dataset_name.startswith('ai4eu-'):
        batch_size = 50
        interval_slow_loop = 100
    elif dataset_name.startswith('nasa-'):
        batch_size = 100
        interval_slow_loop = 200
    else:
        batch_size = 100
        interval_slow_loop = 200

    result = dual_loops.run_experiment(method_config, my_dataset_df, lfs_set, tunable_lfs, feature_set,
                                                  total_size, num_iteration, interval_slow_loop, batch_size,
                                                  balance, epochs, False)

    # make sure the result folder is created
    if not os.path.exists('./results/' + dataset_name):
        os.makedirs('./results/' + dataset_name)

    pickle.dump(result, open('./results/' + dataset_name + "/result_" + method_name + "_" + dataset_name + ".pk", "wb"))


if __name__ == "__main__":
    # set the limit of file descriptors
    resource.setrlimit(resource.RLIMIT_NOFILE, (8192, 8192))
    subprocess.check_output("whoami; ulimit -n", shell=True)

    # Count the arguments
    arguments = len(sys.argv) - 1
    if arguments < 1:
        print("please specify the data set [conference|ai4eu|nasa|anatomy]")
        exit()
    else:
        dataset_name = sys.argv[1]

    cfg = read_config('./config.json')

    for method_name in cfg['methods']:
        method = cfg['methods'][method_name]
        if method['to_be_evaluated']:
            run_evaluation_case(cfg, dataset_name, method_name)
            print("Done with " + method_name)