numo-liblinear 0.3.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: 0ae7bd5566c47d6b045d596945bf7b4b84955b22
4
- data.tar.gz: 13dc445acfcf11c6097dedbbf25544f19810cb60
3
+ metadata.gz: 31b76e6a2a8dcfc5cb643fa0b62cd9ace5b6a76c
4
+ data.tar.gz: 6d8b6d9ed6a7e069ca8fcb78fb9f8999ccdfe1c5
5
5
  SHA512:
6
- metadata.gz: 4dac8c681d092896a0d1947ed3374d4400ea224c3bc18c4fd2ebfa65aa504181e7c01f3ffb68452d92bb22bbe54fc61e831b9bc7197da26cf3908df8b59d9fc3
7
- data.tar.gz: 9b2a82a5a087a1f86113c10be3a11880b03357bb9e3b91191291f2824e26c672c542a7401a69638aefc3ef36a7bcee51bbdfcebad010f0f50c66460aa5e99fac
6
+ metadata.gz: 8efe216d52fc7bba1561f46c3a372e842d6bdaf371c9b71b7662e380a17e9c6396e4a67348156522a41785bf2a12f37675dd137f173a0f52b6c48528c9c70cf7
7
+ data.tar.gz: e23e845ed639ee5e7fff6cbbbe936feed71f3a7e16429c52a27872b019201818649de57576030fb996cd697ff490588a0ec8e8d1e452eb0d441baa4ea00bcf52
@@ -1,3 +1,7 @@
1
+ # 0.4.0
2
+ - Add verbose parameter to output learning process messages.
3
+ - Several documentation improvements.
4
+
1
5
  # 0.3.0
2
6
  - Add random_seed parameter for specifying seed to give to srand function.
3
7
  - Several documentation improvements.
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/yoshoku/numo-liblinear.svg?branch=master)](https://travis-ci.org/yoshoku/numo-liblinear)
4
4
  [![Gem Version](https://badge.fury.io/rb/numo-liblinear.svg)](https://badge.fury.io/rb/numo-liblinear)
5
5
  [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-liblinear/blob/master/LICENSE.txt)
6
- [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/gems/numo-liblinear/0.3.0)
6
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/gems/numo-liblinear/0.4.0)
7
7
 
8
8
  Numo::Liblinear is a Ruby gem binding to the [LIBLINEAR](https://www.csie.ntu.edu.tw/~cjlin/liblinear/) library.
9
9
  LIBLINEAR is one of the famous libraries for large-scale regularized linear classification and regression.
@@ -163,13 +163,14 @@ param = {
163
163
  solver_type: # [Integer] Type of Solver
164
164
  Numo::Liblinear::SolverType::L2R_L2LOSS_SVC_DUAL,
165
165
  eps: 0.01, # [Float] Stopping criterion
166
- C: 1, # [Float] Cost of constraints violation.
167
- nr_weight: 3, # [Integer] Number of weights.
168
- weight_label: # [Numo::Int32] Labels to add weight.
166
+ C: 1, # [Float] Cost of constraints violation
167
+ nr_weight: 3, # [Integer] Number of weights
168
+ weight_label: # [Numo::Int32] Labels to add weight
169
169
  Numo::Int32[0, 1, 2],
170
- weight: # [Numo::DFloat] Weight values.
170
+ weight: # [Numo::DFloat] Weight values
171
171
  Numo::DFloat[0.4, 0.4, 0.2],
172
- p: 0.1, # [Float] Sensitiveness of loss of support vector regression.
172
+ p: 0.1, # [Float] Sensitiveness of loss of support vector regression
173
+ verbose: false, # [Boolean] Whether to output learning process message
173
174
  random_seed: 1 # [Integer/Nil] Random seed
174
175
  }
175
176
  ```
@@ -53,6 +53,7 @@ VALUE numo_liblinear_train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_has
53
53
  narray_t* y_nary;
54
54
  char* err_msg;
55
55
  VALUE random_seed;
56
+ VALUE verbose;
56
57
  VALUE model_hash;
57
58
 
58
59
  if (CLASS_OF(x_val) != numo_cDFloat) {
@@ -99,7 +100,11 @@ VALUE numo_liblinear_train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_has
99
100
  return Qnil;
100
101
  }
101
102
 
102
- set_print_string_function(print_null);
103
+ verbose = rb_hash_aref(param_hash, ID2SYM(rb_intern("verbose")));
104
+ if (verbose != Qtrue) {
105
+ set_print_string_function(print_null);
106
+ }
107
+
103
108
  model = train(problem, param);
104
109
  model_hash = model_to_rb_hash(model);
105
110
  free_and_destroy_model(&model);
@@ -120,6 +125,28 @@ VALUE numo_liblinear_train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_has
120
125
  * @param param [Hash] The parameters of a model.
121
126
  * @param n_folds [Integer] The number of folds.
122
127
  *
128
+ * @example
129
+ * require 'numo/liblinear'
130
+ *
131
+ * # x: samples
132
+ * # y: labels
133
+ *
134
+ * # Define parameters of L2-regularized L2-loss support vector classification.
135
+ * param = {
136
+ * solver_type: Numo::Liblinear::SolverType::L2R_L2LOSS_SVC_DUAL,
137
+ * C: 1,
138
+ * random_seed: 1,
139
+ * verbose: true
140
+ * }
141
+ *
142
+ * # Perform 5-cross validation.
143
+ * n_folds = 5
144
+ * res = Numo::Liblinear::cv(x, y, param, n_folds)
145
+ *
146
+ * # Print mean accuracy.
147
+ * mean_accuracy = y.eq(res).count.fdiv(y.size)
148
+ * puts "Accuracy: %.1f %%" % (100 * mean_accuracy)
149
+ *
123
150
  * @raise [ArgumentError] If the sample array is not 2-dimensional, the label array is not 1-dimensional,
124
151
  * the sample array and label array do not have the same number of samples, or
125
152
  * the hyperparameter has an invalid value, this error is raised.
@@ -136,6 +163,7 @@ VALUE numo_liblinear_cross_validation(VALUE self, VALUE x_val, VALUE y_val, VALU
136
163
  narray_t* y_nary;
137
164
  char* err_msg;
138
165
  VALUE random_seed;
166
+ VALUE verbose;
139
167
  struct problem* problem;
140
168
  struct parameter* param;
141
169
 
@@ -187,7 +215,11 @@ VALUE numo_liblinear_cross_validation(VALUE self, VALUE x_val, VALUE y_val, VALU
187
215
  t_val = rb_narray_new(numo_cDFloat, 1, t_shape);
188
216
  t_pt = (double*)na_get_pointer_for_write(t_val);
189
217
 
190
- set_print_string_function(print_null);
218
+ verbose = rb_hash_aref(param_hash, ID2SYM(rb_intern("verbose")));
219
+ if (verbose != Qtrue) {
220
+ set_print_string_function(print_null);
221
+ }
222
+
191
223
  cross_validation(problem, param, n_folds, t_pt);
192
224
 
193
225
  xfree_problem(problem);
@@ -3,6 +3,6 @@
3
3
  module Numo
4
4
  module Liblinear
5
5
  # The version of Numo::Liblienar you are using.
6
- VERSION = '0.3.0'
6
+ VERSION = '0.4.0'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-liblinear
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-22 00:00:00.000000000 Z
11
+ date: 2019-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray