-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.m
57 lines (45 loc) · 1.32 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
clear all
close all
clc
%% add functions to path
addpath('../fcn/');
%% load data
load data/structural_connectivity.mat
load data/coordinates.mat
load data/brain_states.mat
%% rescale sc matrix
a = sc;
a = a/eigs(a,1);
a = a - eye(length(a));
%% define input matrices
% beta controls the decay rate
beta = 0.15;
n = length(sc);
b_local = eye(n);
b_spatial = exp(-beta*squareform(pdist(coor)));
%% set parameters for optimal control
% same parameters from the manuscript
rho = 100;
T = 1;
%% run all possible transitions
e_global_spatial = zeros(size(cent,2));
e_global_local = e_global_spatial;
% for each initial state
for initial = 1:size(cent,2)
x0 = cent(:,initial);
% for each target state
for target = 1:size(cent,2)
xt = cent(:,target);
% print status
fprintf('%i to %i',initial,target);
tic;
% calculate trajectories and input signals
[x_spatial,u_spatial] = optimalControlContinuous(a,b_spatial,rho,x0,xt,T);
[x_local,u_local] = optimalControlContinuous(a,b_local,rho,x0,xt,T);
% calculate global energy
e_global_spatial(initial,target) = mean(mean(u_spatial(:).^2));
e_global_local(initial,target) = mean(mean(u_local(:).^2));
% print timer
fprintf(' ... %.2f s\n',toc);
end
end