Delete Problems/__pycache__ directory
[Neurips2024_16722.git] / exp4.py
bloba0343f2ef76535db42b65b1d8e9eba2862faa135
1 import numpy as np
2 from Problems.synthetic_cosh import synthetic
3 from analysis.analysis import error
4 from graph.graph import Random
5 from Optimizers import DOPTIMIZER as dopt
6 from utilities import utilities as ut
7 from utilities.plot_utils import plot_exp4
8 import os
11 ### creating times
12 seed = np.random.randint(12345)
13 seed = 8075
14 np.random.seed(seed)
16 #### create asynchronous setup
17 num_nodes = 10
18 dim = 5
19 comp_time_dist = 'random_uniform'
21 mincomp = np.array([1,1,1,1,1,1,1,1,1,1])
22 maxcomp = np.array([5,10,15,20,25,30,35,40,45,50])
24 T_active_exp4, Tv_nodes_exp4, node_comp_time_exp4 = \
25 ut.create_computation_time(num_nodes, max_iter=int(1e5), comp_time_dist=comp_time_dist, mean_comp=None,\
26 min_comp=mincomp, max_comp=maxcomp, variance_comp=None, make_integer=True)
29 #### some parameters of the algorithms
30 learning_rate = 0.01
31 depoch = 12000
32 rho = 0.01
33 alpha = 0.1
34 gamma = 0.5
35 eta = 1.0
36 expScale = 1/10.
38 drop_prob_0 = 0.0
39 drop_prob_1 = 0.25
40 drop_prob_2 = 0.5
41 drop_prob_3 = 0.75
44 #### Problem setup: parameters of the synthetic functions and constraints.
45 prd = synthetic(seed, num_nodes, dim)
46 error_prd = error(prd,np.zeros(num_nodes),0)
49 #### Create gossip matrices
50 zero_row_sum,zero_col_sum,row_stochastic,col_stochastic, N_out, neighbors = Random(num_nodes, prob=0.8, Laplacian_dividing_factor= 2).directed()
53 #### Run the optimization algorithms and compute the performance metrics
54 np.random.seed(seed)
55 x_asy_dagp1, _, _, _, _, Delay_mat_dagp_1 = \
56 dopt.Asy_DAGP(T_active_exp4, Tv_nodes_exp4, prd, zero_row_sum, zero_col_sum, learning_rate, depoch, num_nodes, dim, rho, alpha, gamma, eta, neighbors, \
57 cons = True, delay_type='exp', min_delay=None, max_delay=None, expScale_delay=expScale, \
58 drop_msg=True, drop_prob=drop_prob_1)
59 np.random.seed(seed)
60 x_asy_dagp2, _, _, _, _, Delay_mat_dagp_2 = \
61 dopt.Asy_DAGP(T_active_exp4, Tv_nodes_exp4, prd, zero_row_sum, zero_col_sum, learning_rate, depoch, num_nodes, dim, rho, alpha, gamma, eta, neighbors, \
62 cons = True, delay_type='exp', min_delay=None, max_delay=None, expScale_delay=expScale, \
63 drop_msg=True, drop_prob=drop_prob_2)
64 np.random.seed(seed)
65 x_asy_dagp3, _, _, _, _, Delay_mat_dagp_3 = \
66 dopt.Asy_DAGP(T_active_exp4, Tv_nodes_exp4, prd, zero_row_sum, zero_col_sum, learning_rate, depoch, num_nodes, dim, rho, alpha, gamma, eta, neighbors, \
67 cons = True, delay_type='exp', min_delay=None, max_delay=None, expScale_delay=expScale, \
68 drop_msg=True, drop_prob=drop_prob_3)
69 np.random.seed(seed)
70 x_asy_dagp0, _, _, _, _, Delay_mat_dagp_0 = \
71 dopt.Asy_DAGP(T_active_exp4, Tv_nodes_exp4, prd, zero_row_sum, zero_col_sum, learning_rate, depoch, num_nodes, dim, rho, alpha, gamma, eta, neighbors, \
72 cons = True, delay_type='exp', min_delay=None, max_delay=None, expScale_delay=expScale, \
73 drop_msg=True, drop_prob=drop_prob_0)
76 f_asy_dagp0 = error_prd.cost_path(np.sum(x_asy_dagp0, axis=1)/num_nodes)
77 f_asy_dagp1 = error_prd.cost_path(np.sum(x_asy_dagp1, axis=1)/num_nodes)
78 f_asy_dagp2 = error_prd.cost_path(np.sum(x_asy_dagp2, axis=1)/num_nodes)
79 f_asy_dagp3 = error_prd.cost_path(np.sum(x_asy_dagp3, axis=1)/num_nodes)
82 #### save data and plot results
83 plot_exp4(T_active_exp4, f_asy_dagp0, f_asy_dagp1, f_asy_dagp2, f_asy_dagp3, current_dir=os.path.dirname(os.path.abspath(__file__)), save_results_folder='exp4', plot_iter=depoch)