Re: [AMPL 24051] Approximation of discrete cumulative distribution function

22 views
Skip to first unread message

AMPL Google Group

unread,
Aug 1, 2022, 4:59:16 PM8/1/22
to AMPL Modeling Language
Apparently range2, range3, range4, and max_val are used together to define some kind of approximation. However, the author of this model has not responded; and without some explanation, the logic of the constraints is hard to figure out. Also, the author suggests that possibly there is a mistake in this formulation.


--
Robert Fourer
am...@googlegroups.com
{#HS:1952392617-111051#}
On Mon, Jul 18, 2022 at 3:31 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Can you explain me why are range2 and range3 constraints useful and what are their meanings?
Thnaks in advance.

Il giorno sabato 20 gennaio 2018 alle 18:42:28 UTC+1 cap...@hotmail.it ha scritto:
Hello,

I modified to code, and got it to work but I still have one issue to solve. Here's the updated version :

### SETS

param n
;
param N
;
set Nset:=1..N;
set nset:=1..(n-1);

### PARAMS

param F
{Nset} <= 1, >= 0;
param mult
:= (N-1)/(n-1);
param z
:= N;

### VARS

var G{Nset} <= 1, >= 0;
var t{Nset} <= 1 >= 0;

### CONSTR

###subject to range{d in nset}: G[ceil(mult*d)] <= F[ceil(mult*d)];
subject to range2
{e in nset: e > 1}: G[ceil(mult*(e))] >= F[ceil(mult*(e-1))];
subject to range3
{f in nset} : G[ceil(mult*f)] - G[ceil(mult*(f-1)) + 1] = 0;
subject to range4
{g in Nset: g < z} : G[g] <= G[g+1];
subject to max_val
: G[N] = 1 ;


subject to l1
{h in Nset} : t[h] >= (F[h] - G[h]);
subject to l2
{l in Nset} : t[l] >= -(F[l] - G[l]);

### OBJ
###minimize total_cost : sum{i in Nset}(F[i] - G[i])^2; quadratic formula
###minimize total_cost : sum{i in Nset}(1 + ((0.5)*(((F[i] - G[i])^2) - 1))); taylor's serie
minimize total_cost
: sum{i in Nset}t[i];




Now, given a dataset as following :

### PARAMETERS

param n
:= 4;
param N
:= 10;

param F
:=
1 0.1
2 0.3
3 0.4
4 0.45
5 0.55
6 0.6
7 0.8
8 0.85
9 0.95
10 1;





Using the quadratic function, or Taylor's expansion, the solver gives me the following output, which is also confirmed to be right from math :

G [*] :=
1 0.266667
2 0.266667
3 0.266667
4 0.533333
5 0.533333
6 0.533333
7 0.866667
8 0.866667
9 0.866667
10 1
;


However, for my tutor, using quadratic function is not acceptable cause the solver could produce an output different from what I'm expecting, and using Taylor's serie is not good for the learning purpose.
I got asked to linearize the absolute value, and I proceeded as you can see in my ".mod" file (I added 2 constraints "l1" and "l2" and changed the objective function).
I runned the code but the result is bit different from the one obtained with the first 2 methods :

G [*] :=
1 0.3
2 0.3
3 0.3
4 0.55
5 0.55
6 0.55
7 0.85
8 0.85
9 0.85
10 1
;


I can't figure out the mismatching in the results since the linearization should be right.

Can you help me? what am I doing wrong?

Thanks in advice
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/c9b59a8b-1512-4ddb-af6f-90c48a3e830an%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages