huge commit
- worked on about everything - grid walker using plugable modules - wifi models - new distributions - worked on geometric data-structures - added typesafe timestamps - worked on grid-building - added sensor-classes - added sensor analysis (step-detection, turn-detection) - offline data reader - many test-cases
This commit is contained in:
92
sensors/radio/WiFiProbabilityGrid.h
Normal file
92
sensors/radio/WiFiProbabilityGrid.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef WIFIPROBABILITYGRID_H
|
||||
#define WIFIPROBABILITYGRID_H
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "../../math/Distributions.h"
|
||||
#include "../../data/Timestamp.h"
|
||||
|
||||
#include "WiFiProbability.h"
|
||||
|
||||
|
||||
/**
|
||||
* probability is calculated by comparing pre-calculated wifi-signal-strengths
|
||||
* attached to each grid-node with a given WiFiMeasurements data structure
|
||||
*/
|
||||
class WiFiObserverGrid : public WiFiProbability {
|
||||
|
||||
private:
|
||||
|
||||
/** base-sigma to use for comparison */
|
||||
float sigma = 8.0f;
|
||||
|
||||
/** additional sigma-per-second (measurement age) to*/
|
||||
float sigmaPerSecond = 1.5;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** ctor with uncertainty */
|
||||
WiFiObserverGrid(const float sigma) : sigma(sigma) {
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the given GridNode's probability.
|
||||
* compares the predicted signal-strengths stored on the given node
|
||||
* with the provided WiFi measurements
|
||||
*/
|
||||
template <typename Node> double getProbability(const Node& n, const Timestamp curTime, const WiFiMeasurements& obs) const {
|
||||
|
||||
double prob = 0;
|
||||
|
||||
// process each observed measurement
|
||||
for (const WiFiMeasurement& measurement : obs.entries) {
|
||||
|
||||
// determine the age for this measurement
|
||||
const Timestamp age = curTime - measurement.getTimestamp();
|
||||
|
||||
// sigma grows with measurement age
|
||||
const float sigma = this->sigma + this->sigmaPerSecond * age.sec();
|
||||
|
||||
// the RSSI from the scan
|
||||
const float measuredRSSI = measurement.getRSSI();
|
||||
|
||||
// the RSSI from the model (if available!)
|
||||
const float modelRSSI = n.getRSSI(measurement.getAP().getMAC());
|
||||
|
||||
// no model RSSI available?
|
||||
if (modelRSSI == 0) {continue;}
|
||||
|
||||
// compare both
|
||||
const double p = Distribution::Normal<double>::getProbability(measuredRSSI, sigma, modelRSSI);
|
||||
|
||||
// adjust using log
|
||||
prob += std::log(p);
|
||||
|
||||
}
|
||||
|
||||
//return std::pow(std::exp(prob), 0.1);
|
||||
return std::exp(prob);
|
||||
|
||||
}
|
||||
|
||||
/** gnuplot debug dump */
|
||||
template <typename Node> void dump(Grid<Node>& grid, const Timestamp curTime, const WiFiMeasurements& obs, const std::string& fileName) {
|
||||
|
||||
std::ofstream out(fileName);
|
||||
out << "splot '-' with points palette\n";
|
||||
|
||||
for (const Node& n : grid) {
|
||||
const float p = getProbability(n, curTime, obs);
|
||||
out << n.x_cm << " " << n.y_cm << " " << n.z_cm << " " << p << "\n";
|
||||
}
|
||||
out << "e\n";
|
||||
|
||||
out.close();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // WIFIPROBABILITYGRID_H
|
||||
Reference in New Issue
Block a user