Added optional user function gridDensity#103
Conversation
This is intended to specify the probability distribution function for the internal (i.e. non-sink) grid points. If the user does not supply their own version of this function, it defaults to the algorithm which was previously used.
|
Could you please document the |
|
@AttilaJuhasz : Your PR #71 has a similar purpose than this one. Could you please have a look at what Ian proposes here and let us know what do you think? |
I also changed the type of the par argument from inputPars* to inputPars. This makes the inputPars read-only within the function.
|
Looks good, but LIME seems to hang if void
gridDensity(inputPars par, double x, double y, double z, double *fracDensity){
*fracDensity = .5; // this hangs
/* fracDensity = 1.0; // this works */
} |
|
Also has |
|
I'll look into these. Jeez you guys, it is either nothing or a shitload with you. ;) |
|
Ok, I had a look. The root cause of the 'hang' is the slightly weird algorithm used for selecting grid points. Now that I look closer at it, it is not a straight rejection algorithm as I had assumed (albeit to a flattened density function), but a modification of it with some slightly strange results. In the iteration loop from lines 541 to 574 of grid.c, random point locations are chosen, with a weighting controlled by Consider an example where the random value (the variable Possible solutions I can think of:
I favour 4 immediately and 2 eventually. I could also add another layer of loop outside the choice of |
|
Thanks for looking into this.
This sounds good to me. In fact I thought that |
That is exactly what I intended, and that is exactly the effect it will have, as soon as we can alter the other parts of the algorithm to become a more pure rejection method. Without doing the latter, there is no present way to achieve this. |
In the section dealing with he gridDensity() function, a warning to the user has been added that they should make sure their function returns fracDensity=1 for at least 1 location in the model space.
The algorithm to choose grid point locations is sort of a quasi rejection method. Instead of looping more or less endlessly, generating both a new random 'rejection tester' R as well as a new trial point location at each iteration, which the classic rejection method does, the Lime algorithm chooses a single R between 0 and 1 and just loops over trial positions. This can lead to endless loops if there happens to be no place in the model for which fracDensity is returned with a value higher than R. One could move the generation of R inside the inner loop, but this might have unforeseen effects on the choice algorithm, which contains other non-rejection features. Instead I have included another loop layer outside the choice of R which is intended to be a kind of safety layer to turn endless loops into merely long ones and to generate a warning message if the situation is encountered.
b325d23 to
9e89c89
Compare
This is intended to specify the probability distribution function for the internal (i.e.
non-sink) grid points. If the user does not supply their own version of this function,
it defaults to the algorithm which was previously used.
If this is accepted, I'll re-write the treegrid PR #80 (now #93) to incorporate it, which will avoid the necessity for a lot more user parameters.
This PR is relevant to issues discussed in #62 and will also overlap with or affect #71.