Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
constructing variables and objectives within loops
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
rmi...@umich.edu  
View profile  
 More options May 13, 2:20 pm
From: rmi...@umich.edu
Date: Wed, 13 May 2009 11:20:57 -0700 (PDT)
Local: Wed, May 13 2009 2:20 pm
Subject: constructing variables and objectives within loops
I'm trying to estimate a simple binary choice (probit) model by
maximum likelihood. The outcome variable, y, equals 1 if the latent
variable, z, is less than X*b and equals 0 otherwise. (X is a matrix
of observable variables and b is a parameter vector to be estimated.)
I assume z is a standard normal random variable. Thus, y=1 with
probability Prob(z< X*b). I have a panel of data on N individuals; I
observe each individual for T periods.

Suppose b is just a 2x1 equal to [alpha beta]'; these are the
variables I seek to estimate. But in the process I need to define a
number of auxiliary variables. In this case, that is relatively easy
to do. I define:

var Bnd {i in N, t in T} = alpha + beta*x[i,t];    # this is X*b (the
upper limit of integration)

# Now, I need to evaluate the standard normal CDF at X*b. Ideally, I
would wrap in a function, but it appears the NEOS server does not
accept pipe-in functions. So here, I just calculate it directly. The
parameters N_a1, etc. would be defined earlier in the mod file. (The
code is borrowed from John Burkardt, http://people.sc.fsu.edu/~burkardt.)

var NCDF {i in N, t in T} = 1 -  (
if Bnd[i,t] > N_max then 1   else (
if Bnd[i,t]<= N_con then 0.5-Bnd[i,t]*(N_p - N_q*0.5*Bnd[i,t]^2
                                        /(0.5*Bnd[i,t]^2 +N_a1+N_b1
                                        /(0.5*Bnd[i,t]^2 +N_a2+N_b2
                                        /(0.5*Bnd[i,t]^2 +N_a3))))   else
if Bnd[i,t]  > N_con then N_r*exp(-0.5*Bnd[i,t]^2)
                                /(Bnd[i,t] + N_c1+N_d1
                                /(Bnd[i,t] + N_c2+N_d2
                                /(Bnd[i,t] + N_c3+N_d3
                                /(Bnd[i,t] + N_c4+N_d4
                                /(Bnd[i,t] + N_c5+N_d5
                                /(Bnd[i,t] + N_c6))))))
)
);

# Lastly, I calculate the likelihood contribution of each
observation.
var Like {i in N, t in T} = (
        if y[i,t]=1 then NCDF[i,t] else
        if y[i,t]=0 then 1-NCDF[i,t]
);

maximize Log_Likelihood: sum {i in N, t in T}  Like[i,t];

As far as I can tell, this code works well.

Here, I do not need for loops. But in more complicated problems, it's
a lot easier for me to think in terms of loops. So I wanted to try to
re-estimate this model by building up the likelihood within a for
loop. But thus far, this has been a failure. My code is provided
below. I'm receiving the message, "Unbounded objective". In addition,
even after substitution, my output reads, "50 variables, all linear"
-- but substitution should eliminate all variables except alpha and
beta. Any help would be greatly appreciated. (sorry for such a long
email.)

var alpha := 0.25;
var beta := 0.1;

var Bnd {i in N, t in T};
var NCDF {i in N, t in T};
var Like {i in N, t in T};
var Log_Like {i in N};

for {i in N} {

        for {t in T} {
                let Bnd[i,t] := alpha + beta*x[i,t];

                let NCDF[i,t] := 1 -  (
                if Bnd[i,t] > N_max then 1   else (
                if Bnd[i,t]<= N_con then 0.5-Bnd[i,t]*(N_p - N_q*0.5*Bnd[i,t]^2
                                                        /(0.5*Bnd[i,t]^2 +N_a1+N_b1
                                                        /(0.5*Bnd[i,t]^2 +N_a2+N_b2
                                                        /(0.5*Bnd[i,t]^2 +N_a3))))   else
                if Bnd[i,t]  > N_con then N_r*exp(-0.5*Bnd[i,t]^2)
                                                /(Bnd[i,t] + N_c1+N_d1
                                                /(Bnd[i,t] + N_c2+N_d2
                                                /(Bnd[i,t] + N_c3+N_d3
                                                /(Bnd[i,t] + N_c4+N_d4
                                                /(Bnd[i,t] + N_c5+N_d5
                                                /(Bnd[i,t] + N_c6))))))
                )
                );

                let Like[i,t] := (
                        if y[i,t]=1 then NCDF[i,t] else
                        if y[i,t]=0 then 1-NCDF[i,t]
                );
        }

}

maximize Log_Likelihood: sum {i in N, t in T} Like[i,t];

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Fourer  
View profile  
 More options May 15, 10:49 am
From: "Robert Fourer" <4...@ampl.com>
Date: Fri, 15 May 2009 09:49:56 -0500
Local: Fri, May 15 2009 10:49 am
Subject: RE: [AMPL 2505] constructing variables and objectives within loops

Writing the loop

   for {i in N} {
      for {t in T} {
         ...
            let Like[i,t] := (
               if y[i,t]=1 then NCDF[i,t] else
               if y[i,t]=0 then 1-NCDF[i,t]
            );
      }
   }

does not have the same effect as

   var Like {i in N, t in T} = (
      if y[i,t]=1 then NCDF[i,t] else
      if y[i,t]=0 then 1-NCDF[i,t]
   );

The "let" statement only assigns values to the Like variables, which are passed
to the solver as initial values but which will in general be changed as the
optimum is computed.  Only the "var" statement does what you want, which is to
define the Like variables to represent expressions in the NCDF variables and to
pass those definitions to the solver.

Bob Fourer
4...@ampl.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google