#ifndef WIFIPROBABILITYGRID_H #define WIFIPROBABILITYGRID_H #include #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 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::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 void dump(Grid& 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