2017-07-29 19:47:02 +02:00
|
|
|
import os
|
2017-10-02 07:34:04 +02:00
|
|
|
from operator import itemgetter
|
2017-07-29 19:47:02 +02:00
|
|
|
|
2017-10-02 07:34:04 +02:00
|
|
|
import joblib
|
2017-07-30 13:47:11 +02:00
|
|
|
import numpy as np
|
|
|
|
from sklearn.utils import class_weight
|
|
|
|
|
2017-07-29 19:47:02 +02:00
|
|
|
|
|
|
|
def exists_or_make_path(p):
|
|
|
|
if not os.path.exists(p):
|
|
|
|
os.makedirs(p)
|
2017-07-30 13:47:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_custom_class_weights(client, server):
|
|
|
|
client_class_weight = class_weight.compute_class_weight('balanced', np.unique(client), client)
|
|
|
|
server_class_weight = class_weight.compute_class_weight('balanced', np.unique(server), server)
|
|
|
|
return {
|
|
|
|
"client": client_class_weight,
|
|
|
|
"server": server_class_weight
|
|
|
|
}
|
2017-09-17 10:23:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_custom_sample_weights(client, server):
|
|
|
|
return class_weight.compute_sample_weight("balanced", np.vstack((client, server)).T)
|
2017-10-02 07:34:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
def load_ordered_hyperband_results(path):
|
|
|
|
results = joblib.load(path)
|
|
|
|
return sorted(results, itemgetter("loss"))
|