Use Theil estimator randomized approximation.

This commit is contained in:
Bartosz Taudul 2019-08-04 01:37:04 +02:00
parent 8953a2652e
commit e87b8d455e

View File

@ -13,6 +13,7 @@
#include <math.h> #include <math.h>
#include <mutex> #include <mutex>
#include <numeric> #include <numeric>
#include <random>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
@ -5294,31 +5295,34 @@ void View::DrawOptions()
if( ImGui::Button( "Auto" ) ) if( ImGui::Button( "Auto" ) )
#endif #endif
{ {
double gsum = 0;
size_t lastidx = 0; size_t lastidx = 0;
for( size_t j=0; j<timeline.size(); j++ ) for( size_t j=timeline.size()-1; j > 0; j-- )
{ {
if( timeline[j]->gpuEnd >= 0 ) if( timeline[j]->gpuEnd >= 0 )
{ {
lastidx = j; lastidx = j;
gsum += timeline[j]->gpuStart - timeline[j]->cpuStart; break;
} }
} }
if( lastidx > 0 )
enum { NumSlopes = 10000 };
std::random_device rd;
std::default_random_engine gen( rd() );
std::uniform_int_distribution<size_t> dist( 0, lastidx - 1 );
float slopes[NumSlopes];
size_t idx = 0;
do
{ {
const double cavg = ( timeline[lastidx]->cpuStart + timeline.front()->cpuStart ) * 0.5; const auto p0 = dist( gen );
const double gavg = gsum / double( lastidx ); const auto p1 = dist( gen );
double cov = 0; if( p0 != p1 )
double var = 0;
for( size_t j=0; j<lastidx; j++ )
{ {
const auto csub = timeline[j]->cpuStart - cavg; slopes[idx++] = float( 1.0 - double( timeline[p1]->gpuStart - timeline[p0]->gpuStart ) / double( timeline[p1]->cpuStart - timeline[p0]->cpuStart ) );
cov += csub * ( timeline[j]->gpuStart - timeline[j]->cpuStart - gavg );
var += csub * csub;
} }
const double beta = cov / var;
drift = int( 1000000000 * -beta );
} }
while( idx < NumSlopes );
std::sort( slopes, slopes+NumSlopes );
drift = int( 1000000000 * -slopes[NumSlopes/2] );
} }
} }
ImGui::TreePop(); ImGui::TreePop();