Skip to content

Instantly share code, notes, and snippets.

@chilang
chilang / caption.js
Created November 16, 2023 15:54
hyperaudio-static
/*! (C) The Hyperaudio Project. MIT @license: en.wikipedia.org/wiki/MIT_License. */
/*! Version 2.1.4 */
'use strict';
var caption = function () {
var cap = {};
function formatSeconds(seconds) {
if (typeof seconds == 'number') {
//console.log("seconds = "+seconds);
ttest, pval = ttest_ind(local_mean_f1_scores, fed_avg_f1_scores)
print("statistically significant:", pval < 0.05)
print("p =", pval)
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,
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': {
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 = []
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)
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
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
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))
@chilang
chilang / iOSNotesTo1Password
Last active August 29, 2015 14:04
Import iOS Notes into 1Password
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