Exemple #1
0
def prepare_deterministic(n, k, d, r, max_gd_steps, max_nfe):
    # Find directory for that specific n, k, d
    directories = listdir('data')
    n_string = 'n=' + str(n) + '_'
    directories = [s for s in directories if n_string in s]
    k_string = 'k=' + str(k) + '_'
    directories = [s for s in directories if k_string in s]
    d_string = 'density=' + str(d) + '.'
    directories = [s for s in directories if d_string in s]
    # Raise error if none or multiple directories were found.
    if len(directories) == 0:
        raise PlatypusError('Directory with those n, k, d not found!')
    if len(directories) != 1:
        raise PlatypusError(
            'Multiple directories with those n, k, d was found!')
    directory = 'data/' + directories[0] + '/'
    # Find the names of files that store the values of R matrices.
    matrices = listdir(directory)
    matrices = [s for s in matrices if 'R' in s]
    # Raise error if no files 'R*.csv' were found
    if len(matrices) == 0:
        raise PlatypusError('Directory with those n, k, d not found!')
    R = read_R(directory, matrices, n)
    gd = GradientDescentOptimizerAdam(R)
    local_search = AdamLocalSearch(gd, steps=max_gd_steps)
    problem = TriFactorization(gd)
    generator = ConstantKMatrixGenerator(len(matrices), n)
    hypervolume_dynamics = HypervolumeDynamics(k)
    algorithm = deterministic_algorithm(
        problem=problem,
        local_search=local_search,
        generator=generator,
        hypervolume_dynamics=hypervolume_dynamics)
    termination_condition = MaxEvaluationsAndTreshold(max_nfe)
    return algorithm, termination_condition
# Find directory for that specific n, k, d
dir = '../data'
directories = listdir(dir)
n_string = 'n=' + str(n) + '_'
directories = [s for s in directories if n_string in s]
k_string = 'k=' + str(k) + '_'
directories = [s for s in directories if k_string in s]
d_string = 'density=' + str(d) + '.'
directories = [s for s in directories if d_string in s]

directory = dir + '/' + directories[0] + '/'
# Find the names of files that store the values of R matrices.
matrices = listdir(directory)
matrices = [s for s in matrices if 'R' in s]
R = read_R(directory, matrices, n)

gd = GradientDescentOptimizerAdam(R)
local_search = AdamLocalSearchProgress(gd, steps=gd_steps_part1)
local_search1 = AdamLocalSearchProgress(gd, steps=gd_steps_part_2)

generator = ConstantKMatrixGenerator(len(matrices), n, scale=0.1)
problem = TriFactorization(gd)

# Saved errors for diffrerent k's
gd_step_1_results = dict()
gd_step_2_results = dict()

create_folder(dir_for_pictures)

# def optimization for random init