Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
melodic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
melodic
Commits
7ae0edbd
Commit
7ae0edbd
authored
16 years ago
by
Christian Beckmann
Browse files
Options
Downloads
Patches
Plain Diff
SBCA modified
parent
0402db99
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+8
-3
8 additions, 3 deletions
Makefile
fsl_mvlm.cc
+77
-22
77 additions, 22 deletions
fsl_mvlm.cc
melica.cc
+3
-0
3 additions, 0 deletions
melica.cc
test.cc
+17
-44
17 additions, 44 deletions
test.cc
with
105 additions
and
69 deletions
Makefile
+
8
−
3
View file @
7ae0edbd
...
@@ -12,12 +12,14 @@ USRLDFLAGS = -L${LIB_NEWMAT} -L${LIB_PROB} -L${LIB_GD} -L${LIB_GDC} -L${LIB_PNG}
...
@@ -12,12 +12,14 @@ USRLDFLAGS = -L${LIB_NEWMAT} -L${LIB_PROB} -L${LIB_GD} -L${LIB_GDC} -L${LIB_PNG}
LIBS
=
-lutils
-lnewimage
-lmiscplot
-lmiscpic
-lmiscmaths
-lfslio
-lniftiio
-lznz
-lnewmat
-lprob
-lm
-lgdc
-lgd
-lpng
-lz
LIBS
=
-lutils
-lnewimage
-lmiscplot
-lmiscpic
-lmiscmaths
-lfslio
-lniftiio
-lznz
-lnewmat
-lprob
-lm
-lgdc
-lgd
-lpng
-lz
TEST_OBJS
=
test.o
test2.o
TEST_OBJS
=
test.o
GGMIX_OBJS
=
ggmix.o
GGMIX_OBJS
=
ggmix.o
FSL_GLM_OBJS
=
melhlprfns.o fsl_glm.o
FSL_GLM_OBJS
=
melhlprfns.o fsl_glm.o
FSL_SBCA_OBJS
=
melhlprfns.o fsl_sbca.o
FSL_MVLM_OBJS
=
melhlprfns.o fsl_mvlm.o
FSL_MVLM_OBJS
=
melhlprfns.o fsl_mvlm.o
FSL_REGFILT_OBJS
=
melhlprfns.o fsl_regfilt.o
FSL_REGFILT_OBJS
=
melhlprfns.o fsl_regfilt.o
...
@@ -26,13 +28,13 @@ MELODIC_OBJS = meloptions.o melhlprfns.o melgmix.o meldata.o melpca.o melica.o
...
@@ -26,13 +28,13 @@ MELODIC_OBJS = meloptions.o melhlprfns.o melgmix.o meldata.o melpca.o melica.o
TESTXFILES
=
test
TESTXFILES
=
test
XFILES
=
fsl_glm fsl_mvlm fsl_regfilt melodic
XFILES
=
fsl_glm
fsl_sbca
fsl_mvlm fsl_regfilt melodic
RUNTCLS
=
Melodic
RUNTCLS
=
Melodic
SCRIPTS
=
melodicreport
SCRIPTS
=
melodicreport
all
:
ggmix fsl_regfilt fsl_glm fsl_mvlm melodic
all
:
ggmix fsl_regfilt fsl_glm fsl_mvlm
fsl_sbca
melodic
ggmix
:
${GGMIX_OBJS}
ggmix
:
${GGMIX_OBJS}
${
AR
}
-r
libggmix.a
${
GGMIX_OBJS
}
${
AR
}
-r
libggmix.a
${
GGMIX_OBJS
}
...
@@ -46,6 +48,9 @@ test: ${TEST_OBJS}
...
@@ -46,6 +48,9 @@ test: ${TEST_OBJS}
fsl_glm
:
${FSL_GLM_OBJS}
fsl_glm
:
${FSL_GLM_OBJS}
$(
CXX
)
${
CXXFLAGS
}
${
LDFLAGS
}
-o
$@
${
FSL_GLM_OBJS
}
${
LIBS
}
$(
CXX
)
${
CXXFLAGS
}
${
LDFLAGS
}
-o
$@
${
FSL_GLM_OBJS
}
${
LIBS
}
fsl_sbca
:
${FSL_SBCA_OBJS}
$(
CXX
)
${
CXXFLAGS
}
${
LDFLAGS
}
-o
$@
${
FSL_SBCA_OBJS
}
${
LIBS
}
fsl_mvlm
:
${FSL_MVLM_OBJS}
fsl_mvlm
:
${FSL_MVLM_OBJS}
$(
CXX
)
${
CXXFLAGS
}
${
LDFLAGS
}
-o
$@
${
FSL_MVLM_OBJS
}
${
LIBS
}
$(
CXX
)
${
CXXFLAGS
}
${
LDFLAGS
}
-o
$@
${
FSL_MVLM_OBJS
}
${
LIBS
}
...
...
This diff is collapsed.
Click to expand it.
fsl_mvlm.cc
+
77
−
22
View file @
7ae0edbd
...
@@ -64,7 +64,7 @@ using namespace std;
...
@@ -64,7 +64,7 @@ using namespace std;
string
(
"basename for output files "
),
string
(
"basename for output files "
),
true
,
requires_argument
);
true
,
requires_argument
);
Option
<
string
>
approach
(
string
(
"-a,--alg"
),
string
(
"PCA"
),
Option
<
string
>
approach
(
string
(
"-a,--alg"
),
string
(
"PCA"
),
string
(
"algorithm for decomposition: PCA (or SVD; default), PLS, orthoPLS, CVA, SVD-CVA, MLM"
),
string
(
"algorithm for decomposition: PCA (or SVD; default), PLS, orthoPLS, CVA, SVD-CVA, MLM
, NMF
"
),
false
,
requires_argument
);
false
,
requires_argument
);
Option
<
string
>
fndesign
(
string
(
"-d,--design"
),
string
(
""
),
Option
<
string
>
fndesign
(
string
(
"-d,--design"
),
string
(
""
),
string
(
"file name of the GLM design matrix (time courses or spatial maps)"
),
string
(
"file name of the GLM design matrix (time courses or spatial maps)"
),
...
@@ -81,6 +81,12 @@ using namespace std;
...
@@ -81,6 +81,12 @@ using namespace std;
Option
<
bool
>
perf_demean
(
string
(
"--demean"
),
FALSE
,
Option
<
bool
>
perf_demean
(
string
(
"--demean"
),
FALSE
,
string
(
"switch on de-meaning of design and data"
),
string
(
"switch on de-meaning of design and data"
),
false
,
no_argument
);
false
,
no_argument
);
Option
<
int
>
nmfdim
(
string
(
"--nmf_dim"
),
0
,
string
(
" Number of underlying factors for NMF"
),
false
,
requires_argument
);
Option
<
int
>
nmfitt
(
string
(
"--nmfitt"
),
100
,
string
(
"number of NMF itterations (default 100)"
),
false
,
requires_argument
);
Option
<
int
>
help
(
string
(
"-h,--help"
),
0
,
Option
<
int
>
help
(
string
(
"-h,--help"
),
0
,
string
(
"display this help text"
),
string
(
"display this help text"
),
false
,
no_argument
);
false
,
no_argument
);
...
@@ -202,10 +208,12 @@ int setup(){
...
@@ -202,10 +208,12 @@ int setup(){
design
=
SP
(
design
,
ones
(
design
.
Nrows
(),
1
)
*
pow
(
stdev
(
design
,
1
),
-
1
));
design
=
SP
(
design
,
ones
(
design
.
Nrows
(),
1
)
*
pow
(
stdev
(
design
,
1
),
-
1
));
SVD
(
design
,
svd_X_D
,
svd_X_U
,
svd_X_V
);
SVD
(
design
,
svd_X_D
,
svd_X_U
,
svd_X_V
);
if
(
data
.
Nrows
()
>=
data
.
Ncols
())
if
(
approach
.
value
()
!=
string
(
"NMF"
)){
SVD
(
data
,
svd_Y_D
,
svd_Y_U
,
svd_Y_V
);
if
(
data
.
Nrows
()
>=
data
.
Ncols
())
else
{
SVD
(
data
,
svd_Y_D
,
svd_Y_U
,
svd_Y_V
);
SVD
(
data
.
t
(),
svd_Y_D
,
svd_Y_V
,
svd_Y_U
);
else
{
SVD
(
data
.
t
(),
svd_Y_D
,
svd_Y_V
,
svd_Y_U
);
}
}
}
if
(
fnout
.
value
().
length
()
==
0
){
if
(
fnout
.
value
().
length
()
==
0
){
...
@@ -303,30 +311,75 @@ int do_work(int argc, char* argv[]) {
...
@@ -303,30 +311,75 @@ int do_work(int argc, char* argv[]) {
}
}
if
(
approach
.
value
()
!=
string
(
"MLM"
)
&&
approach
.
value
()
!=
string
(
"CVA"
)
&&
approach
.
value
()
!=
string
(
"PLS"
)
&&
if
(
approach
.
value
()
!=
string
(
"MLM"
)
&&
approach
.
value
()
!=
string
(
"CVA"
)
&&
approach
.
value
()
!=
string
(
"PLS"
)
&&
approach
.
value
()
!=
string
(
"SVD-CVA"
)
&&
approach
.
value
()
!=
string
(
"orthoPLS"
))
approach
.
value
()
!=
string
(
"SVD-CVA"
)
&&
approach
.
value
()
!=
string
(
"orthoPLS"
)
&&
approach
.
value
()
!=
string
(
"NMF"
)
)
message
(
" Using method : PCA"
<<
endl
;);
message
(
" Using method : PCA"
<<
endl
;);
//perform an SVD on data
//perform an SVD on data
outMsize
(
" New Data "
,
data
);
outMsize
(
" New Data "
,
data
);
if
(
approach
.
value
()
!=
string
(
"NMF"
)){
if
(
data
.
Nrows
()
>=
data
.
Ncols
())
SVD
(
data
,
svd_Y_D
,
svd_Y_U
,
svd_Y_V
);
else
{
SVD
(
data
.
t
(),
svd_Y_D
,
svd_Y_V
,
svd_Y_U
);
svd_Y_U
=
svd_Y_U
.
t
();
svd_Y_V
=
svd_Y_V
.
t
();
}
dbgmsg
(
" Finished SVD : "
);
outMsize
(
"svd_Y_U"
,
svd_Y_U
);
outMsize
(
"svd_Y_V"
,
svd_Y_V
);
outMsize
(
"svd_Y_D"
,
svd_Y_D
);
svd_Y_V
=
sqrtm
(
svd_Y_D
)
*
svd_Y_V
;
svd_Y_U
=
svd_Y_U
*
sqrtm
(
svd_Y_D
);
if
(
approach
.
value
()
==
string
(
"SVD-CVA"
))
svd_Y_V
=
svd_Y_V
*
tmpdata
;
}
else
{
//NMF
float
err
,
err_old
;
Matrix
Ratio
,
Diff
;
if
(
nmfdim
.
value
()
==
0
)
nmfdim
.
set_T
(
data
.
Nrows
());
if
(
data
.
Nrows
()
>=
data
.
Ncols
())
message
(
"Using "
<<
nmfdim
.
value
()
<<
" dimensions"
<<
endl
;);
SVD
(
data
,
svd_Y_D
,
svd_Y_U
,
svd_Y_V
);
svd_Y_U
=
unifrnd
(
data
.
Nrows
(),
nmfdim
.
value
());
else
{
svd_Y_V
=
unifrnd
(
nmfdim
.
value
(),
data
.
Ncols
());
SVD
(
data
.
t
(),
svd_Y_D
,
svd_Y_V
,
svd_Y_U
);
// re-scale columns of svd_Y_U to unit amplitude
svd_Y_U
=
svd_Y_U
.
t
();
Ratio
=
pow
(
stdev
(
svd_Y_U
),
-
1
);
svd_Y_V
=
svd_Y_V
.
t
();
svd_Y_U
=
SP
(
svd_Y_U
,
ones
(
svd_Y_U
.
Nrows
(),
1
)
*
Ratio
);
}
Diff
=
data
-
svd_Y_U
*
svd_Y_V
;
err
=
Diff
.
SumAbsoluteValue
()
/
(
data
.
Ncols
()
*
data
.
Nrows
());
for
(
int
k
=
1
;
k
<
nmfitt
.
value
();
k
++
)
{
// Ratio = SP(data,pow(svd_Y_U * svd_Y_V,-1));
// svd_Y_U = SP(svd_Y_U, Ratio * svd_Y_V.t());
// svd_Y_U = SP(svd_Y_U, pow( ones(svd_Y_U.Nrows(),1) * sum(svd_Y_U,1),-1));
// svd_Y_V = SP(svd_Y_V, svd_Y_U.t()* Ratio);
//
// Lee & Seung multiplicatice updates
Ratio
=
SP
(
svd_Y_U
.
t
()
*
data
,
pow
(
svd_Y_U
.
t
()
*
svd_Y_U
*
svd_Y_V
,
-
1
));
svd_Y_V
=
SP
(
svd_Y_V
,
Ratio
);
dbgmsg
(
" Finished SVD : "
);
Ratio
=
SP
(
data
*
svd_Y_V
.
t
(),
pow
(
svd_Y_U
*
(
svd_Y_V
*
svd_Y_V
.
t
()),
-
1
));
outMsize
(
"svd_Y_U"
,
svd_Y_U
);
svd_Y_U
=
SP
(
svd_Y_U
,
Ratio
);
outMsize
(
"svd_Y_V"
,
svd_Y_V
);
outMsize
(
"svd_Y_D"
,
svd_Y_D
);
svd_Y_V
=
sqrtm
(
svd_Y_D
)
*
svd_Y_V
;
svd_Y_U
=
svd_Y_U
*
sqrtm
(
svd_Y_D
);
if
(
approach
.
value
()
==
string
(
"SVD-CVA"
))
// re-scale columns of svd_Y_U to unit amplitude
svd_Y_V
=
svd_Y_V
*
tmpdata
;
Ratio
=
pow
(
stdev
(
svd_Y_U
),
-
1
);
svd_Y_U
=
SP
(
svd_Y_U
,
ones
(
svd_Y_U
.
Nrows
(),
1
)
*
Ratio
);
Diff
=
data
-
svd_Y_U
*
svd_Y_V
;
err_old
=
err
;
err
=
Diff
.
SumSquare
()
/
(
data
.
Ncols
()
*
data
.
Nrows
());
message
(
" Error "
<<
err
<<
endl
;);
}
}
write_res
();
write_res
();
dbgmsg
(
" Leaving <do_work>"
);
dbgmsg
(
" Leaving <do_work>"
);
...
@@ -350,6 +403,8 @@ int main(int argc,char *argv[]){
...
@@ -350,6 +403,8 @@ int main(int argc,char *argv[]){
options
.
add
(
normdes
);
options
.
add
(
normdes
);
options
.
add
(
perfvn
);
options
.
add
(
perfvn
);
options
.
add
(
perf_demean
);
options
.
add
(
perf_demean
);
options
.
add
(
nmfdim
);
options
.
add
(
nmfitt
);
options
.
add
(
help
);
options
.
add
(
help
);
options
.
add
(
verbose
);
options
.
add
(
verbose
);
options
.
add
(
debug
);
options
.
add
(
debug
);
...
...
This diff is collapsed.
Click to expand it.
melica.cc
+
3
−
0
View file @
7ae0edbd
...
@@ -39,6 +39,9 @@ namespace Melodic{
...
@@ -39,6 +39,9 @@ namespace Melodic{
redUMM
=
melodat
.
get_white
()
*
redUMM
=
melodat
.
get_white
()
*
unifrnd
(
melodat
.
get_white
().
Ncols
(),
dim
);
// got to start somewhere
unifrnd
(
melodat
.
get_white
().
Ncols
(),
dim
);
// got to start somewhere
if
(
opts
.
debug
.
value
())
cerr
<<
"redUMM init submatrix : "
<<
endl
<<
redUMM
.
SubMatrix
(
1
,
2
,
1
,
2
)
<<
endl
;
if
(
opts
.
guessfname
.
value
().
size
()
>
1
){
if
(
opts
.
guessfname
.
value
().
size
()
>
1
){
message
(
" Use columns in "
<<
opts
.
guessfname
.
value
()
message
(
" Use columns in "
<<
opts
.
guessfname
.
value
()
<<
" as initial values for the mixing matrix "
<<
endl
);
<<
" as initial values for the mixing matrix "
<<
endl
);
...
...
This diff is collapsed.
Click to expand it.
test.cc
+
17
−
44
View file @
7ae0edbd
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
#include
"miscmaths/miscprob.h"
#include
"miscmaths/miscprob.h"
#include
"utils/options.h"
#include
"utils/options.h"
#include
<vector>
#include
<vector>
#include
<time.h>
#include
"newimage/newimageall.h"
#include
"newimage/newimageall.h"
#include
"melhlprfns.h"
#include
"melhlprfns.h"
...
@@ -20,11 +21,11 @@ using namespace std;
...
@@ -20,11 +21,11 @@ using namespace std;
// The two strings below specify the title and example usage that is
// The two strings below specify the title and example usage that is
// printed out as the help or usage message
// printed out as the help or usage message
string
title
=
string
(
"fsl_
glm (Version 1.0)
"
)
+
string
title
=
string
(
"fsl_
BLAH
"
)
+
string
(
"
\n
Copyright(c) 200
7
, University of Oxford (Christian F. Beckmann)
\n
"
)
+
string
(
"
\n
Copyright(c) 200
8
, University of Oxford (Christian F. Beckmann)
\n
"
)
+
string
(
"
\n
Simple GLM usign ordinary least-squares regression on
\n
"
)
+
string
(
"
\n
\n
"
)
+
string
(
"
time courses and/or 3D/4D volumes
\n
\n
"
);
string
(
"
\n
"
);
string
examples
=
"fsl_
glm <input> -d <design>
[options]"
;
string
examples
=
"fsl_
BLAH
[options]"
;
//Command line Options {
//Command line Options {
Option
<
string
>
fnin
(
string
(
"-i,--in"
),
string
(
""
),
Option
<
string
>
fnin
(
string
(
"-i,--in"
),
string
(
""
),
...
@@ -46,43 +47,7 @@ using namespace std;
...
@@ -46,43 +47,7 @@ using namespace std;
// Local functions
// Local functions
int
do_work
(
int
argc
,
char
*
argv
[])
{
int
do_work
(
int
argc
,
char
*
argv
[])
{
Matrix
design
;
design
=
read_ascii_matrix
(
fnin
.
value
());
Matrix
joined
;
Matrix
weights
;
cerr
<<
" Design : "
<<
design
.
Nrows
()
<<
" x "
<<
design
.
Ncols
()
<<
endl
<<
endl
;
for
(
int
i
=
1
;
i
<
10
;
i
++
){
weights
=
normrnd
(
10
,
design
.
Ncols
());
joined
=
SP
(
design
,
ones
(
design
.
Nrows
(),
1
)
*
weights
.
Row
(
1
));
for
(
int
j
=
2
;
j
<=
weights
.
Nrows
();
j
++
){
Matrix
tmp
;
tmp
=
SP
(
design
,
ones
(
design
.
Nrows
(),
1
)
*
weights
.
Row
(
j
));
joined
&=
tmp
;
}
}
cerr
<<
" joined : "
<<
joined
.
Nrows
()
<<
" x "
<<
joined
.
Ncols
()
<<
endl
<<
endl
;
Matrix
Cols
,
Rows
;
Melodic
::
krfact
(
joined
,
design
.
Nrows
(),
Cols
,
Rows
);
cerr
<<
" Cols : "
<<
Cols
.
Nrows
()
<<
" x "
<<
Cols
.
Ncols
()
<<
endl
<<
endl
;
cerr
<<
" Rows : "
<<
Rows
.
Nrows
()
<<
" x "
<<
Rows
.
Ncols
()
<<
endl
<<
endl
;
cerr
<<
weights
<<
endl
<<
endl
<<
Rows
<<
endl
;
cerr
<<
remmean
(
SP
(
weights
,
pow
(
Rows
,
-
1
)))
<<
endl
;
return
0
;
return
0
;
}
}
...
@@ -94,8 +59,16 @@ int do_work(int argc, char* argv[]) {
...
@@ -94,8 +59,16 @@ int do_work(int argc, char* argv[]) {
try
{
try
{
// must include all wanted options here (the order determines how
// must include all wanted options here (the order determines how
// the help message is printed)
// the help message is printed)
options
.
add
(
fnin
);
double
tmptime
=
time
(
NULL
);
srand
((
unsigned
int
)
tmptime
);
cerr
<<
(
unsigned
int
)
tmptime
<<
endl
<<
endl
;
cerr
<<
unifrnd
(
2
,
2
)
<<
endl
;
exit
(
1
);
/*
options.add(fnin);
options.add(help);
options.add(help);
options.parse_command_line(argc, argv);
options.parse_command_line(argc, argv);
...
@@ -108,7 +81,7 @@ int do_work(int argc, char* argv[]) {
...
@@ -108,7 +81,7 @@ int do_work(int argc, char* argv[]) {
}else{
}else{
// Call the local functions
// Call the local functions
return do_work(argc,argv);
return do_work(argc,argv);
}
}
*/
}
catch
(
X_OptionError
&
e
)
{
}
catch
(
X_OptionError
&
e
)
{
options
.
usage
();
options
.
usage
();
cerr
<<
endl
<<
e
.
what
()
<<
endl
;
cerr
<<
endl
<<
e
.
what
()
<<
endl
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment