X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fexpressions%2Fhelpers.c;h=25fe143728ca2a48444452de3c0a54ef216fbe09;hb=fa489d6ef77150e60c31906ee322bea2901da57f;hp=879b95f493035755e40163752190158814ad12db;hpb=d807ad29cc0d3caa4f0e04ee4b75c70a225cfeaf;p=pspp diff --git a/src/expressions/helpers.c b/src/expressions/helpers.c index 879b95f493..25fe143728 100644 --- a/src/expressions/helpers.c +++ b/src/expressions/helpers.c @@ -158,91 +158,13 @@ alloc_string (struct expression *e, size_t length) } struct fixed_string -copy_string (struct expression *e, const char *old, size_t length) +copy_string (struct expression *e, const unsigned char *old, size_t length) { struct fixed_string s = alloc_string (e, length); memcpy (s.string, old, length); return s; } -struct func_params - { - double Ptarget; - double a; - double b; - }; - -static double -generalized_idf (double P, double a, double b, double (*cdf) (double, void *)) -{ - struct func_params params; - gsl_function f; - gsl_root_fsolver *fsolver; - int iter; - int status; - double root; - - if (P < 0 || P > 1) - return SYSMIS; - - params.Ptarget = P; - params.a = a; - params.b = b; - - f.function = cdf; - f.params = ¶ms; - - fsolver = gsl_root_fsolver_alloc (gsl_root_fsolver_brent); - gsl_root_fsolver_set (fsolver, &f, 0, 1); - - iter = 0; - do - { - double x_lower, x_upper; - - status = gsl_root_fsolver_iterate (fsolver); - if (status != 0) - return SYSMIS; - - x_lower = gsl_root_fsolver_x_lower (fsolver); - x_upper = gsl_root_fsolver_x_upper (fsolver); - status = gsl_root_test_interval (x_lower, x_upper, 0, 2 * DBL_EPSILON); - } - while (status == GSL_CONTINUE && ++iter < 100); - - root = gsl_root_fsolver_root (fsolver); - gsl_root_fsolver_free (fsolver); - return root; -} - -static double -cdf_beta (double x, void *params_) -{ - struct func_params *params = params_; - - return gsl_cdf_beta_P (x, params->a, params->b) - params->Ptarget; -} - -double -idf_beta (double P, double a, double b) -{ -#if 1 - return generalized_idf (P, a, b, cdf_beta); -#else - double x = a / (a + b); - double dx = 1.; - while (fabs (dx) > 2 * DBL_EPSILON) - { - dx = (gsl_sf_beta_inc (a, b, x) - P) / gsl_ran_beta_pdf (x, a, b); - x -= dx; - if (x < 0) - x += (dx - x) / 2; - } - - return x; -#endif -} - /* Returns the noncentral beta cumulative distribution function value for the given arguments. @@ -390,7 +312,7 @@ cdf_bvnor (double x0, double x1, double r) double idf_fdist (double P, double df1, double df2) { - double temp = idf_beta (P, df1 / 2, df2 / 2); + double temp = gslextras_cdf_beta_Pinv (P, df1 / 2, df2 / 2); return temp * df2 / ((1. - temp) * df1); } @@ -417,8 +339,8 @@ idf_fdist (double P, double df1, double df2) * 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. */ /* Returns the density of the noncentral beta distribution with