Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mata: *: 3200 conformability error

    Hi,

    I am trying to minimize "crit" and output a vector "item_price" with the command "optimize()". I am getting the following error:

    Code:
    : p=optimize(S)
                           *:  3200  conformability error
                    i_crit():     -  function returned error
          opt__calluser0_d():     -  function returned error
          opt__d0_calluser():     -  function returned error
        deriv__call1user_d():     -  function returned error
     _deriv__compute_value():     -  function returned error
                    _deriv():     -  function returned error
           opt__eval_nr_d0():     -  function returned error
                 opt__eval():     -  function returned error
    opt__looputil_iter0_common():     -  function returned error
    opt__looputil_iter0_nr():     -  function returned error
              opt__loop_nr():     -  function returned error
                  optimize():     -  function returned error
                     <istmt>:     -  function returned error
    (1 line skipped)
    Here is the code that I am running:

    Code:
    clear*
    sysuse auto, clear
    
    gen n= _n
    drop if n>38
    
    rename price pack_price
    
    mata:
    void i_crit(todo,item_price,crit,g,H)
    {
        external pack_price, item_qty, item_price
        e=pack_price - item_qty*item_price
        crit=(e'*e)
    }
    pack_price = st_data(., "pack_price")
    item_qty=J(rows(pack_price),50,1)
    item_price = J(50,1,0)
    item_price_0 = J(50,1,1)
    
    S=optimize_init()
    
    optimize_init_evaluator(S, &i_crit())
    optimize_init_which(S,"min")
    optimize_init_evaluatortype(S,"d0")
    optimize_init_params(S,item_price_0')
    p=optimize(S)
    p
    end
    I also would like to define inequality constraints on the "item_price" vector (the error that I am getting may be related...)
    LowerBound <= item_price <= UpperBound

    I want to mention that I have printed the matrices, and it does not seem to be a matter of dimensions. Can someone help? Thanks!



  • #2
    Item_price should transposed to make the expression for e comformable.

    Code:
    e=pack_price - item_qty*item_price'

    Comment


    • #3
      Note that the broader problem expressed by

      I also would like to define inequality constraints on the "item_price" vector (the error that I am getting may be related...) LowerBound <= item_price <= UpperBound
      has been described and discussed at www.statalist.org/forums/forum/general-stata-discussion/general/1331316-maximization-problem?p=1331502 and the response following it.

      Comment


      • #4
        How do you define inequality constraints with optimize() then? Thanks!

        Comment


        • #5
          You cannot.

          Comment


          • #6
            I am trying to keep only one side of the inequality in the constraint. I have read it is possible to build it in the code with variable transform. Do you guys know how to do that?

            Comment

            Working...
            X