#include <RipleysKCalculator.h>
Public Member Functions | |
clRipleysKCalculator (clSimManager *p_oSimManager) | |
Constructor. | |
~clRipleysKCalculator () | |
Destructor. | |
void | Action () |
Calculates Ripley's K. | |
void | GetData (xercesc::DOMDocument *p_oDoc) |
Does setup for this behavior. | |
Protected Member Functions | |
void | GetParameterFileData (xercesc::DOMDocument *p_oDoc) |
Reads values from the parameter file and performs setup related to the parameters. | |
void | SetupGrid () |
Sets up the "Ripley's K" grid and registers the data members. | |
void | GetTreeCodes (clTreePopulation *p_oPop) |
Gets the X and Y tree data codes. | |
void | SetUpSearching (clTreePopulation *p_oPop) |
Sets up the structures for searching controls. | |
void | ProcessCell (clTreePopulation *p_oPop, clTree *p_oFirstTree, const int &iX, const int &iY, const int &iNeighX, const int &iNeighY) |
Processes a neighboring cell's trees to find distance pairs. | |
void | ProcessOwnCell (clTree *p_oFirstTree, float *p_fNumTrees, const int &iX, const int &iY) |
Processes a single cell's trees to find distance pairs. | |
Protected Attributes | |
clGridBase * | mp_oGrid |
Grid holding Ripley's K values for the plot plus each species. | |
float ** | mp_fKValues |
Values holding Ripley's K for each timestep. | |
short int ** | mp_iGridCodes |
Holds the codes for the "Ripley's K" grid. | |
short int ** | mp_iXCodes |
Holds codes for X data member. | |
short int ** | mp_iYCodes |
Holds codes for Y data member. | |
bool ** | mp_bCellsSearched |
Which cells have already been paired the current timestep. | |
float * | mp_fIncs |
Distance increment values - array size is m_iNumIncs. | |
float | m_fMaxDistance |
The max distance to which to calculate Ripley's K. | |
float | m_fIncrement |
The distance increment used to step out to the max distance. | |
int | m_iNumIncs |
Number of increments for which to calculate Ripley's K. | |
int | m_iNumXToSearch |
The number of cells to search in the X direction - if the plot is a rectangle and the search distance is long the distances along the two axes may be different. | |
int | m_iNumYToSearch |
The number of cells to search in the Y direction - if the plot is a rectangle and the search distance is long the distances along the two axes may be different. | |
int | m_iNumXCells |
Number of tree population grid cells in X direction. | |
int | m_iNumYCells |
Number of tree population grid cells in Y direction. | |
short int | m_iNumTotalSpecies |
Total number of species. | |
Friends | |
class | clTestRipleysKCalculator |
This behavior calculates Ripley's K. Ripley's K is calculated for successive distances out to a maximum. The user sets the maximum distance and the increment. Ripley's K for a given distance t is calculated as:
K(t) = AX / n2
where A is the area of the plot in square meters, X is the number of pairs of trees <= t meters apart, and n is the total number of trees in the plot. All saplings and adults are counted. All other types are ignored.
When searching for tree pairs it is important to make sure we only find each pair a single time. So the search proceeds by tree population grid cell. For each cell, a square of cells around it is searched. A matrix is used to keep track of which cells have already been paired so they are not paired again.
The statistic is calculated both for all trees and for individual species.
The values are collected into a grid called "Ripley's K".
This class's namestring and parameter file call string are "Ripley's K". Any tree type/species assignments are ignored.
Edit history:
-----------------
August 30, 2007 - Created (LEM)
clRipleysKCalculator::clRipleysKCalculator | ( | clSimManager * | p_oSimManager | ) |
clRipleysKCalculator::~clRipleysKCalculator | ( | ) |
Destructor.
void clRipleysKCalculator::Action | ( | ) | [virtual] |
Calculates Ripley's K.
First, the values in the "Ripley's K" grid are cleared. Then this moves through the grid cells looking for tree pairs. For each cell this searches cells in a circle, using ProcessCell() and ProcessOwnCell() to find pairs. Once tree pairs have been found, this finishes the Ripley's K calculation.
Reimplemented from clBehaviorBase.
void clRipleysKCalculator::GetData | ( | xercesc::DOMDocument * | p_oDoc | ) | [virtual] |
Does setup for this behavior.
Calls:
p_oDoc | DOM tree of parsed input file. |
Implements clWorkerBase.
void clRipleysKCalculator::GetParameterFileData | ( | xercesc::DOMDocument * | p_oDoc | ) | [protected] |
Reads values from the parameter file and performs setup related to the parameters.
This validates the increment and distance.
p_oDoc | DOM tree of parsed input file. |
modelErr | if either the increment or the max distance are less than or equal to zero, or if the increment is less than the max distance. |
void clRipleysKCalculator::SetupGrid | ( | ) | [protected] |
Sets up the "Ripley's K" grid and registers the data members.
void clRipleysKCalculator::GetTreeCodes | ( | clTreePopulation * | p_oPop | ) | [protected] |
Gets the X and Y tree data codes.
p_oPop | Tree population object |
void clRipleysKCalculator::SetUpSearching | ( | clTreePopulation * | p_oPop | ) | [protected] |
Sets up the structures for searching controls.
This sets up the mp_bCellsSearched matrix and finds the search distances in the X and Y directions. If the search distance is more than half the plot length in either direction, then it will be limited to half the plot length. This also sets up the mp_fIncs array.
p_oPop | Tree population object |
void clRipleysKCalculator::ProcessCell | ( | clTreePopulation * | p_oPop, | |
clTree * | p_oFirstTree, | |||
const int & | iX, | |||
const int & | iY, | |||
const int & | iNeighX, | |||
const int & | iNeighY | |||
) | [protected] |
Processes a neighboring cell's trees to find distance pairs.
This finds all pairs of saplings and adults within the max distance and counts each pair into the appropriate bins in the Ripley's K calculator array.
p_oPop | Tree population object. | |
p_oFirstTree | The shortest valid tree in the home cell. | |
iX | X coordinate of home cell. | |
iY | Y coordinate of home cell. | |
iNeighX | X coordinate of the neighbor cell to search for tree pairs. | |
iNeighY | Y coordinate of the neighbor cell to search for tree pairs. |
void clRipleysKCalculator::ProcessOwnCell | ( | clTree * | p_oFirstTree, | |
float * | p_fNumTrees, | |||
const int & | iX, | |||
const int & | iY | |||
) | [protected] |
Processes a single cell's trees to find distance pairs.
This finds all pairs of saplings and adults within the max distance, being careful not to pair a tree with itself, and counts each pair into the appropriate bins in the Ripley's K calculator array. This also counts all the trees in the cell for the purposes of finding the plot's grand total.
p_oFirstTree | The shortest valid tree in the home cell. | |
p_fNumTrees | The array for number of saplings and adults in the cell for each species. | |
iX | X coordinate of home cell. | |
iY | Y coordinate of home cell. |
friend class clTestRipleysKCalculator [friend] |
clGridBase* clRipleysKCalculator::mp_oGrid [protected] |
Grid holding Ripley's K values for the plot plus each species.
The grid name is "Ripley's K". It has one data member for each increment step out to the max for each species, plus one more set for the all-species values. For example, if the max distance is 50 meters and the increment is 1 meter, it will have 50 * (X + 1) data members, where X is the number of species. The names are X_Y, where X is the increment step number (starting at zero) and Y is the species number (starting at zero). It also has two more for the length of distance increment ("inc") and the max distance ("dist"), to make output display easier.
float** clRipleysKCalculator::mp_fKValues [protected] |
Values holding Ripley's K for each timestep.
I tried to make this a temp array each timestep but I got weird crashes. Array size is number of species plus 1 by m_iNumIncs.
short int** clRipleysKCalculator::mp_iGridCodes [protected] |
Holds the codes for the "Ripley's K" grid.
The first array index is number of species, with array size being m_iNumTotalSpecies + 1 (the last index holds the all-species codes). The second array index is buckets for values along the distance line, and is sized m_iNumIncs.
short int** clRipleysKCalculator::mp_iXCodes [protected] |
Holds codes for X data member.
First array index is total # species, second is number types (2 - sapling, adult).
short int** clRipleysKCalculator::mp_iYCodes [protected] |
Holds codes for Y data member.
First array index is total # species, second is number types (2 - sapling, adult).
bool** clRipleysKCalculator::mp_bCellsSearched [protected] |
Which cells have already been paired the current timestep.
The matrix size is number of total cells by number of total cells (flattening the 2D tree population cell matrix into a single array). The index for a tree population grid cell is number of X cells * X cell index + Y cell index. Since every grid cell is paired with every other, once a pair of grid cells is searched, two matrix cells must be switched to true.
float* clRipleysKCalculator::mp_fIncs [protected] |
Distance increment values - array size is m_iNumIncs.
float clRipleysKCalculator::m_fMaxDistance [protected] |
The max distance to which to calculate Ripley's K.
float clRipleysKCalculator::m_fIncrement [protected] |
The distance increment used to step out to the max distance.
int clRipleysKCalculator::m_iNumIncs [protected] |
Number of increments for which to calculate Ripley's K.
int clRipleysKCalculator::m_iNumXToSearch [protected] |
The number of cells to search in the X direction - if the plot is a rectangle and the search distance is long the distances along the two axes may be different.
int clRipleysKCalculator::m_iNumYToSearch [protected] |
The number of cells to search in the Y direction - if the plot is a rectangle and the search distance is long the distances along the two axes may be different.
int clRipleysKCalculator::m_iNumXCells [protected] |
Number of tree population grid cells in X direction.
int clRipleysKCalculator::m_iNumYCells [protected] |
Number of tree population grid cells in Y direction.
short int clRipleysKCalculator::m_iNumTotalSpecies [protected] |
Total number of species.
For the destructor.