pyfmtools 5.3.8__tar.gz → 5.4.0__tar.gz

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.
Files changed (107) hide show
  1. {pyfmtools-5.3.8/src/pyfmtools.egg-info → pyfmtools-5.4.0}/PKG-INFO +9 -2
  2. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/setup.py +1 -1
  3. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/buildPyfmtools.py +15 -1
  4. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/fmrandomsort.inc +1 -1
  5. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/fuzzymeasurefit.cpp +2 -0
  6. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/fuzzymeasurefit.h +2 -0
  7. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/fuzzymeasurefit3.cpp +286 -0
  8. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/fuzzymeasuretools.cpp +105 -12
  9. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/fuzzymeasuretools.h +5 -1
  10. {pyfmtools-5.3.8 → pyfmtools-5.4.0/src/pyfmtools.egg-info}/PKG-INFO +9 -2
  11. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/pyfmtools.py +67 -8
  12. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/wrapperpy.cpp +246 -10
  13. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/wrapperpy.h +19 -8
  14. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/tests/test_wrapper.py +27 -3
  15. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/LICENSE.txt +0 -0
  16. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/MANIFEST.in +0 -0
  17. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/README.md +0 -0
  18. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/setup.cfg +0 -0
  19. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/binarylattice.h +0 -0
  20. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/colamd.c +0 -0
  21. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/colamd.h +0 -0
  22. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/commonlib.c +0 -0
  23. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/commonlib.h +0 -0
  24. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/declare.h +0 -0
  25. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/fmrandom.cpp +0 -0
  26. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/fmrandom.h +0 -0
  27. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/fortify.h +0 -0
  28. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/gbrealloc.c +0 -0
  29. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/generaldefs.h +0 -0
  30. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/hbio.h +0 -0
  31. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/ini.c +0 -0
  32. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/ini.h +0 -0
  33. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/isfixedvar.c +0 -0
  34. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_BFP.h +0 -0
  35. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_BFP1.h +0 -0
  36. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_BFP2.h +0 -0
  37. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_Hash.c +0 -0
  38. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_Hash.h +0 -0
  39. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_LUSOL.c +0 -0
  40. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_LUSOL.h +0 -0
  41. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_MDO.c +0 -0
  42. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_MDO.h +0 -0
  43. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_MPS.c +0 -0
  44. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_MPS.h +0 -0
  45. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_SOS.c +0 -0
  46. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_SOS.h +0 -0
  47. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_crash.c +0 -0
  48. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_crash.h +0 -0
  49. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_etaPFI.h +0 -0
  50. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_explicit.h +0 -0
  51. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_fortify.h +0 -0
  52. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_lib.c +0 -0
  53. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_lib.h +0 -0
  54. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_matrix.c +0 -0
  55. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_matrix.h +0 -0
  56. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_mipbb.c +0 -0
  57. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_mipbb.h +0 -0
  58. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_params.c +0 -0
  59. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_presolve.c +0 -0
  60. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_presolve.h +0 -0
  61. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_price.c +0 -0
  62. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_price.h +0 -0
  63. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_pricePSE.c +0 -0
  64. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_pricePSE.h +0 -0
  65. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_report.c +0 -0
  66. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_report.h +0 -0
  67. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_rlp.h +0 -0
  68. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_scale.c +0 -0
  69. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_scale.h +0 -0
  70. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_simplex.c +0 -0
  71. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_simplex.h +0 -0
  72. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_types.h +0 -0
  73. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_utils.c +0 -0
  74. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_utils.h +0 -0
  75. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_wlp.c +0 -0
  76. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lp_wlp.h +0 -0
  77. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lpkit.h +0 -0
  78. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lpslink56.c +0 -0
  79. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lpsolve.h +0 -0
  80. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusol.c +0 -0
  81. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusol.h +0 -0
  82. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusol1.h +0 -0
  83. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusol2.h +0 -0
  84. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusol6a.h +0 -0
  85. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusol6l0.h +0 -0
  86. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusol6u.h +0 -0
  87. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusol7a.h +0 -0
  88. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusol8a.h +0 -0
  89. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusolio.c +0 -0
  90. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/lusolio.h +0 -0
  91. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/minimalsplus.h +0 -0
  92. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/mmio.c +0 -0
  93. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/mmio.h +0 -0
  94. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/myblas.c +0 -0
  95. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/myblas.h +0 -0
  96. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/pyfmtools.egg-info/SOURCES.txt +0 -0
  97. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/pyfmtools.egg-info/dependency_links.txt +0 -0
  98. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/pyfmtools.egg-info/requires.txt +0 -0
  99. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/pyfmtools.egg-info/top_level.txt +0 -0
  100. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/sparselib.c +0 -0
  101. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/sparselib.h +0 -0
  102. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/stdafx.h +0 -0
  103. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/ufortify.h +0 -0
  104. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/yacc_read.c +0 -0
  105. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/src/yacc_read.h +0 -0
  106. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/tests/test_no_wrapper.py +0 -0
  107. {pyfmtools-5.3.8 → pyfmtools-5.4.0}/tests/test_wrapper0.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: pyfmtools
