[AMPL 2873] Optimization problem for statistical distribution

View: New views
2 Messages — Rating Filter:   Alert me  

[AMPL 2873] Optimization problem for statistical distribution

by Yangqian :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I have had problems when dealing with this question: Optimize the
parameters in a bivariate normal distribution with 1) 2 sets of
numbers, 100 each. 2) some constraints.

My code is the following:
param n;
param x1{i in 1..n};
param x2{i in 1..n};
var mu1;
var se1;
var mu2;
var se2;
var rho;

minimize loglik: sum {i in 1..n}
(log(2*3.14*se1*se2) + 0.5*log(1-rho*rho) + ((x1[i]-mu1)*(x1[i]-mu1)/
(se1*se1) - 2*rho*(x1[i]-mu1)*(x2[i]-mu2)/(se1*se2) + (x2[i]-mu2)*(x2
[i]-mu2)/(se2*se2)) / (2*(1-rho*rho)));

subject to Limit: mu1 + mu2 >= 0;
subject to s1: se1 >= 0;
subject to s2: se2 >= 0;
subject to rho: -1 <= rho <= 1;

#data
param n:=100;
param x1:= 0.41 5.04 3.63 1.41 5.77 0.89 4.67 -3.92 1.75 -0.11 -1.04
2.2 0.51 -0.75 -0.4 2.53 5.34 -0.5 0.9 1.54 3.24 -0.04 2.3 1.24 -0.35
0.83 2.27 0.98 -0.89 0.99 -0.87 -3.98 2.36 2.43 1.87 -0.96
0.96 -1 -0.07 -0.22 1.74 1.53 0.77 -0.16 -1.43 -1.96 3.08 5.55
3.01 -0.97 0.3 3.44 2.22 0.02 2.2 1.95 0.2 1.05 0.55 1.14 3.35 1.46
0.1 3.37 1.53 0.49 3.29 -1.05 1.77 -4.15 1.15 -1.66 0.53 0.43 -1.43
0.52 5.42 0.85 1.91 -3.61 0.55 1.7 2.47 -2.74 1.89 1.5 2.84 0.93 2.59
0.02 4.29 -0.39 -0.08 1.1 -0.99 2.51 -0.41 -0.51 -0.05 6.14;
param x2:= -0.13 -4.24 -2.09 0.28 -3.77 -1.37 -3.24
1.76 -2.74 -0.83 -0.27 -2.5 -2 0.14 0.16 -1.41 -2.66
0.86 -0.06 -1.32 -2.37
0.68 -2.09 -3.31 -0.6 -2 -1.89 -0.35 -0.04 -1.31 -0.06
1.51 -1.67 -2.06 -1.7 0.33 -0.56 -0.98 -0.79
0.16 -2.64 -0.28 -2.11 -0.29 0.28 0.11 -3.17 -3.96 -1.96 -0.26
0.54 -2.22 -2.59 -0.81 -2.33 -1.13 -0.75 -1.08 -1.71 -1.74 -1.32 -0.48 -1.27 -1.91 -0.17 -0.39 -2.09 -0.3 -1.79
1.55 -0.7 0.57 -1.45 -1.59 0.54 -0.87 -3.83 -1.76 -3.15 0.8
0.98 -0.79 -2.51 1.91 -0.61 -0.33 -1.36 -1.68 -2.52 -0.59 -4.2 0.03
0.9 -1.8 0.23 -2.5 0.21 0.53 0.09 -3.76;
===============================================================

The error messages came out a lot:

Tmp/tin25774, line 18 (offset 444):
        rho is already defined
context:  subject to  >>> rho: <<<  -1 <= rho <= 1;

Tmp/tin923, line 23 (offset 1060):
        x1[-1.43] already defined
... ...
Tmp/tin923, line 25 (offset 1636):
        x2[-2.09] already defined
context:  param x2 := -0.13 -4.24 -2.09 0.28 -3.77 -1.37 -3.24 1.76
-2.74 -0.83 -0.27 -2.5 -2 0.14 0.16 -1.41 -2.66 0.86 -0.06 -1.32 -2.37
0.68 -2.09 -3.31 -0.6 -2 -1.89 -0.35 -0.04 -1.31 -0.06 1.51 -1.67
-2.06 -1.7 0.33 -0.56 -0.98 -0.79 0.16 -2.64 -0.28 -2.11 -0.29 0.28
0.11 -3.17 -3.96 -1.96 -0.26 0.54 -2.22 -2.59 -0.81 -2.33 -1.13 -0.75
-1.08 -1.71 -1.74 -1.32 -0.48 -1.27 -1.91 -0.17 -0.39 -2.09 -0.3 -1.79
1.55 -0.7 0.57 -1.45 -1.59 0.54 -0.87 -3.83 -1.76 -3.15 0.8 0.98 -0.79
-2.51 1.91 -0.61 -0.33 -1.36 -1.68 -2.52 -0.59 -4.2 0.03 0.9 -1.8 0.23
-2.5 0.21 0.53 0.09 -3.76 >>> ; <<<

=============================================================

May I know what went wrong here? This is my first time using AMPL.

Yang

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


[AMPL 2874] Re: Optimization problem for statistical distribution

by Paul A. Rubin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


First error:  You are using the same name (rho) for both a constraint
and a variable.  You need to use distinct names.

