Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Constrained optimization in mata
From
Tirthankar Chakravarty <[email protected]>
To
[email protected]
Subject
Re: st: Constrained optimization in mata
Date
Fri, 21 May 2010 00:52:53 +0530
Consider the following example taken from Nichols (2008):
http://www.stata.com/meeting/snasug08/nichols_gmm.pdf
for an example of the use of -optimize_init_constraints()-:
************************************************
clear*
sysuse auto, clear
mata:
void i_crit(todo,b,crit,g,H)
{
external y,X,W
m=X'(y-X*b')
crit=(m'*W*m)
}
y = st_data(., "price")
cons=J(rows(y),1,1)
X = st_data(., "weight length"), cons
W=cholinv(X'X)
init=J(1,cols(X),0)
S=optimize_init()
// build the constraint matrix
C = (1, 0, 0)
c = (0)
Cc = (C, c)
optimize_init_constraints(S,Cc)
optimize_init_evaluator(S, &i_crit())
optimize_init_which(S,"min")
optimize_init_evaluatortype(S,"d0")
optimize_init_params(S,init)
p=optimize(S)
p
end
constraint 1 weight = 0
cnsreg price weight length, constraints(1)
************************************************
T
2010/5/21 <[email protected]>:
> While I have never used it, I think you can add in a line using:
>
> optimize_init_constraints(S,Cp)
>
> as described in the mata manual (page 658). Here, Cp is a matrix
> with rows=number of constraints, and columns=parameters+1. The
> +1 is for the constant value at the end of each constraint. As your
> constraint is b1=0 with two parameters, I think Cp=(1,0,0) should
> do it.
>
> Matt Baker
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
--
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/