3
- Version: 5.3.8
3
+ Version: 5.4.0
4
4
  Summary: Library for handling and fitting fuzzy measures
5
5
  Home-page:
6
6
  Author: Gleb Beliakov, Norbert Henseler
@@ -8,6 +8,13 @@ Author-email: gleb.beliakov@deakin.edu.au, norbert.henseler@deakin.edu.au
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE.txt
10
10
  Requires-Dist: cffi>=1.0.0
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: license-file
16
+ Dynamic: requires-dist
17
+ Dynamic: summary
11
18
 
12
19
  # Pyfmtools
13
20
  Pyfmtools provides various tools for handling fuzzy measures, calculating various indices, Choquet and Sugeno integrals, as well as fitting fuzzy measures to empirical data. This package is designed for Python , but it also includes the C++ source files and a user manual.
@@ -10,7 +10,7 @@ with open("README.md", "r") as fh:
10
10
 
11
11
  setup(
12
12
  name="pyfmtools",
13
- version="5.3.8",
13
+ version="5.4.0",
14
14
  description="Library for handling and fitting fuzzy measures",
15
15
  long_description=open('README.md').read(),
16
16
  long_description_content_type="text/markdown",
@@ -19,7 +19,16 @@ ffibuilder.cdef(r"""
19
19
  int xx[44];};
20
20
  double py_min_subset(double* x, int n, int_64 S);
21
21
  double py_max_subset(double* x, int n, int_64 S);
22
+ int py_IsSubset( int_64 A, int_64 B);
23
+ int py_IsInSet( int_64 A, int B);
24
+ int py_Setunion( int_64 A, int_64 B);
25
+ int py_Setintersection( int_64 A, int_64 B);
26
+ int py_Setdiff( int_64 A, int_64 B);
27
+ int_64 py_AddToSet( int_64 A, int i);
28
+ int_64 py_RemoveFromSet( int_64 A, int i);
29
+ int py_Cardinality( int_64 A);
22
30
  void py_ConvertCard2Bit(double* dest, double* src, struct fm_env* env);
31
+ void py_ConvertBit2Card(double* dest, double* src, struct fm_env* env);
23
32
  double py_min_subsetC(double* x, int n, int_64 S, struct fm_env* env);
24
33
  double py_max_subsetNegC(double* x, int n, int_64 S, struct fm_env* env);
25
34
  int py_SizeArraykinteractive(int n, int k, struct fm_env* env);
@@ -46,13 +55,14 @@ ffibuilder.cdef(r"""
46
55
  void py_FuzzyMeasureFitKtolerant(int datanum, int additive, struct fm_env* env, double* v, double* dataset);
47
56
  void py_FuzzyMeasureFitLPKmaxitive(int datanum, int additive, struct fm_env* env, double* v, double* dataset);
48
57
  void py_FuzzyMeasureFitLPKinteractive(int datanum, int additive, struct fm_env* env, double* v, double* dataset, double* K);
58
+ void py_FuzzyMeasureFitLPKinteractiveLP(int datanum, int additive, struct fm_env* env, double* v, double* dataset, double* K, double* R);
49
59
  void py_FuzzyMeasureFitLPKinteractiveMaxChains(int datanum, int additive, struct fm_env* env, double* v, double* dataset, double* K);
50
60
  void py_FuzzyMeasureFitLPKinteractiveAutoK(int datanum, int additive, struct fm_env* env, double* v, double* dataset, double* K, int* maxiters);
51
61
  void py_FuzzyMeasureFitLPKinteractiveMarginal(int datanum, int additive, struct fm_env* env, double* v, double* dataset, double* K, int submod);
52
62
  void py_FuzzyMeasureFitLPKinteractiveMarginalMaxChain(int datanum, int additive, struct fm_env* env, double* v, double* dataset, double* K, int* maxiters, int submod);
53
63
  void py_FuzzyMeasureFitLP(int datanum, int additive, struct fm_env* env, double* v, double* dataset, int * options, double* indexlow, double* indexhihg, int* option1, double* orness);
54
64
  void py_FuzzyMeasureFitLPMob(int datanum, int additive, struct fm_env* env, double* v, double* dataset, int * options, double* indexlow, double* indexhihg, int* option1, double* orness);
55
- void py_fittingOWA(int datanum, struct fm_env* env, double* v, double* dataset);
65
+ void py_fittingOWA(int datanum, struct fm_env* env, double* v, double* dataset, int ensureon);
56
66
  void py_fittingWAM(int datanum, struct fm_env* env, double* v, double* dataset);
57
67
  void py_Interaction(double* Mob, double* v, struct fm_env* env);
58
68
  void py_InteractionB(double* Mob, double* v, struct fm_env* env);
@@ -149,6 +159,10 @@ ffibuilder.cdef(r"""
149
159
  int py_generate_fm_2additive_randomwalk2(int num, int n, int markov, int option, double step, double * vv, void* extrachecks);
150
160
  int py_generate_fm_minimals_le(int num, int n, int markov, double ratio, double* weights, int_64* vv, struct fm_env* env);
151
161
  int py_generate_fm_minimals(int num, int n, int markov, double ratio, double* weights, double* vv, struct fm_env* env);
162
+ void py_CCM2FM(double* v, double* B, struct fm_env* env);
163
+ void py_FM2CCM(double* v, double* B, struct fm_env* env);
164
+ void py_CCM2Mob(double* v, double* B, struct fm_env* env);
165
+ void py_Mob2CCM(double* v, double* B, struct fm_env* env);
152
166
  """, override=True)
153
167
 
154
168
  pyfmtools_src=['src/colamd.c','src/lp_lib.c','src/lp_params.c','src/lp_simplex.c','src/lusolio.c','src/commonlib.c','src/lp_LUSOL.c','src/lp_presolve.c','src/lpslink56.c','src/mmio.c',
@@ -115,7 +115,7 @@ LIBDLL_API int generate_fm_sorting01(int_64 num, int n, int markov, int option,
115
115
  values[0] = 0; values[m - 1] = 1;
116
116
  // this is unbalanced
117
117
 
118
- for (int_64 i = 1; i < m - 1; i++) values[i] = values[i] * p + (1 - p) * bal[bit2card[i]];
118
+ for (int_64 i = 1; i < m - 1; i++) values[i] = values[i] * p + (1 - p) * bal[i];
119
119
 
120
120
  }
121
121
  values[0] = 0; values[m - 1] = 1; // empty set and N
@@ -507,6 +507,8 @@ int FuzzyMeasureFitLPsymmetric(int n, int K, double *v, double* XYData, int opt
507
507
  // next equality constraint = add to 1
508
508
  double wei=K; // this constraint is taken with that weight, to ensure it is actually satisfied
509
509
  if(wei<1) wei=1;
510
+
511
+ if(options==2) wei=0; // no add to one constraint
510
512
  // despite roundoff errors
511
513
  row[0]=wei; rowno[0]=0; k=1;
512
514
  for(i=0;i<RowsC1+n;i++) {
@@ -208,3 +208,5 @@ LIBDLL_API int FuzzyMeasureFit2additive(int n, int datanum, int length,
208
208
 
209
209
  LIBDLL_API int LinearFunctionFitLP(int n, int K, double *v, double* XYData, int options);
210
210
 
211
+ LIBDLL_API int FuzzyMeasureFitLPKinteractiveLP(int n, int_64 m, int K, int Kadd, double *v, double* XYData, int options,
212
+ double* indexlow, double* indexhigh, int option1, double* orness, double KConst, double Rconst);
@@ -2259,3 +2259,289 @@ LIBDLL_API int FuzzyMeasureFit2additive(int n, int datanum, int length,
2259
2259
 
2260
2260
 
2261
2261
 
2262
+
2263
+ // new 5.4, involves K, R in LP
2264
+ int FuzzyMeasureFitLPKinteractiveLP(int n, int_64 m, int K, int Kadd, double *v, double* XYData, int options,
2265
+ double* indexlow, double* indexhigh, int option1, double* orness, double KConst, double Rconst)
2266
+
2267
+ // in standard representation
2268
+ // K for data, Kadd for k-interactive f.m.
2269
+ // KConst the bound on the constant K for k-interactive fm
2270
+ // uses free Kconst and Rconst if they are specified as negatives
2271
+
2272
+ {
2273
+
2274
+ int counter = 0;
2275
+ unsigned int i, j, k, res;
2276
+ int result;
2277
+ int_64 A, B, C;
2278
+ lprec *MyLP;
2279
+ unsigned int RowsR, RowsC, RowsC1;
2280
+
2281
+ if (Kadd >= n) {
2282
+ Kadd = n - 1; KConst = Rconst;
2283
+ }
2284
+ if (Kadd == n - 1) KConst = Rconst;
2285
+
2286
+ RowsC1 = (cardpos[Kadd] - n - 1); //how many non-singletons ///Check this mu(0)=0. Also fewer variables as all are positive
2287
+ RowsR = K * 2; RowsC = n + RowsC1; /// removed *2
2288
+ unsigned int RowsC2 = (cardpos[Kadd - 1]); // position of the second last cardinality
2289
+ unsigned int ExtraRows=2;
2290
+
2291
+ MyLP = make_lp(RowsR + RowsC + ExtraRows, 0);
2292
+ MyLP->do_presolve = FALSE;
2293
+ set_verbose(MyLP, 0);
2294
+ unsigned int itemp = RowsC + 2 + 1 + ExtraRows; // just the max number of entries per column
2295
+
2296
+ double *row;
2297
+ int *rowno;
2298
+ row = new double[itemp];
2299
+ rowno = new int[itemp];
2300
+ int* ind=new int[n];
2301
+
2302
+ // int re;
2303
+
2304
+ // the first K columns
2305
+ rowno[0] = 0;
2306
+ double factor = 1.0 / (n - Kadd - 1);
2307
+
2308
+ for (k = 0; k<(unsigned int)K; k++) {
2309
+ //rowno[0] is the obj. function
2310
+ row[0] = XYData[k*(n + 1) + n];//y[k]; //
2311
+ rowno[0] = 0;
2312
+
2313
+ myiota(ind, ind + n, 0); // found in <numeric>
2314
+ sort(ind, ind + n, compare_indirect_index <double*>(&(XYData[k*(n + 1)]))); // decreasing order now
2315
+
2316
+ double coefK=0;
2317
+ for (i = 0; i < (unsigned int)(n - Kadd - 1); i++) {
2318
+ coefK += ((&(XYData[k*(n + 1)]))[ind[n-i-1]]);
2319
+ }
2320
+ double coefR=coefK*factor;
2321
+ coefK =-coefK*factor;
2322
+ coefK += ((&(XYData[k*(n + 1)]))[ind[Kadd]]);
2323
+
2324
+ //todo not to include 0
2325
+
2326
+ rowno[1] = k + 1; // 1-based
2327
+ rowno[2] = k + 1 + K;
2328
+ row[1] = -1;
2329
+ row[2] = 1;
2330
+ // now the vales of h_A
2331
+
2332
+ itemp = 0;
2333
+ for (i = 0; i<(unsigned int)n; i++) {// singletons
2334
+ row[2 + itemp + 1] = maxf(0, XYData[k*(n + 1) + i] - max_subset_complement(&(XYData[k*(n + 1)]), n, card2bit[i + 1]));
2335
+ rowno[2 + itemp + 1] = RowsR + i + 1;
2336
+ if (row[2 + itemp + 1] != 0) {
2337
+ counter++; itemp++;
2338
+ }
2339
+ }
2340
+
2341
+
2342
+ //todo: do I need zeroes?
2343
+
2344
+ for (i = 0; i<RowsC1; i++) {
2345
+ row[2 + itemp + 1] = maxf(0, min_subset(&(XYData[k*(n + 1)]), n, card2bit[i + 1 + n]) - max_subset_complement(&(XYData[k*(n + 1)]), n, card2bit[i + 1 + n])); /// new function g_A, need max_subset_complement, also need to move 1s to the RHS with y
2346
+ rowno[2 + itemp + 1] = RowsR + n + i + 1; // was +n in the index
2347
+
2348
+ if (row[2 + itemp + 1] != 0) { counter++; itemp++; }
2349
+ // row[2+i +n + RowsC1+1]= - row[2+i +n+1] ;
2350
+ // rowno[2+i+n + RowsC1+1] = RowsR + n + i +1 + RowsC1;
2351
+ }
2352
+
2353
+ // add K and R
2354
+ rowno[2 + itemp + 1] = RowsR + n + RowsC1 + 1; // was +n in the index
2355
+ row[2 + itemp + 1] =coefK;
2356
+ itemp++;
2357
+
2358
+ rowno[2 + itemp + 1] = RowsR + n + RowsC1+1 + 1; // was +n in the index
2359
+ row[2 + itemp + 1] =coefR;
2360
+ itemp++;
2361
+
2362
+ add_columnex(MyLP, itemp+3, row, rowno);
2363
+
2364
+ // now repeat everything, just change the sign
2365
+ for (i = 0; i<itemp+3; i++) row[i] = -row[i];
2366
+
2367
+ add_columnex(MyLP, itemp+3, row, rowno);
2368
+
2369
+ }
2370
+
2371
+ /// I do not need this as m(N)=1
2372
+
2373
+ // now monotonicity constraints for all |A|>2
2374
+
2375
+
2376
+ for (A = n + 1; A <= RowsC; A++){ ///check if we need <=
2377
+ // cout<<"start subset "<< A<<endl;
2378
+ C = card2bit[A];
2379
+ for (i = 0; i<(unsigned int)n; i++) if (IsInSet(C, i)) { ///check if inequality is reverse
2380
+ row[0] = 0; rowno[0] = 0;
2381
+ k = 1;
2382
+ row[k] = 1;
2383
+ rowno[k] = int( A + RowsR);
2384
+ k++;
2385
+ B = C;
2386
+ RemoveFromSet(&B, i);
2387
+ row[k] = -1;
2388
+ rowno[k] = int(bit2card[B] + RowsR);
2389
+ k++;
2390
+ add_columnex(MyLP, k, row, rowno);
2391
+
2392
+ counter += k;
2393
+ }
2394
+
2395
+ } // A
2396
+
2397
+
2398
+ for (A = RowsC2; A <= RowsC; A++){ ///check if we need <=1 ????????????????
2399
+ // constraint K-m(A)>0
2400
+ row[0] = 0.0; rowno[0] = 0; // Kconst
2401
+ //row[0] = 0;
2402
+ k = 1;
2403
+ row[k] = -1;
2404
+ rowno[k] = int(A + RowsR);
2405
+ k++;
2406
+ row[k] = 1; // Kconst
2407
+ rowno[k] = int(RowsR + n + RowsC1 + 1);
2408
+ k++;
2409
+
2410
+ add_columnex(MyLP, k, row, rowno);
2411
+
2412
+ counter += k;
2413
+ } // i
2414
+
2415
+ //} // subsets
2416
+
2417
+ // add interaction indices if needed
2418
+
2419
+ /// no orness or other options
2420
+
2421
+ // if Rconst and Kconst given, assign their values
2422
+
2423
+
2424
+ // K<R
2425
+ k=3;
2426
+ row[0] = 0.0; rowno[0] = 0; // Kconst
2427
+ row[1]=-1; rowno[1]=RowsR + n + RowsC1 + 1;
2428
+ row[2]=1; rowno[2]=RowsR + n + RowsC1 + 2;
2429
+ add_columnex(MyLP, k, row, rowno);
2430
+ counter += k;
2431
+
2432
+
2433
+ if(KConst>0)
2434
+ {
2435
+ k=2;
2436
+ row[0] = KConst; rowno[0] = 0; // Kconst
2437
+ row[1]=1; rowno[1]=RowsR + n + RowsC1 + 1;
2438
+ add_columnex(MyLP, k, row, rowno);
2439
+ counter += k;
2440
+ row[0] = -KConst;
2441
+ row[1]=-1;
2442
+ add_columnex(MyLP, k, row, rowno);
2443
+ counter += k;
2444
+ }
2445
+
2446
+ if(Rconst>0)
2447
+ {
2448
+ k=2;
2449
+ row[0] = Rconst; rowno[0] = 0; // Kconst
2450
+ row[1]=1; rowno[1]=RowsR + n + RowsC1 + 2;
2451
+ add_columnex(MyLP, k, row, rowno);
2452
+ counter += k;
2453
+ row[0] = -Rconst;
2454
+ row[1]=-1;
2455
+ add_columnex(MyLP, k, row, rowno);
2456
+ counter += k;
2457
+ }
2458
+
2459
+ int RR = get_Nrows(MyLP);
2460
+ int CC = get_Ncolumns(MyLP);
2461
+ for (i = 1; i <= (unsigned int)RR; i++) {
2462
+ set_rh(MyLP, i, 0);
2463
+ set_constr_type(MyLP, i, LE);
2464
+
2465
+ }
2466
+ // for (i = 1; i <= (unsigned int)CC; i++) {
2467
+ // set_bounds(MyLP, i, 0.0, 1.0);
2468
+ // }
2469
+
2470
+
2471
+ for (i = 1; i <= RowsR ; i++) {
2472
+ set_rh(MyLP, i, 1.0);
2473
+ }
2474
+ // for (i = RowsR + RowsC2; i <= RR; i++) {
2475
+ // set_rh(MyLP, i, KConst);
2476
+ // }
2477
+
2478
+ set_maxim(MyLP); // well, we always do that
2479
+
2480
+
2481
+
2482
+ double *sol = (double*)malloc(sizeof(double)*(1 + RR + CC + ExtraRows));
2483
+
2484
+ // cout << n <<"\t"<<K <<"\t"<<Kadd<<"\t"<< RR << "\t" << CC << "\t"<<counter<<endl;
2485
+
2486
+ write_lp(MyLP, "model.lp");
2487
+ // cout<<"finished building LP "<< RR<< " " <<CC<<endl;
2488
+ set_outputfile(MyLP, "log.txt");
2489
+
2490
+ print_lp(MyLP);
2491
+
2492
+ // set_verbose(MyLP,5);
2493
+ // set_outputstream(MyLP, stdout);
2494
+ // print_lp(MyLP);
2495
+ /// change recovery from the output...
2496
+
2497
+ res = solve(MyLP);
2498
+ double minval=10e10;
2499
+
2500
+ if (res == OPTIMAL) {
2501
+ // temp=0;
2502
+ get_dual_solution(MyLP, sol);
2503
+ print_solution(MyLP, 1);
2504
+ minval = get_objective(MyLP); // minimum
2505
+
2506
+ // for (i = 0; i < RR + 1 ; i++) cout << sol[i] << endl;
2507
+ // cout<<" min value "<<minval<<" "<<res<<endl;
2508
+
2509
+ v[0] = 0;// always !!
2510
+ for (i = 1; i <= (unsigned int)n; i++)
2511
+ {
2512
+ v[i] = sol[i + RowsR]; // singletons
2513
+ }
2514
+ for (i = 0; i<RowsC1; i++)
2515
+ {
2516
+ v[i + n + 1] = sol[n + RowsR + 1 + i]; ////- sol[n+RowsR+1 + RowsC1+i]; // other subsets
2517
+ k++;
2518
+ }
2519
+ k = n + RowsC1+1;
2520
+
2521
+ double RC, KC;
2522
+ KC=sol[RowsR + n + RowsC1 + 1];
2523
+ RC=sol[RowsR + n + RowsC1 + 2];
2524
+
2525
+ for (int_64 ii = k; ii < m; ii++){
2526
+ j = card[card2bit[ii]];
2527
+ if (Kadd<n - 1)
2528
+ v[ii] = KC + (j - Kadd - 1.0)*(RC - KC) / (n - Kadd - 1);
2529
+ else v[ii] = KC;
2530
+
2531
+ }
2532
+
2533
+ result = 1;
2534
+ } // no optimal
2535
+ else result = 0;
2536
+
2537
+ // just to cheat the compiler
2538
+ minval = minval + 1;
2539
+ delete[] row;
2540
+ delete[] rowno;
2541
+ delete[] ind;
2542
+
2543
+
2544
+ free(sol);
2545
+ delete_lp(MyLP);
2546
+ return result;
2547
+ }
@@ -230,7 +230,7 @@ int_64 RemoveHighestBit(int_64 a, int K) {
230
230
 
231
231
 
232
232
 
233
- inline int Cardinality(int_64 A) { return bitweight(A); }
233
+ int Cardinality(int_64 A) { return bitweight(A); }
234
234
 
235
235
 
236
236
  unsigned int ShowValue(int_64 s) {
@@ -613,6 +613,70 @@ void Zeta(double* Mob, double* v, int n, int_64 m)
613
613
  v[i]=s;
614
614
  }
615
615
  }
616
+ void FM2CCM(double* v, double* ccm, int n, int_64 m)
617
+ {
618
+ int_64 i;
619
+ int_64 id;
620
+ double s;
621
+ for(i=0;i<m;i++) {
622
+ s=0;
623
+
624
+ for(id=i;id < m;id++) if(IsSubset(id,i)) { // supersets
625
+ int r=1;
626
+ if(IsOdd(Cardinality(id)-Cardinality(i))) r=-1;
627
+ s += r* v[id] ;
628
+ }
629
+ ccm[i]=s;
630
+ }
631
+ }
632
+
633
+ void CCM2FM(double* ccm, double* v, int n, int_64 m)
634
+ {
635
+ int_64 i;
636
+ int_64 id;
637
+ double s;
638
+ for(i=0;i<m;i++) {
639
+ s=0;
640
+ for(id=i;id < m;id++) if(IsSubset(id,i)) { // supersets
641
+ s += ccm[id] ;
642
+ }
643
+ v[i]=s;
644
+ }
645
+ }
646
+
647
+ void Mob2CCM(double* Mob, double* ccm, int n, int_64 m)
648
+ {
649
+ int_64 i;
650
+ int_64 id;
651
+ double s;
652
+ for(i=0;i<m;i++) {
653
+ s=0;
654
+ int r=1;
655
+ if(IsOdd(n-Cardinality(i))) r=-1;
656
+ int_64 NI=Setdiff(m-1,i);
657
+ for(id=NI;id < m;id++) if(IsSubset(id,NI)) { // supersets
658
+ s += Mob[id] ;
659
+ }
660
+ ccm[i]=r*s;
661
+ }
662
+ }
663
+
664
+ void CCM2Mob(double* ccm, double* Mob, int n, int_64 m)
665
+ {
666
+ int_64 i;
667
+ int_64 id;
668
+ double s;
669
+ for(i=0;i<m;i++) {
670
+ s=0;
671
+ int r=1;
672
+ if(IsOdd(1+Cardinality(i)) )r=-1;
673
+ for(id=1;id < m;id++) if(Setintersection(id,i)>0) { // set intersection no null
674
+ s += ccm[id] ;
675
+ }
676
+ Mob[i]=r*s;
677
+ }
678
+ }
679
+
616
680
 
617
681
 
618
682
  void Shapley(double* v, double* x, int n, int_64 m)
@@ -1352,11 +1416,23 @@ void dualMobKadd( myfloat* src, myfloat* dest, int m, int length, int k)
1352
1416
 
1353
1417
  }
1354
1418
 
1355
- // todo: for k-additive, should follow dualMobKadd process with right coefficients
1356
- void Shapley2addMob(double* v, double* x, int n)
1357
- // calculates the array x of Shapley values for 2 additive fm in compact representation (cardinality based)
1419
+
1420
+ void Banzhaf2addMob(double* v, double* x, int n)
1421
+ // calculates the array x of Banzhaf indices for 2 additive fm in compact representation (cardinality based)
1358
1422
  {
1359
- // the formula is singleton + all pairs/2
1423
+
1424
+ for (int i = 0;i < n; i++)
1425
+ x[i]= v[i]; // singleton
1426
+
1427
+ int start=n;
1428
+ for (int i = 0;i < n; i++)
1429
+ for (int j = i+1;j < n;j++){
1430
+ x[i] += v[start] *0.5;
1431
+ x[j] += v[start] *0.5 ;
1432
+ start++;
1433
+ }
1434
+ /*
1435
+ // the formula is singleton + all pairs/3
1360
1436
  for (int i = 0;i < n; i++) {
1361
1437
  x[i] = v[i]; // singleton
1362
1438
 
@@ -1364,8 +1440,8 @@ void Shapley2addMob(double* v, double* x, int n)
1364
1440
  start += (i - 1); if (start < n) start = n; // special case i==0
1365
1441
  if (i > 0) step = n - 1;
1366
1442
  for (int j = 1;j < n;j++) {
1367
- x[i] += v[start] * 0.5; // pair
1368
- // cout << start << " ";
1443
+ x[i] += v[start] *0.5; // pair
1444
+ // cout << start << " ";
1369
1445
  if (row < i) {
1370
1446
  step -= 1; row++; if (row == i) start++;
1371
1447
  }// row not reached
@@ -1375,12 +1451,18 @@ void Shapley2addMob(double* v, double* x, int n)
1375
1451
  start += step;
1376
1452
  }
1377
1453
  }
1454
+ */
1378
1455
  }
1379
1456
 
1380
- void Banzhaf2addMob(double* v, double* x, int n)
1381
- // calculates the array x of Banzhaf indices for 2 additive fm in compact representation (cardinality based)
1457
+
1458
+
1459
+ // todo: for k-additive, should follow dualMobKadd process with right coefficients
1460
+ void Shapley2addMob(double* v, double* x, int n)
1461
+ // calculates the array x of Shapley values for 2 additive fm in compact representation (cardinality based)
1382
1462
  {
1383
- // the formula is singleton + all pairs/3
1463
+ Banzhaf2addMob(v,x,n); // they are the same
1464
+ return;
1465
+ // the formula is singleton + all pairs/2
1384
1466
  for (int i = 0;i < n; i++) {
1385
1467
  x[i] = v[i]; // singleton
1386
1468
 
@@ -1388,8 +1470,8 @@ void Banzhaf2addMob(double* v, double* x, int n)
1388
1470
  start += (i - 1); if (start < n) start = n; // special case i==0
1389
1471
  if (i > 0) step = n - 1;
1390
1472
  for (int j = 1;j < n;j++) {
1391
- x[i] += v[start] *0.5; // pair
1392
- // cout << start << " ";
1473
+ x[i] += v[start] * 0.5; // pair
1474
+ // cout << start << " ";
1393
1475
  if (row < i) {
1394
1476
  step -= 1; row++; if (row == i) start++;
1395
1477
  }// row not reached
@@ -1402,11 +1484,21 @@ void Banzhaf2addMob(double* v, double* x, int n)
1402
1484
  }
1403
1485
 
1404
1486
 
1487
+
1405
1488
  double Choquet2add(double*x, double* Mob, int n)
1406
1489
  /* This is a calculation of the Choquet integral from the Moebius transform for 2-additive capacities.
1407
1490
  */
1408
1491
  {
1409
1492
  double val = 0;
1493
+ for (int i = 0;i < n; i++)
1494
+ val+= Mob[i]*x[i]; // singleton
1495
+ int start=n;
1496
+ for (int i = 0;i < n; i++)
1497
+ for (int j = i+1;j < n;j++){
1498
+ val += Mob[start] * minf(x[i], x[j]);
1499
+ start++;
1500
+ }
1501
+ /*
1410
1502
  // the formula is singleton + all pairs/2
1411
1503
  for (int i = 0;i < n; i++) {
1412
1504
  val+= Mob[i]*x[i]; // singleton
@@ -1426,6 +1518,7 @@ double Choquet2add(double*x, double* Mob, int n)
1426
1518
  start += step;
1427
1519
  }
1428
1520
  }
1521
+ */
1429
1522
  return val;
1430
1523
  }
1431
1524
  /* ====================== Sparse FM in Mobius representation ==================================*/
@@ -187,7 +187,7 @@ LIBDLL_API inline int TopElement(int_64 a) {
187
187
  // return true is a= 11111...
188
188
  return (bitweight(a + 1) == 1);
189
189
  }
190
-
190
+ LIBDLL_API int Cardinality(int_64 A) ;
191
191
 
192
192
 
193
193
  #include "fmrandom.h"
@@ -381,6 +381,10 @@ LIBDLL_API int generate_fm_2additive_convex_sparse(int n, struct SparseFM* cap);
381
381
  /* this is actually a total monotone, Belief measure */
382
382
  LIBDLL_API int generate_fm_kadditive_convex_sparse(int n, int k, int nonzero, struct SparseFM* cap);
383
383
 
384
+ LIBDLL_API void FM2CCM(double* v, double* ccm, int n, int_64 m);
385
+ LIBDLL_API void CCM2FM(double* ccm, double* v, int n, int_64 m);
386
+ LIBDLL_API void Mob2CCM(double* Mob, double* ccm, int n, int_64 m);
387
+ LIBDLL_API void CCM2Mob(double* ccm, double* Mob, int n, int_64 m);
384
388
 
385
389
 
386
390
  #endif
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: pyfmtools
3
- Version: 5.3.8
3
+ Version: 5.4.0
4
4
  Summary: Library for handling and fitting fuzzy measures
5
5
  Home-page:
6
6
  Author: Gleb Beliakov, Norbert Henseler
@@ -8,6 +8,13 @@ Author-email: gleb.beliakov@deakin.edu.au, norbert.henseler@deakin.edu.au
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE.txt
10
10
  Requires-Dist: cffi>=1.0.0
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: license-file
16
+ Dynamic: requires-dist
17
+ Dynamic: summary
11
18
 
12
19
  # Pyfmtools
13
20
  Pyfmtools provides various tools for handling fuzzy measures, calculating various indices, Choquet and Sugeno integrals, as well as fitting fuzzy measures to empirical data. This package is designed for Python , but it also includes the C++ source files and a user manual.