cheap-stats 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e5a30b7e09b21f08359019f9a4a33bb8bc8b4e1e103bea1eed739f12de818f0
4
- data.tar.gz: dc3146cd65e34779373ffe61b5f32c90ac1cfb89218e5fefd81804bf6d40ac59
3
+ metadata.gz: f5a99f35a58f32ff2cfb41964a1ec75a82cf249200ad6b2b2392a9ffd2571976
4
+ data.tar.gz: 6b262daad757204e7d6842de7a43b682f7143d22697b5526d58126e3e9c036c9
5
5
  SHA512:
6
- metadata.gz: 5860b61e54bc57a8ade4724d4f5e5ac62811079b75869177e774c0eb281341fa0a2c7ee7f41f59fbb409355b4a2e5757ccf14a7179d6912d0919d240928759fe
7
- data.tar.gz: a9b091cfcb393b1236dd5eca02eaf2d5742c51ce0ea94da38827171c6752c0a6140856c50679b97d363eceabffbdd2876ffb5795aa99c0e365ffe81ad7f85ffd
6
+ metadata.gz: 54ca8675dcef936be225e9ecc7747aa9e709796fc45b1449b1df81162895427b50349f5497ac1d575f01d13984ac6bfbe89a84045228c0a6222f652fa6eaa1ef
7
+ data.tar.gz: 2488dc611af4b88933755af4b583a712401f8be45d93e7b304249a997491d2acc96af46412ee355985a207245aafb6fc47cb20a49d7e96f3ad35251cb878ab8f
@@ -603,3 +603,37 @@ cheap_stats_pearson_skewness(cheap_stats_t* ptr, double* dst)
603
603
  return ret;
604
604
  }
605
605
 
606
+ int
607
+ cheap_stats_z_score(cheap_stats_t* ptr, double v, double* dst)
608
+ {
609
+ int ret;
610
+
611
+ /*
612
+ * initialize
613
+ */
614
+ ret = 0;
615
+
616
+ /*
617
+ * argument check
618
+ */
619
+ do {
620
+ if (ptr == NULL) {
621
+ ret = DEFAULT_ERROR;
622
+ break;
623
+ }
624
+
625
+ if (dst == NULL) {
626
+ ret = DEFAULT_ERROR;
627
+ break;
628
+ }
629
+ } while (0);
630
+
631
+ /*
632
+ * do test (by Smirnov-Grubbs test)
633
+ */
634
+ if (!ret) {
635
+ *dst = (v - ptr->mean) / ptr->std;
636
+ }
637
+
638
+ return ret;
639
+ }
@@ -33,5 +33,6 @@ int cheap_stats_central_moment(cheap_stats_t* obj, double k, double* dst);
33
33
  int cheap_stats_std_moment(cheap_stats_t* obj, double k, double* dst);
34
34
  int cheap_stats_skewness(cheap_stats_t* obj, double* dst);
35
35
  int cheap_stats_pearson_skewness(cheap_stats_t* obj, double* dst);
36
+ int cheap_stats_z_score(cheap_stats_t* obj, double v, double* res);
36
37
 
37
38
  #endif /* !defined(__SMALL_STATS_H__) */
@@ -484,6 +484,37 @@ rb_cheap_stats_pearson_skewness(VALUE self)
484
484
  return DBL2NUM(ret);
485
485
  }
486
486
 
487
+ /**
488
+ * calc Z-score
489
+ *
490
+ * @param [Numeric] v target value
491
+ *
492
+ * @return [Float] skewness value
493
+ */
494
+ static VALUE
495
+ rb_cheap_stats_z_score(VALUE self, VALUE v)
496
+ {
497
+ rb_cheap_stats_t* ptr;
498
+ int err;
499
+ double ret;
500
+
501
+ /*
502
+ * strip context data
503
+ */
504
+ TypedData_Get_Struct(self, rb_cheap_stats_t, &rb_cheap_stats_data_type, ptr);
505
+
506
+ /*
507
+ * check argument
508
+ */
509
+ err = cheap_stats_z_score(ptr->stats, rb_num2dbl(v), &ret);
510
+ if (err) {
511
+ RUNTIME_ERROR("cheap_stats_z_score() failed [err=%d]", err);
512
+ }
513
+
514
+ return DBL2NUM(ret);
515
+ }
516
+
517
+
487
518
  void
488
519
  Init_cheap_stats()
489
520
  {
@@ -507,6 +538,7 @@ Init_cheap_stats()
507
538
  rb_define_method(klass, "std_moment", rb_cheap_stats_std_moment, 1);
508
539
  rb_define_method(klass, "skewness", rb_cheap_stats_skewness, 0);
509
540
  rb_define_method(klass, "pearson_skewness",rb_cheap_stats_pearson_skewness,0);
541
+ rb_define_method(klass, "z_score",rb_cheap_stats_z_score, 1);
510
542
 
511
543
  rb_alias(klass, rb_intern("average"), rb_intern("mean"));
512
544
  rb_alias(klass, rb_intern("sigma"), rb_intern("std"));
@@ -1,3 +1,3 @@
1
1
  class CheapStats
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cheap-stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Kuwagata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2019-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler