rulelearn-ripper-interactive 0.2.3__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.
- rulelearn_ripper_interactive-0.2.3/LICENSE +201 -0
- rulelearn_ripper_interactive-0.2.3/NOTICE +11 -0
- rulelearn_ripper_interactive-0.2.3/PKG-INFO +164 -0
- rulelearn_ripper_interactive-0.2.3/README.md +126 -0
- rulelearn_ripper_interactive-0.2.3/pyproject.toml +51 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/__init__.py +6 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/__init__.py +0 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/r2n/__init__.py +0 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/r2n/base.py +28 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/r2n/functions.py +25 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/r2n/mask.py +58 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/r2n/preprocessing_layers.py +192 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/r2n/r2n_algo.py +287 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/r2n/simple_rulenet.py +75 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/r2n/training.py +34 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/r2n/utilities.py +117 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/__init__.py +0 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/boolean_rule_cg.py +65 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/rbm/BRCG.py +69 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/rbm/GLRM.py +98 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/rbm/__init__.py +6 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/rbm/beam_search.py +302 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/rbm/boolean_rule_cg.py +245 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/rbm/features.py +544 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/rbm/linear_regression.py +393 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/rbm/logistic_regression.py +447 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/rbm/utils.py +13 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/ripper/__init__.py +10 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/ripper/base.py +81 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/ripper/binding.py +541 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/ripper/mdl.py +97 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/ripper/pruning.py +212 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/ripper/ripper.py +600 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/ripper/ripper_ruleset_generator.py +26 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/algorithms/ripper/single_rule.py +425 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/dise.py +64 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/__init__.py +0 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/classifier/__init__.py +0 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/classifier/ruleset_classifier.py +153 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/core/__init__.py +5 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/core/boolean_evaluator.py +15 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/core/conjunction.py +50 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/core/dnf_ruleset.py +64 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/core/feature.py +155 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/core/predicate.py +98 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/core/ruleset_generator.py +25 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/core/utils.py +40 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/metrics.py +98 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/__init__.py +4 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/__version__.py +1 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/__init__.py +24 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/attribute.py +24 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/characteristics.py +20 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/data_dictionary.py +53 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/mining_schema.py +25 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/pmml_ruleset_model.py +16 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/predicate.py +42 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/rule.py +26 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/ruleset.py +28 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/ruleset_model.py +16 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/models/scorecard.py +35 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/pmml_exporter.py +18 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/reader/__init__.py +2 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/reader/abstract_reader.py +16 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/reader/trxf_reader.py +113 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/serializer/__init__.py +2 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/serializer/abstract_serializer.py +11 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/pmml_export/serializer/nyoka_serializer.py +162 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/scorecard/__init__.py +3 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/scorecard/bins.py +253 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/scorecard/partition.py +71 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ri/trxf/scorecard/scorecard.py +78 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ripper_interactive.egg-info/PKG-INFO +164 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ripper_interactive.egg-info/SOURCES.txt +76 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ripper_interactive.egg-info/dependency_links.txt +1 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ripper_interactive.egg-info/requires.txt +16 -0
- rulelearn_ripper_interactive-0.2.3/rulelearn_ripper_interactive.egg-info/top_level.txt +1 -0
- rulelearn_ripper_interactive-0.2.3/setup.cfg +4 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
rulelearn-ripper-interactive
|
|
2
|
+
Copyright 2026 Aaron Kurz, Hagen Voelzer
|
|
3
|
+
|
|
4
|
+
This product is derived from rulelearn (https://github.com/IBM/rulelearn),
|
|
5
|
+
originally released as part of AI Explainability 360
|
|
6
|
+
(https://github.com/Trusted-AI/AIX360), Copyright IBM Corporation,
|
|
7
|
+
licensed under the Apache License, Version 2.0.
|
|
8
|
+
|
|
9
|
+
Modifications in this fork include constrained single-rule RIPPER optimization
|
|
10
|
+
(optimize_single_rule), pandas 3 compatibility, and renaming of the import
|
|
11
|
+
package to rulelearn_ri.
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rulelearn-ripper-interactive
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: Rule induction toolkit (fork of IBM rulelearn) with interactive, constrained single-rule RIPPER optimization
|
|
5
|
+
Author-email: Aaron Kurz <aaron.kurz@unisg.ch>, Hagen Voelzer <hagen.voelzer@unisg.ch>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/aaronkurz/rulelearn-ripper-interactive
|
|
8
|
+
Project-URL: Upstream, https://github.com/IBM/rulelearn
|
|
9
|
+
Keywords: rule induction,ripper,interpretable machine learning,explainability,rule learning
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
License-File: NOTICE
|
|
24
|
+
Requires-Dist: numpy
|
|
25
|
+
Requires-Dist: pandas
|
|
26
|
+
Requires-Dist: scikit-learn
|
|
27
|
+
Requires-Dist: numba
|
|
28
|
+
Requires-Dist: nyoka==5.4.0
|
|
29
|
+
Provides-Extra: rbm
|
|
30
|
+
Requires-Dist: cvxpy; extra == "rbm"
|
|
31
|
+
Requires-Dist: ecos; extra == "rbm"
|
|
32
|
+
Requires-Dist: matplotlib; extra == "rbm"
|
|
33
|
+
Provides-Extra: r2n
|
|
34
|
+
Requires-Dist: torch; extra == "r2n"
|
|
35
|
+
Provides-Extra: all
|
|
36
|
+
Requires-Dist: rulelearn-ripper-interactive[r2n,rbm]; extra == "all"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# rulelearn-ripper-interactive
|
|
40
|
+
|
|
41
|
+
A rule induction toolkit for learning readable, editable rules from data. It is a fork of
|
|
42
|
+
[IBM's rulelearn](https://github.com/IBM/rulelearn) that adds **interactive, constrained
|
|
43
|
+
single-rule optimization** for RIPPER. You can grow and prune a single conjunctive rule
|
|
44
|
+
while forcing some features or predicates into it and keeping others out.
|
|
45
|
+
|
|
46
|
+
The package installs as `rulelearn_ri`, so it can be installed side by side with the
|
|
47
|
+
upstream `rulelearn` package.
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install rulelearn-ripper-interactive
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
or, to add it to a [uv](https://docs.astral.sh/uv/) project:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
uv add rulelearn-ripper-interactive
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The core install covers RIPPER and TRXF (rule interchange, metrics and PMML export).
|
|
62
|
+
The other algorithms need heavier dependencies, available as extras:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install "rulelearn-ripper-interactive[rbm]" # BRCG / GLRM (cvxpy, ecos, matplotlib)
|
|
66
|
+
pip install "rulelearn-ripper-interactive[r2n]" # Relational Rule Network (torch)
|
|
67
|
+
pip install "rulelearn-ripper-interactive[all]" # everything
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
With uv, use `uv add "rulelearn-ripper-interactive[rbm]"` (or `[r2n]`, `[all]`) instead.
|
|
71
|
+
|
|
72
|
+
Requires Python 3.10 or newer.
|
|
73
|
+
|
|
74
|
+
## Single-rule optimization
|
|
75
|
+
|
|
76
|
+
`optimize_single_rule` learns one conjunctive rule for a target label and returns it as a
|
|
77
|
+
TRXF `Conjunction`:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import pandas as pd
|
|
81
|
+
from rulelearn_ri.algorithms.ripper import optimize_single_rule
|
|
82
|
+
|
|
83
|
+
df = pd.DataFrame({
|
|
84
|
+
'x': [1.0, 2.0, 3.0, 4.0],
|
|
85
|
+
'target': ['True', 'True', 'False', 'False'],
|
|
86
|
+
})
|
|
87
|
+
X, y = df.drop(columns='target'), df['target']
|
|
88
|
+
|
|
89
|
+
rule = optimize_single_rule(X, y, target_label='True')
|
|
90
|
+
print(rule)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Constraints let you steer the rule:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from rulelearn_ri.trxf.core import Feature, Predicate, Relation
|
|
97
|
+
|
|
98
|
+
# Force the feature `x` to appear in the rule (the boundary is still optimized)
|
|
99
|
+
optimize_single_rule(X, y, target_label='True', fixed_attributes=['x'])
|
|
100
|
+
|
|
101
|
+
# Force a specific predicate, with a fixed boundary, into the rule
|
|
102
|
+
optimize_single_rule(
|
|
103
|
+
X, y, target_label='True',
|
|
104
|
+
fixed_predicates=[Predicate(Feature('x'), Relation.LE, 2.5)],
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
# Keep a feature out of the rule (must not clash with any forced feature or predicate)
|
|
108
|
+
optimize_single_rule(X, y, target_label='True', forbidden_attributes=['x'])
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Further options: `pruning_threshold` (minimum number of instances for the grow/prune
|
|
112
|
+
split, default 20), `random_state` (seed for the split, default 0) and `ratio`
|
|
113
|
+
(fraction of the data used for growing, default 2/3).
|
|
114
|
+
|
|
115
|
+
## Included algorithms
|
|
116
|
+
|
|
117
|
+
- Fast Effective Rule Induction (RIPPER) ([William W Cohen, 1995](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.107.2612&rep=rep1&type=pdf)),
|
|
118
|
+
including the full rule-set learner `RipperExplainer`
|
|
119
|
+
- Boolean Decision Rules via Column Generation (Light Edition) ([Dash et al., 2018](https://papers.nips.cc/paper/7716-boolean-decision-rules-via-column-generation)), extra `rbm`
|
|
120
|
+
- Generalized Linear Rule Models ([Wei et al., 2019](http://proceedings.mlr.press/v97/wei19a.html)), extra `rbm`
|
|
121
|
+
- Relational Rule Network (R2N) ([Kusters et al., 2022](https://arxiv.org/abs/2201.06515)), extra `r2n`
|
|
122
|
+
- TRXF (Technical Rule Interchange Format): a common rule-set representation with evaluation tools
|
|
123
|
+
and PMML export
|
|
124
|
+
|
|
125
|
+
Example notebooks are in the [`examples/`](https://github.com/aaronkurz/rulelearn-ripper-interactive/tree/main/examples) directory of the repository.
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
This project uses [uv](https://docs.astral.sh/uv/):
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
git clone git@github.com:aaronkurz/rulelearn-ripper-interactive.git
|
|
133
|
+
cd rulelearn-ripper-interactive
|
|
134
|
+
uv sync --all-extras
|
|
135
|
+
uv run pytest
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Releasing
|
|
139
|
+
|
|
140
|
+
1. Bump `version` in `pyproject.toml`.
|
|
141
|
+
2. Build and check the distributions:
|
|
142
|
+
```bash
|
|
143
|
+
rm -rf dist && uv build
|
|
144
|
+
uvx twine check --strict dist/*
|
|
145
|
+
```
|
|
146
|
+
3. Upload to TestPyPI first, then check it installs in a clean environment:
|
|
147
|
+
```bash
|
|
148
|
+
uv publish --publish-url https://test.pypi.org/legacy/ --token <testpypi-token>
|
|
149
|
+
```
|
|
150
|
+
4. Upload to PyPI and tag the release:
|
|
151
|
+
```bash
|
|
152
|
+
uv publish --token <pypi-token>
|
|
153
|
+
git tag v<version> && git push origin v<version>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Acknowledgements
|
|
157
|
+
|
|
158
|
+
This package is derived from [rulelearn](https://github.com/IBM/rulelearn) by IBM,
|
|
159
|
+
originally released as part of [AI Explainability 360](https://github.com/Trusted-AI/AIX360).
|
|
160
|
+
See [NOTICE](https://github.com/aaronkurz/rulelearn-ripper-interactive/blob/main/NOTICE) for details.
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
Apache License 2.0. See [LICENSE](https://github.com/aaronkurz/rulelearn-ripper-interactive/blob/main/LICENSE).
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# rulelearn-ripper-interactive
|
|
2
|
+
|
|
3
|
+
A rule induction toolkit for learning readable, editable rules from data. It is a fork of
|
|
4
|
+
[IBM's rulelearn](https://github.com/IBM/rulelearn) that adds **interactive, constrained
|
|
5
|
+
single-rule optimization** for RIPPER. You can grow and prune a single conjunctive rule
|
|
6
|
+
while forcing some features or predicates into it and keeping others out.
|
|
7
|
+
|
|
8
|
+
The package installs as `rulelearn_ri`, so it can be installed side by side with the
|
|
9
|
+
upstream `rulelearn` package.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install rulelearn-ripper-interactive
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
or, to add it to a [uv](https://docs.astral.sh/uv/) project:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
uv add rulelearn-ripper-interactive
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The core install covers RIPPER and TRXF (rule interchange, metrics and PMML export).
|
|
24
|
+
The other algorithms need heavier dependencies, available as extras:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install "rulelearn-ripper-interactive[rbm]" # BRCG / GLRM (cvxpy, ecos, matplotlib)
|
|
28
|
+
pip install "rulelearn-ripper-interactive[r2n]" # Relational Rule Network (torch)
|
|
29
|
+
pip install "rulelearn-ripper-interactive[all]" # everything
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
With uv, use `uv add "rulelearn-ripper-interactive[rbm]"` (or `[r2n]`, `[all]`) instead.
|
|
33
|
+
|
|
34
|
+
Requires Python 3.10 or newer.
|
|
35
|
+
|
|
36
|
+
## Single-rule optimization
|
|
37
|
+
|
|
38
|
+
`optimize_single_rule` learns one conjunctive rule for a target label and returns it as a
|
|
39
|
+
TRXF `Conjunction`:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import pandas as pd
|
|
43
|
+
from rulelearn_ri.algorithms.ripper import optimize_single_rule
|
|
44
|
+
|
|
45
|
+
df = pd.DataFrame({
|
|
46
|
+
'x': [1.0, 2.0, 3.0, 4.0],
|
|
47
|
+
'target': ['True', 'True', 'False', 'False'],
|
|
48
|
+
})
|
|
49
|
+
X, y = df.drop(columns='target'), df['target']
|
|
50
|
+
|
|
51
|
+
rule = optimize_single_rule(X, y, target_label='True')
|
|
52
|
+
print(rule)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Constraints let you steer the rule:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from rulelearn_ri.trxf.core import Feature, Predicate, Relation
|
|
59
|
+
|
|
60
|
+
# Force the feature `x` to appear in the rule (the boundary is still optimized)
|
|
61
|
+
optimize_single_rule(X, y, target_label='True', fixed_attributes=['x'])
|
|
62
|
+
|
|
63
|
+
# Force a specific predicate, with a fixed boundary, into the rule
|
|
64
|
+
optimize_single_rule(
|
|
65
|
+
X, y, target_label='True',
|
|
66
|
+
fixed_predicates=[Predicate(Feature('x'), Relation.LE, 2.5)],
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Keep a feature out of the rule (must not clash with any forced feature or predicate)
|
|
70
|
+
optimize_single_rule(X, y, target_label='True', forbidden_attributes=['x'])
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Further options: `pruning_threshold` (minimum number of instances for the grow/prune
|
|
74
|
+
split, default 20), `random_state` (seed for the split, default 0) and `ratio`
|
|
75
|
+
(fraction of the data used for growing, default 2/3).
|
|
76
|
+
|
|
77
|
+
## Included algorithms
|
|
78
|
+
|
|
79
|
+
- Fast Effective Rule Induction (RIPPER) ([William W Cohen, 1995](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.107.2612&rep=rep1&type=pdf)),
|
|
80
|
+
including the full rule-set learner `RipperExplainer`
|
|
81
|
+
- Boolean Decision Rules via Column Generation (Light Edition) ([Dash et al., 2018](https://papers.nips.cc/paper/7716-boolean-decision-rules-via-column-generation)), extra `rbm`
|
|
82
|
+
- Generalized Linear Rule Models ([Wei et al., 2019](http://proceedings.mlr.press/v97/wei19a.html)), extra `rbm`
|
|
83
|
+
- Relational Rule Network (R2N) ([Kusters et al., 2022](https://arxiv.org/abs/2201.06515)), extra `r2n`
|
|
84
|
+
- TRXF (Technical Rule Interchange Format): a common rule-set representation with evaluation tools
|
|
85
|
+
and PMML export
|
|
86
|
+
|
|
87
|
+
Example notebooks are in the [`examples/`](https://github.com/aaronkurz/rulelearn-ripper-interactive/tree/main/examples) directory of the repository.
|
|
88
|
+
|
|
89
|
+
## Development
|
|
90
|
+
|
|
91
|
+
This project uses [uv](https://docs.astral.sh/uv/):
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
git clone git@github.com:aaronkurz/rulelearn-ripper-interactive.git
|
|
95
|
+
cd rulelearn-ripper-interactive
|
|
96
|
+
uv sync --all-extras
|
|
97
|
+
uv run pytest
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Releasing
|
|
101
|
+
|
|
102
|
+
1. Bump `version` in `pyproject.toml`.
|
|
103
|
+
2. Build and check the distributions:
|
|
104
|
+
```bash
|
|
105
|
+
rm -rf dist && uv build
|
|
106
|
+
uvx twine check --strict dist/*
|
|
107
|
+
```
|
|
108
|
+
3. Upload to TestPyPI first, then check it installs in a clean environment:
|
|
109
|
+
```bash
|
|
110
|
+
uv publish --publish-url https://test.pypi.org/legacy/ --token <testpypi-token>
|
|
111
|
+
```
|
|
112
|
+
4. Upload to PyPI and tag the release:
|
|
113
|
+
```bash
|
|
114
|
+
uv publish --token <pypi-token>
|
|
115
|
+
git tag v<version> && git push origin v<version>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Acknowledgements
|
|
119
|
+
|
|
120
|
+
This package is derived from [rulelearn](https://github.com/IBM/rulelearn) by IBM,
|
|
121
|
+
originally released as part of [AI Explainability 360](https://github.com/Trusted-AI/AIX360).
|
|
122
|
+
See [NOTICE](https://github.com/aaronkurz/rulelearn-ripper-interactive/blob/main/NOTICE) for details.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
Apache License 2.0. See [LICENSE](https://github.com/aaronkurz/rulelearn-ripper-interactive/blob/main/LICENSE).
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rulelearn-ripper-interactive"
|
|
7
|
+
version = "0.2.3"
|
|
8
|
+
description = "Rule induction toolkit (fork of IBM rulelearn) with interactive, constrained single-rule RIPPER optimization"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Aaron Kurz", email = "aaron.kurz@unisg.ch" },
|
|
15
|
+
{ name = "Hagen Voelzer", email = "hagen.voelzer@unisg.ch" },
|
|
16
|
+
]
|
|
17
|
+
keywords = ["rule induction", "ripper", "interpretable machine learning", "explainability", "rule learning"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 4 - Beta",
|
|
20
|
+
"Intended Audience :: Science/Research",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Programming Language :: Python :: 3.14",
|
|
28
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"numpy",
|
|
32
|
+
"pandas",
|
|
33
|
+
"scikit-learn",
|
|
34
|
+
"numba",
|
|
35
|
+
"nyoka==5.4.0",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
rbm = ["cvxpy", "ecos", "matplotlib"]
|
|
40
|
+
r2n = ["torch"]
|
|
41
|
+
all = ["rulelearn-ripper-interactive[rbm,r2n]"]
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
Repository = "https://github.com/aaronkurz/rulelearn-ripper-interactive"
|
|
45
|
+
Upstream = "https://github.com/IBM/rulelearn"
|
|
46
|
+
|
|
47
|
+
[dependency-groups]
|
|
48
|
+
dev = ["pytest", "xmltodict"]
|
|
49
|
+
|
|
50
|
+
[tool.setuptools.packages.find]
|
|
51
|
+
include = ["rulelearn_ri*"]
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
from torch import nn
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class RuleNetwork(nn.Module, ABC):
|
|
7
|
+
"""
|
|
8
|
+
Encapsulates a neural network that corresponds syntactically to some ruleset.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
@abstractmethod
|
|
12
|
+
def extract_ruleset(self):
|
|
13
|
+
""" Extract a symbolic representation of the learned ruleset. The semantics of the ruleset must be provided
|
|
14
|
+
externally.
|
|
15
|
+
|
|
16
|
+
:return: A 2D list representing a ruleset in Disjunctive Normal Form. An inner list takes values from {-1, 0, 1}
|
|
17
|
+
representing a single rule, indicating the inclusion of the negated condition, exclusion,
|
|
18
|
+
and inclusion of the condition, respectively.
|
|
19
|
+
E.g. [[1, 0, 0, -1], [0, 1, 0, 0]] represents the ruleset
|
|
20
|
+
"(condition0 ^ not condition3) v condition1" for a rule network with 4 input conditions.
|
|
21
|
+
"""
|
|
22
|
+
raise NotImplementedError
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class PredicateLearningLayer(nn.Module, ABC):
|
|
26
|
+
@abstractmethod
|
|
27
|
+
def get_predicates(self, *args, **kwargs):
|
|
28
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DifferentiableHeaviside(torch.autograd.Function):
|
|
5
|
+
@staticmethod
|
|
6
|
+
def forward(ctx, input):
|
|
7
|
+
ctx.save_for_backward(input)
|
|
8
|
+
return torch.heaviside(input, torch.ones_like(input))
|
|
9
|
+
|
|
10
|
+
@staticmethod
|
|
11
|
+
def backward(ctx, grad_output):
|
|
12
|
+
input, = ctx.saved_tensors
|
|
13
|
+
return grad_output * torch.sigmoid(input) * (1 - torch.sigmoid(input))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DifferentiableClamp(torch.autograd.Function):
|
|
17
|
+
@staticmethod
|
|
18
|
+
def forward(ctx, input):
|
|
19
|
+
ctx.save_for_backward(input)
|
|
20
|
+
return torch.clamp(input, max=1)
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def backward(ctx, grad_output):
|
|
24
|
+
input, = ctx.saved_tensors
|
|
25
|
+
return grad_output
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
from torch import nn
|
|
5
|
+
|
|
6
|
+
from rulelearn_ri.algorithms.r2n.functions import DifferentiableHeaviside
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class WeightMask(nn.Module, ABC):
|
|
10
|
+
"""
|
|
11
|
+
Abstract class for the mask that is applied to the weight matrix of the NN.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, dim_out, dim_in):
|
|
15
|
+
super(WeightMask, self).__init__()
|
|
16
|
+
self.dim_out = dim_out
|
|
17
|
+
self.dim_in = dim_in
|
|
18
|
+
self.loc = torch.nn.Parameter(torch.randn(self.dim_out, self.dim_in), requires_grad=True)
|
|
19
|
+
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def forward(self):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class SimpleWeightMask(WeightMask):
|
|
26
|
+
"""
|
|
27
|
+
Binary weight mask that is used in the AND/OR layer. Note that depening of the Boolean value cooling, we either implement a cooled sigmoid or stricly binary differentiable heavyside function.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(self, dim_out, dim_in, temp, cooling):
|
|
31
|
+
super(SimpleWeightMask, self).__init__(dim_out, dim_in)
|
|
32
|
+
self.cooling = cooling
|
|
33
|
+
self.temp = temp
|
|
34
|
+
|
|
35
|
+
def forward(self):
|
|
36
|
+
if self.cooling is True:
|
|
37
|
+
return torch.sigmoid((1 / self.temp) * self.loc)
|
|
38
|
+
else:
|
|
39
|
+
return DifferentiableHeaviside.apply(self.loc)
|
|
40
|
+
|
|
41
|
+
def set_temp(self, temp):
|
|
42
|
+
self.temp = temp
|
|
43
|
+
|
|
44
|
+
def get_temp(self):
|
|
45
|
+
return self.temp
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class DeterministicWeightMask(WeightMask):
|
|
49
|
+
"""
|
|
50
|
+
Simple deterministic weight mask.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def __init__(self, mask):
|
|
54
|
+
super(DeterministicWeightMask, self).__init__(mask.size()[0], mask.size()[1])
|
|
55
|
+
self.mask = mask
|
|
56
|
+
|
|
57
|
+
def forward(self):
|
|
58
|
+
return self.mask
|