ConFooBio / gmse

An R package for simulating Generalised Management Strategy Evaluation
http://confoobio.github.io/gmse
10 stars 5 forks source link

TODO list for GMSE v0.7 #64

Closed bradduthie closed 2 years ago

bradduthie commented 4 years ago

Please add to this list as desired

Additional updates to make

bradduthie commented 3 years ago

Hi @jejoenje @jejoenje @nbunne @mattnuttall00 -- I'm going to now start going through each of these one by one. Just let me know if there are any new features that should be added or bugs that should be fixed for the new GMSE version. I've got one pull request from @jejoenje and one from @AdrianBach that I'll incorporate first. I'm not sure how long it will take for the version update, but I'm hoping that most of it can be done by the end of next week. I might also just go back through the code and see if there is anything that can be refactored easily or improved upon.

AdrianBach commented 3 years ago

Many thanks Brad! Let me know if I can help with anything regarding my code.

Cheers, Adrian


From: Brad Duthie @.> Sent: 27 July 2021 15:29 To: ConFooBio/gmse @.> Cc: Adrian Bach @.>; Mention @.> Subject: Re: [ConFooBio/gmse] TODO list for GMSE v0.7 (#64)

CAUTION: This email originated from outside University of Stirling. Do not follow links or open attachments if you doubt the authenticity of the sender or the content.


Hi @jejoenjehttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjejoenje&data=04%7C01%7Cadrian.bach%40stir.ac.uk%7Ccfed2291573d4fa9440508d9510afabd%7C4e8d09f7cc794ccb9149a4238dd17422%7C0%7C0%7C637629929867131600%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=hlGSKre%2B9Idev59M4kbeXuvgBtZTBSM4i61ziOatT24%3D&reserved=0 @jejoenjehttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjejoenje&data=04%7C01%7Cadrian.bach%40stir.ac.uk%7Ccfed2291573d4fa9440508d9510afabd%7C4e8d09f7cc794ccb9149a4238dd17422%7C0%7C0%7C637629929867141603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=DnnZe4DWh87ijBpil3TtJsraEymZC8pnIKCQUhwxVHo%3D&reserved=0 @nbunnehttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnbunne&data=04%7C01%7Cadrian.bach%40stir.ac.uk%7Ccfed2291573d4fa9440508d9510afabd%7C4e8d09f7cc794ccb9149a4238dd17422%7C0%7C0%7C637629929867141603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=gkMt8A1xhNkWM4GdAlcoHvvqVVGIr3WsBKB5VCESoUc%3D&reserved=0 @mattnuttall00https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmattnuttall00&data=04%7C01%7Cadrian.bach%40stir.ac.uk%7Ccfed2291573d4fa9440508d9510afabd%7C4e8d09f7cc794ccb9149a4238dd17422%7C0%7C0%7C637629929867151593%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=XODM0yAs%2FnLMh2OXI1xioRi42nrtsSv7njBrqB6ViHA%3D&reserved=0 -- I'm going to now start going through each of these one by one. Just let me know if there are any new features that should be added or bugs that should be fixed for the new GMSE version. I've got one pull request from @jejoenjehttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjejoenje&data=04%7C01%7Cadrian.bach%40stir.ac.uk%7Ccfed2291573d4fa9440508d9510afabd%7C4e8d09f7cc794ccb9149a4238dd17422%7C0%7C0%7C637629929867151593%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=UTmQakmtTv6hqdthwndV7Z8UTwOlo6jsHGBf2M16yiI%3D&reserved=0 and one from @AdrianBachhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAdrianBach&data=04%7C01%7Cadrian.bach%40stir.ac.uk%7Ccfed2291573d4fa9440508d9510afabd%7C4e8d09f7cc794ccb9149a4238dd17422%7C0%7C0%7C637629929867161591%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=n7d6tJL7rhcabfHutG39EniMIlVk3JXIMerz2LH1eoY%3D&reserved=0 that I'll incorporate first. I'm not sure how long it will take for the version update, but I'm hoping that most of it can be done by the end of next week. I might also just go back through the code and see if there is anything that can be refactored easily or improved upon.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FConFooBio%2Fgmse%2Fissues%2F64%23issuecomment-887561785&data=04%7C01%7Cadrian.bach%40stir.ac.uk%7Ccfed2291573d4fa9440508d9510afabd%7C4e8d09f7cc794ccb9149a4238dd17422%7C0%7C0%7C637629929867171583%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Er4EbGd1hOkqEgiima8wL8YyvNBdOrO7qQh4S85G6zI%3D&reserved=0, or unsubscribehttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKMP6UQUW5G3A67WBB2V4OTTZ27FFANCNFSM4QLWJLSA&data=04%7C01%7Cadrian.bach%40stir.ac.uk%7Ccfed2291573d4fa9440508d9510afabd%7C4e8d09f7cc794ccb9149a4238dd17422%7C0%7C0%7C637629929867171583%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=XMlo9N7N%2FtbZGaRbydZSGkNozHzyoFFj9CxMVwv1eRM%3D&reserved=0.

[ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/ConFooBio/gmse/issues/64#issuecomment-887561785", "url": "https://github.com/ConFooBio/gmse/issues/64#issuecomment-887561785", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.": "Organization", "name": "GitHub", "url": "https://github.com" } } ]


The University achieved an overall 5 stars in the QS World University Rankings 2020 UK Sports University of the Year 2020 (Times Higher Good University Guide) The University of Stirling is a charity registered in Scotland, number SC 011159.

jejoenje commented 3 years ago

Thank you @bradduthie ! I can't think of anything off the top of my head, in addition to the things that are already in as pull requests. Happy to help any way I can, just let me know.

On Tue, Jul 27, 2021 at 3:29 PM Brad Duthie @.***> wrote:

Hi @jejoenje https://github.com/jejoenje @jejoenje https://github.com/jejoenje @nbunne https://github.com/nbunne @mattnuttall00 https://github.com/mattnuttall00 -- I'm going to now start going through each of these one by one. Just let me know if there are any new features that should be added or bugs that should be fixed for the new GMSE version. I've got one pull request from @jejoenje https://github.com/jejoenje and one from @AdrianBach https://github.com/AdrianBach that I'll incorporate first. I'm not sure how long it will take for the version update, but I'm hoping that most of it can be done by the end of next week. I might also just go back through the code and see if there is anything that can be refactored easily or improved upon.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ConFooBio/gmse/issues/64#issuecomment-887561785, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMZMESW4TEE7NX76LGQOUTTZ27FFANCNFSM4QLWJLSA .

mattnuttall00 commented 3 years ago

Thanks @bradduthie!

The main feature I will be needing for the second half of my GMSE chapter (or the 2nd stand alone GMSE chapter) is some kind of incentive "payment" for the users that will replicate payment for ecosystem services, or REDD+ type payments. In other word, they get some "benefit" for choosing to NOT cut down trees.

I of course want to make your life as simple as possible, so if there is a way that we can tweak existing features/flexibility to do what we want, without you having to code new features, then that's obviously the best option.

Just off the top of my head, could we use the yield in some way? Perhaps alter the tend_crop_yield parameter to increase the value of the users yield by a certain amount to replicate this benefit?

Happy to chat about this tomorrow during our call

bradduthie commented 3 years ago

A feature that includes some kind of benefit in terms of compensation to users has been an idea that has been challenging since the first published version of GMSE. The issue, partly, is how this benefit would manifest in the dynamics of the model. At first I was thinking that such a feature might be redundant given the use of the farming option in GMSE, and I do think that there is a way to use the tend_crop_yield argument to mimic some kind of payment incentive as you suggest. But managers can't control the farming, so this might be limited. Is what we want, I assume, something that the manager can set for users to do nothing rather than something?

Would this be different, in terms of the modelling, from interpreting a high cost set by the manager as an incentive to do nothing rather than a disincentive to cull? I've not quite been able to separate these out in my head in terms of the code (i.e., if I were to code up a payment scheme, would it not actually work the exact same as the costs for culling do now -- just reversed in terms of the numbers, but identical in their effect on the system). I'm quite keen to think about this more, especially in the long term (and very open to suggestions!), but I just can't quite get my head around how an incentive to not hunt is separate, model-wise, from a disincentive (cost) to hunt.

jejoenje commented 3 years ago

The point about incorporating some form of option for a compensation "payment" is an interesting one, and it's also interesting given a bit of feedback we've seen on the Animal & Farm game you may have seen yesterday @bradduthie.

I think I see what you mean re. using tend_crop_yld to mimic this, but if so, would that not mean the tend_crop_yld option could not be varied independently from any compensation payments? I.e. if you'd want to set up a sim exploring both variation in return on yield as well as variation in compensation payments, that would lead to issues?

In terms of being the same as the manager setting a high cost for culling, I'm not sure. I think what we'd want ideally, is some way of the manager having a separate option of allocating budget - i.e. instead of investing budget into one of the permissable actions, the manager could opt to spend some of its budget on compensation payments. Perhaps the manager essentially forfeiting a chosen proportion of their budget, which is then allocated to the users? I'm not sure how challenging this would be, but if some procedure like that could be implemented prior to actually running the GA, it may just amount to a modulation of budget? I'm not sure whether that would make it entirely separate to a disincentive for doing something else... I guess it could be if there is a scenario where the likely efficacy of just providing a bit of compensation would likely produce a better outcome (from the manager's perspective) ... I'm not sure if I can think of a specific example of this, though...

bradduthie commented 3 years ago

Ah! @jejoenje -- we should have had you join @mattnuttall00 and me this morning. We might have figured out a workaround as a start, which is not quite what as nice as what you suggested, but a bit better than just using tend_crop_yld. I'll just paste the script below, but note that you'll need to download the most recent version on GitHub due to a coding error being fixed (tl;dr, a 'castration' column was being printed where it should have been a 'feeding' column in some gmse_apply output).

The general idea is to set feeding = TRUE to allow managers to incentivise feeding offspring, but then changing perceive_feed to be < 0 so that users perceive feeding the offspring has having a beneficial effect for themselves. If this works, it kind of relies on the unique situation where @mattnuttall00 has no birth, and therefore lambda = 0, because feeding increases lambda by 100%. But some tweaks could change this to make it a more versatile payment for ecosystem services approach. The investment in the action by the user could then be interpreted as some kind of monetary payoff (e.g., low cost, big PES payoff). Does that make sense?

devtools::install_github("ConFooBio/GMSE");
library(GMSE);

# First a baseline simulation with no feeding or perceiving feeding
sim1 <- gmse_apply(land_dim_1 = 150, land_dim_2 = 150, stakeholders = 20,
                   land_ownership = TRUE, res_move_type = 0, res_death_type = 0,
                   lambda = 0, res_consume = 0.08, RESOURCE_ini = 10000,
                   manage_target = 10000, feeding = FALSE);
# The results are as you would expect

# Now set 'feeding = TRUE', where we're going to interpret 'feeding' to mean 
# collecting ecosystem service payments. Managers perceive feeding to increase
# population size, so they will try to encourage it. Usually users also perceive
# feeding as increasing population size, but we can trick them by setting
# perceive_feed to a negative value, so they think the benefit due to fewer
# resources on the landscape (though the why doesn't really matter).
# Note that 'feeding' actions increase the lambda of a resource by 100%, so
# because lambda = 0, there will be no actual increase. 
# Feeding actions have no effect, except to reduce harvesting.
# But users will spend actions on feeding because they perceive feeding will
# decrease the number of trees on their landscape (can then see how many users
# decide to feed and attach some kind of assumed benefit for these actions).

# Let's first look at a very low value of perceived effect
sim2 <- gmse_apply(land_dim_1 = 150, land_dim_2 = 150, stakeholders = 20,
                   land_ownership = TRUE, res_move_type = 0, res_death_type = 0,
                   lambda = 0, res_consume = 0.08, RESOURCE_ini = 10000,
                   manage_target = 10000, feeding = TRUE, perceive_feed = -0.1);
# Users don't really decide to take the ecosystem services (0.1 is too low)

# Now let's increase the perceived benefit of accepting ecosystem services
sim3 <- gmse_apply(land_dim_1 = 150, land_dim_2 = 150, stakeholders = 20,
                   land_ownership = TRUE, res_move_type = 0, res_death_type = 0,
                   lambda = 0, res_consume = 0.08, RESOURCE_ini = 10000,
                   manage_target = 10000, feeding = TRUE, perceive_feed = -1.0);
# Now everyone takes the ecosystem service payment, and there is no culling!
# The manager has reduced the cost of feeding (i.e., increased the PES that can
# be collected), causing users to take it.

# Let's try a gmse run over time. Note that I changed manage_target
sim4 <- gmse(land_dim_1 = 150, land_dim_2 = 150, stakeholders = 20,
             land_ownership = TRUE, res_move_type = 0, res_death_type = 0,
             lambda = 0, res_consume = 0.08, RESOURCE_ini = 10000,
             manage_target = 8000, feeding = TRUE, perceive_feed = -0.5,
             time_max = 20);

Working my way through the TODO list above still.

jejoenje commented 3 years ago

Huh, that's interesting and a clever workaround! I like it. :) I'd forgotten @mattnuttall00 set up re. zero growth; so the key point here is that this solution does rely on there being no resource growth, right? And I guess, more conceptually speaking, it has the implicit assumption that any ecosystem service payments (ie. feeding actions) are always effective - i.e. conceptually this doesn't allow for less than 100% effective ES payments?

bradduthie commented 3 years ago

Yeah, @jejoenje -- the hack wouldn't work unless lambda = 0, though we could potentially play around with this (see below). The assumption is that payments are always effective, but perhaps we could add some stochasticity?

Wow, it really doesn't feel like that long ago that we were introducing some of these issues. @jejoenje -- did we resolve Issue #54 already? We did already with this commit, right? Or is there some part of it that I can't remember that I still need to take care of?

Likewise, can you remember what the plan was for "add gmse_apply function that checks the structure of inputs", by chance? I think I did this already with the error catch of Issue #65 -- but I could extend this to look at the structure of other (non-scalar) arguments. I don't see any other way of interpreting that point.

I still need to fix the Y scale plots and integrate the code of @AdrianBach into the package. I don't think that the rest will actually take too long though, I hope! Everything after on the TODO list has to do with the documentation, which is a bit tedious but not difficult. I think that I'll also go through the main code line by line just to remind myself of where everything is and refactor areas where it could be useful.

I feel like I could get through this and potentially still have time for a medium size feature addition, if anyone has any ideas -- @nbunne @jejoenje @AdrianBach @MattNuttall00 -- I'll raise the opportunity at tomorrow's ConFooBio meeting. I'm happy to add something new, but I'm reluctant to do so unless we can reasonably suspect that it will result in something that someone will use (e.g., for a paper, dissertation project, game option) and it's not a feature that someone else is already keen to code. Some potential thoughts:

I should add that we can potentially get some additional code for free from the helicoverpa package that I'm writing for the ENDORSE project, if desired. The package is focused on evolutionary genetics and biopesticide resistance, but since it's my coding style (a bit improved since the origin of GMSE, I think), it might not be difficult to lift some code from there to GMSE.

mattnuttall00 commented 3 years ago

Thanks @bradduthie for that code, and for the super cool hack! I totally understand it now (I'll admit I only vaguely followed yesterday morning, having no prior knowledge of feeding or perceive_feed). I think for what I need, it will work nicely.

Am I correct in thinking that to set the feeding (or any action) cost low, the manager uses less budget than if they were to set it high? If this is correct, might we run into the issue that it is costing the manager very little to set the PES payment high (i.e., feeding cost is low), which results in fewer trees being lost, and therefore this will be what the manager defaults to all the time? It might end up being the reverse of reality i.e., setting high PES payments is cheap for the manager. I guess this will be goverened in part by what the perceive_feed is set at....

Sorry - still processing this all in my head! Looking forrward to experimenting with it.

@jejoenje - when you say the manager could potentially forfeit a portion of their budget and allocate that to the user, do you mean actually take some of the manager budget and add it on to the user budget? If so, would this not simply result in the user having more power to cull and the manger having less power to prevent it? This may result in higher PES payments = more culling. Or did you mean that the portion of the manager budget gets allocated to the users in some other non-budgetary way that they perceive to be beneficial, thus reducing their need/incentive to cull? Apologies if I have totally misinterpreted what you said!

jejoenje commented 3 years ago

@bradduthie Thanks for all this. We can discuss at the meeting, but very briefly, in terms of the new feature suggestions you made, they're all really good, personally I would tend towards no. 1 (implementing some form of ES payments / compensation feature through an overhaul of the feeding option (personally I don't envisage feeding being used that much if at all? I also really like no. 5 (landscape option limiting movement somehow, reflecting fencing). Either of those options are highly relevant to a number of case studies we've all worked on, and I think would be really useful in the future. Curious re. the implementation of the fencing option, though - we can discuss?

One further possibility that I think would be incredibly useful is having some function that ties resource movement to the availability of "high quality" habitat, e.g. crop. I.e. resources would be more likely to move to higher yield cells. That, also, I think would be very useful and would really reflect much of the ecology/conservation issues we're modelling - e.g. thinking of geese or elephants, much of their movement will depend on grazing quality. Another one to discuss.

jejoenje commented 3 years ago

@mattnuttall00 Yeaaah you're dead right, that would be an issue in what I suggested, good point. Maybe for that to work then, there would need to be a further restriction in how users could invest the compensation payments (e.g. they could only be used towards investment in scaring or tend_crop? Perhaps this would be too complex after all...

bradduthie commented 3 years ago

Now worked through integrating code from @AdrianBach -- gmse_apply and testthat updated for the new paras vector, and all CRAN checks appear to pass in Rstudio. Next up is to do the following:

  1. Get the documentation updated
  2. Go through the whole package again
  3. Run Valgrind to check for any memory leaks
  4. Do the more exhaustive CRAN checks on WinBuilder.

After that, we should be good to submit to CRAN. I should update the GMSE notebook too, and the news (probably should have done that for the minor updates too).