This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ttest, pval = ttest_ind(local_mean_f1_scores, fed_avg_f1_scores) | |
print("statistically significant:", pval < 0.05) | |
print("p =", pval) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hyperparams = { | |
'n_runners': 10, | |
'sample_size': 5, | |
'rounds': 100, | |
'combine': 'weighted', # or 'mean' | |
'partition_params': { | |
'scheme': 'uniform' # stratified, non-iidness, noise injection etc. | |
}, | |
'runner_hyperparams': { | |
'epochs': 1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
skews = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.99} | |
scores = {} | |
for skew in skews: | |
print("eval", skew) | |
hyperparams = { | |
'n_runners': 10, | |
'sample_size': 10, | |
'rounds': 1, | |
'combine': 'weighted', # or 'mean' | |
'partition_params': { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compare_f1(hyperparams, rounds=1): | |
local_mean_f1_scores = [] | |
local_max_f1_scores = [] | |
fed_avg_f1_scores = [] | |
for i in range(0, rounds): | |
fed_avg = FedAvg(**hyperparams) | |
fed_avg.fit(X_train, y_train) | |
preds = fed_avg.predict(X_test) | |
fed_avg_f1_scores.append(f1_score(y_test, preds, average='weighted')) | |
tmp = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def label_distribution_skew(x, y, partitions, skew=1): | |
def runner_split(N_labels, N_runners): | |
"""number of labels to assign to n runners""" | |
runner_labels = round(max(1, N_labels / N_runners)) | |
runner_split = round(max(1, N_runners / N_labels)) | |
return runner_labels, runner_split | |
runner_data = [] | |
N_labels = np.unique(y).shape[0] | |
n_labels, n_runners = runner_split(N_labels, partitions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for _ in range(self.rounds): | |
r_intercepts, r_coefs, r_weights = self._collect_models(runners, N) | |
self.intercept_ = np.average(r_intercepts, axis=0, weights=r_weights) | |
self.coef_ = np.average(r_coefs, axis=0, weights=r_weights) | |
self.global_model = set_weights(self.intercept_, self.coef_, np.unique(y)) | |
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _collect_models(self, runners, N): | |
r_intercepts, r_coefs, r_weights = [], [], [] | |
self.models = [] | |
for runner in random.sample(runners, k=self.sample_size): | |
r_model = runner.optimise(self.intercept_, self.coef_, self.runner_hyperparams) | |
self.models.append(r_model) | |
r_intercepts.append(r_model.intercept_) | |
r_coefs.append(r_model.coef_) | |
r_weights.append(runner.dataset_size()/N if self.combine == 'weighted' else 1/self.sample_size) | |
return r_intercepts, r_coefs, r_weights |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fit(self, X, y): | |
if self.intercept_ is None or self.coef_ is None: | |
features = X.shape[1] | |
self.intercept_ = np.zeros(1) | |
self.coef_ = np.zeros((1, features)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Backup iPad/iPhone to Mac (without encryption) | |
2. Locate backup folder and run https://code.google.com/p/iphone-dataprotection/: | |
python python_scripts/backup_tool.py ~/Library/Application\ Support/MobileSync/Backup/XXXXXXX outdir | |
3. Open sqlite db under using SquirrelSQL: | |
outdir/HomeDomain/Library/Notes/notes.sqlite |
NewerOlder