How to treat missing data in AMPL

384 views
Skip to first unread message

jacob....@gmail.com

unread,
Apr 29, 2015, 6:14:55 PM4/29/15
to am...@googlegroups.com
To Whom It May Concern,

My objective function is trying to minimize the sum of a set of covariance values. As a result, I have a decision variable indexed in two dimensions. However, the covariance matrix is relatively sparse, and so includes a lot of "." values. When I try to solve the problem with these "." values, I get an error saying that the value doesn't exist, and so the model will not run. Is there any way I can limit the decision variable so that it only looks at cells in the covariance table that are populated (i.e., not equal to ".")?

Thanks!


Jake

Robert Fourer

unread,
Apr 30, 2015, 10:44:37 AM4/30/15
to am...@googlegroups.com
You can model your covariance matrix as a sparse matrix in AMPL. As a small example, in the model you could write

param m integer > 0;
set C within {1..m,1..m};
param cov {C};

Then in an AMPL data file, the covariance matrix could be given by

param m := 4;
param: C: cov: 1 2 3 4 :=
1 36 . . -2
2 . 7 3 .
3 . . -8 16
4 12 3 . 77 ;

The second param statement defines both C and cov, as you can see by displaying them after reading above statements:

ampl: option display_1col 0;
ampl: display C, cov;
set C := (1,1) (1,4) (2,2) (2,3) (3,3) (3,4) (4,1) (4,2) (4,4);

cov [*,*]
: 1 2 3 4 :=
1 36 . . -2
2 . 7 3 .
3 . . -8 16
4 12 3 . 77 ;

Then in your model, instead of indexing over {i in 1..m, j in 1..m} you would index over {(i,j) in C} so that you refer only to the nonzero elements of cov.

Alternatively you can define the covariances as, say,

param cov {1..m,1..m} default 0.0;

so that cov[i,j] gets a value of zero (or some other number you choose) wherever there is a . in the data. Then you can write indexing expressions like {i in 1..m, j in 1..m: cov[i,j] <> 0} to index over only the significant values. For large problems this can become inefficient, however.

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages