Newer
Older
/* glimGls.cc
Mark Woolrich, FMRIB Image Analysis Group
Copyright (C) 1999-2000 University of Oxford */
#include "miscmaths/miscmaths.h"
#include "utils/log.h"
#include "miscmaths/volume.h"
#include "miscmaths/volumeseries.h"
using namespace Utilities;
namespace FILM {
void GlimGls::CleanUp()
{
corrections.CleanUp();
sigmaSquareds.CleanUp();
b.CleanUp();
r.CleanUp();
}
void GlimGls::setData(const ColumnVector& y, const Matrix& x, const int ind)
{
// compute b
Stephen Smith
committed
//Matrix inv_xx = (x.t()*x).i();
Matrix inv_xx = pinv(x.t()*x);
b.Column(ind) = inv_xx*x.t()*y;
// compute r
Matrix I(sizeTS, sizeTS);
Identity(I);
// sigmaSquareds(ind) = (r.t()*r/sizeTS).AsScalar();
sigmaSquareds(ind) = (r.t()*r).AsScalar()/R.Trace();
// set corrections
SetCorrection(inv_xx, ind);
}
void GlimGls::Save(const VolumeInfo& pvolinfo, const ColumnVector& prethreshpos)
{
// Need to save b, sigmaSquareds, corrections and dof
// b:
Volume peVol;
for(int i = 1; i <= numParams; i++)
{
peVol = b.Row(i).AsColumn();
ostringstream osc;
osc << i;
peVol.writeAsFloat(logger.getDir() + "/pe" + osc.str().c_str());
sigmaSquareds.setPreThresholdPositions(prethreshpos);
sigmaSquareds.unthreshold();
sigmaSquareds.writeAsFloat(logger.getDir() + "/sigmasquareds");
// dof:
ColumnVector dofVec(1);
dofVec = dof;
write_ascii_matrix(logger.appendDir("dof"), dofVec);
// corrections (are the pes correlation matrix (x.t()*x).i() reshapen to a vector):
VolumeInfo newvolinfo = volinfo;
newvolinfo.v = numParams*numParams;
//corrections.setInfo(newvolinfo);
//corrections.setPreThresholdPositions(prethreshpos);
//corrections.unthresholdSeries();
//corrections.writeAsFloat(logger.getDir() + "/corrections");
corrections.writeThresholdedSeriesAsFloat(newvolinfo,prethreshpos,logger.getDir() + "/corrections");
}
void GlimGls::SetCorrection(const Matrix& corr, const int ind)
{
Tracer ts("SetCorrection");
// puts Matrix corr which is p*p into Matrix correction
// as a p*p length row:
int p = corr.Nrows();
for (int i = 1; i <= p; i++)
{
for (int j = 1; j <= p; j++)
{