activated interval smoothing for evaluation
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
#include <KLib/math/filter/particles/ParticleFilter.h>
|
||||
#include <KLib/math/filter/particles/ParticleFilterHistory.h>
|
||||
#include <KLib/math/filter/smoothing/BackwardSimulation.h>
|
||||
#include <KLib/math/filter/smoothing/CondensationBackwardFilter.h>
|
||||
#include <KLib/math/filter/smoothing/sampling/ParticleTrajectorieSampler.h>
|
||||
#include <KLib/math/filter/smoothing/sampling/CumulativeSampler.h>
|
||||
#include <KLib/math/statistics/Statistics.h>
|
||||
|
||||
#include "GroundTruthWay.h"
|
||||
@@ -19,13 +22,16 @@
|
||||
#include "../particles/MyInitializer.h"
|
||||
#include "../particles/smoothing/MySmoothingTransition.h"
|
||||
#include "../particles/smoothing/MySmoothingTransitionSimple.h"
|
||||
#include "../particles/smoothing/MySmoothingTransitionExperimental.h"
|
||||
|
||||
#include "../reader/SensorReader.h"
|
||||
#include "../reader/SensorReaderStep.h"
|
||||
#include "../reader/SensorReaderTurn.h"
|
||||
#include "../reader/SensorReaderAccel.h"
|
||||
|
||||
#include "../lukas/TurnObservation.h"
|
||||
#include "../lukas/StepObservation.h"
|
||||
#include "../lukas/ActivityDetection.h"
|
||||
|
||||
#include "../toni/BarometerSensorReader.h"
|
||||
|
||||
@@ -33,8 +39,6 @@
|
||||
#include "../frank/BeaconSensorReader.h"
|
||||
#include "../frank/OrientationSensorReader.h"
|
||||
|
||||
static int smoothing_time_delay = 0;
|
||||
float stepSize = 0.71;
|
||||
|
||||
class SmoothingEvalBase {
|
||||
|
||||
@@ -71,6 +75,8 @@ protected:
|
||||
std::vector<int> path4 = {29, 28, 27, 32, 33, 34, 35, 36, 10, 9, 8, 22, 37, 38, 39, 40, 41, 42, 43, 44};
|
||||
std::vector<int> path4dbl = {29, 29, 28, 27, 32, 33, 34, 35, 36, 10, 9, 8, 22, 37, 38, 39, 40, 41, 42, 43, 44}; // duplicate 1st waypoint!
|
||||
|
||||
float stepSize = 0.71;
|
||||
|
||||
public:
|
||||
|
||||
SmoothingEvalBase() : grid(MiscSettings::gridSize_cm), floors(Helper::getFloors(grid)) {
|
||||
@@ -130,7 +136,7 @@ public:
|
||||
|
||||
// sensor numbers
|
||||
const int s_wifi = 8; const int s_beacons = 9; const int s_barometer = 5; const int s_orientation = 6;
|
||||
//const int s_linearAcceleration = 2;
|
||||
const int s_accel = 0;
|
||||
|
||||
std::list<TurnObservation> turn_observations;
|
||||
std::list<StepObservation> step_observations;
|
||||
@@ -138,6 +144,8 @@ public:
|
||||
//Create an BarometerSensorReader
|
||||
BarometerSensorReader baroSensorReader;
|
||||
|
||||
// activity detection
|
||||
ActivityDetection actDet;
|
||||
|
||||
//Read all turn Observations
|
||||
while(srt->hasNext()) {
|
||||
@@ -186,8 +194,16 @@ public:
|
||||
|
||||
K::Statistics<double> statsFiltering;
|
||||
K::Statistics<double> statsSmoothing;
|
||||
K::Statistics<float> statsDistFiltering;
|
||||
K::Statistics<float> statsDistSmoothing;
|
||||
int cnt = 0;
|
||||
|
||||
// error per update-step
|
||||
std::vector<float> errorsNorm;
|
||||
std::vector<float> errorsSmooth;
|
||||
std::vector<float> errorsDistNorm;
|
||||
std::vector<float> errorsDistSmooth;
|
||||
|
||||
//stats file
|
||||
std::ofstream statsout("/tmp/unsmoothed_" + runName + ".stats");
|
||||
|
||||
@@ -220,13 +236,21 @@ public:
|
||||
|
||||
case s_barometer: {
|
||||
obs.barometer = baroSensorReader.readBarometer(se);
|
||||
actDet.addBaro(baroSensorReader.getHPA(se));
|
||||
break;
|
||||
}
|
||||
|
||||
// case s_linearAcceleration:{
|
||||
// baroSensorReader.readVerticalAcceleration(se);
|
||||
// break;
|
||||
// }
|
||||
case s_accel: {
|
||||
float acc[3];
|
||||
SensorReaderAccel sre; sre.read(se, acc);
|
||||
actDet.addAccel(acc);
|
||||
break;
|
||||
}
|
||||
|
||||
// case s_linearAcceleration:{
|
||||
// baroSensorReader.readVerticalAcceleration(se);
|
||||
// break;
|
||||
// }
|
||||
|
||||
case s_orientation: {
|
||||
obs.orientation = OrientationSensorReader::read(se);
|
||||
@@ -251,6 +275,13 @@ public:
|
||||
|
||||
}
|
||||
|
||||
// currently detected activity
|
||||
// TODO: feed sensor values!
|
||||
ctrl.currentActivitiy = actDet.getCurrentActivity();
|
||||
|
||||
// this is just for testing purposes
|
||||
obs.currentActivity = actDet.getCurrentActivity();
|
||||
|
||||
|
||||
// time for a transition?
|
||||
if (se.ts - lastTransitionTS > MiscSettings::timeSteps) {
|
||||
@@ -266,16 +297,24 @@ public:
|
||||
const Point3 curEst = est.pCur;
|
||||
|
||||
// error calculation. compare ground-truth to estimation
|
||||
const int offset = 750;
|
||||
const int offset = 0;
|
||||
const Point3 curGT = gtw.getPosAtTime(se.ts - offset);
|
||||
const Point3 diff = curEst - curGT;
|
||||
|
||||
pathEst.push_back(curEst);
|
||||
const float err = diff.length();
|
||||
const float errDist = gtw.getMinDist(curEst); // minimum distance between estimation and ground-truth
|
||||
|
||||
++cnt;
|
||||
|
||||
// skip the first 24 scans due to uniform distribution start
|
||||
if (++cnt > 24) {
|
||||
pathEst.push_back(curEst);
|
||||
const float err = diff.length();
|
||||
if (cnt > 35) {
|
||||
statsFiltering.add(err);
|
||||
std::cout << statsFiltering.asString() << std::endl;
|
||||
statsDistFiltering.add(errDist);
|
||||
errorsNorm.push_back(err);
|
||||
errorsDistNorm.push_back(errDist);
|
||||
std::cout << "FilteringTime: " << se.ts << " " << statsFiltering.asString() << std::endl;
|
||||
std::cout << "FilteringDist: " << se.ts << " " << statsDistFiltering.asString() << std::endl;
|
||||
|
||||
//save the current estimation for later smoothing.
|
||||
pfHistory.push_back(pf->getNonResamplingParticles());
|
||||
@@ -326,28 +365,37 @@ public:
|
||||
bf->reset();
|
||||
|
||||
MyState estBF;
|
||||
int currentParticleSetToSmoothAtTimet = 0;
|
||||
|
||||
while(currentParticleSetToSmoothAtTimet != pfHistory.size() - 1){
|
||||
//iterate thru all particle sets from T to t (currentParticleSetToSmoothAtTimeT)
|
||||
for(int i = pfHistory.size() - 1; i >= 0 ; i -= MiscSettings::fixedLagGap){
|
||||
//Set time
|
||||
((MySmoothingTransitionSimple*)bf->getTransition())->setCurrentTime(tsHistory[i]);
|
||||
estBF = bf->update(pfHistory[i]);
|
||||
|
||||
//iterate thru all particle sets from T to t (currentParticleSetToSmoothAtTimeT)
|
||||
for(int i = pfHistory.size() - 1; i >= currentParticleSetToSmoothAtTimet; i -= smoothing_time_delay){
|
||||
//Set time
|
||||
((MySmoothingTransitionSimple*)bf->getTransition())->setCurrentTime(tsHistory[i]);
|
||||
estBF = bf->update(pfHistory[i]);
|
||||
}
|
||||
smoothedEst.push_back(estBF.pCur);
|
||||
}
|
||||
|
||||
const Point3 curSmoothedEst = estBF.pCur;
|
||||
std::reverse(smoothedEst.begin(), smoothedEst.end());
|
||||
|
||||
smoothedEst.push_back(curSmoothedEst);
|
||||
for(int t = 0; t < smoothedEst.size(); ++t){
|
||||
|
||||
const Point3 curSmoothedEst = smoothedEst[t];
|
||||
|
||||
// error calculation. compare ground-truth to estimation
|
||||
const Point3 curGTSmoothed = gtw.getPosAtTime(tsHistory[currentParticleSetToSmoothAtTimet]);
|
||||
const Point3 curGTSmoothed = gtw.getPosAtTime(tsHistory[t]);
|
||||
const Point3 diffSmoothed = curSmoothedEst - curGTSmoothed;
|
||||
|
||||
|
||||
const float errSmoothed = diffSmoothed.length();
|
||||
const float errDistSmoothed = gtw.getMinDist(curSmoothedEst); // minimum distance between smoothed-estimation and ground-truth
|
||||
|
||||
statsSmoothing.add(errSmoothed);
|
||||
std::cout << statsSmoothing.asString() << std::endl;
|
||||
statsDistSmoothing.add(errDistSmoothed);
|
||||
errorsSmooth.push_back(errSmoothed);
|
||||
errorsDistSmooth.push_back(errDistSmoothed);
|
||||
|
||||
std::cout << "SmoothingTime: " << tsHistory[(tsHistory.size() - 1) - MiscSettings::lag] << " " << statsSmoothing.asString() << std::endl;
|
||||
std::cout << "SmoothingDist: " << tsHistory[(tsHistory.size() - 1) - MiscSettings::lag] << " " << statsDistSmoothing.asString() << std::endl;
|
||||
|
||||
|
||||
// plot
|
||||
@@ -356,7 +404,7 @@ public:
|
||||
const K::Particle<MyState>& p = bf->getbackwardParticles().back()[j];
|
||||
vis.addState(p.state.walkState);
|
||||
}
|
||||
vis.setTimestamp(tsHistory[currentParticleSetToSmoothAtTimet]);
|
||||
vis.setTimestamp(tsHistory[t]);
|
||||
vis.addGroundTruth(gtw);
|
||||
vis.addEstPath(smoothedEst);
|
||||
vis.setEstAndShould(curSmoothedEst, curGTSmoothed);
|
||||
@@ -365,6 +413,7 @@ public:
|
||||
vis.gp << "set label 112 'baro: " << obs.barometer->hpa << "' at screen 0.1,0.2\n";
|
||||
}
|
||||
vis.gp << "set label 111 '" <<ctrl.walked_m << ":" << ctrl.headingChange_rad << "' at screen 0.1,0.1\n";
|
||||
vis.gp << "set label 112 '" << "Act: " << actDet.toString() << "' at screen 0.1,0.15\n";
|
||||
|
||||
//vis.gp << "set label 111 '" <<ctrl.walked_m << ":" << obs.orientation.values[0] << "' at screen 0.1,0.1\n";
|
||||
|
||||
@@ -377,12 +426,71 @@ public:
|
||||
|
||||
// prevent gnuplot errors
|
||||
usleep(1000*33);
|
||||
|
||||
++currentParticleSetToSmoothAtTimet;
|
||||
}
|
||||
|
||||
//statsout2.close();
|
||||
|
||||
{ // detailled error-description (normally filtered)
|
||||
std::ofstream oError("/tmp/err_norm_" + runName + ".dat");
|
||||
for (float f : errorsNorm) {oError << f << "\n";}
|
||||
oError.close();
|
||||
}
|
||||
|
||||
{ // detailled error-description (smothed)
|
||||
std::ofstream oError("/tmp/err_smooth_" + runName + ".dat");
|
||||
for (float f : errorsSmooth) {oError << f << "\n";}
|
||||
oError.close();
|
||||
}
|
||||
|
||||
{ // detailled distance-error-description (normally filtered)
|
||||
std::ofstream oError("/tmp/err_dist_norm_" + runName + ".dat");
|
||||
for (float f : errorsDistNorm) {oError << f << "\n";}
|
||||
oError.close();
|
||||
}
|
||||
|
||||
{ // detailled distance-error-description (smothed)
|
||||
std::ofstream oError("/tmp/err_dist_smooth_" + runName + ".dat");
|
||||
for (float f : errorsDistSmooth) {oError << f << "\n";}
|
||||
oError.close();
|
||||
}
|
||||
|
||||
// plot
|
||||
//vis.clearStates();
|
||||
vis.gp.setTerminal("png", K::GnuplotSize(1280 * 2.54, 720 * 2.54) );
|
||||
vis.gp.setOutput("/tmp/" + runName + ".png");
|
||||
vis.gp << "set view 60," << 40 << "\n"; //For fixed position
|
||||
|
||||
for (int j = 0; j < (int) bf->getbackwardParticles().back().size(); j+=15) {
|
||||
const K::Particle<MyState>& p = bf->getbackwardParticles().back()[j];
|
||||
vis.addState(p.state.walkState);
|
||||
}
|
||||
//vis.setTimestamp(se.ts);
|
||||
vis.setFilteringMedian(statsFiltering.getMedian());
|
||||
vis.setSmoothingMedian(statsSmoothing.getMedian());
|
||||
vis.addGroundTruth(gtw);
|
||||
vis.addEstPath(pathEst);
|
||||
vis.addSmoothPath(smoothedEst);
|
||||
//vis.setEstAndShould(curEst, curGT);
|
||||
//vis.setEstAndShould2(curSmoothedEst, curGTSmoothed);
|
||||
|
||||
if (obs.barometer != nullptr) {
|
||||
vis.gp << "set label 112 'baro: " << obs.barometer->hpa << "' at screen 0.1,0.2\n";
|
||||
}
|
||||
vis.gp << "set label 111 '" <<ctrl.walked_m << ":" << ctrl.headingChange_rad << "' at screen 0.1,0.1\n";
|
||||
|
||||
//vis.gp << "set label 111 '" <<ctrl.walked_m << ":" << obs.orientation.values[0] << "' at screen 0.1,0.1\n";
|
||||
|
||||
Point2 p1(0.1, 0.1);
|
||||
Point2 p2 = p1 + Angle::getPointer(ctrl.headingChange_rad) * 0.05;
|
||||
//Point2 p2 = p1 + Angle::getPointer(obs.orientation.values[0]) * 0.05;
|
||||
vis.gp << "set arrow 999 from screen " << p1.x<<","<<p1.y << " to screen " << p2.x<<","<<p2.y<<"\n";
|
||||
|
||||
vis.show();
|
||||
|
||||
// prevent gnuplot errors
|
||||
usleep(1000*33);
|
||||
|
||||
|
||||
// append error for each run to a file
|
||||
std::ofstream oTError("/tmp/errorsFilter.txt", std::ios_base::app);
|
||||
oTError << runName << "\n\t"; statsFiltering.appendTo(oTError); oTError << "\n\n";
|
||||
@@ -393,11 +501,22 @@ public:
|
||||
oSError << runName << "\n\t"; statsSmoothing.appendTo(oSError); oSError << "\n\n";
|
||||
oSError.close();
|
||||
|
||||
// append error for each run to a file
|
||||
std::ofstream oTDError("/tmp/errorsDistFiltering.txt", std::ios_base::app);
|
||||
oTDError << runName << "\n\t"; statsDistFiltering.appendTo(oTDError); oTDError << "\n\n";
|
||||
oTDError.close();
|
||||
|
||||
// append error for each run to a file
|
||||
std::ofstream oSDError("/tmp/errorsDistSmoothing.txt", std::ios_base::app);
|
||||
oSDError << runName << "\n\t"; statsDistSmoothing.appendTo(oSDError); oSDError << "\n\n";
|
||||
oSDError.close();
|
||||
|
||||
|
||||
// plot-data
|
||||
std::ofstream oPath("/tmp/path_" + runName + ".dat"); vis.groundTruth.addDataTo(oPath); oPath.close(); // ground truth
|
||||
std::ofstream oEstN("/tmp/est_norm" + runName + ".dat"); vis.estPath.addDataTo(oEstN); oEstN.close(); // estimation via filter itself
|
||||
std::ofstream oEstS("/tmp/est_smooth" + runName + ".dat"); vis.smoothPath.addDataTo(oEstS); oEstS.close(); // estimation via smoothing
|
||||
std::ofstream oFloor("/tmp/floors.dat"); vis.floors.addDataTo(oFloor); oFloor.close();
|
||||
std::ofstream oPath("/tmp/path_" + runName + ".dat"); vis.groundTruth.addDataTo(oPath); oPath.close(); // ground truth
|
||||
std::ofstream oEstN("/tmp/est_norm_" + runName + ".dat"); vis.estPath.addDataTo(oEstN); oEstN.close(); // estimation via filter itself
|
||||
std::ofstream oEstS("/tmp/est_smooth_" + runName + ".dat"); vis.smoothPath.addDataTo(oEstS); oEstS.close(); // estimation via smoothing
|
||||
std::ofstream oFloor("/tmp/floors.dat"); vis.floors.addDataTo(oFloor); oFloor.close();
|
||||
|
||||
std::ofstream oPlot("/tmp/plot_" + runName + ".gp");
|
||||
|
||||
@@ -417,12 +536,28 @@ public:
|
||||
oPlot << "unset ztics\n";
|
||||
|
||||
oPlot << "splot \\\n";
|
||||
oPlot << "'floors.dat' skip 21 notitle with lines lc rgb '#777777', \\\n";
|
||||
oPlot << "'path_fixed_interval.dat' skip 21 notitle with lines lw 2.5 dashtype 2 lc rgb '#007700', \\\n";
|
||||
oPlot << "'est_norm_fixed_interval.dat' skip 21 notitle with lines lw 2.5 lc rgb '#000099', ";
|
||||
oPlot << "'est_smooth_fixed_interval.dat' skip 21 notitle with lines lw 2.5 lc rgb '#000000' ";
|
||||
oPlot << "'floors.dat' skip 21 notitle with lines lc rgb '#777777', \\\n";
|
||||
oPlot << "'path_" << runName << ".dat' skip 21 notitle with lines lw 2.5 dashtype 2 lc rgb '#007700', \\\n";
|
||||
oPlot << "'est_norm_" << runName << ".dat' skip 21 notitle with lines lw 2.5 lc rgb '#000099', ";
|
||||
oPlot << "'est_smooth_" << runName << ".dat' skip 21 notitle with lines lw 2.5 lc rgb '#000000' ";
|
||||
|
||||
oPlot.close();
|
||||
|
||||
{
|
||||
std::ofstream oErrPlot("/tmp/plot_err_" + runName + ".gp");
|
||||
oErrPlot << "plot \\\n";
|
||||
oErrPlot << "'err_norm_" << runName << ".dat' with lines, \\\n";
|
||||
oErrPlot << "'err_smooth_" << runName << ".dat' with lines";
|
||||
oErrPlot.close();
|
||||
}
|
||||
|
||||
{
|
||||
std::ofstream oErrPlot("/tmp/plot_dist_err_" + runName + ".gp");
|
||||
oErrPlot << "plot \\\n";
|
||||
oErrPlot << "'err_dist_norm_" << runName << ".dat' with lines, \\\n";
|
||||
oErrPlot << "'err_dist_smooth_" << runName << ".dat' with lines";
|
||||
oErrPlot.close();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user