Discussion:
matrix inverse without IML
(too old to reply)
oloolo
2009-07-30 16:23:48 UTC
Permalink
by understanding the operations behind a matrix inversion, we certainly can
resort to SVD algorithm

SVD on a square matrix X is
X=UEV'
and once we got matrix U, E, V, we can obtain the inverse of X as
inv(X)=UE^{-1}V'

since matrix E is an diagonal matrix, its inverse is simply inversion of
its diagonal scalar elements which can be easily done, taking numerical
stability into consideration.

Well, I've also point out a way in SAS to do SVD (hence generalized
inverse) without IML (but you do need SAS/STAT) at
sas-programming.blogspot.com

now you don't IML or other software and the overhead in exchange data
between them.

On Thu, 7 Jun 2001 14:21:18 -0700, David L. Cassell
Here's an alternative.
You probably have Excel.
Excel has a function (MINVERSE) for inverting matrices.
You could put the data into Excel, do the calculation, then get the data
back into SAS.
Very clever [as usual]. But are you aware that Excel does *not* do a
good job on some matrix and stat functions? I believe there is an ACM
paper of last year in which two authors tested Excel on NIST test data
sets for stats and it did wretchedly. I wouldn't use Excel to invert a
matrix
without substantial testing first. And if the matrix is ill-conditioned,
Excel [or most non-matrix/stat software for that matter] may do a *ghastly*
job of inverting the matrix properly. BTW, this is not just another MS
slam,
because I wouldn't trust any of the popular spreadsheets to do this well
without
testing first.
OTOH, there are realtively inexpensive matrix mainpulation and stats
packages
which could be used in place of Excel here. GLIM comes to mind, as does
Perl's PDL module [which is free - if you can get it to compile on your
OS!]
and the R system [also free].
David
--
David Cassell, CSC
Senior computing specialist
mathematical statistician
Mike Zdeb
2009-07-30 18:04:22 UTC
Permalink
hi ... wow, a reference to a post from 2001 !!!

well, since then, if you don't have IML, you can use some matrix functions PROC FCMP

as was pointed out by a couple postings by Dale McLerran in a few postings, among them ...

http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0812B&L=sas-l&P=R31866

http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0905A&L=sas-l&P=R24270


data x;
input m1-m3;
datalines;
1 3 3
1 4 3
1 3 4
;
run;

proc fcmp;
array temp[3,3] / nosymbols;
array im[3,3];
rc = read_array('work.x',temp);
call inv(temp, inverse);
rc = write_array('work.y',im);
quit;

title 'matrix';
proc print data=x noobs;
run;

title 'inverse';
proc print data=y noobs;
run;

matrix
m1 m2 m3
1 3 3
1 4 3
1 3 4

inverse
im1 im2 im3
7 -3 -3
-1 1 0
-1 0 1

--
Mike Zdeb
***@Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
Post by oloolo
by understanding the operations behind a matrix inversion, we certainly can
resort to SVD algorithm
SVD on a square matrix X is
X=UEV'
and once we got matrix U, E, V, we can obtain the inverse of X as
inv(X)=UE^{-1}V'
since matrix E is an diagonal matrix, its inverse is simply inversion of
its diagonal scalar elements which can be easily done, taking numerical
stability into consideration.
Well, I've also point out a way in SAS to do SVD (hence generalized
inverse) without IML (but you do need SAS/STAT) at
sas-programming.blogspot.com
now you don't IML or other software and the overhead in exchange data
between them.
On Thu, 7 Jun 2001 14:21:18 -0700, David L. Cassell
Here's an alternative.
You probably have Excel.
Excel has a function (MINVERSE) for inverting matrices.
You could put the data into Excel, do the calculation, then get the data
back into SAS.
Very clever [as usual]. But are you aware that Excel does *not* do a
good job on some matrix and stat functions? I believe there is an ACM
paper of last year in which two authors tested Excel on NIST test data
sets for stats and it did wretchedly. I wouldn't use Excel to invert a
matrix
without substantial testing first. And if the matrix is ill-conditioned,
Excel [or most non-matrix/stat software for that matter] may do a *ghastly*
job of inverting the matrix properly. BTW, this is not just another MS
slam,
because I wouldn't trust any of the popular spreadsheets to do this well
without
testing first.
OTOH, there are realtively inexpensive matrix mainpulation and stats
packages
which could be used in place of Excel here. GLIM comes to mind, as does
Perl's PDL module [which is free - if you can get it to compile on your
OS!]
and the R system [also free].
David
--
David Cassell, CSC
Senior computing specialist
mathematical statistician
oloolo
2009-07-30 18:32:50 UTC
Permalink
the point here is to do the matrix inversion and other basic matrix
manipulation (such as to get determinant) on a real-valued arbitrary size
matrix with high numerical precision.

