predicateneuron 0.1.1__tar.gz → 0.1.2__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.
- predicateneuron-0.1.2/.idea/workspace.xml +119 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/PKG-INFO +1 -1
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/pyproject.toml +1 -1
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/src/predicateneuron/__init__.py +1 -1
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/src/predicateneuron/keras/functional.py +4 -6
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/src/predicateneuron/torch/functional.py +5 -4
- predicateneuron-0.1.1/.idea/workspace.xml +0 -75
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/.gitignore +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/.idea/.gitignore +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/.idea/misc.xml +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/.idea/modules.xml +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/.idea/predicateneuron.iml +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/.idea/vcs.xml +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/CITATION.cff +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/LICENSE +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/README.md +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/reference/original_tf.py +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/src/predicateneuron/keras/__init__.py +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/src/predicateneuron/keras/layers.py +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/src/predicateneuron/tf.py +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/src/predicateneuron/torch/__init__.py +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/src/predicateneuron/torch/layers.py +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/tests/test_keras.py +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/tests/test_parity_with_original.py +0 -0
- {predicateneuron-0.1.1 → predicateneuron-0.1.2}/tests/test_torch.py +0 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ChangeListManager">
|
|
4
|
+
<list default="true" id="559a1296-1549-4b57-aea7-e3c5fde5b111" name="Changes" comment="">
|
|
5
|
+
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
|
6
|
+
<change afterPath="$PROJECT_DIR$/.idea/.gitignore" afterDir="false" />
|
|
7
|
+
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
|
|
8
|
+
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
|
9
|
+
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
|
10
|
+
<change afterPath="$PROJECT_DIR$/.idea/predicateneuron.iml" afterDir="false" />
|
|
11
|
+
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
|
12
|
+
<change afterPath="$PROJECT_DIR$/CITATION.cff" afterDir="false" />
|
|
13
|
+
<change afterPath="$PROJECT_DIR$/LICENSE" afterDir="false" />
|
|
14
|
+
<change afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
|
15
|
+
<change afterPath="$PROJECT_DIR$/pyproject.toml" afterDir="false" />
|
|
16
|
+
<change afterPath="$PROJECT_DIR$/reference/original_tf.py" afterDir="false" />
|
|
17
|
+
<change afterPath="$PROJECT_DIR$/src/predicateneuron/__init__.py" afterDir="false" />
|
|
18
|
+
<change afterPath="$PROJECT_DIR$/src/predicateneuron/keras/__init__.py" afterDir="false" />
|
|
19
|
+
<change afterPath="$PROJECT_DIR$/src/predicateneuron/keras/functional.py" afterDir="false" />
|
|
20
|
+
<change afterPath="$PROJECT_DIR$/src/predicateneuron/keras/layers.py" afterDir="false" />
|
|
21
|
+
<change afterPath="$PROJECT_DIR$/src/predicateneuron/tf.py" afterDir="false" />
|
|
22
|
+
<change afterPath="$PROJECT_DIR$/src/predicateneuron/torch/__init__.py" afterDir="false" />
|
|
23
|
+
<change afterPath="$PROJECT_DIR$/src/predicateneuron/torch/functional.py" afterDir="false" />
|
|
24
|
+
<change afterPath="$PROJECT_DIR$/src/predicateneuron/torch/layers.py" afterDir="false" />
|
|
25
|
+
<change afterPath="$PROJECT_DIR$/tests/test_keras.py" afterDir="false" />
|
|
26
|
+
<change afterPath="$PROJECT_DIR$/tests/test_parity_with_original.py" afterDir="false" />
|
|
27
|
+
<change afterPath="$PROJECT_DIR$/tests/test_torch.py" afterDir="false" />
|
|
28
|
+
</list>
|
|
29
|
+
<option name="SHOW_DIALOG" value="false" />
|
|
30
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
31
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
32
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
33
|
+
</component>
|
|
34
|
+
<component name="Git.Settings">
|
|
35
|
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
36
|
+
</component>
|
|
37
|
+
<component name="MarkdownSettingsMigration">
|
|
38
|
+
<option name="stateVersion" value="1" />
|
|
39
|
+
</component>
|
|
40
|
+
<component name="ProjectId" id="3L4p8byrBjmgCn1f0kxoOtLdrTO" />
|
|
41
|
+
<component name="ProjectViewState">
|
|
42
|
+
<option name="autoscrollFromSource" value="true" />
|
|
43
|
+
<option name="hideEmptyMiddlePackages" value="true" />
|
|
44
|
+
<option name="showLibraryContents" value="true" />
|
|
45
|
+
</component>
|
|
46
|
+
<component name="PropertiesComponent">
|
|
47
|
+
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
|
48
|
+
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
|
49
|
+
<property name="WebServerToolWindowFactoryState" value="false" />
|
|
50
|
+
</component>
|
|
51
|
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
52
|
+
<component name="TaskManager">
|
|
53
|
+
<task active="true" id="Default" summary="Default task">
|
|
54
|
+
<changelist id="559a1296-1549-4b57-aea7-e3c5fde5b111" name="Changes" comment="" />
|
|
55
|
+
<created>1792723035825</created>
|
|
56
|
+
<option name="number" value="Default" />
|
|
57
|
+
<option name="presentableId" value="Default" />
|
|
58
|
+
<updated>1792723035825</updated>
|
|
59
|
+
<workItem from="1792723037060" duration="8477000" />
|
|
60
|
+
</task>
|
|
61
|
+
<task id="LOCAL-00001" summary="-initial commit">
|
|
62
|
+
<created>1792727916775</created>
|
|
63
|
+
<option name="number" value="00001" />
|
|
64
|
+
<option name="presentableId" value="LOCAL-00001" />
|
|
65
|
+
<option name="project" value="LOCAL" />
|
|
66
|
+
<updated>1792727916775</updated>
|
|
67
|
+
</task>
|
|
68
|
+
<task id="LOCAL-00002" summary="-fix tests">
|
|
69
|
+
<created>1792728400664</created>
|
|
70
|
+
<option name="number" value="00002" />
|
|
71
|
+
<option name="presentableId" value="LOCAL-00002" />
|
|
72
|
+
<option name="project" value="LOCAL" />
|
|
73
|
+
<updated>1792728400664</updated>
|
|
74
|
+
</task>
|
|
75
|
+
<task id="LOCAL-00003" summary="-fix tests">
|
|
76
|
+
<created>1792729978834</created>
|
|
77
|
+
<option name="number" value="00003" />
|
|
78
|
+
<option name="presentableId" value="LOCAL-00003" />
|
|
79
|
+
<option name="project" value="LOCAL" />
|
|
80
|
+
<updated>1792729978834</updated>
|
|
81
|
+
</task>
|
|
82
|
+
<task id="LOCAL-00004" summary="-fix docs">
|
|
83
|
+
<created>1792730252536</created>
|
|
84
|
+
<option name="number" value="00004" />
|
|
85
|
+
<option name="presentableId" value="LOCAL-00004" />
|
|
86
|
+
<option name="project" value="LOCAL" />
|
|
87
|
+
<updated>1792730252536</updated>
|
|
88
|
+
</task>
|
|
89
|
+
<task id="LOCAL-00005" summary="-fix docs">
|
|
90
|
+
<created>1792739970105</created>
|
|
91
|
+
<option name="number" value="00005" />
|
|
92
|
+
<option name="presentableId" value="LOCAL-00005" />
|
|
93
|
+
<option name="project" value="LOCAL" />
|
|
94
|
+
<updated>1792739970105</updated>
|
|
95
|
+
</task>
|
|
96
|
+
<option name="localTasksCounter" value="6" />
|
|
97
|
+
<servers />
|
|
98
|
+
</component>
|
|
99
|
+
<component name="TypeScriptGeneratedFilesManager">
|
|
100
|
+
<option name="version" value="3" />
|
|
101
|
+
</component>
|
|
102
|
+
<component name="Vcs.Log.Tabs.Properties">
|
|
103
|
+
<option name="TAB_STATES">
|
|
104
|
+
<map>
|
|
105
|
+
<entry key="MAIN">
|
|
106
|
+
<value>
|
|
107
|
+
<State />
|
|
108
|
+
</value>
|
|
109
|
+
</entry>
|
|
110
|
+
</map>
|
|
111
|
+
</option>
|
|
112
|
+
</component>
|
|
113
|
+
<component name="VcsManagerConfiguration">
|
|
114
|
+
<MESSAGE value="-initial commit" />
|
|
115
|
+
<MESSAGE value="-fix tests" />
|
|
116
|
+
<MESSAGE value="-fix docs" />
|
|
117
|
+
<option name="LAST_COMMIT_MESSAGE" value="-fix docs" />
|
|
118
|
+
</component>
|
|
119
|
+
</project>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: predicateneuron
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Differentiable predicate neuron (intersection / union / symmetric difference) and predicate layers for Keras, TensorFlow and PyTorch
|
|
5
5
|
Project-URL: Homepage, https://github.com/IoannisKonstantoulas/predicateneuron
|
|
6
6
|
Project-URL: Paper, https://TODO
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "predicateneuron"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "Differentiable predicate neuron (intersection / union / symmetric difference) and predicate layers for Keras, TensorFlow and PyTorch"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -5,4 +5,4 @@ from predicateneuron.keras import PredicateLayer, MinimalPredicateLayer, Minimal
|
|
|
5
5
|
from predicateneuron.tf import PredicateLayer, MinimalPredicateLayer, MinimalJointPredicateLayer # tf.keras users
|
|
6
6
|
from predicateneuron.torch import PredicateLayer, MinimalPredicateLayer, MinimalJointPredicateLayer # PyTorch
|
|
7
7
|
"""
|
|
8
|
-
__version__ = "0.1.
|
|
8
|
+
__version__ = "0.1.2"
|
|
@@ -13,27 +13,25 @@ def predicate_neuron(x1, x2, theta, temperature=0.06, hard_forward=True, hard_ba
|
|
|
13
13
|
(behaviour of the original paper code).
|
|
14
14
|
hard_backward=False: exact derivative of the soft mixture,
|
|
15
15
|
sum_k p_k * d(op_k)/dx.
|
|
16
|
-
Implemented with stop_gradient, so it works on every Keras backend.
|
|
17
16
|
"""
|
|
17
|
+
|
|
18
18
|
sg = ops.stop_gradient
|
|
19
19
|
|
|
20
20
|
intersection = x1 * x2
|
|
21
21
|
union = x1 + x2 - intersection
|
|
22
22
|
symmetric_diff = x1 + x2 - 2.0 * intersection
|
|
23
23
|
|
|
24
|
-
# hard path (differentiable w.r.t. x only; the gate itself is a constant)
|
|
25
24
|
t = sg(theta)
|
|
26
25
|
gate = ops.where(t < 0.25, 0, ops.where(t < 0.75, 1, 2))
|
|
27
26
|
y_hard = ops.where(gate == 0, intersection, ops.where(gate == 1, union, symmetric_diff))
|
|
28
27
|
|
|
29
|
-
# soft path
|
|
30
28
|
positions = ops.cast(ops.convert_to_tensor([0.0, 0.5, 1.0]), x1.dtype)
|
|
31
29
|
values = ops.stack([intersection, union, symmetric_diff], axis=-1)
|
|
32
30
|
logits = -ops.square(ops.expand_dims(theta, -1) - positions) / temperature
|
|
33
31
|
p = ops.softmax(logits, axis=-1)
|
|
34
|
-
y_soft_theta = ops.sum(sg(values) * p, axis=-1)
|
|
35
|
-
y_soft_x = ops.sum(values * sg(p), axis=-1)
|
|
32
|
+
y_soft_theta = ops.sum(sg(values) * p, axis=-1)
|
|
33
|
+
y_soft_x = ops.sum(values * sg(p), axis=-1)
|
|
36
34
|
|
|
37
35
|
forward = ops.where(hard_forward, y_hard, y_soft_theta)
|
|
38
|
-
y_x = ops.where(hard_backward, y_hard, y_soft_x)
|
|
36
|
+
y_x = ops.where(hard_backward, y_hard, y_soft_x)
|
|
39
37
|
return sg(forward) + (y_soft_theta - sg(y_soft_theta)) + (y_x - sg(y_x))
|
|
@@ -13,21 +13,22 @@ def predicate_neuron(x1, x2, theta, temperature=0.06, hard_forward=True, hard_ba
|
|
|
13
13
|
(behaviour of the original paper code).
|
|
14
14
|
hard_backward=False: exact derivative of the soft mixture,
|
|
15
15
|
sum_k p_k * d(op_k)/dx.
|
|
16
|
-
|
|
16
|
+
"""
|
|
17
|
+
|
|
17
18
|
intersection = x1 * x2
|
|
18
19
|
union = x1 + x2 - intersection
|
|
19
20
|
symmetric_diff = x1 + x2 - 2.0 * intersection
|
|
20
21
|
|
|
21
22
|
t = theta.detach()
|
|
22
|
-
gate = (t >= 0.25).long() + (t >= 0.75).long()
|
|
23
|
+
gate = (t >= 0.25).long() + (t >= 0.75).long()
|
|
23
24
|
y_hard = torch.where(gate == 0, intersection, torch.where(gate == 1, union, symmetric_diff))
|
|
24
25
|
|
|
25
26
|
positions = torch.tensor([0.0, 0.5, 1.0], dtype=x1.dtype, device=x1.device)
|
|
26
27
|
values = torch.stack([intersection, union, symmetric_diff], dim=-1)
|
|
27
28
|
logits = -torch.square(theta.unsqueeze(-1) - positions) / temperature
|
|
28
29
|
p = torch.softmax(logits, dim=-1)
|
|
29
|
-
y_soft_theta = (values.detach() * p).sum(dim=-1)
|
|
30
|
-
y_soft_x = (values * p.detach()).sum(dim=-1)
|
|
30
|
+
y_soft_theta = (values.detach() * p).sum(dim=-1)
|
|
31
|
+
y_soft_x = (values * p.detach()).sum(dim=-1)
|
|
31
32
|
|
|
32
33
|
hf = torch.as_tensor(hard_forward, dtype=torch.bool, device=x1.device)
|
|
33
34
|
hb = torch.as_tensor(hard_backward, dtype=torch.bool, device=x1.device)
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ChangeListManager">
|
|
4
|
-
<list default="true" id="559a1296-1549-4b57-aea7-e3c5fde5b111" name="Changes" comment="">
|
|
5
|
-
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
|
6
|
-
</list>
|
|
7
|
-
<option name="SHOW_DIALOG" value="false" />
|
|
8
|
-
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
9
|
-
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
10
|
-
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
11
|
-
</component>
|
|
12
|
-
<component name="Git.Settings">
|
|
13
|
-
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
14
|
-
</component>
|
|
15
|
-
<component name="MarkdownSettingsMigration">
|
|
16
|
-
<option name="stateVersion" value="1" />
|
|
17
|
-
</component>
|
|
18
|
-
<component name="ProjectId" id="3L4p8byrBjmgCn1f0kxoOtLdrTO" />
|
|
19
|
-
<component name="ProjectViewState">
|
|
20
|
-
<option name="autoscrollFromSource" value="true" />
|
|
21
|
-
<option name="hideEmptyMiddlePackages" value="true" />
|
|
22
|
-
<option name="showLibraryContents" value="true" />
|
|
23
|
-
</component>
|
|
24
|
-
<component name="PropertiesComponent">
|
|
25
|
-
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
|
26
|
-
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
|
27
|
-
<property name="WebServerToolWindowFactoryState" value="false" />
|
|
28
|
-
</component>
|
|
29
|
-
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
30
|
-
<component name="TaskManager">
|
|
31
|
-
<task active="true" id="Default" summary="Default task">
|
|
32
|
-
<changelist id="559a1296-1549-4b57-aea7-e3c5fde5b111" name="Changes" comment="" />
|
|
33
|
-
<created>1792723035825</created>
|
|
34
|
-
<option name="number" value="Default" />
|
|
35
|
-
<option name="presentableId" value="Default" />
|
|
36
|
-
<updated>1792723035825</updated>
|
|
37
|
-
<workItem from="1792723037060" duration="6851000" />
|
|
38
|
-
</task>
|
|
39
|
-
<task id="LOCAL-00001" summary="-initial commit">
|
|
40
|
-
<created>1792727916775</created>
|
|
41
|
-
<option name="number" value="00001" />
|
|
42
|
-
<option name="presentableId" value="LOCAL-00001" />
|
|
43
|
-
<option name="project" value="LOCAL" />
|
|
44
|
-
<updated>1792727916775</updated>
|
|
45
|
-
</task>
|
|
46
|
-
<task id="LOCAL-00002" summary="-fix tests">
|
|
47
|
-
<created>1792728400664</created>
|
|
48
|
-
<option name="number" value="00002" />
|
|
49
|
-
<option name="presentableId" value="LOCAL-00002" />
|
|
50
|
-
<option name="project" value="LOCAL" />
|
|
51
|
-
<updated>1792728400664</updated>
|
|
52
|
-
</task>
|
|
53
|
-
<option name="localTasksCounter" value="3" />
|
|
54
|
-
<servers />
|
|
55
|
-
</component>
|
|
56
|
-
<component name="TypeScriptGeneratedFilesManager">
|
|
57
|
-
<option name="version" value="3" />
|
|
58
|
-
</component>
|
|
59
|
-
<component name="Vcs.Log.Tabs.Properties">
|
|
60
|
-
<option name="TAB_STATES">
|
|
61
|
-
<map>
|
|
62
|
-
<entry key="MAIN">
|
|
63
|
-
<value>
|
|
64
|
-
<State />
|
|
65
|
-
</value>
|
|
66
|
-
</entry>
|
|
67
|
-
</map>
|
|
68
|
-
</option>
|
|
69
|
-
</component>
|
|
70
|
-
<component name="VcsManagerConfiguration">
|
|
71
|
-
<MESSAGE value="-initial commit" />
|
|
72
|
-
<MESSAGE value="-fix tests" />
|
|
73
|
-
<option name="LAST_COMMIT_MESSAGE" value="-fix tests" />
|
|
74
|
-
</component>
|
|
75
|
-
</project>
|
|
File without changes
|
|
File without changes
|
{predicateneuron-0.1.1 → predicateneuron-0.1.2}/.idea/inspectionProfiles/profiles_settings.xml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|