Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

git-svn-id: http://rb-gsl.rubyforge.org/svn/trunk/rb-gsl@87 6e764f74-…

…f39f-46f8-8c54-8307d62afe8d
  • Loading branch information...
commit e8c6e0b815fa0a55bf0e18bb626650ca4f8cf2db 1 parent 927fe32
ytsunesada authored
View
4 ChangeLog
@@ -1,3 +1,7 @@
+Thu Feb 2 12:16:38 JST 2009
+ * Fixed a bug in GSL::Histogram.alloc_uniform() (bug [#23040])
+ * Fixed a bug in GSL::Vector#/ (bug [#23334])
+
Thu Nov 6 17:34:18 JST 2008
* Match with the tensor extension version 0.99
* now not compatible for the versions older than tensor-0.97.
View
3  ext/array.c
@@ -406,7 +406,7 @@ void gsl_matrix_complex_mul_vector(gsl_vector_complex *vnew,
}
/*****/
-
+#ifndef GSL_1_12_LATER
int gsl_vector_complex_add(gsl_vector_complex *cv, const gsl_vector_complex *cv2)
{
size_t i;
@@ -483,6 +483,7 @@ int gsl_vector_complex_div(gsl_vector_complex *cv, const gsl_vector_complex *cv2
}
return 0;
}
+#endif
VALUE rb_gsl_range2ary(VALUE obj)
{
View
77 ext/histogram.c
@@ -1489,6 +1489,75 @@ static VALUE rb_gsl_histogram_reverse(VALUE obj)
return Data_Wrap_Struct(cgsl_histogram, 0, gsl_histogram_free, hnew);
}
+/* The functions below are not included in GSL */
+/*
+ * Returns an x value at which the histogram integration
+ * reaches the given percentile. The x value is calculated
+ * by an interpolation between the ranges in which the percentile
+ * is found.
+ */
+static double histogram_percentile(const gsl_histogram *h, double f)
+{
+ double sum = gsl_histogram_sum(h), sf;
+ double val, s = 0, x;
+ double ri, ri1;
+ size_t i;
+ sf = sum * f;
+ for (i = 0; i < h->n; i++) {
+ val = gsl_histogram_get(h, i);
+ if ((s+val) > sf) break;
+ s += val;
+ }
+ ri = h->range[i];
+ ri1 = h->range[i+1];
+ x = (sf - s)*(ri1 - ri)/val + ri;
+ return x;
+}
+
+static double histogram_median(const gsl_histogram *h)
+{
+ return histogram_percentile(h, 0.5);
+}
+
+static VALUE rb_gsl_histogram_percentile(VALUE obj, VALUE f)
+{
+ gsl_histogram *h;
+ Data_Get_Struct(obj, gsl_histogram, h);
+ return rb_float_new(histogram_percentile(h, NUM2DBL(f)));
+}
+
+static VALUE rb_gsl_histogram_median(VALUE obj)
+{
+ gsl_histogram *h;
+ Data_Get_Struct(obj, gsl_histogram, h);
+ return rb_float_new(histogram_median(h));
+}
+
+static double histogram_percentile_inv(const gsl_histogram *h, double x)
+{
+ double sum = gsl_histogram_sum(h);
+ double val, s = 0;
+ double ri, ri1, q;
+ size_t i;
+
+ for (i = 0; i < h->n; i++) {
+ val = gsl_histogram_get(h, i);
+ if (h->range[i+1] > x) break;
+ s += val;
+ }
+ ri = h->range[i];
+ ri1 = h->range[i+1];
+ q = s + val/(ri1 - ri)*(x - ri);
+ return q/sum;
+}
+
+static VALUE rb_gsl_histogram_percentile_inv(VALUE obj, VALUE x)
+{
+ gsl_histogram *h;
+ Data_Get_Struct(obj, gsl_histogram, h);
+ return rb_float_new(histogram_percentile_inv(h, NUM2DBL(x)));
+}
+
void Init_gsl_histogram(VALUE module)
{
VALUE cgsl_histogram_pdf;
@@ -1507,9 +1576,9 @@ void Init_gsl_histogram(VALUE module)
rb_define_singleton_method(cgsl_histogram, "[]", rb_gsl_histogram_alloc, -1);
rb_define_singleton_method(cgsl_histogram, "alloc_uniform",
- rb_gsl_histogram_alloc_uniform, 3);
+ rb_gsl_histogram_alloc_uniform, -1);
rb_define_singleton_method(cgsl_histogram, "new_uniform",
- rb_gsl_histogram_alloc_uniform, 3);
+ rb_gsl_histogram_alloc_uniform, -1);
rb_define_singleton_method(cgsl_histogram, "alloc_with_min_max_step",
rb_gsl_histogram_alloc_with_min_max_step, 3);
@@ -1641,4 +1710,8 @@ void Init_gsl_histogram(VALUE module)
rb_define_alias(cgsl_histogram, "mergebin", "rebin");
rb_define_method(cgsl_histogram, "reverse", rb_gsl_histogram_reverse, 0);
+
+ rb_define_method(cgsl_histogram, "percentile", rb_gsl_histogram_percentile, 1);
+ rb_define_method(cgsl_histogram, "median", rb_gsl_histogram_median, 0);
+ rb_define_method(cgsl_histogram, "percentile_inv", rb_gsl_histogram_percentile_inv, 1);
}
View
2  ext/linalg.c
@@ -3488,6 +3488,8 @@ static VALUE rb_gsl_linalg_hessenberg_set_zero(VALUE module, VALUE HH)
CHECK_MATRIX(HH);
Data_Get_Struct(HH, gsl_matrix, H);
return INT2FIX(gsl_linalg_hessenberg_set_zero(H));
+ /* gsl_linalg_hessenberg_set_zero(H);
+ return INT2FIX(0);*/
}
static VALUE rb_gsl_linalg_hesstri_decomp(int argc, VALUE *argv, VALUE module)
{
View
8 lib/gsl/oper.rb
@@ -22,10 +22,10 @@ def /(other)
a = GSL::Poly[1]; a[0] = self
GSL::Rational.new(a, other)
elsif other.kind_of?(GSL::Vector::Col)
- other.scale(1.0/pow_2(other.dnrm2))
+ other.scale(1.0/GSL::pow_2(other.dnrm2))
elsif other.kind_of?(GSL::Vector::Int::Col)
v = other.to_f
- v.scale(1.0/pow_2(v.dnrm2))
+ v.scale(1.0/GSL::pow_2(v.dnrm2))
else
self._orig_div(other)
end
@@ -57,10 +57,10 @@ def /(other)
a = GSL::Poly[1]; a[0] = self
GSL::Rational.new(a, other)
elsif other.kind_of?(GSL::Vector::Col)
- other.scale(1.0/pow_2(other.dnrm2))
+ other.scale(1.0/GSL::pow_2(other.dnrm2))
elsif other.kind_of?(GSL::Vector::Int::Col)
v = other.to_f
- v.scale(1.0/pow_2(v.dnrm2))
+ v.scale(1.0/GSL::pow_2(v.dnrm2))
else
self._orig_div(other)
end
Please sign in to comment.
Something went wrong with that request. Please try again.