SHAZAM Community
Ask Your Question
1

Can I estimate Non-Negative Least Squares (NNLS) in SHAZAM?

asked 2011-03-12 07:47:13 +0000

updated 2011-03-12 08:49:42 +0000

David gravatar image

A SHAZAM User asked:

Is it possible to solve a non-negative least-squares constraints problem of the form shown below in SHAZAM?

${\min_{x}\left \| B.x-a \right \|^2_2},\quad where\quad x\geq 0$

Could this be done with the NL command?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2011-03-12 07:54:19 +0000

David gravatar image

updated 2011-03-12 08:02:24 +0000

Yes, this can be done.

The simplest way is to specify the equation on the NL command like

EQ Y = a + (b*b)*X

will make the coefficient on X always positive because b*b is always zero or positive.

You could also create a SHAZAM procedure using the PROC command which for two variables might look like this:

* PROC NNLS2
*
* SHAZAM Procedure to perform Non Negative Least Squares for 2 variables
*
* INPUTS:     [YIN]
*             [XIN]
*             [STARTIN]
*
* OUTPUTS:    [BETAOUT]
*
PROC NNLS2

  MATRIX X1_=[XIN](0,1)
  GENR X1_=X1_
  MATRIX X2_=[XIN](0,2)
  GENR X2_=X2_

  NL 1 / NCOEF=[VARSIN] START=[STARTIN] GENRVAR
  EQ [YIN]=(B1_*B1_)*X1_+(B2_*B2_)*X2_
  END

  GENR B11_=B1_*B1_
  GENR B22_=B2_*B2_
  MATRIX [BETAOUT](1,1)=B11_
  MATRIX [BETAOUT](2,1)=B22_

PROCEND
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2011-03-12 07:47:13 +0000

Seen: 227 times

Last updated: Mar 12 '11