Skip to content
Snippets Groups Projects
melhlprfns.h 4.67 KiB
Newer Older
/*  MELODIC - Multivariate exploratory linear optimized decomposition into 
              independent components
    
    melhlprfns.cc - misc functions

    Christian F. Beckmann, FMRIB Image Analysis Group
    
    Copyright (C) 1999-2008 University of Oxford */
/*  CCOPYRIGHT  */

#ifndef __MELODICHLPR_h
#define __MELODICHLPR_h

#include "newimage/newimageall.h"
#include "newmatap.h"
#include "newmatio.h"

using namespace NEWIMAGE;

namespace Melodic{

  void update_mask(volume<float>& mask, Matrix& Data);
  void del_vols(volume4D<float>& in, int howmany);

  Matrix smoothColumns(const Matrix& inp);
  Matrix calc_FFT(const Matrix& Mat, const bool logpwr = 0);

  Matrix convert_to_pbsc(Matrix& Mat);

  RowVector varnorm(Matrix& in, int dim = 30, float level = 1.6);
Christian Beckmann's avatar
Christian Beckmann committed
       void varnorm(Matrix& in, const RowVector& vars);
  RowVector varnorm(Matrix& in, Matrix& Corr, int dim = 30, float level = 1.6);

  Matrix SP2(const Matrix& in, const Matrix& weights, bool econ = 0);

  RowVector Feta(int n1,int n2);
  RowVector cumsum(const RowVector& Inp);

Christian Beckmann's avatar
Christian Beckmann committed
  Matrix corrcoef(const Matrix& in1, const Matrix& in2);
Christian Beckmann's avatar
Christian Beckmann committed
  Matrix corrcoef(const Matrix& in1, const Matrix& in2, const Matrix& part);
  Matrix calc_corr(const Matrix& in, bool econ = 0);
  Matrix calc_corr(const Matrix& in, const Matrix& weights, bool econ = 0);

Christian Beckmann's avatar
Christian Beckmann committed
  float calc_white(const Matrix& tmpE, const RowVector& tmpD, const RowVector& PercEV, int dim, Matrix& param, Matrix& paramS, Matrix& white, Matrix& dewhite);
  float calc_white(const Matrix& tmpE, const RowVector& tmpD, const RowVector& PercEV, int dim, Matrix& white, Matrix& dewhite);
Christian Beckmann's avatar
Christian Beckmann committed
  void calc_white(const Matrix& tmpE, const RowVector& tmpD, int dim, Matrix& param, Matrix& paramS, Matrix& white, Matrix& dewhite);
  void calc_white(const Matrix& tmpE, const RowVector& tmpD, int dim, Matrix& white, Matrix& dewhite);
  void calc_white(const Matrix& Corr, int dim, Matrix& white, Matrix& dewhite);
  
  void std_pca(const Matrix& Mat, Matrix& Corr, Matrix& evecs, RowVector& evals);
  void std_pca(const Matrix& Mat, const Matrix& weights, Matrix& Corr, Matrix& evecs, RowVector& evals);
  void em_pca(const Matrix& Mat, Matrix& evecs, RowVector& evals, int num_pc = 1, int iter = 20);
  void em_pca(const Matrix& Mat, Matrix& guess, Matrix& evecs, RowVector& evals, int num_pc = 1, int iter = 20);

Christian Beckmann's avatar
Christian Beckmann committed
  float rankapprox(const Matrix& Mat, Matrix& cols, Matrix& rows, int dim = 1);
  RowVector krfact(const Matrix& Mat, Matrix& cols, Matrix& rows);
  RowVector krfact(const Matrix& Mat, int colnum, Matrix& cols, Matrix& rows);
  Matrix krprod(const Matrix& cols, const Matrix& rows);
  Matrix krapprox(const Matrix& Mat, int size_col, int dim = 1);

  void adj_eigspec(const RowVector& in, RowVector& out1, RowVector& out2, RowVector& out3, int& out4, int num_vox, float resels);
  void adj_eigspec(const RowVector& in, RowVector& out1, RowVector& out2);

Christian Beckmann's avatar
Christian Beckmann committed
  int ppca_dim(const Matrix& in, const Matrix& weights, Matrix& PPCA, RowVector& AdjEV, RowVector& PercEV, Matrix& Corr, Matrix& tmpE, RowVector &tmpD, float resels, string which);
  int ppca_dim(const Matrix& in, const Matrix& weights, Matrix& PPCA, RowVector& AdjEV, RowVector& PercEV, float resels, string which);
  int ppca_dim(const Matrix& in, const Matrix& weights, float resels, string which);
Christian Beckmann's avatar
Christian Beckmann committed
  ColumnVector ppca_select(Matrix& PPCAest, int& dim, int maxEV, string which);
  Matrix ppca_est(const RowVector& eigenvalues, const int N1, const float N2);
  Matrix ppca_est(const RowVector& eigenvalues, const int N);

  ColumnVector acf(const ColumnVector& in, int order);
  ColumnVector pacf(const ColumnVector& in, int maxorder = 1);
  Matrix est_ar(const Matrix& Mat, int maxorder);
  ColumnVector gen_ar(const ColumnVector& in, int maxorder = 1);
  Matrix gen_ar(const Matrix& in, int maxorder);
  Matrix gen_arCorr(const Matrix& in, int maxorder);
Christian Beckmann's avatar
Christian Beckmann committed
	class basicGLM{
Christian Beckmann's avatar
Christian Beckmann committed
		public:
		
			//constructor
			basicGLM(){}
		
			//destructor
			~basicGLM(){}
		
			void olsfit(const Matrix& data, const Matrix& design, 
Matthew Webster's avatar
Matthew Webster committed
				const Matrix& contrasts, int DOFadjust = -1);
Christian Beckmann's avatar
Christian Beckmann committed

			inline Matrix& get_t(){return t;}
			inline Matrix& get_z(){return z;}
			inline Matrix& get_p(){return p;}
			inline Matrix& get_f_fmf(){return f_fmf;}
			inline Matrix& get_pf_fmf(){return pf_fmf;}
			inline Matrix& get_cbeta(){return cbeta;}
			inline Matrix& get_beta(){return beta;}
Christian Beckmann's avatar
Christian Beckmann committed
			inline Matrix& get_varcb(){return varcb;}
			inline Matrix& get_sigsq(){return sigsq;}
			inline Matrix& get_residu(){return residu;}
			inline int get_dof(){return dof;}
			
		private:
			Matrix beta;
			Matrix residu;
			Matrix sigsq;
			Matrix varcb;
			Matrix cbeta;
			Matrix f_fmf, pf_fmf;
			int dof;
			Matrix t;
			Matrix z;
			Matrix p;
Christian Beckmann's avatar
Christian Beckmann committed
  };
Christian Beckmann's avatar
Christian Beckmann committed
//	Matrix glm_ols(const Matrix& dat, const Matrix& design);