fncentry.gms : Test correctness of centropy(x,y,d) intrinsic exceptions

Description

centropy(x,y,delta) = x * log((x+delta)/(y+delta))

ENUM            VAL
----            ---
rcOK            0
rcFUNC          1
rcGRAD          2
rcHESS          3
rcSYSTEM        4

ecOK            0
ecDOMAIN        1
ecSINGULAR      2
ecOVERFLOW      3

Contributor: Steve Dirkse


Small Model of Type : GAMS


Category : GAMS Test library


Main file : fncentry.gms   includes :   fnset_xy.inc [htmlfntest_xy.inc [html]

$title 'Test correctness of centropy(x,y,d) intrinsic exceptions' (FNCENTRY,SEQ=359)

$onText

centropy(x,y,delta) = x * log((x+delta)/(y+delta))

ENUM            VAL
----            ---
rcOK            0
rcFUNC          1
rcGRAD          2
rcHESS          3
rcSYSTEM        4

ecOK            0
ecDOMAIN        1
ecSINGULAR      2
ecOVERFLOW      3

Contributor: Steve Dirkse

$offText

$include fnset_xy.inc

reps = 2e-13;
relToInput = 0;
set
   T      / t0 * t7, t101*t105 /,
   T1(T)  / t0 * t7            /,
   T2(T)  /          t101*t105 /;

$set OFLO  1.e299
scalar d / 1e-20 /;

table data(T,V)
        x       y       d       f_      fx_     fy_     fxx_    fxy_    fyy_    rc_     ec_
t0      1       1      -1                                                        1       1
t1      1       -1      1                                                        1       1
t2      1       0       1                                                        1       2
t3     -1       1       1                                                        1       1
t4      0       1       0       0    -%OFLO%           %OFLO%    -1              2       2
t5    1e298     1       0     %OFLO%  123456  -1e298   1e-198    -1     1e298    1       3
t6    1e151   1e-150  1e-150  123456  123456  -%OFLO%  1e-151  -5e149   %OFLO%   2       2
t7    1e100   1e-100  1e-100  123456          -5e199   1e-100  -5e099   %OFLO%   3       2

t101    1       -1                                                               1       1
t102    1       0                                                                1       2
t103   -1       1                                                                1       1
t104    0       1                      123456          123456    -1
t105  1e298     1             %OFLO%   123456 -1e298   1e-198    -1     1e298    1       3
;

data(T,'fx_' )$[sameas('t5',T) or sameas('t105',T)] = log(1e298) + 1;
data(T,'fxx_')$[sameas('t5',T) or sameas('t105',T)] = data(T,'fxx_') * 1e-100;
data('t6','f_') = 1e151 * [ log(1e151) - log(2e-150) ];
data('t6','fx_') = [ log(1e151) - log(2e-150) ] + 1;
data('t7','f_') = 1e100 * [ log(1e100) - log(2e-100) ];
data('t7','fx_') = [ log(1e100) - log(2e-100) ] + 1;
data('t104','fx_' ) = log(d);
data('t104','fxx_') = 2 / d;

data(T,'fyx_') = data(T,'fxy_');

loop {T1,
  data(T1,  'f') = centropy.value (    data(T1,'x'), data(T1,'y'), data(T1,'d'));
  data(T1, 'fx') = centropy.grad  (1:  data(T1,'x'), data(T1,'y'), data(T1,'d'));
  data(T1, 'fy') = centropy.grad  (2:  data(T1,'x'), data(T1,'y'), data(T1,'d'));
  data(T1,'fxx') = centropy.hess  (1:1:data(T1,'x'), data(T1,'y'), data(T1,'d'));
  data(T1,'fxy') = centropy.hess  (1:2:data(T1,'x'), data(T1,'y'), data(T1,'d'));
  data(T1,'fyx') = centropy.hess  (2:1:data(T1,'x'), data(T1,'y'), data(T1,'d'));
  data(T1,'fyy') = centropy.hess  (2:2:data(T1,'x'), data(T1,'y'), data(T1,'d'));
  data(T1, 'rc') = mathlastrc;
  data(T1, 'ec') = mathlastec;
};

* if the third arg is not passed, it defaults to 1e-20
loop {T2,
  data(T2,  'f') = centropy.value (    data(T2,'x'), data(T2,'y'));
  data(T2, 'fx') = centropy.grad  (1:  data(T2,'x'), data(T2,'y'));
  data(T2, 'fy') = centropy.grad  (2:  data(T2,'x'), data(T2,'y'));
  data(T2,'fxx') = centropy.hess  (1:1:data(T2,'x'), data(T2,'y'));
  data(T2,'fxy') = centropy.hess  (1:2:data(T2,'x'), data(T2,'y'));
  data(T2,'fyx') = centropy.hess  (2:1:data(T2,'x'), data(T2,'y'));
  data(T2,'fyy') = centropy.hess  (2:2:data(T2,'x'), data(T2,'y'));
  data(T2, 'rc') = mathlastrc;
  data(T2, 'ec') = mathlastec;
};

abort$(execerror lt 10)
 'Should get execution errors getting func/grad/hess of centropy(x,y,d)';
execerror = 0;

$include fntest_xy.inc