Skip to content

Commit

Permalink
big push
Browse files Browse the repository at this point in the history
  • Loading branch information
TheColdIce committed Oct 8, 2024
1 parent 39ecdc0 commit 96b9a22
Show file tree
Hide file tree
Showing 15 changed files with 771 additions and 286 deletions.
Binary file added experiments/data.zip
Binary file not shown.
143 changes: 143 additions & 0 deletions experiments/hyperparams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@

LogRegClient_params = {
'default': {
'lr_patience': 5,
'es_patience': 15,
'n_rounds': 10,
'eval_every': 10,
'batch_size': 512,
'optimizer': {
'SGD': {
'lr': 0.01,
'momentum': 0.0,
'weight_decay': 0.0,
'dampening': 0.0,
}
},
'criterion': {
'ClassBalancedLoss': {
'gamma': 0.9
}
}
},
'search_space': {
'batch_size': [128, 256, 512],
'optimizer': {
'SGD': {
'lr': (0.001, 0.1),
'momentum': (0.0, 1.0),
'weight_decay': (0.0, 1.0),
'dampening': (0.0, 1.0),
},
'Adam': {
'lr': (0.001, 0.1),
'weight_decay': (0.0, 1.0),
'amsgrad': [True, False]
}
},
'criterion': {
'ClassBalancedLoss': {
'gamma': (0.5, 0.9999)
},
'CrossEntropyLoss': {}
}
}
}

DecisionTreeClient_params = {
'default': {
'criterion': 'gini',
'splitter': 'best',
'max_depth': None,
'random_state': 42,
'class_weight': 'balanced'
},
'search_space': {
'criterion': ['gini', 'entropy', 'log_loss'],
'splitter': ['best', 'random'],
'max_depth': (1, 100),
'class_weight': ['balanced', None]
}
}

RandomForestClient_params = {
'default': {
'n_estimators': 100,
'criterion': 'gini',
'max_depth': None,
'random_state': 42,
'class_weight': 'balanced'
},
'search_space': {
'n_estimators': (10, 1000),
'criterion': ['gini', 'entropy', 'log_loss'],
'max_depth': (1, 100),
'class_weight': ['balanced', None]
}
}

GradientBoostingClient_params = {
'default': {
'loss': 'log_loss',
'learning_rate': 0.1,
'n_estimators': 100,
'criterion': 'friedman_mse',
'max_depth': 3,
'random_state': 42
},
'search_space': {
'loss': ['log_loss', 'exponential'],
'learning_rate': (0.01, 1.0),
'n_estimators': (10, 200),
'criterion': ['friedman_mse', 'squared_error'],
'max_depth': (2, 100),
'random_state': 42
}
}

SVMClient_params = {
'default': {
'C': 1.0,
'kernel': 'rbf',
'degree': 3,
'gamma': 'scale',
'coef0': 0.0,
'shrinking': True,
'probability': False,
'class_weight': 'balanced',
'cache_size': 7000,
'max_iter': 1000,
'random_state': 42
},
'search_space': {
'C': (0.1, 10.0),
'kernel': ['linear', 'poly', 'rbf', 'sigmoid'],
'degree': (2, 5),
'gamma': ['scale', 'auto'],
'coef0': (0.0, 1.0),
'shrinking': [True, False],
'probability': [False, True],
'class_weight': ['balanced', None],
'random_state': 42
}
}

KNNClient_params = {
'default': {
'n_neighbors': 5,
'weights': 'uniform',
'algorithm': 'auto',
'leaf_size': 30,
'p': 2,
'metric': 'minkowski',
'n_jobs': -1
},
'search_space': {
'n_neighbors': (3, 100),
'weights': ['uniform', 'distance'],
'algorithm': ['auto', 'ball_tree', 'kd_tree', 'brute'],
'leaf_size': (10, 50),
'p': [1, 2],
'metric': 'minkowski'
}
}
25 changes: 11 additions & 14 deletions experiments/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ def main():
parser.add_argument('--seed', type=int, help='Seed.', default=42)
parser.add_argument('--n_rounds', type=int, help='Number of traning rounds.', default=3)
parser.add_argument('--eval_every', type=int, help='Number of rounds between evaluations.', default=1)
parser.add_argument('--local_epochs', type=int, help='Number of local epochs at clients.', default=1)
#parser.add_argument('--local_epochs', type=int, help='Number of local epochs at clients.', default=1)
parser.add_argument('--batch_size', type=int, help='Batch size.', default=512)
parser.add_argument('--lr', type=float, help='Learning rate.', default=0.02)
parser.add_argument('--n_workers', type=int, help='Number of processes.', default=3)
parser.add_argument('--device', type=str, help='Device for computations. Can be "cpu" or cuda device, e.g. "cuda:0".', default="cuda:0")
parser.add_argument('--lr_patience', type=int, help='Number of epochs to wait before reducing learning rate.', default=5)
parser.add_argument('--es_patience', type=int, help='Number of epochs to wait before early stopping.', default=15)
parser.add_argument('--results_dir', type=str, default='/home/edvin/Desktop/flib/experiments/results/3_banks_homo_easy/')
args = parser.parse_args()

print()
print(f'clients: {args.clients}')
print(f'\nclients: {args.clients}')
print(f'settings: {args.settings}')
print(f'traindata files:')
for traindata_file in args.traindata_files:
Expand All @@ -60,13 +61,12 @@ def main():
print(f'seed: {args.seed}')
print(f'n_rounds: {args.n_rounds}')
print(f'eval_every: {args.eval_every}')
print(f'local_epochs: {args.local_epochs}')
#print(f'local_epochs: {args.local_epochs}')
print(f'batch_size: {args.batch_size}')
print(f'lr: {args.lr}')
print(f'n_workers: {args.n_workers}')
print(f'device: {args.device}')
print(f'results_dir: {args.results_dir}')
print()
print(f'results_dir: {args.results_dir}\n')

train_dfs = []
val_dfs = []
Expand Down Expand Up @@ -101,8 +101,8 @@ def main():
criterion=args.criterion,
n_epochs=args.n_rounds,
eval_every=args.eval_every,
lr_patience=5,
es_patience=15,
lr_patience=args.lr_patience,
es_patience=args.es_patience,
optimizer=args.optimizer,
beta=args.beta,
batch_size=args.batch_size,
Expand All @@ -117,8 +117,7 @@ def main():
os.makedirs(results_dir, exist_ok=True)
with open(os.path.join(results_dir, 'results.pkl'), 'wb') as f:
pickle.dump(results, f)
print(f'Saved results to {results_dir}/results.pkl')
print()
print(f'Saved results to {results_dir}/results.pkl\n')
if 'federated' in args.settings:
print(f'Training {client} in federated setting.')
t = time.time()
Expand All @@ -145,8 +144,7 @@ def main():
os.makedirs(results_dir, exist_ok=True)
with open(os.path.join(results_dir, 'results.pkl'), 'wb') as f:
pickle.dump(results, f)
print(f'Saved results to {results_dir}/results.pkl')
print()
print(f'Saved results to {results_dir}/results.pkl\n')
if 'isolated' in args.settings:
print(f'Training {client} in isolated setting')
t = time.time()
Expand Down Expand Up @@ -175,8 +173,7 @@ def main():
os.makedirs(results_dir, exist_ok=True)
with open(os.path.join(results_dir, 'results.pkl'), 'wb') as f:
pickle.dump(results, f)
print(f'Saved results to {results_dir}/results.pkl')
print()
print(f'Saved results to {results_dir}/results.pkl\n')

if __name__ == '__main__':
main()
Expand Down
Loading

0 comments on commit 96b9a22

Please sign in to comment.