<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Parameters and Example Data
Step1:  True Changepoints
Step2:  Estimated Changepoints with GFGL smoother
Step3:  Visualising Graphical Models
To visualise the estimated graphical model in comparison to the ground truth, we simply feed the $\Theta$ elements into the DynamicGraphicalModel holding a number of graphs.
Step4:  Note that we only select three graphs to compare with the ground truth, i.e. those that lay inbetween the major changepoints at 30 and 60.
Step5:  Generating Dynamic Graphical Models
<ASSISTANT_TASK:>
Python Code:
y = np.load('../data/y.npy')
sigma = np.load('../data/sigma.npy')
sigma_inv = np.load('../data/sigma_inv.npy')
T = 90 # Steps
K = 2 # Changepoints
P = 10 # Variables
M = 5 # Active Edges
eps = 0.000001 # Edge threshold epsilon
Explanation: Parameters and Example Data
End of explanation
edges = get_edges(sigma_inv[0], eps)
change_points = get_change_points(sigma_inv, eps)
fig = plot_data_with_cps(y, change_points, ymin=-5, ymax=5)
verbose = False
tol = 1e-4
max_iter = 500
gammas = [1, 1, 1] # gamma_V1, gamma_V2, gamma_W
lambda1G = 0.15
lambda2G = 25
lambda1I = 0.25
lambda2I = 2
Explanation: True Changepoints
End of explanation
gfgl = GroupFusedGraphLasso(lambda1G, lambda2G, gammas[0], gammas[1], gammas[2], tol, max_iter, verbose)
gfgl.fit(y)
cps = get_change_points(gfgl.sparse_Theta, 0.01)
fig = plot_data_with_cps(y, cps, ymin=-5, ymax=5)
Explanation: Estimated Changepoints with GFGL smoother
End of explanation
from graphtime.simulate import DynamicGraphicalModel
Explanation: Visualising Graphical Models
To visualise the estimated graphical model in comparison to the ground truth, we simply feed the $\Theta$ elements into the DynamicGraphicalModel holding a number of graphs.
End of explanation
DGM = DynamicGraphicalModel.from_Thetas(sigma_inv)
DGM_est = DynamicGraphicalModel.from_Thetas(gfgl.sparse_Theta[[0, 45, 75]], eps=0.1)
DGM.draw();
DGM_est.draw();
Explanation: Note that we only select three graphs to compare with the ground truth, i.e. those that lay inbetween the major changepoints at 30 and 60.
End of explanation
DGM = DynamicGraphicalModel(10)
DGM.generate_graphs(n_edges_list=[3, 6])
DGM.draw();
X = DGM.sample(60, changepoints=[30])
plot_data_with_cps(X, [30]);
Explanation: Generating Dynamic Graphical Models
End of explanation
<END_TASK>