-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.jl
88 lines (79 loc) · 3.52 KB
/
utils.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
module Utils
using JSON, ..Metrics, ..Mutation, ..Recombination, ..FunctionsCollection
function get_algo_params()
file_path = pwd() * "/algo_inputs.json"
parameters = JSON.parse(read(file_path, String))
parameters["error_function"] = select_error_function(parameters["error_function"])
parameters["recombination_type"] = select_recombination_type(parameters["recombination_type"])
parameters["mutation_type"] = select_mutation_type(parameters["mutation_type"])
parameters["evaluate_function"] = select_evaluate_function(parameters["evaluate_function"])
parameters["output_file"] = select_output_file(parameters["output_file"])
return parameters
end
function select_output_file(output_file)
letters = Set(output_file)
if length(letters) == 1 && ' ' in letters
return nothing
elseif output_file == ""
return nothing
else
return output_file
end
end
function select_evaluate_function(evaluate_function)
if evaluate_function[end] == '1'
return FunctionsCollection.function1
elseif evaluate_function[end] == '2'
return FunctionsCollection.function2
elseif evaluate_function[end] == '3'
return FunctionsCollection.function3
elseif evaluate_function[end] == '4'
return FunctionsCollection.function4
elseif evaluate_function[end] == '5'
return FunctionsCollection.function5
else
throw(ArgumentError("Function to evaluate requested not available. Options are:
function1, function2, function3, function4, function5"))
end
end
# Get error function based on possibilities
function select_error_function(error_function)
if error_function == "mean_sqr_error"
return Metrics.mean_sqr_error
elseif error_function == "mean_absolute_error"
return Metrics.mean_absolute_error
elseif error_function == "weighted_mean_abs_error"
return Metrics.weighted_mean_abs_error
else
throw(ArgumentError("Error function requested not available. Options are: mean_sqr_error,
mean_absolute_error, weighted_mean_abs_error"))
end
end
# Get recombination based on possibilities
function select_recombination_type(recombination_type)
if recombination_type == "intermediary_recombination"
Recombination.intermediary_recombination
elseif recombination_type == "discrete_recombination"
Recombination.discrete_recombination
else
throw(ArgumentError("Recombination type requested not available. Options are:
intermediary_recombination, discrete_recombination"))
end
end
# Get mutation type based on possibilities
function select_mutation_type(mutation_type)
if mutation_type == "uncorr_mutation_onestepsize"
return Mutation.uncorr_mutation_onestepsize
elseif mutation_type == "uncorr_mutation_n_stepsize"
return Mutation.uncorr_mutation_n_stepsize
else
throw(ArgumentError("Mutation type requested not available. Options are:
uncorr_mutation_onestepsize, uncorr_mutation_n_stepsize"))
end
end
# Linspace like utils
function generate_linespace(min, max, n_values)
step = (max-min)/n_values
return collect(min:step:max)
end
end