29 #include "../../common/Exception.h"
30 #include "../../common/Translator.h"
31 #include "../../common/progress/TaskProgress.h"
32 #include "../../datatype/SimpleData.h"
33 #include "../../graph/core/Edge.h"
34 #include "../../graph/core/GraphMetadata.h"
35 #include "../../graph/core/Vertex.h"
36 #include "../../graph/iterator/MemoryIterator.h"
46 #include <boost/random/mersenne_twister.hpp>
47 #include <boost/random/uniform_int_distribution.hpp>
75 while(!it->isVertexIteratorAfterEnd())
78 double excludeSum = totalSum - attrValue;
80 double GStar = attrValue;
85 std::set<int>::iterator itNeighbours = neighbours.begin();
86 int nNeighbours = (int)neighbours.size();
88 while(itNeighbours != neighbours.end())
106 GStar += attrValueTo;
113 GStar /= (nNeighbours+1);
129 v = it->getNextVertex();
144 bool normalized =
true;
162 while(!it->isVertexIteratorAfterEnd())
169 std::set<int>::iterator itNeighbours = neighbours.begin();
170 int nNeighbours = (int)neighbours.size();
172 while(itNeighbours != neighbours.end())
195 attrWeight = attrWeight/nNeighbours;
197 sum += attrWeight * attrValue;
214 v = it->getNextVertex();
248 while(!it->isVertexIteratorAfterEnd())
252 double stdDezZ = attrValue - mean;
264 v = it->getNextVertex();
272 bool normalized =
true;
284 while(!it->isVertexIteratorAfterEnd())
291 std::set<int>::iterator itNeighbours = neighbours.begin();
292 int nNeighbours = (int)neighbours.size();
294 while(itNeighbours != neighbours.end())
317 attrWeight = attrWeight/nNeighbours;
319 sum += attrWeight * attrValue;
335 v = it->getNextVertex();
374 while(!it->isVertexIteratorAfterEnd())
381 ZxWZ = (zValue*wzValue)/variance;
396 v = it->getNextVertex();
415 bool normalized =
true;
422 std::size_t numberObjs = it->getVertexInteratorCount();
424 while(!it->isVertexIteratorAfterEnd())
428 double weightSum = 0.;
433 std::set<int>::iterator itNeighbours = neighbours.begin();
434 int nNeighbours = (int)neighbours.size();
436 while(itNeighbours != neighbours.end())
458 attrWeight = attrWeight/nNeighbours;
460 li += attrWeight*(normNeighVal)*(normObjVal);
462 weightSum += attrWeight;
473 v = it->getNextVertex();
477 return moran/(variance*(numberObjs - 1));
479 return moran/variance;
493 std::vector<double> deviations;
498 while(!it->isVertexIteratorAfterEnd())
505 v = it->getNextVertex();
509 std::vector<double> permutationsResults(permutationsNumber);
511 boost::random::mt19937 gen;
512 boost::random::uniform_int_distribution<> dist(0, deviations.size() - 1);
518 task.setMessage(
TE_TR(
"Calculating Global Moran Significance."));
520 for(
int i = 0; i < permutationsNumber; ++i)
525 while(!it->isVertexIteratorAfterEnd())
527 double value = deviations[dist(gen)];
531 v = it->getNextVertex();
534 permutationsResults[i] =
MoranIndex(gpm, mean, variance, attrIdx);
546 v = it->getFirstVertex();
548 while(!it->isVertexIteratorAfterEnd())
550 double value = deviations[count];
556 v = it->getNextVertex();
561 double significance = 0.;
563 for(
int i = 0; i < permutationsNumber; i++)
565 if(moranIndex < permutationsResults[i])
570 significance = (double)(position+1)/(double)(permutationsNumber+1);
572 significance = (double)(permutationsNumber-position)/(double)(permutationsNumber+1);
594 int nNeighboursAttrIdx;
602 std::vector<double> deviations;
607 while(!it->isVertexIteratorAfterEnd())
614 v = it->getNextVertex();
622 boost::random::mt19937 gen;
623 boost::random::uniform_int_distribution<> dist(0, deviations.size() - 1);
633 v = it->getFirstVertex();
635 while(!it->isVertexIteratorAfterEnd())
642 std::vector<double> permut(permutationsNumber);
644 for(
int i = 0; i < permutationsNumber; ++i)
648 std::set<int> neighSet;
650 for(
int j = 0; j < nNeighbours; ++j)
654 if(index == pos || neighSet.find(pos) != neighSet.end())
660 neighSet.insert(pos);
661 sum += deviations[pos];
668 WZperm = sum/nNeighbours;
673 permut[i] = deviations[index] * WZperm / variance;
678 for(
int k = 0; k < permutationsNumber; k++)
680 if(lisaValue > permut[k])
685 double significance = 0.;
688 significance = (double) (permutationsNumber-position)/(permutationsNumber+1);
690 significance = (double) position/( permutationsNumber + 1 );
704 v = it->getNextVertex();
739 while(!it->isVertexIteratorAfterEnd())
746 if(zValue >= mean && wzValue >= mean)
748 else if(zValue < mean && wzValue >= mean)
750 else if(zValue < mean && wzValue < mean)
752 else if(zValue >= mean && wzValue < mean)
765 v = it->getNextVertex();
795 while(!it->isVertexIteratorAfterEnd())
799 int significanceClass = 0;
801 if(lisaSigValue <= 0.001)
802 significanceClass = 3;
803 else if(lisaSigValue <= 0.01 && lisaSigValue > 0.001)
804 significanceClass = 2;
805 else if(lisaSigValue <= 0.05 && lisaSigValue > 0.01)
806 significanceClass = 1;
818 v = it->getNextVertex();
853 while(!it->isVertexIteratorAfterEnd())
860 if(lisaMapValue != 0)
861 result = boxMapValue;
873 v = it->getNextVertex();
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the vertex elements.
void setMessage(const std::string &message)
Set the task message.
Functions used in statistics operations.
TESAEXPORT void MoranMap(te::sa::GeneralizedProximityMatrix *gpm)
Function used to calculate the moran map info for a gpm, classifies the objects based in the scatterp...
TESAEXPORT double GlobalMoranSignificance(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx, int permutationsNumber, double moranIndex)
Function used to calculate the global moran significance.
This class defines a Generalized Proximity Matrix.
TESAEXPORT double FirstMoment(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx)
Function used to calculate mean (first moment) of a specific attribute from a gpm.
virtual te::graph::Edge * getEdge(int id)=0
It returns the edge element if it's exist.
This class can be used to inform the progress of a task.
TESAEXPORT void LocalMean(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx)
Function used to calculate the local mean of each vertex from gpm graph.
std::vector< te::dt::AbstractData * > & getAttributes()
It returns the vector of attributes associated with this element.
#define TE_TR(message)
It marks a string in order to get translated.
Utilitary function for spatial analysis module.
#define TE_SA_GSTAR_ATTR_NAME
TESAEXPORT int AddGraphVertexAttribute(te::graph::AbstractGraph *graph, std::string attrName, int dataType, int srid=TE_UNKNOWN_SRS, int subType=te::gm::UnknownGeometryType)
Function used to create the vertex attribute metadata in the graph of the gpm.
bool isActive() const
Verify if the task is active.
Functions used to calculate spatial statistics operations.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
void setTotalSteps(int value)
Set the task total stepes.
virtual te::graph::GraphMetadata * getMetadata()=0
Function used to access the graph metadata.
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
TESAEXPORT void LisaStatisticalSignificance(te::sa::GeneralizedProximityMatrix *gpm, int permutationsNumber)
Function used to calculate LISA Statical Significance for each gpm element.
TESAEXPORT double Sum(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx)
Function used to calculate sum of a specific attribute from a gpm.
#define TE_SA_LISAMAP_ATTR_NAME
#define TE_SA_WEIGHT_ATTR_NAME
#define TE_SA_STDDEVZ_ATTR_NAME
#define TE_SA_LOCALMEAN_ATTR_NAME
Abstract class used to define the main functions of graph struct. All graph implementations must used...
#define TE_SA_BOXMAP_ATTR_NAME
TESAEXPORT void LISAMap(te::sa::GeneralizedProximityMatrix *gpm, int permutationsNumber)
Function used to calculate the lisa map info for a gpm, classifies the objects based in the statistic...
#define TE_SA_LISASIGNIFICANCE_ATTR_NAME
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
A base class for values that can be retrieved from the data access module.
std::set< int > & getSuccessors()
Returns the Successors vector.
int getIdFrom()
It returns the vertex origin identification.
#define TE_SA_NUMNEIGHBORS_ATTR_NAME
TESAEXPORT void BoxMap(te::sa::GeneralizedProximityMatrix *gpm, double mean)
Function used to calculate the box map info for a gpm, classifies the objects in quadrants based in t...
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
TESAEXPORT void ZAndWZ(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx)
Function used to calculate the standard deviation Z and local mean of the desviation Z (WZ)...
#define TE_SA_LOCALMEANWZ_ATTR_NAME
TESAEXPORT bool GetGraphVertexAttrIndex(te::graph::AbstractGraph *graph, std::string attrName, int &index)
Function used to get the vertex attribute index in the graph of the gpm.
TESAEXPORT double MoranIndex(te::sa::GeneralizedProximityMatrix *gpm)
Function used to calculate the moran index, also calculates the local moran value.
#define TE_SA_MORANINDEX_ATTR_NAME
#define TE_SA_G_ATTR_NAME
int getId()
It returns the vertex id.
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
A template for atomic data types (integers, floats, strings and others).
TESAEXPORT double SecondMoment(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx, double mean)
Function used to calculate variance (second moment) of a specific attribute from a gpm...
TESAEXPORT double GetDataValue(te::dt::AbstractData *ad)
Function used to get the numeric value from a gpm property.
virtual te::graph::Vertex * getVertex(int id)=0
It returns the vertex element if it's exist.
#define TE_SA_MORANMAP_ATTR_NAME
TESAEXPORT void GStatistics(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx)
The local spatial statistic G is calculated for each zone based on the spatial weights object used...
std::vector< te::dt::AbstractData * > & getAttributes()
It returns the vector of attributes associated with this element.
TESAEXPORT bool GetGraphEdgeAttrIndex(te::graph::AbstractGraph *graph, std::string attrName, int &index)
Function used to get the edge attribute index in the graph of the gpm.
te::graph::AbstractGraph * getGraph()
int getIdTo()
It returns the vertex destiny identification.
This class defines the GPM class.