certainly a user written data step function is good, well, you don't need a
Data Step function to do this because you use array anyway in a data step,
why not directly write the routine in data step which will be much more
efficient? Sample codes are everywhere, say, the famous "Numeric Receipes".
Post by Mike Zdeb
hi ... wow, a reference to a post from 2001 !!!
well, since then, if you don't have IML, you can use some matrix functions
PROC FCMP
Post by Mike Zdeb
as was pointed out by a couple postings by Dale McLerran in a few
postings, among them ...
Post by Mike Zdeb
http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0812B&L=sas-l&P=R31866
http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0905A&L=sas-l&P=R24270
data x;
input m1-m3;
datalines;
1 3 3
1 4 3
1 3 4
;
run;
proc fcmp;
array temp[3,3] / nosymbols;
array im[3,3];
rc = read_array('work.x',temp);
call inv(temp, inverse);
rc = write_array('work.y',im);
quit;
title 'matrix';
proc print data=x noobs;
run;
title 'inverse';
proc print data=y noobs;
run;
matrix
m1 m2 m3
1 3 3
1 4 3
1 3 4
inverse
im1 im2 im3
7 -3 -3
-1 1 0
-1 0 1
--
Mike Zdeb
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
Post by oloolo
by understanding the operations behind a matrix inversion, we certainly
can
Post by Mike Zdeb
Post by oloolo
resort to SVD algorithm
SVD on a square matrix X is
X=UEV'
and once we got matrix U, E, V, we can obtain the inverse of X as
inv(X)=UE^{-1}V'
since matrix E is an diagonal matrix, its inverse is simply inversion of
its diagonal scalar elements which can be easily done, taking numerical
stability into consideration.
Well, I've also point out a way in SAS to do SVD (hence generalized
inverse) without IML (but you do need SAS/STAT) at
sas-programming.blogspot.com
now you don't IML or other software and the overhead in exchange data
between them.
On Thu, 7 Jun 2001 14:21:18 -0700, David L. Cassell
Here's an alternative.
You probably have Excel.
Excel has a function (MINVERSE) for inverting matrices.
You could put the data into Excel, do the calculation, then get the
data
Post by Mike Zdeb
Post by oloolo
back into SAS.
Very clever [as usual]. But are you aware that Excel does *not* do a
good job on some matrix and stat functions? I believe there is an ACM
paper of last year in which two authors tested Excel on NIST test data
sets for stats and it did wretchedly. I wouldn't use Excel to invert a
matrix
without substantial testing first. And if the matrix is ill-conditioned,
Excel [or most non-matrix/stat software for that matter] may do a
*ghastly*
Post by Mike Zdeb
Post by oloolo
job of inverting the matrix properly. BTW, this is not just another MS
slam,
because I wouldn't trust any of the popular spreadsheets to do this well
without
testing first.
OTOH, there are realtively inexpensive matrix mainpulation and stats
packages
which could be used in place of Excel here. GLIM comes to mind, as does
Perl's PDL module [which is free - if you can get it to compile on your
OS!]
and the R system [also free].
David
--
David Cassell, CSC
Senior computing specialist
mathematical statistician
Dale McLerran
2009-07-30 19:50:11 UTC
Permalink
The FCMP matrix operations which SAS has made available do
have limited utility. The methods which L Xie (oloolo) has
proposed do merit serious consideration. However, if one
really needs to operate on ill-conditioned matrices and if
there is need for subsequent matrix manipulations, then one
really should have IML or be using other software better
suited to such operations (like R).

Dale

