num4tststatistic 0.1.1-java → 0.2.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8035ed8852a010c953dc1f89787acb056eb516252687ed2a52ff558fb588ebf6
4
- data.tar.gz: 61ed13288b017bf0845b3cc3bf6807694eb655666a71126a4b31c9b67fe61aa4
3
+ metadata.gz: 53537fb9aa34673abd7db4fd6de0bdf1c32094c719d91cbec7be5ee030c8df14
4
+ data.tar.gz: 6e1f38c4918b3476dca195f41b5182e6122e96b6e1f86886708a54b8c318fa48
5
5
  SHA512:
6
- metadata.gz: 6031d267ff6f19ad8c12bc397cde2a6ae8aa95b0280564039c7f5a0c5cc8485455663bb7fd168d9358d8a180c17776440e620190c80af322ff8c21e863f622bc
7
- data.tar.gz: f2214a6320e064958b12e7afd72162edad09a8f355690215028126bd9f230ed52dff4e048ca064393b115375c9499cbb7af59ed788dce0b33fbd41c82070eca5
6
+ metadata.gz: a8c31d24cde63ff7e098de9d56bac19e3cc11d33ba611b5de7ae63de768b7af010d303d96529533b6c793cf0a7f248c594e4dbf6dcb5cc6473c52b1725fd52ae
7
+ data.tar.gz: 2d05cd849ef9e963cfd93c23da369250e304976a7b0a92d27ec7625a0bc7496a2520226eb2d28cb7f98c09cca514e45e3c65d0ed11836328d4f55b367ad6db59
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.2.1] - 2024-01-07
6
+ ### add
7
+ - add function of errbar.
8
+
5
9
  ## [0.1.1] - 2023-12-27
6
10
 
7
11
  ### add
data/Rakefile CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'rake/javaextensiontask'
2
2
 
3
+ jars = Dir.glob("lib/*.jar")
3
4
  Rake::JavaExtensionTask.new(name='num4tststatistic') do | ext |
4
5
  ext.release = '11'
5
- ext.classpath = 'lib/commons-math3-3.6.1.jar'
6
+ ext.classpath = jars.map { |x| File.expand_path x }.join ":"
6
7
  end
7
8
  task :default => [:compile]