Second and third errors: In the data statements (param x1 := ...) AMPL
takes the values two numbers at a time, index followed by value.  So
"param x1:= 0.41 5.04 ..." means 0.41 is an index and 5.04 is the
corresponding value (x1[0.41] = 5.04), and so on.

/Paul

On Oct 9, 4:26 am, Yangqian <cathariney...@...> wrote:

> I have had problems when dealing with this question: Optimize the
> parameters in a bivariate normal distribution with 1) 2 sets of
> numbers, 100 each. 2) some constraints.
>
> My code is the following:
> param n;
> param x1{i in 1..n};
> param x2{i in 1..n};
> var mu1;
> var se1;
> var mu2;
> var se2;
> var rho;
>
> minimize loglik: sum {i in 1..n}
> (log(2*3.14*se1*se2) + 0.5*log(1-rho*rho) + ((x1[i]-mu1)*(x1[i]-mu1)/
> (se1*se1) - 2*rho*(x1[i]-mu1)*(x2[i]-mu2)/(se1*se2) + (x2[i]-mu2)*(x2
> [i]-mu2)/(se2*se2)) / (2*(1-rho*rho)));
>
> subject to Limit: mu1 + mu2 >= 0;
> subject to s1: se1 >= 0;
> subject to s2: se2 >= 0;
> subject to rho: -1 <= rho <= 1;
>
> #data
> param n:=100;
> param x1:= 0.41 5.04    3.63    1.41    5.77    0.89    4.67    -3.92   1.75    -0.11   -1.04
> 2.2     0.51    -0.75   -0.4    2.53    5.34    -0.5    0.9     1.54    3.24    -0.04   2.3     1.24    -0.35
> 0.83    2.27    0.98    -0.89   0.99    -0.87   -3.98   2.36    2.43    1.87    -0.96
> 0.96    -1      -0.07   -0.22   1.74    1.53    0.77    -0.16   -1.43   -1.96   3.08    5.55
> 3.01    -0.97   0.3     3.44    2.22    0.02    2.2     1.95    0.2     1.05    0.55    1.14    3.35    1.46
> 0.1     3.37    1.53    0.49    3.29    -1.05   1.77    -4.15   1.15    -1.66   0.53    0.43    -1.43
> 0.52    5.42    0.85    1.91    -3.61   0.55    1.7     2.47    -2.74   1.89    1.5     2.84    0.93    2.59
> 0.02    4.29    -0.39   -0.08   1.1     -0.99   2.51    -0.41   -0.51   -0.05   6.14;
> param x2:= -0.13        -4.24   -2.09   0.28    -3.77   -1.37   -3.24
> 1.76    -2.74   -0.83   -0.27   -2.5    -2      0.14    0.16    -1.41   -2.66
> 0.86    -0.06   -1.32   -2.37
> 0.68    -2.09   -3.31   -0.6    -2      -1.89   -0.35   -0.04   -1.31   -0.06
> 1.51    -1.67   -2.06   -1.7    0.33    -0.56   -0.98   -0.79
> 0.16    -2.64   -0.28   -2.11   -0.29   0.28    0.11    -3.17   -3.96   -1.96   -0.26
> 0.54    -2.22   -2.59   -0.81   -2.33   -1.13   -0.75   -1.08   -1.71   -1.74   -1.32   -0.48   -1.27   -1.91   -0.17   -0.39   -2.09   -0.3    -1.79
> 1.55    -0.7    0.57    -1.45   -1.59   0.54    -0.87   -3.83   -1.76   -3.15   0.8
> 0.98    -0.79   -2.51   1.91    -0.61   -0.33   -1.36   -1.68   -2.52   -0.59   -4.2    0.03
> 0.9     -1.8    0.23    -2.5    0.21    0.53    0.09    -3.76;
> ===============================================================
>
> The error messages came out a lot:
>
> Tmp/tin25774, line 18 (offset 444):
>         rho is already defined
> context:  subject to  >>> rho: <<<  -1 <= rho <= 1;
>
> Tmp/tin923, line 23 (offset 1060):
>         x1[-1.43] already defined
> ... ...
> Tmp/tin923, line 25 (offset 1636):
>         x2[-2.09] already defined
> context:  param x2 := -0.13 -4.24 -2.09 0.28 -3.77 -1.37 -3.24 1.76
> -2.74 -0.83 -0.27 -2.5 -2 0.14 0.16 -1.41 -2.66 0.86 -0.06 -1.32 -2.37
> 0.68 -2.09 -3.31 -0.6 -2 -1.89 -0.35 -0.04 -1.31 -0.06 1.51 -1.67
> -2.06 -1.7 0.33 -0.56 -0.98 -0.79 0.16 -2.64 -0.28 -2.11 -0.29 0.28
> 0.11 -3.17 -3.96 -1.96 -0.26 0.54 -2.22 -2.59 -0.81 -2.33 -1.13 -0.75
> -1.08 -1.71 -1.74 -1.32 -0.48 -1.27 -1.91 -0.17 -0.39 -2.09 -0.3 -1.79
> 1.55 -0.7 0.57 -1.45 -1.59 0.54 -0.87 -3.83 -1.76 -3.15 0.8 0.98 -0.79
> -2.51 1.91 -0.61 -0.33 -1.36 -1.68 -2.52 -0.59 -4.2 0.03 0.9 -1.8 0.23
> -2.5 0.21 0.53 0.09 -3.76 >>> ; <<<
>
> =============================================================
>
> May I know what went wrong here? This is my first time using AMPL.
>
> Yang
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---