numo-liblinear 2.3.0 → 2.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
  SHA256:
3
- metadata.gz: e365bea9ec3f7879a2eb5ca59356a5687b5f9991d850838e1667f3eff4177727
4
- data.tar.gz: e6943a95893d8ecbe8e7d1b690829e20c20820148f120ed3f6c6e0c5892043ad
3
+ metadata.gz: 5c3697071b67bf2898d6c75e461c4b40cfc1c665b06d36b007e2572487805afb
4
+ data.tar.gz: 595a2214e41b9654422cad1bf4604b1cb84df40f1430b5b7756e23bbb1f4ee95
5
5
  SHA512:
6
- metadata.gz: 4ec40f71737aa4bbea21726b7c38c2f66c1c8e98967c4098b6bb910bf54010becb48218fd1bee441a2d8fe5290d1a7114ecf06426ef2826c7b473186e757185a
7
- data.tar.gz: 133e1114abeccd511a38c785afeac8122d12cfa00e082e7384df067b13cec42050740b8d1f9a7669cadd9934985d7786f8bc7d13c6a56342a40b440474cb57d9
6
+ metadata.gz: cffb328201a5ad1be57613933dd28bf03e47c2cd439c5e601cf7b5c284d8cf0b2abcc0ad8aeab57d3e63651d43854a418e366b44d96d29a3b53e984f72b66407
7
+ data.tar.gz: c547f4c52f80c049e9ccb9eb033321367821bb3fc3fc474e99bf7acca9c7421435a30acc267aa6f4a65bff968abb47f4a2b0c5d5abb3426de12d6c1a55807af0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # [[2.4.0](https://github.com/yoshoku/numo-liblinear/compare/v2.3.0...v2.4.0)] - 2025-05-31
2
+
3
+ - Update bundled LIBLINEAR to 2.49
4
+ - Add `w_recalc` parameter.
5
+
1
6
  # 2.3.0
2
7
  - Update bundled LIBLINEAR to 2.46
3
8
 
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
@@ -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 = '2.4.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,14 +1,13 @@
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: 2.4.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
13
  name: numo-narray
@@ -63,7 +62,6 @@ metadata:
63
62
  source_code_uri: https://github.com/yoshoku/numo-liblinear
64
63
  documentation_uri: https://yoshoku.github.io/numo-liblinear/doc/
65
64
  rubygems_mfa_required: 'true'
66
- post_install_message:
67
65
  rdoc_options: []
68
66
  require_paths:
69
67
  - lib
@@ -78,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
76
  - !ruby/object:Gem::Version
79
77
  version: '0'
80
78
  requirements: []
81
- rubygems_version: 3.3.26
82
- signing_key:
79
+ rubygems_version: 3.6.7
83
80
  specification_version: 4
84
81
  summary: Numo::Liblinear is a Ruby gem binding to the LIBLINEAR library. Numo::Liblinear
85
82
  makes to use the LIBLINEAR functions with dataset represented by Numo::NArray.