some fixes [multithreading,..]
needed interface changes [new options] logger for android wifi-ap-optimization new test-cases
This commit is contained in:
@@ -6,14 +6,17 @@
|
||||
#include "../../math/Distributions.h"
|
||||
#include "../../data/Timestamp.h"
|
||||
|
||||
#include "WiFiGridNode.h"
|
||||
#include "WiFiProbability.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
template <typename Node> class WiFiObserverGrid : public WiFiProbability {
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -21,14 +24,23 @@ private:
|
||||
float sigma = 8.0f;
|
||||
|
||||
/** additional sigma-per-second (measurement age) to*/
|
||||
float sigmaPerSecond = 1.5;
|
||||
float sigmaPerSecond = 3;
|
||||
|
||||
std::unordered_set<MACAddress> knownAPs;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor with uncertainty */
|
||||
WiFiObserverGrid(const float sigma) : sigma(sigma) {
|
||||
;
|
||||
|
||||
//StaticAssert::AinheritsB<Node, WiFiGridNode>();
|
||||
|
||||
for (const AccessPoint& ap : Node::getMapAPs()) {
|
||||
knownAPs.insert(ap.getMAC());
|
||||
}
|
||||
|
||||
Assert::isFalse(knownAPs.empty(), "no APs known to the grid nodes?!");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,43 +48,66 @@ public:
|
||||
* 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 getProbability(const Node& n, const Timestamp curTime, const WiFiMeasurements& obs) const {
|
||||
|
||||
double prob = 0;
|
||||
// compile-time sanity check. Node must be a subclass off WiFiGridNode
|
||||
//StaticAssert::AinheritsB<Node, WiFiGridNode>();
|
||||
|
||||
double prob = 1;
|
||||
int numMatchingAPs = 0;
|
||||
|
||||
// process each observed measurement
|
||||
for (const WiFiMeasurement& measurement : obs.entries) {
|
||||
|
||||
// if an AP is not known to any of the nodes, just skip it
|
||||
if (knownAPs.find(measurement.getAP().getMAC()) == knownAPs.end()) {
|
||||
continue;}
|
||||
|
||||
// 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();
|
||||
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());
|
||||
float modelRSSI = n.getRSSI(measurement.getAP().getMAC());
|
||||
|
||||
// no model RSSI available?
|
||||
if (modelRSSI == 0) {continue;}
|
||||
// if no model RSSI is available, that means,
|
||||
// the AP in question is not / only barely visible at this location
|
||||
// assume a very low signal-strength and increase the sigma
|
||||
if (modelRSSI == 0) {
|
||||
modelRSSI = -100;
|
||||
sigma *= 2;
|
||||
}
|
||||
|
||||
// compare both
|
||||
const double p = Distribution::Normal<double>::getProbability(measuredRSSI, sigma, modelRSSI);
|
||||
//const double p = Distribution::Region<double>::getProbability(measuredRSSI, sigma, modelRSSI);
|
||||
|
||||
// adjust using log
|
||||
prob += std::log(p);
|
||||
//prob += std::log(p);
|
||||
prob *= p;
|
||||
|
||||
++numMatchingAPs;
|
||||
|
||||
}
|
||||
|
||||
//return std::pow(std::exp(prob), 0.1);
|
||||
return std::exp(prob);
|
||||
// sanity check
|
||||
// Assert::isTrue(numMatchingAPs > 0, "not a single measured AP was matched against known ones. coding error? model error?");
|
||||
// if (numMatchingAPs == 0) {return 0;}
|
||||
|
||||
// as not every node has the same number of visible/matching APs
|
||||
// we MUST return something like the average probability
|
||||
return prob;
|
||||
//return std::pow(prob, 1.0/3.0);
|
||||
|
||||
}
|
||||
|
||||
/** gnuplot debug dump */
|
||||
template <typename Node> void dump(Grid<Node>& grid, const Timestamp curTime, const WiFiMeasurements& obs, const std::string& fileName) {
|
||||
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";
|
||||
|
||||
Reference in New Issue
Block a user