From: Mikko Rasa Date: Sat, 21 May 2011 10:35:33 +0000 (+0000) Subject: Don't use too short speed measurements for quantizer learning X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e77b01f9fed6d5f653dbd0123f0f1f61a13c3dfa;p=r2c2.git Don't use too short speed measurements for quantizer learning Wait for enough learning data before using it for quantization --- diff --git a/source/libr2c2/speedquantizer.cpp b/source/libr2c2/speedquantizer.cpp index 710e104..acd1983 100644 --- a/source/libr2c2/speedquantizer.cpp +++ b/source/libr2c2/speedquantizer.cpp @@ -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=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=weight_limit) { last = i; if(steps[i].speed>=speed) diff --git a/source/libr2c2/speedquantizer.h b/source/libr2c2/speedquantizer.h index d6dc1ac..2f9aedd 100644 --- a/source/libr2c2/speedquantizer.h +++ b/source/libr2c2/speedquantizer.h @@ -36,6 +36,7 @@ private: }; std::vector steps; + float weight_limit; public: SpeedQuantizer(unsigned); diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 93ebebe..ba1a861 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -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;