@@ -0,0 +1,167 @@
1
+ import org.jfree.chart.ChartFactory;
2
+ import org.jfree.chart.StandardChartTheme;
3
+ import org.jfree.chart.JFreeChart;
4
+ import org.jfree.chart.StandardChartTheme;
5
+ import org.jfree.chart.plot.CategoryPlot;
6
+ import org.jfree.data.statistics.BoxAndWhiskerCategoryDataset;
7
+ import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
8
+ import org.jfree.data.statistics.BoxAndWhiskerCalculator;
9
+ import org.jfree.data.statistics.BoxAndWhiskerItem;
10
+ import org.jfree.data.category.CategoryDataset;
11
+ import org.jfree.data.category.DefaultCategoryDataset;
12
+ import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
13
+ import org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator;
14
+ import org.jfree.chart.plot.PlotOrientation;
15
+ import org.jfree.chart.plot.DatasetRenderingOrder;
16
+ import org.jfree.chart.axis.CategoryAxis;
17
+ import org.jfree.chart.axis.NumberAxis;
18
+ import org.jfree.chart.renderer.category.LineAndShapeRenderer;
19
+ import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
20
+
21
+ import org.jfree.chart.ChartUtils;
22
+ import java.io.File;
23
+ import java.io.IOException;
24
+
25
+ import java.util.Arrays;
26
+ import java.util.List;
27
+ import java.util.ArrayList;
28
+
29
+ import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
30
+ public class Outlier {
31
+ private static Outlier outlier = new Outlier();
32
+ public static Outlier getInstance() {
33
+ return outlier;
34
+ }
35
+ public double grubbs(double[] xi, double xk) {
36
+ Grubbs g = new Grubbs();
37
+
38
+ return g.calcStatistics(xi, xk);
39
+ }
40
+
41
+ public void errbar(String dname, double[] xi) {
42
+ ChartPlot plot = new ErrorBarChartPlot();
43
+ JFreeChart chart = plot.createChart("エラーバー", dname, xi);
44
+
45
+ plot.writeJPEG("errbar.jpeg", chart, 800, 500);
46
+
47
+ }
48
+ /*********************************/
49
+ /* interface define */
50
+ /*********************************/
51
+ private interface ChartPlot {
52
+ JFreeChart createChart(String title, String dname, double[] xi);
53
+ default void writeJPEG(String fname, JFreeChart chart, int width, int height) {
54
+ File file = new File(fname);
55
+ try {
56
+ ChartUtils.saveChartAsJPEG(file, chart, width, height);
57
+ } catch (IOException e) {
58
+ e.printStackTrace();
59
+ }
60
+ }
61
+ }
62
+ private interface CreatePlot {
63
+ CategoryPlot createPlot(String dname, double[] xi);
64
+ }
65
+ /*********************************/
66
+ /* Class define */
67
+ /*********************************/
68
+ //
69
+ private class Grubbs {
70
+ private SummaryStatistics stat = new SummaryStatistics();
71
+ public double calcStatistics(double[] xi, double xk) {
72
+ Arrays.stream(xi).forEach(stat::addValue);
73
+ double m = stat.getMean(); // 平均
74
+ double sd = stat.getStandardDeviation();// 標準偏差
75
+ double min = stat.getMin();
76
+ double max = stat.getMax();
77
+ double t = 0.0;
78
+
79
+ if (xk == min) { t = (m - xk) / sd; }
80
+ if (xk == max) { t = (xk - m) / sd; }
81
+ return t;
82
+ }
83
+ }
84
+ // error bar
85
+ private class ErrorBarChartPlot implements ChartPlot{
86
+ public JFreeChart createChart(String title, String dname, double[] xi) {
87
+ CategoryPlot plot = createPlot(dname, xi);
88
+
89
+ ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
90
+ JFreeChart chart = new JFreeChart(title, plot);
91
+
92
+ ChartUtils.applyCurrentTheme(chart);
93
+ return chart;
94
+ }
95
+ private CategoryPlot createPlot(String dname, double[] xi) {
96
+ CreatePlot plotImpl = new ErrorBarPlot();
97
+
98
+ return plotImpl.createPlot(dname, xi);
99
+ }
100
+ public class ErrorBarPlot implements CreatePlot {
101
+ public CategoryPlot createPlot(String dname, double[] xi) {
102
+ BoxAndWhiskerRenderer renderer0 = new BoxAndWhiskerRenderer();
103
+ LineAndShapeRenderer renderer1 = new LineAndShapeRenderer(false, true);
104
+
105
+ renderer0.setDefaultToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
106
+ renderer0.setMaximumBarWidth(0.2);
107
+ renderer1.setDefaultToolTipGenerator(
108
+ new StandardCategoryToolTipGenerator());
109
+
110
+ CategoryPlot plot = new CategoryPlot();
111
+ plot.setOrientation(PlotOrientation.VERTICAL);
112
+ plot.mapDatasetToRangeAxis(0,0);
113
+ plot.mapDatasetToRangeAxis(1,0);
114
+ plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
115
+
116
+ /*--- 横軸 ---*/
117
+ CategoryAxis categoryAxis = new CategoryAxis();
118
+ plot.setDomainAxis(categoryAxis);
119
+
120
+ /*--- 縦軸 ---*/
121
+ NumberAxis valueAxis = new NumberAxis();
122
+ valueAxis.setAutoRangeIncludesZero(false);
123
+ plot.setRangeAxis(valueAxis);
124
+
125
+ plot.setRenderer(0, renderer0);
126
+ plot.setDataset(0, createDataset0(dname, xi));
127
+ plot.setRenderer(1, renderer1);
128
+ plot.setDataset(1, createDataset1(dname, xi));
129
+
130
+ return plot;
131
+ }
132
+ private CategoryDataset createDataset0(String dname, double[] xi) {
133
+ DefaultBoxAndWhiskerCategoryDataset data =
134
+ new DefaultBoxAndWhiskerCategoryDataset();
135
+ List<Double> values = new ArrayList<Double>();
136
+ Arrays.stream(xi).forEach(values::add);
137
+
138
+ BoxAndWhiskerItem item =
139
+ BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values);
140
+
141
+ data.add(item, dname, "dt1");
142
+ return data;
143
+ }
144
+ private CategoryDataset createDataset1(String dname, double[] xi) {
145
+ DefaultCategoryDataset data = new DefaultCategoryDataset();
146
+ SummaryStatistics stat = new SummaryStatistics();
147
+ List<Double> values = new ArrayList<Double>();
148
+
149
+ Arrays.stream(xi).forEach(stat::addValue);
150
+ Arrays.stream(xi).forEach(values::add);
151
+
152
+ BoxAndWhiskerItem item =
153
+ BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values);
154
+ double minQ = ((Double)item.getMinOutlier()).doubleValue();
155
+ double min = stat.getMin();
156
+ double maxQ = ((Double)item.getMaxOutlier()).doubleValue();
157
+ double max = stat.getMax();
158
+
159
+ if (min < minQ) { data.addValue(min, dname, "dt1"); };
160
+ if (max > maxQ) { data.addValue(max, dname, "dt1"); };
161
+ return data;
162
+ }
163
+ }
164
+ }
165
+ }
166
+
167
+
Binary file
Binary file
@@ -1,8 +1,9 @@
1
1
  require 'java'
