16 #include <Eigen/Dense>
17 #include <Eigen/IterativeSolvers>
54 int rank,
size_t poweriters,
double varthresh,
double cvarthresh,
55 MatrixXd* U=NULL, MatrixXd* V=NULL);
76 vector<std::string> inputs, std::string prefix,
double maxmem,
bool normts,
106 void gicaReduceFull(std::string inpref, std::string outpref,
double varthresh,
107 double cvarthresh,
size_t maxrank,
bool verbose);
139 void gicaReduceProb(std::string inpref, std::string outpref,
double varthresh,
140 double cvarthresh,
size_t rank,
size_t poweriters,
bool verbose);
152 std::string outpref,
bool verbose);
163 void gicaSpatialICA(std::string reorgpref, std::string reducepref,
164 std::string outpref,
bool verbose);
178 VectorXd
covSVD(
const MatrixReorg& A,
double varthresh,
double cvarthresh,
179 size_t maxrank, MatrixXd* U, MatrixXd* V);
202 create(filename, rows, cols);
214 MatMap(std::string filename,
bool writeable=
false) :
mat(NULL, 0, 0)
216 open(filename, writeable);
230 void open(std::string filename,
bool writeable =
false);
241 void create(std::string filename,
size_t newrows,
size_t newcols);
253 const size_t&
rows()
const {
return m_rows; };
254 const size_t&
cols()
const {
return m_cols; };
256 Eigen::Map<MatrixXd>
mat;
283 MatrixReorg(std::string prefix=
"",
size_t maxd=(1<<30),
bool verbose=
true);
315 int createMats(
size_t timeblocks,
size_t spaceblocks,
316 const std::vector<std::string>& masknames,
317 const std::vector<std::string>& filenames,
bool normts =
true);
329 inline int ntall()
const {
return m_outcols.size(); };
343 return m_prefix+
"_tall_"+std::to_string(ii);
348 return m_prefix+
"_mask_"+std::to_string(ii)+
".nii.gz";
351 void preMult(Eigen::Ref<MatrixXd> out,
const Eigen::Ref<const MatrixXd> in,
352 bool transpose =
false)
const;
354 void postMult(Eigen::Ref<MatrixXd> out,
const Eigen::Ref<const MatrixXd> in,
355 bool transpose =
false)
const;
357 inline int rows()
const {
return m_totalrows; };
358 inline int cols()
const {
return m_totalcols; };
362 return m_prefix+
"_mask_"+std::to_string(ii)+
".nii.gz";
367 return m_prefix+
".info";
371 return m_prefix+
"_tall_"+std::to_string(ii);
377 std::string m_prefix;
380 vector<int> m_outcols;
393 void fmriGLM(ptr<const MRImage> fmri,
const MatrixXd& X,
394 ptr<MRImage> bimg, ptr<MRImage> Timg, ptr<MRImage> pimg);
405 void fmriBandPass(ptr<MRImage> inimg,
double cuton,
double cutoff);
415 ptr<MRImage>
regressOut(ptr<const MRImage> inimg,
const MatrixXd& X);
434 ptr<const MRImage> labelmap);
454 ptr<const MRImage> labelmap,
size_t outsz);
474 ptr<const MRImage> labelmap,
size_t outsz);
478 #endif //ICA_HELPERS_H
void create(std::string filename, size_t newrows, size_t newcols)
Open an new file as a memory map. ANY OLD FILE WILL BE DELETED The file is always opened for writing ...
MatMap(std::string filename, bool writeable=false)
Open an existing file as a memory map. The file must already exist. If writeable is true then the fil...
MatMap()
default constructor no file is opened
std::string mask_name(size_t ii) const
void postMult(Eigen::Ref< MatrixXd > out, const Eigen::Ref< const MatrixXd > in, bool transpose=false) const
std::string info_name() const
MatrixReorg(std::string prefix="", size_t maxd=(1<< 30), bool verbose=true)
Constructor.
void gicaTemporalICA(std::string reorgpref, std::string reducepref, std::string outpref, bool verbose)
Perform ICA with each dimension as a separate timeseries. This is essentially unmixing in space and p...
void gicaReduceFull(std::string inpref, std::string outpref, double varthresh, double cvarthresh, size_t maxrank, bool verbose)
Compute PCA for the given group, defined.
const vector< int > & tallMatCols() const
bool isopen()
Return true if a file is currently open.
void gicaCreateMatrices(size_t tcat, size_t scat, vector< std::string > masks, vector< std::string > inputs, std::string prefix, double maxmem, bool normts, bool verbose)
Create on disk matrices based on an array of input images. The array will be concatinated in time tca...
void gicaReduceProb(std::string inpref, std::string outpref, double varthresh, double cvarthresh, size_t rank, size_t poweriters, bool verbose)
Compute PCA for the given group, defined.
MatrixXd extractLabelAVG(ptr< const MRImage > fmri, ptr< const MRImage > labelmap)
Creates a matrix of timeseries, then perfrorms principal components analysis on it to reduce the numb...
MatrixXd extractLabelICA(ptr< const MRImage > fmri, ptr< const MRImage > labelmap, size_t outsz)
Creates a matrix of timeseries, then perfrorms principal components analysis on it to reduce the numb...
void close()
Close the current file (if one is open). data() will return NULL and size() will return 0 after this ...
MatrixXd extractLabelPCA(ptr< const MRImage > fmri, ptr< const MRImage > labelmap, size_t outsz)
Creates a matrix of timeseries, then perfrorms principal components analysis on it to reduce the numb...
Memory map class. The basic gyst is that this works like a malloc except that data may be initialized...
std::string inColMaskName(size_t ii) const
void gicaSpatialICA(std::string reorgpref, std::string reducepref, std::string outpref, bool verbose)
Perform ICA with each dimension as a separate timeseries. This is essentially unmixing in space and p...
VectorXd onDiskSVD(const MatrixReorg &A, int rank, size_t poweriters, double varthresh, double cvarthresh, MatrixXd *U=NULL, MatrixXd *V=NULL)
Uses randomized subspace approximation to reduce the input matrix (made up of blocks stored on disk w...
MatMap(std::string filename, size_t rows, size_t cols)
Open an new file as a memory map. ANY OLD FILE WILL BE DELETED The file is always opened for writing ...
VectorXd covSVD(const MatrixReorg &A, double varthresh, double cvarthresh, size_t maxrank, MatrixXd *U, MatrixXd *V)
Computes the SVD from XXt using the JacobiSVD.
void fmriGLM(ptr< const MRImage > fmri, const MatrixXd &X, ptr< MRImage > bimg, ptr< MRImage > Timg, ptr< MRImage > pimg)
Performs general linear model analysis on a 4D image.
void fmriBandPass(ptr< MRImage > inimg, double cuton, double cutoff)
Takes the FFT of each line of the image, performs bandpass filtering on the line and then invert FFTs...
const size_t & rows() const
int createMats(size_t timeblocks, size_t spaceblocks, const std::vector< std::string > &masknames, const std::vector< std::string > &filenames, bool normts=true)
Creates two sets of matrices from a set of input images. The matrices (images) are ordered in column ...
void open(std::string filename, bool writeable=false)
Open an existing file as a memory map. The file must already exist. If writeable is true then the fil...
std::string tall_name(size_t ii) const
std::string tallMatName(size_t ii) const
void preMult(Eigen::Ref< MatrixXd > out, const Eigen::Ref< const MatrixXd > in, bool transpose=false) const
Reorganizes input images into tall and wide matrices (matrices that span the total rows and cols...
int checkMats()
Loads existing matrices by first reading ${prefix}_tall_0, ${prefix}_wide_0, and ${prefix}_mask_*, and checking that all the dimensions can be made to match (by loading the appropriate number of matrices/masks).
Eigen::Map< MatrixXd > mat
const size_t & cols() const
ptr< MRImage > regressOut(ptr< const MRImage > inimg, const MatrixXd &X)
Regresses out the given variables, creating time series which are uncorrelated with X...