|
<< Click to Display Table of Contents >> Balancing (RAS/GRAS) |
![]() ![]()
|
TODO: On this page, the balance() function will be fully documented. Until then, you can try the following. The types 'ras' and 'gras' are most stable and have been tested the most at the moment.
reset; |
When using #exo, #constraints and #weights, remember than in Gekko a list with 1 element is written as for instance ('x',), not ('x'). In the latter case Gekko just removes the parentheses and reads it as 'x'. (The same logic is known from Python tuples).
Types
In the following, x[i, j] is the resulting cell, and a[i, j] is the original/initial cell.
•%type = 'ras'. Normal RAS procedure where first the rows are adjusted to match the sums, then the columns, then the rows, etc. An optimization solver is not used.
•%type = 'gras'. GRAS is the "generalized" RAS procedure, where first the rows are adjusted to match the sums, then the columns, then the rows, etc. The difference relative to the RAS procedure is that positive and negative cells for a row or column move in the same direction. An optimization solver is not used. If all the input cells are >= 0, GRAS returns the same cells as RAS.
•%type = 'entropy'. For each cell, the measure abs(a[i, j]) * (x[i, j] / a[i, j] * log(x[i, j] / a[i, j]) - x[i, j] / a[i, j] + 1) is used. With only #exo constraints, and when this solves, the result is the same as %type = 'gras'. Refer to 2013 article.
•%type = 'entropy2003'. For each cell, the measure x[i, j] * log(x[i, j] / a[i, j]) is used. Refer to 2003 article.
•%type = 'sqdif'. For each cell, the measure (x[i, j] - a[i, j])**2 is used.
•%type = 'sqrel'. For each cell, the measure ((x[i, j] - a[i, j])/a[i, j])**2 is used.
•%type = 'distdif'. For each cell, the measure abs(x[i, j] - a[i, j]) is used.
•%type = 'distrel'. For each cell, the measure abs((x[i, j] - a[i, j])/a[i, j]) is used.
'entropy' should be better than 'entropy2003' for some corner cases, but mostly yield identical results.
Tolerance
In addition to %type = ... , #exo = ..., #constraints = ... and #weights = ... , you may also change the tolerance with %tol = ... . The default value is 0.0001, and is set as an absolute value. The smaller the tolerance, the more precision regarding the cells (including how well the output cell row and column totals match the input rowsum and colsum).
Exogenized cells
Exogenization (#exo = ...) works for all types, and the input is simply a list of cell coordinates.
Constraints and weights
Constraints (#constraints = ...) will bind for each type. Constraints are not allowed for 'ras' or 'gras' (unless exogenizing single cells: use an #exo list).
Weights (#weights = ...) are multiplied onto each cell, the default weight being value 1. So a weight > 1 will make the cell move less relative to its original value. Weights are not possible for 'ras' or 'gras'.
Iterations min/max
You may set %itermin = ... and %itermax = ... . With these, you can limit the iterations. Since RAS/GRAS are fast, and the convergence checks need more work, setting an %itermin = 1000 may not be a bad idea to make sure the cell tolerances are met.