Fitpack Library- How to use it?

questions about GAMS' tools
Post Reply
polppp
User
User
Posts: 3
Joined: 5 years ago

Fitpack Library- How to use it?

Post by polppp »

Could somebody help me with this simple example so I can understand how this function works?

I have 10 measurements y every, one per hour.

Now I wan to analyse this data in 5 minutes frame resolution so I need to fit a curve of 120 points at this 10 points (x,y) .

I create the 3 dimensional fit.gdx file that the fitfclib function needs.

And then I write this:

$funclibin fitcurve fitfclib

function fitp /fitcurve.fitparam/
fit /fitcurve.fitfunc / ;

But I don't understand from the gams documentation (https://www.gams.com/latest/testlib_ml/ ... lib_fitlib) how to use the fit function and take the resulting curve. I attached the .gms file.
Attachments
example1.gms
(1.53 KiB) Downloaded 371 times
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Fitpack Library- How to use it?

Post by bussieck »

Hi,

There are a few things that are not quite right with your model:

1) The function data (fitpack) is loaded at compile time but you create this at run time. That won't work. Since you data is simple you can just have the fitdata table with data statement and then use $gdxout fn/$unload/$gdxout (compile time GDX export) to create the GDX file before GAMS loads the function library. Read more about the difference between compile and run time at https://www.gams.com/latest/docs/UG_Gam ... ll_TwoPass

2) You have 10 measures (one for each hour) this only covers 9 hour intervals (you need to have points for the boundaries). So to cover the 120 5-minute points you would need to have the function at hour 0. So the program below only gives you the function values starting starting after hour 1 (i.e. Tf=12). You can change the bounds via the fitParam function (second argument 4) (you renamed it fitp in your model) as described here (https://www.gams.com/latest/docs/UG_Ext ... ackLibrary) but this will give you poor function values because it depends very much on the degree of the spline you use. So better make an additional data point.

The program is pretty short:

Code: Select all

SET T  'Set: hours'        /1*10/
    Tf 'Set: five minutes' /1*120/;

Table fitdata(*,T,*)
      x    y
1.1   1    5
1.2   2   10
1.3   3   16
1.4   4   15
1.5   5    7
1.6   6   18
1.7   7   14
1.8   8   16
1.9   9   10
1.10 10    8;
$gdxout fit
$unload fitdata
$gdxout

$funclibin fitcurve fitfclib

function fitp /fitcurve.fitparam/
         fit  /fitcurve.fitfunc / ;

Parameter fiveMinuteSpline(Tf);

fiveMinuteSpline(Tf)$(ord(Tf)>=12) = fit(1,Tf.val/12);
display fiveMinuteSpline;
The display gives you:

Code: Select all

----     31 PARAMETER fiveMinuteSpline  

12   5.005,    13   5.147,    14   5.356,    15   5.626,    16   5.952,    17   6.330
18   6.753,    19   7.217,    20   7.715,    21   8.244,    22   8.797,    23   9.370
24   9.956,    25  10.551,    26  11.150,    27  11.747,    28  12.336,    29  12.913
30  13.473,    31  14.009,    32  14.517,    33  14.991,    34  15.427,    35  15.818
36  16.160,    37  16.447,    38  16.674,    39  16.838,    40  16.933,    41  16.954
42  16.897,    43  16.757,    44  16.530,    45  16.210,    46  15.794,    47  15.276
48  14.652,    49  13.922,    50  13.114,    51  12.256,    52  11.382,    53  10.521
54   9.706,    55   8.967,    56   8.336,    57   7.844,    58   7.522,    59   7.402
60   7.514,    61   7.878,    62   8.464,    63   9.232,    64  10.139,    65  11.144
66  12.206,    67  13.283,    68  14.334,    69  15.317,    70  16.192,    71  16.915
72  17.447,    73  17.758,    74  17.865,    75  17.800,    76  17.593,    77  17.273
78  16.872,    79  16.419,    80  15.946,    81  15.482,    82  15.057,    83  14.703
84  14.448,    85  14.317,    86  14.295,    87  14.364,    88  14.504,    89  14.694
90  14.913,    91  15.143,    92  15.362,    93  15.551,    94  15.690,    95  15.758
96  15.735,    97  15.606,    98  15.378,    99  15.062,    100 14.668,    101 14.209
102 13.695,    103 13.138,    104 12.550,    105 11.940,    106 11.321,    107 10.704
108 10.100,    109  9.520,    110  8.977,    111  8.480,    112  8.041,    113  7.672
114  7.384,    115  7.188,    116  7.095,    117  7.117,    118  7.264,    119  7.549
120  7.983
-Michael
Post Reply