X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fpercentiles.c;h=8782c36a9b7e77f3fa5c3a60b9f17b0e543dbbba;hb=c434e369b6695f8135a2914e9a425edcdd09ef35;hp=9719676d5c424925d76b942d7623399d81873c1e;hpb=4239c455e7b1061b7c960b793f9080e113123845;p=pspp-builds.git diff --git a/src/percentiles.c b/src/percentiles.c index 9719676d..8782c36a 100644 --- a/src/percentiles.c +++ b/src/percentiles.c @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. */ +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301, USA. */ #include "factor_stats.h" #include "percentiles.h" @@ -80,18 +80,22 @@ ptile_round(const struct weighted_value **wv, const struct ptile_params *par) { double x; + double a=0; + + if ( par->k1 >= 0 ) + a = wv[par->k1]->v.f; if ( wv[par->k1 + 1]->w >= 1 ) { if ( par->g1_star < 0.5 ) - x = wv[par->k1]->v.f; + x = a; else x = wv[par->k1 + 1]->v.f; } else { if ( par->g1 < 0.5 ) - x = wv[par->k1]->v.f; + x = a; else x = wv[par->k1 + 1]->v.f; @@ -105,6 +109,9 @@ double ptile_haverage(const struct weighted_value **wv, const struct ptile_params *par) { + + double a=0; + if ( par->g2_star >= 1.0 ) return wv[par->k2 + 1]->v.f ; @@ -117,15 +124,17 @@ ptile_haverage(const struct weighted_value **wv, return wv[par->k2]->v.f; } - assert(par->k2 >= 0); + /* Ditto for k2 < 0 */ + if ( par->k2 >= 0 ) + { + a = wv[par->k2]->v.f; + } if ( wv[par->k2 + 1]->w >= 1.0 ) - return ( (1 - par->g2_star) * wv[par->k2]->v.f - + + return ( (1 - par->g2_star) * a + par->g2_star * wv[par->k2 + 1]->v.f); else - return ( (1 - par->g2) * wv[par->k2]->v.f - + + return ( (1 - par->g2) * a + par->g2 * wv[par->k2 + 1]->v.f); } @@ -137,16 +146,21 @@ double ptile_waverage(const struct weighted_value **wv, const struct ptile_params *par) { + double a=0; + if ( par->g1_star >= 1.0 ) return wv[par->k1 + 1]->v.f ; + if ( par->k1 >= 0 ) + { + a = wv[par->k1]->v.f; + } + if ( wv[par->k1 + 1]->w >= 1.0 ) - return ( (1 - par->g1_star) * wv[par->k1]->v.f - + + return ( (1 - par->g1_star) * a + par->g1_star * wv[par->k1 + 1]->v.f); else - return ( (1 - par->g1) * wv[par->k1]->v.f - + + return ( (1 - par->g1) * a + par->g1 * wv[par->k1 + 1]->v.f); } @@ -305,7 +319,8 @@ void tukey_hinges(const struct weighted_value **wv, int n_data, double w, - double hinges[3]) + double hinge[3] + ) { int i; double c_star = DBL_MAX; @@ -340,38 +355,47 @@ tukey_hinges(const struct weighted_value **wv, for ( i = 0 ; i < 3 ; i++ ) { - assert(h[i] + 1< n_data); if ( h[i] >= 0 ) a_star = l[i] - wv[h[i]]->cc ; else a_star = l[i]; - a = a_star / ( wv[h[i]+1]->cc ) ; + if ( h[i] + 1 >= n_data ) + { + assert( a_star < 1 ) ; + hinge[i] = (1 - a_star) * wv[h[i]]->v.f; + continue; + } + else + { + a = a_star / ( wv[h[i] + 1]->cc ) ; + } if ( a_star >= 1.0 ) { - hinges[i] = wv[h[i] + 1]->v.f ; + hinge[i] = wv[h[i] + 1]->v.f ; continue; } - if ( wv[h[i]+1]->w >= 1) + if ( wv[h[i] + 1]->w >= 1) { - hinges[i] = ( 1 - a_star)* wv[h[i]]->v.f - + a_star * wv[h[i]+1]->v.f; + hinge[i] = ( 1 - a_star) * wv[h[i]]->v.f + + a_star * wv[h[i] + 1]->v.f; continue; } - hinges[i] = ( 1 - a)* wv[h[i]]->v.f + a * wv[h[i]+1]->v.f; + hinge[i] = (1 - a) * wv[h[i]]->v.f + a * wv[h[i] + 1]->v.f; } - assert(hinges[0] <= hinges[1]); - assert(hinges[1] <= hinges[2]); + assert(hinge[0] <= hinge[1]); + assert(hinge[1] <= hinge[2]); } + int ptile_compare(const struct percentile *p1, const struct percentile *p2,