---------------------------------------
Dale McLerran
Fred Hutchinson Cancer Research Center
mailto: ***@NO_SPAMfhcrc.org
Ph: (206) 667-2926
Fax: (206) 667-5977
---------------------------------------
Subject: Re: matrix inverse without IML
Date: Thursday, July 30, 2009, 11:32 AM
the point here is to do the matrix
inversion and other basic matrix
manipulation (such as to get determinant) on a real-valued
arbitrary size
matrix with high numerical precision.
certainly a user written data step function is good, well,
you don't need a
Data Step function to do this because you use array anyway
in a data step,
why not directly write the routine in data step which will
be much more
efficient? Sample codes are everywhere, say, the famous
"Numeric Receipes".
Post by Mike Zdeb
hi ... wow, a reference to a post from 2001 !!!
well, since then, if you don't have IML, you can use
some matrix functions
PROC FCMP
Post by Mike Zdeb
as was pointed out by a couple postings by Dale
McLerran in a few
postings, among them ...
Post by Mike Zdeb
http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0812B&L=sas-l&P=R31866
http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0905A&L=sas-l&P=R24270
data x;
input m1-m3;
datalines;
1 3 3
1 4 3
1 3 4
;
run;
proc fcmp;
array temp[3,3] / nosymbols;
array im[3,3];
rc = read_array('work.x',temp);
call inv(temp, inverse);
rc = write_array('work.y',im);
quit;
title 'matrix';
proc print data=x noobs;
run;
title 'inverse';
proc print data=y noobs;
run;
matrix
m1 m2 m3
1 3 3
1 4 3
1 3 4
inverse
im1 im2 im3
7 -3
-3
Post by Mike Zdeb
-1 1 0
-1 0 1
--
Mike Zdeb
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
Post by oloolo
by understanding the operations behind a matrix
inversion, we certainly
can
Post by Mike Zdeb
Post by oloolo
resort to SVD algorithm
SVD on a square matrix X is
X=UEV'
and once we got matrix U, E, V, we can obtain the
inverse of X as
Post by Mike Zdeb
Post by oloolo
inv(X)=UE^{-1}V'
since matrix E is an diagonal matrix, its inverse
is simply inversion of
Post by Mike Zdeb
Post by oloolo
its diagonal scalar elements which can be easily
done, taking numerical
Post by Mike Zdeb
Post by oloolo
stability into consideration.
Well, I've also point out a way in SAS to do SVD
(hence generalized
Post by Mike Zdeb
Post by oloolo
inverse) without IML (but you do need SAS/STAT)
at
Post by Mike Zdeb
Post by oloolo
sas-programming.blogspot.com
now you don't IML or other software and the
overhead in exchange data
Post by Mike Zdeb
Post by oloolo
between them.
On Thu, 7 Jun 2001 14:21:18 -0700, David L.
Cassell
Post by Mike Zdeb
Post by oloolo
Here's an alternative.
You probably have Excel.
Excel has a function (MINVERSE) for
inverting matrices.
Post by Mike Zdeb
Post by oloolo
You could put the data into Excel, do the
calculation, then get the
data
Post by Mike Zdeb
Post by oloolo
back into SAS.
Very clever [as usual]. But are you aware
that Excel does *not* do a
Post by Mike Zdeb
Post by oloolo
good job on some matrix and stat
functions? I believe there is an ACM
Post by Mike Zdeb
Post by oloolo
paper of last year in which two authors tested
Excel on NIST test data
Post by Mike Zdeb
Post by oloolo
sets for stats and it did wretchedly. I
wouldn't use Excel to invert a
Post by Mike Zdeb
Post by oloolo
matrix
without substantial testing first. And if
the matrix is ill-conditioned,
Post by Mike Zdeb
Post by oloolo
Excel [or most non-matrix/stat software for
that matter] may do a
*ghastly*
Post by Mike Zdeb
Post by oloolo
job of inverting the matrix properly.
BTW, this is not just another MS
Post by Mike Zdeb
Post by oloolo
slam,
because I wouldn't trust any of the popular
spreadsheets to do this well
Post by Mike Zdeb
Post by oloolo
without
testing first.
OTOH, there are realtively inexpensive matrix
mainpulation and stats
Post by Mike Zdeb
Post by oloolo
packages
which could be used in place of Excel
here. GLIM comes to mind, as does
Post by Mike Zdeb
Post by oloolo
Perl's PDL module [which is free - if you can
get it to compile on your
Post by Mike Zdeb
Post by oloolo
OS!]
and the R system [also free].
David
--
David Cassell, CSC
Senior computing specialist
mathematical statistician
oloolo
2009-07-30 20:40:30 UTC
Permalink
I do agree with you.

And I think SAS does need to do some modification to its architecture so
that end users have a more powerful tool set to write their own (complex)
functions. By powerful tool set, I mean a set of well designed basic matrix
operators that work within DATA STEP (not like those only supported by IML).

There are several points to support this argument. SAS can't catch up with
ever increasing faster development in machine learning and statistical
learning area, and with powerful set of matrix operators, end users are
able to contribute to this software, making its up-to-date. It is vital to
keep SAS's competitive edge in BI and its traditional backyard

