29 #include "../../common/Exception.h" 30 #include "../../core/translator/Translator.h" 31 #include "../../common/progress/TaskProgress.h" 32 #include "../../dataaccess/datasource/DataSource.h" 33 #include "../../dataaccess/datasource/DataSourceManager.h" 34 #include "../../dataaccess/utils/Utils.h" 35 #include "../../datatype/SimpleProperty.h" 36 #include "../../geometry/Geometry.h" 37 #include "../../geometry/GeometryProperty.h" 38 #include "../../graph/core/AbstractGraph.h" 39 #include "../../graph/core/Edge.h" 40 #include "../../graph/core/Vertex.h" 41 #include "../../memory/DataSet.h" 42 #include "../../memory/DataSetItem.h" 60 int eventType =
m_inputParams->m_ds->getPropertyDataType(eventIdx);
65 int popType =
m_inputParams->m_ds->getPropertyDataType(popIdx);
73 eventIdx = outDsType->getPropertyPosition(
m_inputParams->m_eventAttrName);
74 popIdx = outDsType->getPropertyPosition(
m_inputParams->m_populationAttrName);
76 std::size_t idIdx = outDsType->getPropertyPosition(
m_inputParams->m_gpmAttrLink);
81 runBayesLocal(outDs.get(), idIdx, eventIdx, popIdx, neighEventIdx, neighPopIdx, bayesIdx,
static_cast<size_t>(gpmEventIdx), static_cast<size_t>(gpmPopIdx));
98 std::map<std::string, std::string> options;
110 std::vector<te::dt::Property*> propertyVec = dsType->
getProperties();
112 for(std::size_t t = 0; t < propertyVec.size(); ++t)
120 dataSetType->add(newProp);
125 dataSetType->add(neighEvent);
129 dataSetType->add(neighPop);
133 dataSetType->add(bayesProperty);
151 for(std::size_t t = 0; t < nProp; ++t)
168 outDataset->add(outDSetItem);
175 std::size_t neighEventIdx, std::size_t neighPopIdx, std::size_t bayesIdx, std::size_t gpmEventIdx, std::size_t gpmPopIdx)
186 task.
setMessage(
TE_TR(
"Calculating events and population for each element."));
195 int id = atoi(strId.c_str());
197 double totEvent = ds->
getDouble(eventIdx);
205 std::set<int>::iterator itNeighbours = neighbours.begin();
206 while(itNeighbours != neighbours.end())
214 vTo = graph->getVertex(e->
getIdTo());
256 int id = atoi(strId.c_str());
258 double myEvent = ds->
getDouble(eventIdx);
261 double totEvent = ds->
getDouble(neighEventIdx);
262 double totPop = ds->
getDouble(neighPopIdx);
267 double mean = totEvent / totPop;
269 double thetaI = (myPop > 0) ? myEvent / myPop : 0.0;
276 std::set<int>::iterator itNeighbours = neighbours.begin();
277 int nNeighbours =
static_cast<int>(neighbours.size());
281 double variance = myPop * pow((myEvent / myPop) - mean, 2);
283 while(itNeighbours != neighbours.end())
291 vTo = graph->getVertex(e->
getIdTo());
301 variance += toPop * pow((toEvent / toPop) - mean, 2);
309 double aux = variance - (mean * (
static_cast<double>(nNeighbours + 1.)) / totPop);
316 if(aux != 0. || mean != 0.)
317 wI = aux / (aux + (mean / myPop));
319 thetaI = wI * (myEvent / myPop) + (1 - wI) * mean;
std::size_t size() const
It returns the collection size, if it is known.
Class that represents the Bayes output parameters.
This file contains a class that represents the bayes global operation.
void setMessage(const std::string &message)
Set the task message.
void saveDataSet(te::da::DataSet *dataSet, te::da::DataSetType *dsType)
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
An atomic property like an integer or double.
A class that models the description of a dataset.
This class can be used to inform the progress of a task.
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
static te::dt::Date ds(2010, 01, 01)
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.
virtual Property * clone() const =0
It returns a clone of the object.
It models a property definition.
bool isActive() const
Verify if the task is active.
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.
void setId(unsigned int id)
It sets the property identifier.
std::unique_ptr< te::da::DataSetType > createDataSetType(te::da::DataSetType *dsType)
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
~BayesLocalOperation()
Virtual destructor.
#define TE_SA_BAYESPOP_ATTR_NAME
BayesLocalOperation()
Default constructor.
#define TE_SA_BAYES_ATTR_NAME
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
Abstract class used to define the main functions of graph struct. All graph implementations must used...
#define TE_SA_BAYESEVENT_ATTR_NAME
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
virtual std::string getAsString(std::size_t i, int precision=0) const
Method for retrieving a data value as a string plain representation.
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.
Utility functions for the data access module.
std::unique_ptr< te::mem::DataSet > createDataSet(te::da::DataSet *inputDataSet, te::da::DataSetType *dsType)
TESAEXPORT int AssociateGPMVertexAttribute(te::sa::GeneralizedProximityMatrix *gpm, te::da::DataSource *ds, std::string dataSetName, std::string attrLink, std::string attr, int dataType, int srid=TE_UNKNOWN_SRS, int subType=static_cast< int >(te::gm::UnknownGeometryType))
Function used to set a an attribute valeu from a dataset to the vertex objects from a gpm...
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
bool moveNext()
It moves the internal pointer to the next item of the collection.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
A dataset is the unit of information manipulated by the data access module of TerraLib.
double getDouble(std::size_t i) const
Method for retrieving a double attribute value.
void runBayesLocal(te::mem::DataSet *ds, std::size_t idIdx, std::size_t eventIdx, std::size_t popIdx, std::size_t neighEventIdx, std::size_t neighPopIdx, std::size_t bayesIdx, std::size_t gpmEventIdx, std::size_t gpmPopIdx)
virtual std::unique_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
std::unique_ptr< te::sa::BayesOutputParams > m_outputParams
Attribute with the bayes output parameters.
TESAEXPORT double GetDataValue(te::dt::AbstractData *ad)
Function used to get the numeric value from a gpm property.
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
void setParameters(te::sa::BayesInputParams *inParams, te::sa::BayesOutputParams *outParams)
std::unique_ptr< te::sa::BayesInputParams > m_inputParams
Attribute with the bayes input parameters.
void setDouble(std::size_t i, double value)
void execute()
Function to execute the bayes operation.
int getIdTo()
It returns the vertex destiny identification.
void setParent(Property *p)
It associate this property to the informed parent.