2
2
  require 'num4tststatistic.jar'
3
3
  require 'commons-math3-3.6.1.jar'
4
+ require 'jfreechart-1.5.4.jar'
4
5
 
5
- java_import 'TstStatistic'
6
+ java_import 'Outlier'
6
7
  java_import 'ParametrixTest'
7
8
  java_import 'NonParametrixTest'
8
9
 
@@ -319,7 +320,10 @@ module Num4TstStatisticLib
319
320
  return @nonParamTest.ks2test(xi1.to_java(Java::double), xi2.to_java(Java::double), a)
320
321
  end
321
322
  end
322
- class << self
323
+ class OutlierLib
324
+ def initialize
325
+ @outlier = Outlier.getInstance()
326
+ end
323
327
  # グラプス・スミルノフの外れ値の検定量
324
328
  #
325
329
  # @overload grubbs(xi, xk)
@@ -333,7 +337,22 @@ module Num4TstStatisticLib
333
337
  # @note
334
338
  # 外れ値の検定に従う
335
339
  def grubbs(xi, xk)
336
- return TstStatistic.grubbs(xi.to_java(Java::double), xk)
340
+ return @outlier.grubbs(xi.to_java(Java::double), xk)
341
+ end
342
+ # エラーバー出力
343
+ #
344
+ # @overload errbar(dname, xi)
345
+ # @param [String] dname データ名
346
+ # @param [Array] xi xiのデータ(double[])
347
+ # @return [void] errbar.jpegファイルを出力
348
+ # @example
349
+ # xi = [3.4, 3.5, 3.3, 2.2, 3.3, 3.4, 3.6, 3.2]
350
+ # Num4TstStatisticLib.grubbs("LDH", xi)
351
+ # => errbar.jpeg
352
+ # @note
353
+ # グラフは、jfreechartを使用
354
+ def errbar(dname, xi)
355
+ return @outlier.errbar(dname, xi.to_java(Java::double))
337
356
  end
338
357
  end
339
358
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: num4tststatistic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: java
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-27 00:00:00.000000000 Z
11
+ date: 2024-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -62,9 +62,11 @@ files:
62
62
  - LICENSE
63
63
  - Rakefile
64
64
  - ext/num4tststatistic/NonParametrixTest.java
65
+ - ext/num4tststatistic/Outlier.java
65
66
  - ext/num4tststatistic/ParametrixTest.java
66
- - ext/num4tststatistic/TstStatistic.java
67
67
  - lib/commons-math3-3.6.1.jar
68
+ - lib/jcommon-1.0.23.jar
69
+ - lib/jfreechart-1.5.4.jar
68
70
  - lib/num4tststatistic.rb
69
71
  homepage: http://github.com/siranovel/num4tststatistic
70
72
  licenses:
@@ -1,21 +0,0 @@
1
- import java.util.Arrays;
2
-
3
- import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
4
- public class TstStatistic {
5
- public static double grubbs(double[] xi, double xk) {
6
- SummaryStatistics stat = new SummaryStatistics();
7
-
8
- Arrays.stream(xi).forEach(stat::addValue);
9
- double m = stat.getMean(); // 平均
10
- double sd = stat.getStandardDeviation();// 標準偏差
11
- double min = stat.getMin();
12
- double max = stat.getMax();
13
- double t = 0.0;
14
-
15
- if (xk == min) { t = (m - xk) / sd; }
16
- if (xk == max) { t = (xk - m) / sd; }
17
- return t;
18
- }
19
- }
20
-
21
-