On Thu, 30 Jul 2009 12:50:11 -0700, Dale McLerran
Post by Dale McLerran
The FCMP matrix operations which SAS has made available do
have limited utility. The methods which L Xie (oloolo) has
proposed do merit serious consideration. However, if one
really needs to operate on ill-conditioned matrices and if
there is need for subsequent matrix manipulations, then one
really should have IML or be using other software better
suited to such operations (like R).
Dale
---------------------------------------
Dale McLerran
Fred Hutchinson Cancer Research Center
Ph: (206) 667-2926
Fax: (206) 667-5977
---------------------------------------
Subject: Re: matrix inverse without IML
Date: Thursday, July 30, 2009, 11:32 AM
the point here is to do the matrix
inversion and other basic matrix
manipulation (such as to get determinant) on a real-valued
arbitrary size
matrix with high numerical precision.
certainly a user written data step function is good, well,
you don't need a
Data Step function to do this because you use array anyway
in a data step,
why not directly write the routine in data step which will
be much more
efficient? Sample codes are everywhere, say, the famous
"Numeric Receipes".
Post by Mike Zdeb
hi ... wow, a reference to a post from 2001 !!!
well, since then, if you don't have IML, you can use
some matrix functions
PROC FCMP
Post by Mike Zdeb
as was pointed out by a couple postings by Dale
McLerran in a few
postings, among them ...
Post by Mike Zdeb
http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0812B&L=sas-l&P=R31866
http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0905A&L=sas-l&P=R24270
data x;
input m1-m3;
datalines;
1 3 3
1 4 3
1 3 4
;
run;
proc fcmp;
array temp[3,3] / nosymbols;
array im[3,3];
rc = read_array('work.x',temp);
call inv(temp, inverse);
rc = write_array('work.y',im);
quit;
title 'matrix';
proc print data=x noobs;
run;
title 'inverse';
proc print data=y noobs;
run;
matrix
m1 m2 m3
1 3 3
1 4 3
1 3 4
inverse
im1 im2 im3
7 -3
-3
Post by Mike Zdeb
-1 1 0
-1 0 1
--
Mike Zdeb
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
Post by oloolo
by understanding the operations behind a matrix
inversion, we certainly
can
Post by Mike Zdeb
Post by oloolo
resort to SVD algorithm
SVD on a square matrix X is
X=UEV'
and once we got matrix U, E, V, we can obtain the
inverse of X as
Post by Mike Zdeb
Post by oloolo
inv(X)=UE^{-1}V'
since matrix E is an diagonal matrix, its inverse
is simply inversion of
Post by Mike Zdeb
Post by oloolo
its diagonal scalar elements which can be easily
done, taking numerical
Post by Mike Zdeb
Post by oloolo
stability into consideration.
Well, I've also point out a way in SAS to do SVD
(hence generalized
Post by Mike Zdeb
Post by oloolo
inverse) without IML (but you do need SAS/STAT)
at
Post by Mike Zdeb
Post by oloolo
sas-programming.blogspot.com
now you don't IML or other software and the
overhead in exchange data
Post by Mike Zdeb
Post by oloolo
between them.
On Thu, 7 Jun 2001 14:21:18 -0700, David L.
Cassell
Post by Mike Zdeb
Post by oloolo
Here's an alternative.
You probably have Excel.
Excel has a function (MINVERSE) for
inverting matrices.
Post by Mike Zdeb
Post by oloolo
You could put the data into Excel, do the
calculation, then get the
data
Post by Mike Zdeb
Post by oloolo
back into SAS.
Very clever [as usual]. But are you aware
that Excel does *not* do a
Post by Mike Zdeb
Post by oloolo
good job on some matrix and stat
functions? I believe there is an ACM
Post by Mike Zdeb
Post by oloolo
paper of last year in which two authors tested
Excel on NIST test data
Post by Mike Zdeb
Post by oloolo
sets for stats and it did wretchedly. I
wouldn't use Excel to invert a
Post by Mike Zdeb
Post by oloolo
matrix
without substantial testing first. And if
the matrix is ill-conditioned,
Post by Mike Zdeb
Post by oloolo
Excel [or most non-matrix/stat software for
that matter] may do a
*ghastly*
Post by Mike Zdeb
Post by oloolo
job of inverting the matrix properly.
BTW, this is not just another MS
Post by Mike Zdeb
Post by oloolo
slam,
because I wouldn't trust any of the popular
spreadsheets to do this well
Post by Mike Zdeb
Post by oloolo
without
testing first.
OTOH, there are realtively inexpensive matrix
mainpulation and stats
Post by Mike Zdeb
Post by oloolo
packages
which could be used in place of Excel
here. GLIM comes to mind, as does
Post by Mike Zdeb
Post by oloolo
Perl's PDL module [which is free - if you can
get it to compile on your
Post by Mike Zdeb
Post by oloolo
OS!]
and the R system [also free].
David
--
David Cassell, CSC
Senior computing specialist
mathematical statistician
Loading...