Skip to content

Treegrid#80

Closed
allegroLeiden wants to merge 6 commits intolime-rt:masterfrom
allegroLeiden:treegrid
Closed

Treegrid#80
allegroLeiden wants to merge 6 commits intolime-rt:masterfrom
allegroLeiden:treegrid

Conversation

@allegroLeiden
Copy link
Copy Markdown
Contributor

This is a new optional algorithm for generating grid points. The original algorithm is based on the rejection method, but this is slow when the (number) density function is highly peaked (i.e. when its maximum value is many times its average value). To compensate for this, the original algorithm flattens the user-input density function by raising it to a small positive power. An effect of this is that dense areas of the model are undersampled.

I ran this fairly extensive code addition/modification through valgrind to fix reported memory leaks etc. This addition seems to work ok in that it produces images broadly similar to the previous; it probably needs some more extensive testing though to investigate the effects of the new algorithm.

Previously there was a singularity at r==0.
Code that was in grid.c and weights.c has been put in a new module, random_points.c.
This is in preparation for the introduction of a new grid-point-selection algorithm.
The module weights.c is no longer compiled, since it is now obsolete.

Additional changes connected with the above:
	- Added a new (optional) user parameter 'samplingAlgorithm'.
	- Added external variables modelRadiusSquared, densityNormalizer,
          numCollisionPartners.
	- Added macro DENSITY_POWER.
	- New struct locusType.
The new algorithm calls the function randomsViaTree() recursively in a 2^D-tree
divide-and-conquer approach. The aim of this is to allow more accurate
representation of models for which the density varies strongly across the model,
without the severe time penalties that straightforward use of the rejection method
would entail. (The previous algorithm uses rejection method, but it 'flattens' the
density function in order to avoid long run times, which has the effect that
high-density regions are undersampled.) The algorithm assesses the density gradients
over a sub-volume of the model space, and if those gradients are judged too large
for quick results from the rejection method, the sub-volume is divided into 8
smaller sub-volumes and the same function is called for each one of these. The
division is performed by cutting the volume approximately in halves (at the 0.5
point plus some random dither) along each of the (3) axes of the coordinate space.

Additional changes connected with the above:
	- New macros:
		N_TREE_RANDOMS
		MAX_RECURSION
		MAX_N_TRIALS_TREE
		TREE_DITHER
The new grid-selection algorithm estimates the density gradients within a
sub-volume. This estimate may be too low if the function has narrow peaks. In this
case, the functioning of the algorithm is improved if the user pre-supplies a list
of the maximal values of the density function.

Additional changes connected with the above:
	- New (optional) user parameters numDensityMaxima, densityMaxLoc,
densityMaxValue. Note that I have left the appropriate lines commented out for now
in the example model.c file.
	- New macro:
		MAX_N_HIGH
In general it seems desirable to have the grid point number density follow the total
density of the collision partners, as is now more accurately provided by the new
algorithm. If the density function is heavily peaked, whereas the chosen number of
grid points is kept relatively small, a situation could arise in which the
distribution of points in the low-density regions of the model was very sparse. To
prevent this occurring, the user can now set a parameter minPointNumDensity. The
units of this should if possible save the user calculation, and to be
scale-invariant: the chosen unit therefore is points per spherical model volume.

Note that this feature is only implemented when par->samplingAlgorithm==1.

Additional changes connected with the above:
	- A new extern variable minDensity is defined.
@smaret smaret mentioned this pull request Feb 26, 2016
@smaret
Copy link
Copy Markdown
Contributor

smaret commented Feb 26, 2016

Superseded by #93.

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