many eval things

moved obsolete code
TeX work
This commit is contained in:
2017-04-10 18:20:11 +02:00
parent b2adb16b49
commit 32674e3fbb
21 changed files with 1063 additions and 251 deletions

View File

@@ -167,7 +167,16 @@ public:
Result fixedPosOptParamsForAll() {
// resulting error using the given txp,exp,waf for ALL APs
// get fingerprints for each AP [once]
std::unordered_map<MACAddress, std::vector<WiFiFingerprint>> fps;
for (const auto _ap : mapAPs) {
const Floorplan::AccessPoint* ap = _ap.first;
const MACAddress mac(ap->mac);
fps[mac] = calib.getFingerprintsFor(mac);
}
// resulting error
auto errFunc = [&] (const float txp, const float exp, const float waf) -> Result {
Result res(map);
@@ -179,7 +188,7 @@ public:
const MACAddress mac(ap->mac);
const Point3 pos_m = ap->getPos(floor);
res.model.addAP(mac, pos_m, txp, exp, waf, false); // allow unsafe txp,exp,waf params
K::Statistics<float> err = getError(mac, res.model);
K::Statistics<float> err = getError(mac, res.model, fps[mac]);
res.errAvg.add(err.getAvg());
res.errSingle.add(err);
}
@@ -188,16 +197,16 @@ public:
};
// to-be-optimized function: reduce average error among all fingerprints/AP's
// to-be-optimized function
auto optFunc = [&] (const float* params) {
return errFunc(params[0], params[1], params[2]).errSingle.getAvg();
return whatToOpt(errFunc(params[0], params[1], params[2]).errSingle);
};
// use simplex
float params[3] = {-40, 2, -8};
K::NumOptAlgoDownhillSimplex<float> opt(3);
opt.setMaxIterations(40);
opt.setNumRestarts(20);
opt.setMaxIterations(50);
opt.setNumRestarts(25);
opt.calculateOptimum(optFunc, params);
// // use genetic
@@ -232,7 +241,7 @@ public:
const Point3 pos_m = ap->getPos(floor);
const std::vector<WiFiFingerprint> fps = getFingerprints(mac);
// resulting error using the given txp,exp,waf for ALL APs
// resulting error
auto errFunc = [&] (const float txp, const float exp, const float waf) -> K::Statistics<float> {
WiFiModelLogDistCeiling model(map); // new, empty model for this AP
model.addAP(mac, pos_m, txp, exp, waf, false); // allow unsafe txp,exp,waf params
@@ -240,16 +249,16 @@ public:
return err;
};
// to-be-optimized function: reduce average error among all fingerprints/AP's
// to-be-optimized function
auto optFunc = [&] (const float* params) {
return errFunc(params[0], params[1], params[2]).getAvg();
return whatToOpt(errFunc(params[0], params[1], params[2]));
};
// use simplex
float params[3] = {-40, 2, -8};
K::NumOptAlgoDownhillSimplex<float> opt(3);
opt.setMaxIterations(40);
opt.setNumRestarts(20);
opt.setMaxIterations(50);
opt.setNumRestarts(25);
opt.calculateOptimum(optFunc, params);
// // use genetic
@@ -289,7 +298,7 @@ public:
const MACAddress mac(ap->mac);
const std::vector<WiFiFingerprint> fps = getFingerprints(mac);
// resulting error using the given txp,exp,waf for ALL APs
// resulting error
auto errFunc = [&] (const Point3 pos_m, const float txp, const float exp, const float waf) -> K::Statistics<float> {
WiFiModelLogDistCeiling model(map); // new, empty model for this AP
model.addAP(mac, pos_m, txp, exp, waf, false); // allow unsafe txp,exp,waf params
@@ -297,10 +306,10 @@ public:
return err;
};
// to-be-optimized function: reduce average error among all fingerprints/AP's
// to-be-optimized function
auto optFunc = [&] (const float* params) {
const Point3 pos_m(params[0], params[1], params[2]);
return errFunc(pos_m, params[3], params[4], params[5]).getAvg(); // AVG
return whatToOpt(errFunc(pos_m, params[3], params[4], params[5]));
};
// params
@@ -344,7 +353,7 @@ public:
K::NumOptAlgoRangeRandom<float> opt(valRegion);
opt.setPopulationSize(300);
opt.setNumIerations(75);
opt.setNumIerations(100);
opt.calculateOptimum(optFunc, params);
@@ -376,6 +385,14 @@ public:
private:
// the stats to optimize
static inline float whatToOpt(const K::Statistics<float>& s) {
//return s.getAvg() + s.getStdDev() / 2 + s.getMax() / 4; // for dBm
//return s.getAvg() + s.getStdDev() * 2 + s.getMax() / 2; // for probability
//return s.getQuantile(0.96);
return s.getAvg();
}
std::vector<WiFiFingerprint> getFingerprints(const MACAddress& mac) {
// get all fingerprints where the given mac was seen
@@ -432,10 +449,14 @@ private:
if (scan_rssi < -100) {throw Exception("scan rssi out of range for " + mac.asString());}
if (scan_rssi > -35) {throw Exception("scan rssi out of range for " + mac.asString());}
// difference
//const float err = model_rssi - scan_rssi;
const float err = -std::log(Distribution::Normal<float>::getProbability(model_rssi, 7, scan_rssi));
float aErr = std::abs(err);
// dB error
const float err = model_rssi - scan_rssi;
// probability matching error
//const float err = -std::log(Distribution::Normal<float>::getProbability(model_rssi, 8, scan_rssi));
// quadratic
float aErr = std::pow(std::abs(err), 2);
// penalty
// if (model.getAP(mac).waf > -2) {aErr += 9999;}