Class: Numo::GSL::Rstat

Inherits:
Object
  • Object
show all
Defined in:
ext/numo/gsl/rstat/gsl_rstat.c

Defined Under Namespace

Classes: Quantile

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newObject

allocate instance of Rstat class.

This function allocates a workspace for computing running statistics. The size of the workspace is O(1).



58
59
60
61
62
63
64
65
66
67
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 58

static VALUE
rstat_s_new(VALUE self)
{
    gsl_rstat_workspace *w;
    w = gsl_rstat_alloc();
    if (!w) {
        rb_raise(rb_eNoMemError,"fail to allocate struct");
    }
    return TypedData_Wrap_Struct(cRstat, &rstat_data_type, (void*)w);
}

Instance Method Details

#add(w) ⇒ Rstat

This function adds the data point x to the statistical accumulator, updating calculations of the mean, variance, standard deviation, skewness, kurtosis, and median.

Parameters:

  • w (DFloat)

Returns:



125
126
127
128
129
130
131
132
133
134
135
136
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 125

static VALUE
rstat_add(VALUE self, VALUE v1)
{
    gsl_rstat_workspace *w;
    ndfunc_arg_in_t ain[1] = {{cDF,0}};
    ndfunc_t ndf = {iter_rstat_add, FULL_LOOP, 1,0, ain,0};

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    na_ndloop3(&ndf, w, 1, v1);
    return self;
}

#kurtosisFloat

This function returns the kurtosis of all data added to the accumulator, defined as

kurtosis = ((1/N) \sum ((x_i - \Hat\mu)/\Hat\sigma)^4) - 3

Returns:

  • (Float)


332
333
334
335
336
337
338
339
340
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 332

static VALUE
rstat_kurtosis(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return DBL2NUM(gsl_rstat_kurtosis(w));
}

#maxFloat

This function returns the maximum value added to the accumulator.

Returns:

  • (Float)


182
183
184
185
186
187
188
189
190
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 182

static VALUE
rstat_max(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return DBL2NUM(gsl_rstat_max(w));
}

#meanFloat

This function returns the mean of all data added to the accumulator, defined as

\Hat\mu = (1/N) \sum x_i

Returns:

  • (Float)


204
205
206
207
208
209
210
211
212
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 204

static VALUE
rstat_mean(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return DBL2NUM(gsl_rstat_mean(w));
}

#medianFloat

This function returns an estimate of the median of the data added to the accumulator.

Returns:

  • (Float)


351
352
353
354
355
356
357
358
359
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 351

static VALUE
rstat_median(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return DBL2NUM(gsl_rstat_median(w));
}

#minFloat

This function returns the minimum value added to the accumulator.

Returns:

  • (Float)


164
165
166
167
168
169
170
171
172
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 164

static VALUE
rstat_min(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return DBL2NUM(gsl_rstat_min(w));
}

#nInteger Also known as: size, length

This function returns the number of data so far added to the accumulator.

Returns:

  • (Integer)


146
147
148
149
150
151
152
153
154
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 146

static VALUE
rstat_n(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return SIZET2NUM(gsl_rstat_n(w));
}

#resetObject

This function resets the workspace w to its initial state, so it can begin working on a new set of data.



77
78
79
80
81
82
83
84
85
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 77

static VALUE
rstat_reset(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);
    gsl_rstat_reset(w);
    return Qnil;
}

#rmsFloat

This function returns the root mean square of all data added to the accumulator, defined as

rms = \sqrt ( 1/N \sum x_i^2 )

Returns:

  • (Float)


288
289
290
291
292
293
294
295
296
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 288

static VALUE
rstat_rms(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return DBL2NUM(gsl_rstat_rms(w));
}

#sdFloat

This function returns the standard deviation of all data added to the accumulator, defined as the square root of the variance given above.

Returns:

  • (Float)


245
246
247
248
249
250
251
252
253
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 245

static VALUE
rstat_sd(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return DBL2NUM(gsl_rstat_sd(w));
}

#sd_meanFloat

This function returns the standard deviation of the mean, defined as

sd_mean = \Hat\sigma / \sqrt[N]

Returns:

  • (Float)


266
267
268
269
270
271
272
273
274
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 266

static VALUE
rstat_sd_mean(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return DBL2NUM(gsl_rstat_sd_mean(w));
}

#skewFloat

This function returns the skewness of all data added to the accumulator, defined as

skew = (1/N) \sum ((x_i - \Hat\mu)/\Hat\sigma)^3

Returns:

  • (Float)


310
311
312
313
314
315
316
317
318
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 310

static VALUE
rstat_skew(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return DBL2NUM(gsl_rstat_skew(w));
}

#varianceFloat

This function returns the variance of all data added to the accumulator, defined as

\Hat\sigma^2 = (1/(N-1)) \sum (x_i - \Hat\mu)^2

Returns:

  • (Float)


226
227
228
229
230
231
232
233
234
# File 'ext/numo/gsl/rstat/gsl_rstat.c', line 226

static VALUE
rstat_variance(VALUE self)
{
    gsl_rstat_workspace *w;

    TypedData_Get_Struct(self, gsl_rstat_workspace, &rstat_data_type, w);

    return DBL2NUM(gsl_rstat_variance(w));
}