Skip to content

Commit 1ff7b9b

Browse files
authored
Merge pull request #53 from CosmoStat/gmca
gmca bug correction
2 parents 3f9d548 + f00319d commit 1ff7b9b

File tree

13 files changed

+489
-295
lines changed

13 files changed

+489
-295
lines changed

src/mc/mcmain1d/mr1d_gmca.cc

+21-20
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@
2727
#include "Array.h"
2828
#include "NR.h"
2929
#include "IM_Obj.h"
30+
#include "IM_IO.h"
3031
#include "GMCA.h"
3132
#include "MR1D1D.h"
3233
#include "IM_Noise.h"
3334
#include "MR1D_NoiseModel.h"
3435
#include "MR1D_Filter.h"
3536

3637
/****************************************************************************/
37-
38-
class GMCA_1D: public MR1D1D, public GMCA
38+
39+
class GMCA_1D: public MR1D1D, public GMCA
3940
{
4041
public:
4142
Bool UseRMSMap;
@@ -46,7 +47,7 @@ class GMCA_1D: public MR1D1D, public GMCA
4647
void inpainting_run(fltarray &TabCannels, fltarray & InpData);
4748
void transrecons_sources(fltarray &TabVect,fltarray &Recdata);
4849
void transform_sources(fltarray &Data,fltarray &TabVect);
49-
void recons_sources(fltarray &DataIn, fltarray &EstSources); // Applying the matrix on the data
50+
void recons_sources(dblarray &DataIn, dblarray &EstSources); // Applying the matrix on the data
5051
void HT_Sources(fltarray &TabSource, float &KThrd) ;
5152

5253
~GMCA_1D() {} ;
@@ -170,12 +171,12 @@ void GMCA_1D::transrecons_sources(fltarray &TabVect,fltarray &Recdata)
170171

171172
/****************************************************************************/
172173

173-
void GMCA_1D::recons_sources(fltarray &DataIn, fltarray &EstSources) // Applying the matrix on the data
174+
void GMCA_1D::recons_sources(dblarray &DataIn, dblarray &EstSources) // Applying the matrix on the data
174175
{
175176
int Nx = DataIn.nx();
176177
int Ny = DataIn.ny();
177178
int i,k,l;
178-
fltarray RefData,RefSources;
179+
dblarray RefData,RefSources;
179180
int Deb = 0;
180181

181182
// cout << "NEW recons_sources " << endl;
@@ -588,7 +589,7 @@ int test_main(int argc, char *argv[])
588589

589590
int main(int argc, char *argv[])
590591
{
591-
fltarray Dat;
592+
dblarray Dat;
592593
/* Get command line arguments, open input file(s) if necessary */
593594
fitsstruct Header;
594595
char Cmd[512];
@@ -624,7 +625,7 @@ int main(int argc, char *argv[])
624625

625626
if (Verbose == True) cout << "\n Reading the data"<< endl;
626627

627-
fits_read_fltarr(Name_Cube_In, Dat, &Header);
628+
fits_read_dblarr(Name_Cube_In, Dat);
628629

629630
int Nx = Dat.nx();
630631
int Ny = Dat.ny();
@@ -676,8 +677,8 @@ int main(int argc, char *argv[])
676677

677678
// WT.write(Name_Out);
678679
// Compute the 2D1D transform
679-
fltarray TabVect;
680-
WT.transform_to_vectarray(Dat, TabVect);
680+
dblarray TabVect;
681+
WT.transform_to_vectdblarray(Dat, TabVect);
681682
// fits_write_fltarr ("xx_tabvect.fits", TabVect);
682683

683684
// Initalize the class for GMCA
@@ -699,7 +700,7 @@ int main(int argc, char *argv[])
699700
WT.GlobThrd = GThrd;
700701
WT.SVConst = UsePCA;
701702
WT.MatNbrScale1D = Nbr_Plan;
702-
fltarray QSVec;
703+
dblarray QSVec;
703704

704705
if (UsePCA == True)
705706
{
@@ -709,13 +710,13 @@ int main(int argc, char *argv[])
709710

710711
if (UseMask == True)
711712
{
712-
fits_read_fltarr (Name_Mask, WT.Mask);
713+
fits_read_dblarr (Name_Mask, WT.Mask);
713714
}
714715

715716

716717
if (UseKnownColomn == True)
717718
{
718-
fits_read_fltarr (Name_KnowColumn, WT.MatKnownColumn);
719+
fits_read_dblarr (Name_KnowColumn, WT.MatKnownColumn);
719720
if (WT.MatKnownColumn.naxis() == 1) WT.NbrKnownColumn = 1;
720721
else WT.NbrKnownColumn = WT.MatKnownColumn.axis(2);
721722
}
@@ -726,7 +727,7 @@ int main(int argc, char *argv[])
726727

727728
if (EstimNbSources == False) // THE NUMBER OF SOURCES IS FIXED
728729
{
729-
fltarray TabSource;
730+
dblarray TabSource;
730731
int NbrCoef = TabVect.nx();
731732
TabSource.alloc(NbrCoef,NbrSources);
732733
WT.GMCA::Verbose = Verbose;
@@ -749,7 +750,7 @@ int main(int argc, char *argv[])
749750
NbrSources++;
750751
if (Verbose == True) cout << "Running GMCA ... Number of Estimated Sources : " << NbrSources << endl;
751752
WT.NbrSources = NbrSources;
752-
fltarray TabSource;
753+
dblarray TabSource;
753754
int NbrCoef = TabVect.nx();
754755
TabSource.alloc(NbrCoef,NbrSources);
755756
WT.GMCA::Verbose = Verbose;
@@ -782,7 +783,7 @@ int main(int argc, char *argv[])
782783

783784
// Reconstruction :
784785
if (Verbose == True) cout << "Reconstruction ... "<< endl;
785-
fltarray EstSources;
786+
dblarray EstSources;
786787
// cout << "GO REC" << endl;
787788

788789
WT.recons_sources(Dat,EstSources);
@@ -795,16 +796,16 @@ int main(int argc, char *argv[])
795796
// fits_write_fltarr ("xx_InvMixingMat.fits", WT.InvMixingMat);
796797

797798
// Header.origin = Cmd;
798-
fits_write_fltarr(Name_Out, EstSources);
799-
if (WriteMixing == True) fits_write_fltarr (Name_Out_2, WT.RecMixingMat);
800-
if (WriteChannels == True)
799+
fits_write_dblarr(Name_Out, EstSources);
800+
if (WriteMixing == True) fits_write_dblarr (Name_Out_2, WT.RecMixingMat);
801+
if (WriteChannels == True)
801802
{
802-
fltarray EstChannels, TranspMixingMat;
803+
dblarray EstChannels, TranspMixingMat;
803804
MatOper MAT; // See file $Tools/MatrixOper.cc and .h
804805
MAT.transpose(WT.MixingMat,TranspMixingMat);
805806
WT.apply_mat(EstSources, TranspMixingMat, EstChannels);
806807
// WT.apply_mat(EstSources, WT.MixingMat, EstChannels);
807-
fits_write_fltarr (Name_Out_3, EstChannels);
808+
fits_write_dblarr (Name_Out_3, EstChannels);
808809
}
809810
exit(0);
810811
}

src/mc/mcmain2d/mr_gmca.cc

+34-30
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,18 @@ static void usage(char *argv[])
229229
fprintf(OUTMAN, " Apply a l_1 constraint also on the mixing matrix. Default is no. \n");
230230
fprintf(OUTMAN, " [-d]\n");
231231
fprintf(OUTMAN, " Estimate the number of sources. Default is no. \n");
232-
fprintf(OUTMAN, " [-d]\n");
233-
fprintf(OUTMAN, " Estimate the number of sources. Default is no. \n");
234232
fprintf(OUTMAN, " [-m]\n");
235233
fprintf(OUTMAN, " Mad-based stopping criterion when the number of sources is estimated. Default is 5 - default criterion is l2-based. \n");
236234
fprintf(OUTMAN, " [-L]\n");
237235
fprintf(OUTMAN, " L2-based stopping criterion when the number of sources is estimated. Default is 40 (in dB). \n");
238-
fprintf(OUTMAN, " [-D] \n");
239-
fprintf(OUTMAN, " Spectra with disjoint supports for thresholds higher than 7 Mad. \n"); // Should be an option
236+
// fprintf(OUTMAN, " [-D] \n");
237+
// fprintf(OUTMAN, " Spectra with disjoint supports for thresholds higher than 7 Mad. \n"); // Should be an option
240238
fprintf(OUTMAN, " [-K Last K-Mad]\n");
241239
fprintf(OUTMAN, " Last value of K for K-Mad Thresholding. \n");
242240
fprintf(OUTMAN, " [-G Global Thresholding]\n");
243-
fprintf(OUTMAN, " [-O]\n");
244-
fprintf(OUTMAN, " Orthogonalization of the spectra\n");
245-
verbose_usage();
241+
// fprintf(OUTMAN, " [-O]\n");
242+
// fprintf(OUTMAN, " Orthogonalization of the spectra\n");
243+
verbose_usage();
246244
vm_usage();
247245
manline();
248246
exit(-1);
@@ -435,7 +433,7 @@ static void transinit(int argc, char *argv[])
435433

436434
int main(int argc, char *argv[])
437435
{
438-
fltarray Dat;
436+
dblarray Dat;
439437
/* Get command line arguments, open input file(s) if necessary */
440438
fitsstruct Header;
441439
char Cmd[512];
@@ -466,38 +464,44 @@ int main(int argc, char *argv[])
466464

467465
if (Verbose == True) cout << "\n Reading the data"<< endl;
468466

469-
io_3d_read_data(Name_Cube_In, Dat, &Header);
470-
467+
// io_3d_read_data(Name_Cube_In, Dat, &Header);
468+
fits_read_dblarr (Name_Cube_In, Dat);
469+
471470
int Nx = Dat.nx();
472471
int Ny = Dat.ny();
473472
int Nz = Dat.nz();
474-
if (Verbose == True) cout << "Nx = " << Dat.nx() << " Ny = " << Dat.ny() << " Nz = " << Dat.nz() << endl;
475-
473+
if (Verbose == True)
474+
cout << "Nx = " << Dat.nx() << " Ny = " << Dat.ny() << " Nz = " << Dat.nz() << endl;
475+
// Dat.info("READ data");
476+
477+
476478
if (Normalize == True)
477479
{
478480
double Mean = Dat.mean();
479481
double Sigma = Dat.sigma();
482+
// cout << "Data mean = " << Mean << " Sigma = " << Sigma << endl;
483+
// printf("Sigmad=f = %f", Sigma);
480484
for (int i=0;i<Nx;i++)
481485
for (int j=0;j<Ny;j++)
482486
for (int k=0;k<Nz;k++) Dat(i,j,k) = (Dat(i,j,k)-Mean)/Sigma;
483487
}
484-
488+
// Dat.info("Normalized data");
489+
485490

486491
// MR2D1D WT;
487492
GMCA_2D WT;
488-
489493
if (Verbose == True) cout << "Alloc ... " << endl;
490494
WT.alloc(Nx, Ny, Nz, Transform, NbrScale2d, 1); // On ne regularise que la MixingMat
491495

492496
if (Verbose == True) cout << "2d1d_trans ... "<< endl;
493497

494498
//WT.transform (Dat); // Pas utile
495-
499+
496500
// WT.write(Name_Out);
497501
// Compute the 2D1D transform
498-
fltarray TabVect;
499-
WT.transform_to_vectarray(Dat, TabVect);
500-
// fits_write_fltarr ("xx_tabvect.fits", TabVect);
502+
dblarray TabVect;
503+
WT.transform_to_vectdblarray(Dat, TabVect);
504+
// fits_write_dblarr ("xx_tabvect.fits", TabVect);
501505

502506
// Initalize the class for GMCA
503507

@@ -518,7 +522,7 @@ int main(int argc, char *argv[])
518522
WT.GlobThrd = GThrd;
519523
WT.SVConst = UsePCA;
520524
WT.MatNbrScale1D = Nbr_Plan;
521-
fltarray QSVec;
525+
dblarray QSVec;
522526

523527
if (UsePCA == True)
524528
{
@@ -528,12 +532,12 @@ int main(int argc, char *argv[])
528532

529533
if (UseMask == True)
530534
{
531-
fits_read_fltarr (Name_Mask, WT.Mask);
535+
fits_read_dblarr (Name_Mask, WT.Mask);
532536
}
533537

534538
if (UseKnownColomn == True)
535539
{
536-
fits_read_fltarr (Name_KnowColumn, WT.MatKnownColumn);
540+
fits_read_dblarr (Name_KnowColumn, WT.MatKnownColumn);
537541
if (WT.MatKnownColumn.naxis() == 1) WT.NbrKnownColumn = 1;
538542
else WT.NbrKnownColumn = WT.MatKnownColumn.axis(2);
539543
}
@@ -543,7 +547,7 @@ int main(int argc, char *argv[])
543547

544548
if (EstimNbSources == False) // THE NUMBER OF SOURCES IS FIXED
545549
{
546-
fltarray TabSource;
550+
dblarray TabSource;
547551
int NbrCoef = TabVect.nx();
548552
TabSource.alloc(NbrCoef,NbrSources);
549553
WT.GMCA::Verbose = Verbose;
@@ -554,19 +558,19 @@ int main(int argc, char *argv[])
554558
if (EstimNbSources == TRUE) // THE NUMBER OF SOURCES IS ESTIMATED
555559
{
556560
int NbrSourcesMax = NbrSources;
557-
float RelError = 0;
561+
double RelError = 0;
558562
//float SigmaData=TabVect.sigma();
559563
NbrSources = 1;
560564
bool ExitCriterion = False; /// CHANGEDDDDD
561-
float OldRelError=0;
562-
float DiffRelError;
565+
double OldRelError=0;
566+
double DiffRelError;
563567

564568
while (NbrSources <= NbrSourcesMax && ExitCriterion == False)
565569
{
566570
NbrSources++;
567571
if (Verbose == True) cout << "Running GMCA ... Number of Estimated Sources : " << NbrSources << endl;
568572
WT.NbrSources = NbrSources;
569-
fltarray TabSource;
573+
dblarray TabSource;
570574
int NbrCoef = TabVect.nx();
571575
TabSource.alloc(NbrCoef,NbrSources);
572576
WT.GMCA::Verbose = Verbose;
@@ -605,17 +609,17 @@ int main(int argc, char *argv[])
605609

606610
// Reconstruction :
607611
if (Verbose == True) cout << "Reconstruction ... "<< endl;
608-
fltarray EstSources;
612+
dblarray EstSources;
609613
WT.recons_sources(Dat,EstSources);
610614
// WT.Sort_Sources(EstSources);
611615

612616
if (Verbose == True) cout << "Write results ... "<< endl;
613617
// fits_write_fltarr ("xx_EstSources.fits", EstSources);
614-
fits_write_fltarr ("xx_EstMixmat.fits", WT.MixingMat);
615-
fits_write_fltarr ("xx_InvMixingMat.fits", WT.InvMixingMat);
618+
fits_write_dblarr ("xx_EstMixmat.fits", WT.MixingMat);
619+
fits_write_dblarr ("xx_InvMixingMat.fits", WT.InvMixingMat);
616620

617621
// Header.origin = Cmd;
618-
fits_write_fltarr(Name_Out, EstSources);
622+
fits_write_dblarr(Name_Out, EstSources);
619623

620624
exit(0);
621625
}

0 commit comments

Comments
 (0)