numo-liblinear 2.3.0 → 3.0.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
  SHA256:
3
- metadata.gz: e365bea9ec3f7879a2eb5ca59356a5687b5f9991d850838e1667f3eff4177727
4
- data.tar.gz: e6943a95893d8ecbe8e7d1b690829e20c20820148f120ed3f6c6e0c5892043ad
3
+ metadata.gz: 801d6ed5e1bee82b834821190bd146dc2a0c2d99342808cf93d4521e4d74a0a2
4
+ data.tar.gz: 0dd5510dcd7cc2f2b5963141374c6993ca5030d5dc2c3d60a896ae336123b037
5
5
  SHA512:
6
- metadata.gz: 4ec40f71737aa4bbea21726b7c38c2f66c1c8e98967c4098b6bb910bf54010becb48218fd1bee441a2d8fe5290d1a7114ecf06426ef2826c7b473186e757185a
7
- data.tar.gz: 133e1114abeccd511a38c785afeac8122d12cfa00e082e7384df067b13cec42050740b8d1f9a7669cadd9934985d7786f8bc7d13c6a56342a40b440474cb57d9
6
+ metadata.gz: fa81218b4c8c4b7a6afad06e83606d57521a1dce0c75c76cb24ab92530639becdf57e89637a7be8f67c1a0d2fd0136c219a55d3e984e82df28920a7ccc764916
7
+ data.tar.gz: c2b756af42d1de564d2c4e527a96174239a240f85cd6f882cc4009f0cef0002e4001e9d133aba6bfa56ce1524c44fd394a22d6d99d5d9fbee297a80cd5c94b0c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # [[3.0.0](https://github.com/yoshoku/numo-liblinear/compare/v2.4.0...v3.0.0)] - 2025-10-01
2
+
3
+ **Breaking chage**
4
+
5
+ - Change dependency from numo-narray to [numo-narray-alt](https://github.com/yoshoku/numo-narray-alt).
6
+
7
+ # [[2.4.0](https://github.com/yoshoku/numo-liblinear/compare/v2.3.0...v2.4.0)] - 2025-05-31
8
+
9
+ - Update bundled LIBLINEAR to 2.49
10
+ - Add `w_recalc` parameter.
11
+
1
12
  # 2.3.0
2
13
  - Update bundled LIBLINEAR to 2.46
3
14
 
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2019-2023 Atsushi Tatsuma
1
+ Copyright (c) 2019-2025 Atsushi Tatsuma
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -14,6 +14,8 @@ Note: There are other useful Ruby gems binding to LIBLINEAR:
14
14
  [liblinear-ruby](https://github.com/kei500/liblinear-ruby) by Kei Tsuchiya and
15
15
  [liblinear-ruby-swig](https://github.com/tomz/liblinear-ruby-swig) by Tom Zeng.
16
16
 
17
+ Note: Since v3.0.0, this library uses [Numo::NArray Alternative](https://github.com/yoshoku/numo-narray-alt) instead of Numo::NArray as a dependency.
18
+
17
19
  ## Installation
18
20
  Numo::Liblinear bundles LIBLINEAR. There is no need to install LIBLINEAR in advance.
19
21
 
@@ -26,7 +26,19 @@ if RUBY_PLATFORM.match?(/darwin/) && Gem::Version.new('3.1.0') <= Gem::Version.n
26
26
  end
27
27
  end
28
28
 
29
- abort 'libstdc++ is not found.' unless have_library('stdc++')
29
+
30
+ have_libcpp = false
31
+ if RUBY_PLATFORM.include?('darwin')
32
+ if have_library('c++')
33
+ have_libcpp = true
34
+ else
35
+ warn 'libc++ is not found.'
36
+ end
37
+ end
38
+
39
+ if !have_libcpp && !RUBY_PLATFORM.include?('mswin')
40
+ warn 'libstdc++ is not found.' unless have_library('stdc++')
41
+ end
30
42
 
31
43
  $srcs = Dir.glob("#{$srcdir}/**/*.cpp").map { |path| File.basename(path) }
32
44
  $srcs.concat(%w[daxpy.c ddot.c dnrm2.c dscal.c])
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2019-2023 Atsushi Tatsuma
2
+ * Copyright (c) 2019-2024 Atsushi Tatsuma
3
3
  * All rights reserved.
4
4
  *
5
5
  * Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2019-2023 Atsushi Tatsuma
2
+ * Copyright (c) 2019-2024 Atsushi Tatsuma
3
3
  * All rights reserved.
4
4
  *
5
5
  * Redistribution and use in source and binary forms, with or without
@@ -234,6 +234,8 @@ LibLinearParameter* convertHashToLibLinearParameter(VALUE param_hash) {
234
234
  el = rb_hash_aref(param_hash, ID2SYM(rb_intern("init_sol")));
235
235
  param->init_sol = !NIL_P(el) ? convertNArrayToVectorXd(el) : NULL;
236
236
  param->regularize_bias = 1;
237
+ el = rb_hash_aref(param_hash, ID2SYM(rb_intern("w_recalc")));
238
+ param->w_recalc = !NIL_P(el) ? (RTEST(el) ? true : false) : false;
237
239
  return param;
238
240
  }
239
241
 
@@ -250,6 +252,7 @@ VALUE convertLibLinearParameterToHash(const LibLinearParameter* const param) {
250
252
  rb_hash_aset(param_hash, ID2SYM(rb_intern("p")), DBL2NUM(param->p));
251
253
  rb_hash_aset(param_hash, ID2SYM(rb_intern("nu")), DBL2NUM(param->nu));
252
254
  rb_hash_aset(param_hash, ID2SYM(rb_intern("init_sol")), Qnil);
255
+ rb_hash_aset(param_hash, ID2SYM(rb_intern("w_recalc")), param->w_recalc ? Qtrue : Qfalse);
253
256
  return param_hash;
254
257
  }
255
258
 
@@ -1064,6 +1064,21 @@ static int solve_l2r_l1l2_svc(const problem *prob, const parameter *param, doubl
1064
1064
  info("Objective value = %lf\n",v/2);
1065
1065
  info("nSV = %d\n",nSV);
1066
1066
 
1067
+ // Reconstruct w from the primal-dual relationship w=sum(\alpha_i y_i x_i)
1068
+ // This may reduce the weight density. Some zero weights become non-zeros
1069
+ // due to the numerical update w <- w + (alpha[i] - alpha_old) y_i x_i.
1070
+ if (param->w_recalc)
1071
+ {
1072
+ for(i=0; i<w_size; i++)
1073
+ w[i] = 0;
1074
+ for(i=0; i<l; i++)
1075
+ {
1076
+ feature_node * const xi = prob->x[i];
1077
+ if(alpha[i] > 0)
1078
+ sparse_operator::axpy(y[i]*alpha[i], xi, w);
1079
+ }
1080
+ }
1081
+
1067
1082
  delete [] QD;
1068
1083
  delete [] alpha;
1069
1084
  delete [] y;
@@ -2194,11 +2209,14 @@ static int partition(feature_node *nodes, int low, int high)
2194
2209
  return index;
2195
2210
  }
2196
2211
 
2197
- // rearrange nodes so that nodes[:k] contains nodes with the k smallest values.
2212
+ // rearrange nodes so that
2213
+ // nodes[i] <= nodes[k] for all i < k
2214
+ // nodes[k] <= nodes[j] for all j > k
2215
+ // low and high are the bounds of the index range during the rearranging process
2198
2216
  static void quick_select_min_k(feature_node *nodes, int low, int high, int k)
2199
2217
  {
2200
2218
  int pivot;
2201
- if(low == high)
2219
+ if(low == high || high < k)
2202
2220
  return;
2203
2221
  pivot = partition(nodes, low, high);
2204
2222
  if(pivot == k)
@@ -3718,6 +3736,11 @@ const char *check_parameter(const problem *prob, const parameter *param)
3718
3736
  && param->solver_type != L2R_L2LOSS_SVR)
3719
3737
  return "Initial-solution specification supported only for solvers L2R_LR, L2R_L2LOSS_SVC, and L2R_L2LOSS_SVR";
3720
3738
 
3739
+ if(param->w_recalc == true
3740
+ && param->solver_type != L2R_L2LOSS_SVC_DUAL
3741
+ && param->solver_type != L2R_L1LOSS_SVC_DUAL)
3742
+ return "Recalculating w in the end is only for dual solvers for L2-regularized L1/L2-loss SVM";
3743
+
3721
3744
  return NULL;
3722
3745
  }
3723
3746
 
@@ -1,7 +1,8 @@
1
+ #include <stdbool.h>
1
2
  #ifndef _LIBLINEAR_H
2
3
  #define _LIBLINEAR_H
3
4
 
4
- #define LIBLINEAR_VERSION 246
5
+ #define LIBLINEAR_VERSION 249
5
6
 
6
7
  #ifdef __cplusplus
7
8
  extern "C" {
@@ -39,6 +40,7 @@ struct parameter
39
40
  double nu;
40
41
  double *init_sol;
41
42
  int regularize_bias;
43
+ bool w_recalc; /* for -s 1, 3; may be extended to -s 12, 13, 21 */
42
44
  };
43
45
 
44
46
  struct model
@@ -3,6 +3,6 @@
3
3
  module Numo
4
4
  module Liblinear
5
5
  # The version of Numo::Liblienar you are using.
6
- VERSION = '2.3.0'
6
+ VERSION = '3.0.0'
7
7
  end
8
8
  end
@@ -36,6 +36,7 @@ module Numo
36
36
  weight: Numo::DFloat?,
37
37
  p: Float?,
38
38
  nu: Float?,
39
+ w_recalc: bool?,
39
40
  verbose: bool?,
40
41
  random_seed: Integer?
41
42
  }
metadata CHANGED
@@ -1,29 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-liblinear
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-03-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: numo-narray
13
+ name: numo-narray-alt
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ">="
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: 0.9.1
18
+ version: 0.9.3
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ">="
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: 0.9.1
25
+ version: 0.9.3
27
26
  description: |
28
27
  Numo::Liblinear is a Ruby gem binding to the LIBLINEAR library.
29
28
  LIBLINEAR is one of the famous libraries for large-scale regularized linear classification and regression.
@@ -61,9 +60,9 @@ licenses:
61
60
  metadata:
62
61
  homepage_uri: https://github.com/yoshoku/numo-liblinear
63
62
  source_code_uri: https://github.com/yoshoku/numo-liblinear
64
- documentation_uri: https://yoshoku.github.io/numo-liblinear/doc/
63
+ changelog_uri: https://github.com/yoshoku/numo-liblinear/blob/main/CHANGELOG.md
64
+ documentation_uri: https://gemdocs.org/gems/numo-liblinear/3.0.0/
65
65
  rubygems_mfa_required: 'true'
66
- post_install_message:
67
66
  rdoc_options: []
68
67
  require_paths:
69
68
  - lib
@@ -78,8 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
77
  - !ruby/object:Gem::Version
79
78
  version: '0'
80
79
  requirements: []
81
- rubygems_version: 3.3.26
82
- signing_key:
80
+ rubygems_version: 3.6.9
83
81
  specification_version: 4
84
82
  summary: Numo::Liblinear is a Ruby gem binding to the LIBLINEAR library. Numo::Liblinear
85
83
  makes to use the LIBLINEAR functions with dataset represented by Numo::NArray.