mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added hierarchical estimation of the y intercept
This commit is contained in:
parent
e90a3b601b
commit
9958f54184
1 changed files with 45 additions and 0 deletions
|
|
@ -61,5 +61,50 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
template <typename TYPE, int SIZE>
|
||||
class RepeatedMedianEstimator2
|
||||
{
|
||||
TYPE inner_[SIZE-1], outer_[SIZE];
|
||||
TYPE xint_, yint_, slope_;
|
||||
public:
|
||||
RepeatedMedianEstimator2() : xint_(0), yint_(0), slope_(0) {}
|
||||
void compute(TYPE *x, TYPE *y, int LEN)
|
||||
{
|
||||
if (LEN > SIZE)
|
||||
LEN = SIZE;
|
||||
for (int i = 0; i < LEN; ++i) {
|
||||
int count = 0;
|
||||
for (int j = 0; j < LEN; ++j)
|
||||
if (x[j] != x[i])
|
||||
inner_[count++] = (y[j] - y[i]) / (x[j] - x[i]);
|
||||
std::nth_element(inner_, inner_+count/2, inner_+count);
|
||||
outer_[i] = inner_[count/2];
|
||||
}
|
||||
std::nth_element(outer_, outer_+LEN/2, outer_+LEN);
|
||||
slope_ = outer_[LEN/2];
|
||||
for (int i = 0; i < LEN; ++i)
|
||||
outer_[i] = y[i] - slope_ * x[i];
|
||||
std::nth_element(outer_, outer_+LEN/2, outer_+LEN);
|
||||
yint_ = outer_[LEN/2];
|
||||
xint_ = - yint_ / slope_;
|
||||
}
|
||||
TYPE xint()
|
||||
{
|
||||
return xint_;
|
||||
}
|
||||
TYPE slope()
|
||||
{
|
||||
return slope_;
|
||||
}
|
||||
TYPE yint()
|
||||
{
|
||||
return yint_;
|
||||
}
|
||||
TYPE operator () (TYPE x)
|
||||
{
|
||||
return yint_ + slope_ * x;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue