forsys-sp / forsysr

An R implementation of the ForSys program
GNU General Public License v3.0
8 stars 3 forks source link

Non-monotonic decline in objective scores due to resampling #89

Closed codyevers closed 1 year ago

codyevers commented 1 year ago

While the new RNG seed will produce consistent results between runs, sampled stands within the same run are not consistent. In other words, each time a search occurs, a different set of 10% of stands are evaluated. This means that later ptach scores can be higher than ones already selected. I believe the solution is to assign the sample of a function that is only run once, and that the search will run on this same sample each time.

codyevers commented 1 year ago

Also, this is specific to Patchmax, not Forsys.

codyevers commented 1 year ago

This appears fixed after removing the area adjustment from patchmax and changing the sampling approach when the searching less than 100%

michelledayusfs commented 1 year ago

I've lost how to examine stand outputs in stand alone patchmax. pm$describe() no longer exists, just pm$summarize()

michelledayusfs commented 1 year ago

Also, I'm not seeing a monotonic decrease in patch objective totals. Did the area weight automation get removed?

Testing_patchmax_monotonic_decline.txt

codyevers commented 1 year ago

Sorry, I changed pm$describe() to pm$summarize()

Also, you can pull the individual stands using pm$patch_stands and additional patch stats using pm$patch_stats.

How I've been judging monotonic decline is...

plot(pm$patch_stands$objective)

Message ID: @.***>

codyevers commented 1 year ago

I'm seeing the same issue. This is great. I just need to investigate now.

Also, there's a chance in setting the sample fraction. Ex....

pm$random_sample(sample_frac = 1)
pm$search()

On Jan 20, 2023 at 8:39 AM -0800, Cody Evers @.***>, wrote:

Sorry, I changed pm$describe() to pm$summarize()

Also, you can pull the individual stands using pm$patch_stands and additional patch stats using pm$patch_stats.

How I've been judging monotonic decline is...

plot(pm$patch_stands$objective)

Message ID: @.***>

michelledayusfs commented 1 year ago

So, does this not give you a 1 sample frac?

pm$simulate(10, 1)

michelledayusfs commented 1 year ago

I added this to the end of my script:

patch.wts <- pm$summarize() %>% filter(DoTreat==1)
head(patch.wts)
plot(patch.wts$bioacre)
plot(pm$patch_stands$objective)
codyevers commented 1 year ago

Not anymore...  The way you run this now is:

pm$random_sample(1)
pm$simulation(10)

On Jan 20, 2023 at 8:48 AM -0800, Michelle Day @.***>, wrote:

So, does this not give you a 1 sample frac? pm$simulate(10, 1) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were assigned.Message ID: @.***>

michelledayusfs commented 1 year ago

Why did it work?

codyevers commented 1 year ago

Make sure to pull the latest patchmax, clean and build, then restart R. I think your package might be out of date.

Check to make sure that pm$patch_stats doesn't have a field called objective_area anymore.

If it does, it's probably out of date.

Actually, I think patchmax is working correctly (monotonic decline)

michelledayusfs commented 1 year ago

Well, I did that first thing this morning. I always do now. I'll try again.

michelledayusfs commented 1 year ago

pm$random_sample(1) Error: attempt to apply non-function pm$simulation(10) Error: attempt to apply non-function

Are you sure you pushed your changes? Also github desktop didn't alert me there were any, but I pulled anyway.

codyevers commented 1 year ago

Good catch Michelle. Indeed, I forgot to push the update. It should be there now. Stupid mistake on my part.

michelledayusfs commented 1 year ago

pm$random_sample(1) 1330 (100%) stands randomly selected for search pm$simulation(10) Error: attempt to apply non-function pm$random_sample(1) pm$simulation(10) Error: unexpected symbol in "pm$random_sample(1) pm"

thoughts?

michelledayusfs commented 1 year ago

Got it. It is pm$simulate. I found it in the code. Patting myself on back now.

michelledayusfs commented 1 year ago

okay, at the patch level this is working, but something weird is happening. See attached script. The ONLY place I call "Am4RevBio" is in the plot call. Otherwise I am only using "bioacre" in the patchmax object. Yet when you look at patch_standsoutput, the objective is clearly "Am4RevBio"

Image

Testing_patchmax_monotonic_decline.txt

. I'm not even sure how this is possible. I looked at the plotcode in the script but it is too complicated for me to follow.

codyevers commented 1 year ago

Ok, it's fixed now. The objectve in the pm$patch_stands was being multiplied by the area. I forgot to fix this when I removed the area weighting from the objective search. See some additional comments that I made to your script describing some of the other recent changes I've made.

Testing_patchmax_monotonic_decline_CE.txt

michelledayusfs commented 1 year ago

Looks good now.

michelledayusfs commented 1 year ago

Also works with patchmax within forsys.

Image

codyevers commented 1 year ago

Hooray!

Message ID: @.***>