1 #ifndef TRANSFEROPERATORTEST_HPP 2 #define TRANSFEROPERATORTEST_HPP 6 #include <gsl/gsl_vector.h> 7 #include <gsl/gsl_vector_int.h> 8 #include <gsl/gsl_matrix.h> 9 #include <gsl/gsl_rng.h> 10 #include <gsl/gsl_randist.h> 11 #include <Eigen/Dense> 12 #include <Eigen/Sparse> 18 typedef Eigen::Triplet<double>
triplet;
20 typedef Eigen::SparseMatrix<double, Eigen::ColMajor>
SpMatCSC;
21 typedef Eigen::SparseMatrix<double, Eigen::RowMajor>
SpMatCSR;
25 void getSurrogateSpectrum(gsl_vector_int *,
size_t,
size_t, gsl_matrix *, gsl_matrix *,
26 const char *,
double,
int,
int,
bool,
double *);
27 void getSurrogateSpectrumFromCount(SpMatCSR *, gsl_rng *, gsl_matrix *, gsl_matrix*,
28 const char *,
double,
int,
int,
bool,
double *);
29 SpMatCSR *getShuffledCountMatrix(SpMatCSR *, gsl_vector *, gsl_rng *);
30 void getShuffledRow(SpMatCSR *,
size_t,
size_t,
tripletVector *, gsl_rng *);
34 void getSurrogateSpectrum(gsl_vector_int * gridMem,
size_t N,
size_t tauStep,
35 gsl_matrix *EigValRealDist, gsl_matrix *EigValImagDist,
36 const char *which=
"LM",
double tol=0.,
int maxit=0,
int ncv=0,
37 bool AutoShift=
true,
double *resid=NULL)
41 std::vector< std::vector <int > > boxDest;
42 std::vector<int> rowTmp;
43 const gsl_rng_type *rngType = gsl_rng_ranlxs1;
47 T = getTransitionCountTriplets(gridMem, tauStep);
50 C->setFromTriplets(T->begin(), T->end());
53 gsl_rng *r = gsl_rng_alloc(rngType);
57 getSurrogateSpectrumFromCount(C, r, EigValRealDist, EigValImagDist,
58 which, tol, maxit, ncv, AutoShift, resid);
68 void getSurrogateSpectrumFromCount(SpMatCSR *C, gsl_rng *r,
69 gsl_matrix *EigValRealDist, gsl_matrix *EigValImagDist,
70 const char *which=
"LM",
double tol=0.,
int maxit=0,
71 int ncv=0,
bool AutoShift=
true,
double *resid=NULL)
73 int nev = EigValRealDist->size1;
74 int Ns = EigValRealDist->size2;
76 gsl_vector *nTransPerRow;
87 ARluNonSymMatrix<double, double> *PsAR;
95 for (
int s = 0; s < Ns; s++){
97 std::cout <<
"Getting surrogate eigenvalues " << s <<
" out of " << (Ns-1)
99 Ps = getShuffledCountMatrix(&CCopy, nTransPerRow, r);
108 EigValReal =
new double[nev + 2];
109 EigValImag =
new double[nev + 2];
110 getEigValNonSym(PsAR, EigValReal, EigValImag, nev, which, tol, maxit, ncv,
114 for (
int ev = 0; ev < nev; ev++){
115 gsl_matrix_set(EigValRealDist, ev, s, EigValReal[ev]);
116 gsl_matrix_set(EigValImagDist, ev, s, EigValImag[ev]);
128 gsl_vector_free(nTransPerRow);
134 SpMatCSR *getShuffledCountMatrix(SpMatCSR *C, gsl_vector *nTransPerRow, gsl_rng *r)
136 size_t N = C->rows();
142 Ts->reserve(C->nonZeros());
145 for (
size_t i = 0; i < N; i++){
146 nTrans = (size_t) round(gsl_vector_get(nTransPerRow, i));
148 getShuffledRow(C, i, nTrans, Ts, r);
152 Cs->setFromTriplets(Ts->begin(), Ts->end());
158 void getShuffledRow(SpMatCSR *C,
size_t iRow,
size_t nTrans,
163 gsl_vector_int *dstRepeat = gsl_vector_int_alloc(nTrans);
164 unsigned long int sampleIdx;
169 for (SpMatCSR::InnerIterator it(*C, iRow); it; ++it){
170 for (
int r = 0; r < it.value(); r++){
171 gsl_vector_int_set(dstRepeat, k, it.col());
177 for (k = 0; k < nTrans; k++){
178 sampleIdx = gsl_rng_uniform_int(r, nTrans);
179 sample = gsl_vector_int_get(dstRepeat, sampleIdx);
180 Ts->push_back(
triplet(iRow, sample, 1));
183 gsl_vector_int_free(dstRepeat);
Eigen::Triplet< double > triplet
Eigen triplet of double.
Eigen::SparseMatrix< double, Eigen::RowMajor > SpMatCSR
Eigen sparse CSR matrix of double type.
gsl_vector * getRowSum(SpMatCSR *)
Get the sum of each row of an Eigen CSR matrix.
std::vector< triplet > tripletVector
STD vector of Eigen triplet of double.
Input, output and conversion routines.
Calculate discretized approximation of transfer operators from time series.
Get spectrum of sparse matrices using ARPACK++.
ARluNonSymMatrix< double, double > * Eigen2AR(SpMatCSC *)
Converts an Eigen CSC matrix to an ARPACK++ nonsymmetric CSC matrix.
Eigen::SparseMatrix< double, Eigen::ColMajor > SpMatCSC
Eigen sparse CSC matrix of double type.