-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize_A.m
111 lines (100 loc) · 4.21 KB
/
initialize_A.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function A = initialize_A( evs, init )
% This file is part of GPCCA.
%
% Copyright (c) 2018, 2017 Bernhard Reuter
%
% If you use this code or parts of it, cite the following reference:
%
% Reuter, B., Weber, M., Fackeldey, K., Röblitz, S., & Garcia, M. E. (2018). Generalized
% Markov State Modeling Method for Nonequilibrium Biomolecular Dynamics: Exemplified on
% Amyloid β Conformational Dynamics Driven by an Oscillating Electric Field. Journal of
% Chemical Theory and Computation, 14(7), 3579–3594. https://doi.org/10.1021/acs.jctc.8b00079
%
% GPCCA is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published
% by the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% -------------------------------------------------------------------------
% initialize the A (n,n)-matrix
%
% A = initialize_A( evs, init )
%
% Input:
% init = 0: A will be read from file
% = 1: A will be calculated by inverting of the n first
% eigen- or Schurvectors
% evs the n first eigen- or Schurvectors
%
% Output:
% A the A (n,n)-matrix
%
% Written by Bernhard Reuter, Theoretical Physics II,
% University of Kassel, 2017
% -----------------------------------------------------------------------
class_t = class(evs) ;
function r = num_t(expression)
if (nargin > 0)
if(strcmpi(class_t,'mp')), r = mp(expression) ;
else
if isnumeric(expression)
r = expression ;
else
r = eval(expression) ;
end ;
end ;
else
r = class_t ;
end ;
end % num_t
% -----------------------------------------------------------------------
[N,k]=size(evs) ;
dummy = ( abs(evs(:,1) - 1) < ( num_t('100') * eps(num_t) ) ) ;
assert(all(dummy(:)), 'initialize_A:FirstColumnError', ...
'evs(:,1) isnt equal 1!')
assert(N>=k,'initialize_A:MatrixShapeError1',['The Eigen- or ', ...
'Schurvector matrix has more columns than rows. You cant ', ...
'cluster N datapoints into k>N clusters.'])
assert(N~=k,'initialize_A:MatrixShapeError2',['The Eigen- or ', ...
'Schurvector matrix has equal number of columns and rows. ', ...
'There is no point in clustering N datapoints into k=N clusters.'])
if init == 1
% search start simplex vertices ('inner simplex algorithm')
index = indexsearch(evs) ;
% compute transformation matrix A as initial guess for local
% optimization (maybe not feasible)
A = evs(index,:) ;
dummy = cond(A) ;
assert((dummy < (num_t('1')/eps(num_t))), ...
'initialize_A:A_ConditionError', ...
['The condition number of the initial guess for A is too ', ...
'high: cond(A)=%.15e'],double(dummy))
if (dummy > 1e4)
disp(['Warning for ' num2str(k) ' clusters: The condition ' ...
'number of the initial guess for A is > 1e4'])
end
disp(' ')
disp(['condition number of EVS(index,:) for ' num2str(k) ...
' clusters: ' num2str(dummy)])
%disp(num2str(dummy))
clearvars dummy
disp(' ')
A = pinv(A) ;
A = double(A) ;
elseif init == 0
oldfileid = inputT(['Enter the fileid (IN QUOTES) of the files ' ...
'containing the initial A to optimize: '],'oldfileid') ;
name = strcat(oldfileid,'-','n=',int2str(k),'-','A','.mat') ;
load(name, 'A') ;
else
error('initialize_A:InputError', ...
'invalid input: init has to be either 0 or 1')
end
end