]> git.tdb.fi Git - r2c2.git/commitdiff
Don't use too short speed measurements for quantizer learning
authorMikko Rasa <tdb@tdb.fi>
Sat, 21 May 2011 10:35:33 +0000 (10:35 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 21 May 2011 10:35:33 +0000 (10:35 +0000)
Wait for enough learning data before using it for quantization

source/libr2c2/speedquantizer.cpp
source/libr2c2/speedquantizer.h
source/libr2c2/train.cpp

index 710e1041fb1d1f42a74dee61fe717d84394def9c..acd1983f0ab0d42eee5da5509b0e331eaab04d54 100644 (file)
@@ -13,7 +13,8 @@ using namespace Msp;
 namespace R2C2 {
 
 SpeedQuantizer::SpeedQuantizer(unsigned n):
-       steps(n+1)
+       steps(n+1),
+       weight_limit(10)
 {
        if(n<1)
                throw InvalidParameterValue("Must have at leats one speed step");
@@ -30,16 +31,16 @@ float SpeedQuantizer::get_speed(unsigned i) const
 {
        if(i==0)
                return 0;
-       if(steps[i].weight)
+       if(steps[i].weight>=weight_limit)
                return steps[i].speed;
 
        unsigned low;
        unsigned high;
        for(low=i; low>0; --low)
-               if(steps[low].weight)
+               if(steps[low].weight>=weight_limit)
                        break;
        for(high=i; high+1<steps.size(); ++high)
-               if(steps[high].weight)
+               if(steps[high].weight>=weight_limit)
                        break;
 
        if(steps[high].weight)
@@ -69,7 +70,7 @@ unsigned SpeedQuantizer::find_speed_step(float speed) const
        unsigned high = 0;
        unsigned last = 0;
        for(unsigned i=0; (!high && i<steps.size()); ++i)
-               if(steps[i].weight)
+               if(steps[i].weight>=weight_limit)
                {
                        last = i;
                        if(steps[i].speed>=speed)
index d6dc1acd02cb0ebdc8fab126105d3213a6dea49f..2f9aeddcc8983e00b4b5617c962232b283683fc7 100644 (file)
@@ -36,6 +36,7 @@ private:
        };
 
        std::vector<SpeedStep> steps;
+       float weight_limit;
 
 public:
        SpeedQuantizer(unsigned);
index 93ebebec3c16ef66502da7045fe6df24cf429a4d..ba1a861b9e24ec75f14a91049d8d3a76b54fc29f 100644 (file)
@@ -763,7 +763,7 @@ void Train::block_state_changed(Block &block, Block::State state)
                        // Compute speed and update related state
                        float travel_time_secs = (Time::now()-last_entry_time)/Time::sec;
 
-                       if(pure_speed && speed_quantizer && current_speed_step>0)
+                       if(pure_speed && speed_quantizer && current_speed_step>0 && travel_time_secs>=2)
                                speed_quantizer->learn(current_speed_step, travel_dist/travel_time_secs, travel_time_secs);
 
                        travel_dist = 0;