1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/**
*
* This file is part of Tulip (www.tulip-software.org)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux
*
* Tulip is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Tulip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
#ifndef INPUTSAMPLE_H_
#define INPUTSAMPLE_H_
#include <map>
#include <vector>
#include <tulip/Graph.h>
#include <tulip/Observable.h>
#include <tulip/NumericProperty.h>
#include "DynamicVector.h"
/**
* Handle all the the samples data used to train the SOM. Take a graph and a vector of NumericProperties to use it as sample data.
* This object can handle standard or normalized values.
**/
namespace tlp {
class InputSample: public tlp::Observable {
public:
InputSample(tlp::Graph *graph = NULL);
InputSample(tlp::Graph *graph,
const std::vector<std::string>& propertiesToListen);
void setGraph(tlp::Graph *graph);
void setGraph(tlp::Graph *graph,
const std::vector<std::string>& propertiesToListen);
void setPropertiesToListen(const std::vector<std::string>& propertiesToListen);
std::vector<std::string> getListenedProperties();
virtual ~InputSample();
const DynamicVector<double>& getWeight(tlp::node n);
tlp::Iterator<tlp::node>* getNodes();
tlp::Iterator<tlp::node>* getRandomNodeOrder();
inline unsigned int getSampleSize() const {
assert(rootGraph);
return rootGraph->numberOfNodes();
}
inline unsigned int getDimensionOfSample() const {
return propertiesList.size();
}
inline tlp::Graph* getGraph() {
return rootGraph;
}
void update(std::set<tlp::Observable *>::iterator begin, std::set<
tlp::Observable *>::iterator end);
void observableDestroyed(Observable *) {
}
;
void addNode(tlp::Graph *, const tlp::node);
void delNode(tlp::Graph *, const tlp::node);
void delLocalProperty(tlp::Graph*, const std::string&);
double getMeanProperty(const std::string& propertyName);
double getSDProperty(const std::string& propertyName);
bool isUsingNormalizedValues() const;
void setUsingNormalizedValues(bool);
/**
* Search the index of the property with the given name.
**/
unsigned findIndexForProperty(const std::string& propertyName)const;
//recover normalized value for val according to meanProperties[propNum] and sdProperties[propNum]
double normalize(double val,unsigned propNum);
//convinience function
double normalize(double val,const std::string& propertyName) {
return normalize(val,findIndexForProperty(propertyName));
}
//recover unnormalized value for val according to meanProperties[propNum] and sdProperties[propNum]
double unnormalize(double val,unsigned propNum);
double unnormalize(double val,const std::string& propertyName) {
return unnormalize(val,findIndexForProperty(propertyName));
}
protected:
void initGraphObs();
void clearGraphObs();
void initPropertiesObs();
void clearPropertiesObs();
void buildPropertyVector(const std::vector<std::string>& propertiesToListen);
//Compute the mean value of propertiesList[i] and store it in meanProperties[i]
void updateMeanValue(unsigned int);
//Compute the standard deviation value of propertiesList[i] and store it in sdProperties[i]
void updateSDValue(unsigned int);
//Compute the mean values of all propertiesList and store them in meanProperties
void updateAllMeanValues();
//Compute the standard deviation values of all propertiesList and store them in sdProperties
void updateAllSDValues();
//void buildNodeVector(unsigned int i);
void buildNodeVector(tlp::node n);
tlp::node getNodeNumber(unsigned int i);
unsigned int getNumberForNode(tlp::node n);
//Data sources
tlp::Graph *rootGraph;
//Cache for data avoid to create a somVector each time we need
//tlp::MutableContainer<DynamicVector<double> > mWeightTab;
std::map<unsigned int ,DynamicVector<double> > mWeightTab;
//Container used to store random list
std::vector<tlp::node> randomVector;
//The number of properties to listen
std::vector<std::string> propertiesNameList;
std::vector<tlp::NumericProperty*> propertiesList;
//The mean of each property
std::vector<double> meanProperties;
//The standard deviation of each property
std::vector<double> sdProperties;
//Indicates whether or not normalized values should be used
bool usingNormalizedValues;
};
}
#endif /* INPUTSAMPLE_H_ */
|