Skip to content

Commit

Permalink
I have fixed utils.lua documentation, please read it @pedro-andrade-inpe
Browse files Browse the repository at this point in the history


reopen #110
  • Loading branch information
agojunior committed Dec 12, 2015
1 parent e6d8d16 commit 32cff14
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 43 deletions.
29 changes: 19 additions & 10 deletions lua/MultipleRuns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ function MultipleRuns(data)

chDir(folder)
folderDir = currentDir()
chDir(firstDir)
local variables = {}
switch(data, "strategy"):caseof{
-- Prepares the variables and executes the model according to each strategy.
Expand All @@ -584,26 +585,29 @@ function MultipleRuns(data)
repeated = true
end

chDir(folderDir)
for i = 1, data.quantity do
resultTable = factorialRecursive(data, Params, 1, variables, resultTable, addFunctions, s, i, repeated)
end

chDir(firstDir)
end,
repeated = function()
mandatoryTableArgument(data, "quantity", "number")
if data.parameters.seed ~= nil or data.model().seed ~= nil then
customError("Models using repeated strategy cannot use seed or all results will be the same.")
end

chDir(folderDir)
for i = 1, data.quantity do
local repeatedParam = clone(data.parameters)
local m = data.model(repeatedParam)
m:execute()
resultTable.simulations[#resultTable.simulations + 1] = ""..(#resultTable.simulations + 1)..""
local testDir = currentDir()
mkDir(""..(#resultTable.simulations).."")
chDir(testDir..s..""..(#resultTable.simulations).."")
chDir(folderDir..s..""..(#resultTable.simulations).."")
testAddFunctions(resultTable, addFunctions, data, m)
chDir(testDir)
chDir(folderDir)
forEachOrderedElement(data.parameters, function ( idx2, att2, typ2)
if resultTable[idx2] == nil then
resultTable[idx2] = {}
Expand All @@ -612,18 +616,19 @@ function MultipleRuns(data)
resultTable[idx2][#resultTable[idx2] + 1] = att2
end)
end
chDir(firstDir)
end,
sample = function()
mandatoryTableArgument(data, "quantity", "number")
chDir(folderDir)
for i = 1, data.quantity do
local sampleParams = {}
local m = randomModel(data.model, data.parameters)
resultTable.simulations[#resultTable.simulations + 1] = ""..(#resultTable.simulations + 1)..""
local testDir = currentDir()
resultTable.simulations[#resultTable.simulations + 1] = ""..(#resultTable.simulations + 1)..""
mkDir(""..(#resultTable.simulations).."")
chDir(testDir..s..""..(#resultTable.simulations).."")
chDir(folderDir..s..""..(#resultTable.simulations).."")
testAddFunctions(resultTable, addFunctions, data, m)
chDir(testDir)
chDir(folderDir)
forEachOrderedElement(data.parameters, function(idx2, att2, typ2)
if typ2 ~= "table" then
sampleParams[idx2] = m.idx2
Expand All @@ -646,17 +651,19 @@ function MultipleRuns(data)
resultTable[idx2][#resultTable[idx2] + 1] = att2
end)
end

chDir(firstDir)
end,
selected = function()
chDir(folderDir)
forEachOrderedElement(data.parameters, function(idx, att, atype)
local m = data.model(att)
m:execute()
resultTable.simulations[#resultTable.simulations + 1] = ""..(idx)..""
local testDir = currentDir()
mkDir(""..(idx).."")
chDir(testDir..s..""..(idx).."")
chDir(folderDir..s..""..(idx).."")
testAddFunctions(resultTable, addFunctions, data, m)
chDir(testDir)
chDir(folderDir)
forEachOrderedElement(data.parameters[idx], function(idx2, att2, typ2)
if resultTable[idx2] == nil then
resultTable[idx2] = {}
Expand All @@ -665,6 +672,8 @@ function MultipleRuns(data)
resultTable[idx2][#resultTable[idx2] + 1] = att2
end)
end)

chDir(firstDir)
end
}
setmetatable(data, metaTableMultipleRuns_)
Expand Down
18 changes: 9 additions & 9 deletions lua/utils.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
--- Function to be used by Multiple Runs and SAMDE, to test if a Choice type
-- range of possible values is valid to be used as a given Model parameter.
-- @arg values A table with the group of values to be checked.
-- @arg values The table containing the valid set of parameters in a model.
-- @arg idx The index of the parameter to be checked in the parameters table.
-- @arg Param The table containing the valid set of parameters in a model.
-- @arg Param A table with the group of values to be checked.
-- @usage
-- import("calibration")
-- local myModel = Model{
Expand All @@ -18,7 +18,7 @@
-- end
-- }
-- local parameters = {x = Choice{-100, 1, 2}, y = Choice{min = 3, max = 5}}
-- checkParametersRange({min = 3, max = 5}, "y", myModel().y)
-- checkParametersRange(myModel().y, "y", {min = 3, max = 5})
function checkParametersRange(values, idx, Param)
--test if the range of values in the Calibration/Multiple Runs type are inside the accepted model range of values.
if values.min == nil and values.max == nil then
Expand Down Expand Up @@ -59,9 +59,9 @@ end
--- Function to be used by Multiple Runs and SAMDE to test if a
-- value is valid to be used as a given Model parameter.
-- @arg mParam The table containing the valid set of parameters in a model.
-- @arg value The value to be checked.
-- @arg idx The name of the parameter to be checked in the parameters table.
-- @arg idx2 The numerical index, of the parameter value to be checked, in the choosen parameter Choice table.
-- @arg value The value to be checked.
-- @usage
-- import("calibration")
-- local myModel = Model{
Expand Down Expand Up @@ -107,9 +107,9 @@ end

--- Function to be used by Multiple Runs and SAMDE,
-- to test if a Choice type table of possible values is valid to be used as a given Model parameter.
-- @arg values A table with the group of values to be checked.
-- @arg modelParam The table containing the valid set of parameters in a model.
-- @arg idx The index of the parameter to be checked in the parameters table.
-- @arg Param The table containing the valid set of parameters in a model.
-- @arg parameters A table with the group of parameter values to be checked.
-- @usage
-- import("calibration")
-- local myModel = Model{
Expand All @@ -126,10 +126,10 @@ end
-- }
-- local parameters = {x = Choice{-100, 1, 2}, y = Choice{min = 3, max = 5}}
-- checkParametersSet({-100, 1, 2}, "x", myModel().x)
function checkParametersSet(values, idx, Param)
function checkParametersSet(modelParam, idx, parameters)
-- test if the group of values in the Calibration/Multiple Runs type are inside the accepted model range of values
forEachOrderedElement(Param.values, function(idx2, att2, type2)
checkParameterSingle(values, idx, idx2, att2)
forEachOrderedElement(parameters.values, function(idx2, att2, type2)
checkParameterSingle(modelParam, idx, idx2, att2)
end)
end

Expand Down
24 changes: 0 additions & 24 deletions tests/core/alternative/MultipleRuns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,6 @@ return{
end

unitTest:assertError(error_func, "Parameter y step is out of the model range.")
error_func = function()
local m4 =MultipleRuns{
folderName = tmpDir()..s.."UtilsAlternativeTests",
model = MyModel,
strategy = "factorial",
parameters = {x = Choice{-100, -1, 0, 1, 2, 100}, y = Choice{min = 0, max = 10, step = 1}},
output = function(model)
return model.value
end}
end

unitTest:assertError(error_func, "Parameter y min is out of the model range.")
error_func = function()
local m4 =MultipleRuns{
folderName = tmpDir()..s.."UtilsAlternativeTests",
Expand All @@ -317,18 +305,6 @@ return{
end

unitTest:assertError(error_func, "Parameter y min is out of the model range.")
error_func = function()
local m4 =MultipleRuns{
folderName = tmpDir()..s.."UtilsAlternativeTests",
model = MyModel,
strategy = "factorial",
parameters = {x = Choice{-100, -1, 0, 1, 2, 100}, y = Choice{min = 1, max = 11, step = 1}},
output = function(model)
return model.value
end}
end

unitTest:assertError(error_func, "Parameter y max is out of the model range.")
error_func = function()
local m4 =MultipleRuns{
folderName = tmpDir()..s.."UtilsAlternativeTests",
Expand Down

0 comments on commit 32cff14

Please sign in to comment.