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

Added getMinAOO which uses Simulated annealing to determine the optim… #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

johnWilshire
Copy link
Collaborator

…al shift parameters.

You can run the changes after pulling and building with
examples(getMinAOO)

One problem that might come up is that I dont think the values of xshift and yshift are constrained but I havent run into any issues yet.

Added parscale that scales with grid.size and maxit.
@calvinkflee
Copy link
Collaborator

I tried running the function with a test dataset I have which is a subset of mangroves in Victoria (it has a dimension of 1167x1502, resolution at 30m) and running it at the default maxiter (10,000) took way too long. I've cut that down to 500 to try it out, but it didn't manage to capture a good AOO.
I'm playing with the parscale function since moving the grid 1m at a time when the grid.size is 10,000 (and at 500 iterations I'm not surprised I'm not getting a good minAOO), adding a parscale of grid.size/20.
This led to the whole window going out of bounds, as John suggested might happen, since xshift and yshift is unconstrained. Is there anyway it can be constrained?
At my current parameters, it still took just under 4 minutes to run, and it's still quite a small dataset, so I actually am thinking of even smaller maxiter/larger parscale, but this will not work if the window just loses focus every time.

@johnWilshire
Copy link
Collaborator Author

Would you be able to upload the dataset as part of the package so we can use in the @examples? and so I can have something to test it on.

The SANN method of optim is pretty slow but the function we are trying to optimize is very flat a lot of the time so the much faster gradient methods tend to think that we are in a global min all the time based off local flat information.

In the latest commit I have implemented it as a call to constrOptim with max it = 500 it seems to be running a lot faster.
I am assuming the bounds for each parameter are 0, grid.size?

@@ -199,12 +198,25 @@ getMinAOO <- function(ecosystem.data, grid.size,
min.percent.rule = min.percent.rule,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the previous line: grid = shift(grid, x = x[1], y = x[2]), doesn't x[2] just make the value default to NA?
Since optim() only takes 1 variable for optimization, doesn't that mean it just searches diagonally (x=y)? Or am I completely misunderstanding what x[2] does...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

objective_function takes a vector
run print(o) before the function exits to see, $par is the argmin

@calvinkflee
Copy link
Collaborator

Bounds of either (0, grid.size) or (-0.5grid.size, 0.5grid.size) will both be good.

temp = grid.size,
tmax = 50,
maxit = 500,
parscale = c(grid.size, grid.size),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand of the parscale parameter, doesn't this mean that the adjustments moved will be too big (the whole grid we're working at)?

@calvinkflee
Copy link
Collaborator

Thanks John, I can't say that I 100% understand how the barrier function works, but it looks good!

I was wondering if there's a way of forcing o$par to be an integer, rather than numeric? It doesn't make much sense to be varying at those levels when our bounds are at 10,000. Might also give us better results if it's running at larger steps (as opposed to 3d.p.)

I'm also a bit worried about the run-time because the outer.iterations I got here was 3, which adds up to ~10 minutes for a relatively tiny raster. However, the function won't really work if we only run it once, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants