Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calibrate predator-prey model #154

Open
pedro-andrade-inpe opened this issue Jul 25, 2016 · 0 comments
Open

calibrate predator-prey model #154

pedro-andrade-inpe opened this issue Jul 25, 2016 · 0 comments
Milestone

Comments

@pedro-andrade-inpe
Copy link
Member

Calibrate predator-prey model using MultipleRuns only. Use the current version of sysdyn in github instead of the version available in the repository. This will be a very nice example for calibration package. See the code below:

import("sysdyn")
import("calibration")

data = {
    hares = {30, 47.2, 70.2, 77.4, 36.3, 20.6, 18.1, 21.4, 22, 25.4, 27.1, 40.3, 57, 76.6, 52.3, 19.5, 11.2, 7.6, 14.6, 16.2, 24.7},
    lynx = {4, 6.1, 9.8, 35.2, 59.4, 41.7, 19, 13, 8.3, 9.1, 7.4, 8, 12.3, 19.5, 45.7, 51.1, 29.7, 15.8, 9.7, 10.1, 8.6}
}

minimum = math.huge

MultipleRuns{
    model = PredatorPrey,
    hideGraphs = true,
    parameters = {
        rabbits = data.hares[1],
        wolves = data.lynx[1],
        finalTime = 20,
        predDeath = Choice{0.001, 0.002, 0.003},
        predGrowthKills = Choice{0.00002, 0.00004, 0.00008},
        preyDeathPred = Choice{0.001, 0.002, 0.004},
        preyGrowth = Choice{0.09, 0.18, 0.36}
    },
    fit = function(model)
        sum = 0

        data.predator = model.predator
        data.prey     = model.prey
        for i = 1, 20 do
            dif = (data.predator[i] - data.lynx[i]) ^ 2 + 
                  (data.hares[i] - data.prey[i]) ^ 2

            sum = sum + dif
        end

        if sum < minimum then
            minimum = sum
            minimumModel = model
        end
    end
}

print(minimum)
print(minimumModel)

data.predator = minimumModel.predator
data.prey     = minimumModel.prey

Chart{
    data = data,
    select = {"hares", "lynx", "predator", "prey"}
}
@pedro-andrade-inpe pedro-andrade-inpe added this to the 0.3 milestone Jul 25, 2016
@pedro-andrade-inpe pedro-andrade-inpe modified the milestones: 0.3, 0.4 Aug 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant