graph-attention-engine 0.7.25__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.
- graph_attention_engine-0.7.25/LICENSE +179 -0
- graph_attention_engine-0.7.25/PKG-INFO +214 -0
- graph_attention_engine-0.7.25/README.md +189 -0
- graph_attention_engine-0.7.25/gae/__init__.py +367 -0
- graph_attention_engine-0.7.25/gae/ablation.py +203 -0
- graph_attention_engine-0.7.25/gae/batch_pipeline.py +404 -0
- graph_attention_engine-0.7.25/gae/bootstrap.py +311 -0
- graph_attention_engine-0.7.25/gae/calibration.py +874 -0
- graph_attention_engine-0.7.25/gae/contracts.py +217 -0
- graph_attention_engine-0.7.25/gae/convergence.py +1313 -0
- graph_attention_engine-0.7.25/gae/covariance.py +277 -0
- graph_attention_engine-0.7.25/gae/dk_estimator.py +272 -0
- graph_attention_engine-0.7.25/gae/enrichment_advisor.py +80 -0
- graph_attention_engine-0.7.25/gae/evaluation.py +304 -0
- graph_attention_engine-0.7.25/gae/events.py +121 -0
- graph_attention_engine-0.7.25/gae/evolution.py +557 -0
- graph_attention_engine-0.7.25/gae/factors.py +129 -0
- graph_attention_engine-0.7.25/gae/judgment.py +227 -0
- graph_attention_engine-0.7.25/gae/kernel_selector.py +492 -0
- graph_attention_engine-0.7.25/gae/kernels.py +345 -0
- graph_attention_engine-0.7.25/gae/learning.py +689 -0
- graph_attention_engine-0.7.25/gae/novelty.py +143 -0
- graph_attention_engine-0.7.25/gae/oracle.py +245 -0
- graph_attention_engine-0.7.25/gae/primitives.py +161 -0
- graph_attention_engine-0.7.25/gae/profile_scorer.py +1345 -0
- graph_attention_engine-0.7.25/gae/referral.py +345 -0
- graph_attention_engine-0.7.25/gae/scoring.py +210 -0
- graph_attention_engine-0.7.25/gae/shrinkage.py +81 -0
- graph_attention_engine-0.7.25/gae/snr.py +313 -0
- graph_attention_engine-0.7.25/gae/store.py +200 -0
- graph_attention_engine-0.7.25/gae/synthetic.py +380 -0
- graph_attention_engine-0.7.25/gae/two_phase.py +94 -0
- graph_attention_engine-0.7.25/graph_attention_engine.egg-info/PKG-INFO +214 -0
- graph_attention_engine-0.7.25/graph_attention_engine.egg-info/SOURCES.txt +93 -0
- graph_attention_engine-0.7.25/graph_attention_engine.egg-info/dependency_links.txt +1 -0
- graph_attention_engine-0.7.25/graph_attention_engine.egg-info/requires.txt +5 -0
- graph_attention_engine-0.7.25/graph_attention_engine.egg-info/top_level.txt +1 -0
- graph_attention_engine-0.7.25/pyproject.toml +51 -0
- graph_attention_engine-0.7.25/setup.cfg +4 -0
- graph_attention_engine-0.7.25/tests/test_ablation.py +114 -0
- graph_attention_engine-0.7.25/tests/test_adversarial_inputs.py +394 -0
- graph_attention_engine-0.7.25/tests/test_api_contract.py +478 -0
- graph_attention_engine-0.7.25/tests/test_batch_pipeline.py +397 -0
- graph_attention_engine-0.7.25/tests/test_bootstrap.py +143 -0
- graph_attention_engine-0.7.25/tests/test_calibration.py +1021 -0
- graph_attention_engine-0.7.25/tests/test_conservation_monitor.py +307 -0
- graph_attention_engine-0.7.25/tests/test_conservation_state_machine.py +255 -0
- graph_attention_engine-0.7.25/tests/test_consumer_contracts.py +357 -0
- graph_attention_engine-0.7.25/tests/test_consumer_roundtrip.py +83 -0
- graph_attention_engine-0.7.25/tests/test_contracts.py +114 -0
- graph_attention_engine-0.7.25/tests/test_convergence.py +816 -0
- graph_attention_engine-0.7.25/tests/test_covariance.py +221 -0
- graph_attention_engine-0.7.25/tests/test_deferred_math_invariants.py +93 -0
- graph_attention_engine-0.7.25/tests/test_determinism.py +230 -0
- graph_attention_engine-0.7.25/tests/test_diagonal_kernel.py +144 -0
- graph_attention_engine-0.7.25/tests/test_dk_estimator.py +280 -0
- graph_attention_engine-0.7.25/tests/test_entropy_edge_cases.py +25 -0
- graph_attention_engine-0.7.25/tests/test_evaluation.py +142 -0
- graph_attention_engine-0.7.25/tests/test_events.py +87 -0
- graph_attention_engine-0.7.25/tests/test_evolution.py +331 -0
- graph_attention_engine-0.7.25/tests/test_factors.py +90 -0
- graph_attention_engine-0.7.25/tests/test_fw04_integration.py +234 -0
- graph_attention_engine-0.7.25/tests/test_fw05_phase_a_gate.py +534 -0
- graph_attention_engine-0.7.25/tests/test_fw08_checkpoint.py +207 -0
- graph_attention_engine-0.7.25/tests/test_fw09_phase_b_gate.py +310 -0
- graph_attention_engine-0.7.25/tests/test_fw13_build_scorer_strategy.py +193 -0
- graph_attention_engine-0.7.25/tests/test_generic_domains.py +734 -0
- graph_attention_engine-0.7.25/tests/test_harness_validation.py +514 -0
- graph_attention_engine-0.7.25/tests/test_judgment.py +138 -0
- graph_attention_engine-0.7.25/tests/test_kernel_properties.py +319 -0
- graph_attention_engine-0.7.25/tests/test_kernel_selector.py +612 -0
- graph_attention_engine-0.7.25/tests/test_kernels.py +530 -0
- graph_attention_engine-0.7.25/tests/test_learning.py +353 -0
- graph_attention_engine-0.7.25/tests/test_mathematical_properties.py +392 -0
- graph_attention_engine-0.7.25/tests/test_novelty.py +184 -0
- graph_attention_engine-0.7.25/tests/test_numerical_stability.py +298 -0
- graph_attention_engine-0.7.25/tests/test_oracle.py +199 -0
- graph_attention_engine-0.7.25/tests/test_primitives.py +115 -0
- graph_attention_engine-0.7.25/tests/test_profile_scorer.py +1184 -0
- graph_attention_engine-0.7.25/tests/test_recommend_edge_cases.py +41 -0
- graph_attention_engine-0.7.25/tests/test_referral.py +291 -0
- graph_attention_engine-0.7.25/tests/test_score_edge_cases.py +76 -0
- graph_attention_engine-0.7.25/tests/test_scoring.py +127 -0
- graph_attention_engine-0.7.25/tests/test_serialization.py +288 -0
- graph_attention_engine-0.7.25/tests/test_setter_edge_cases.py +39 -0
- graph_attention_engine-0.7.25/tests/test_shape_contracts.py +241 -0
- graph_attention_engine-0.7.25/tests/test_shrinkage.py +132 -0
- graph_attention_engine-0.7.25/tests/test_snr.py +181 -0
- graph_attention_engine-0.7.25/tests/test_soc_integration.py +556 -0
- graph_attention_engine-0.7.25/tests/test_store.py +100 -0
- graph_attention_engine-0.7.25/tests/test_synthetic.py +107 -0
- graph_attention_engine-0.7.25/tests/test_two_phase.py +56 -0
- graph_attention_engine-0.7.25/tests/test_update_edge_cases.py +125 -0
- graph_attention_engine-0.7.25/tests/test_val01_conservation_coord_descent.py +241 -0
- graph_attention_engine-0.7.25/tests/test_weight_provenance.py +162 -0
|
@@ -0,0 +1,179 @@
|
|
|
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 made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other transformations
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of recording and
|
|
55
|
+
discussing modifications to the Work, but excluding communication that
|
|
56
|
+
is conspicuously marked or designated in writing by the copyright owner
|
|
57
|
+
as "Not a Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any Derivative
|
|
81
|
+
Work constitutes direct or contributory patent infringement, then any
|
|
82
|
+
patent licenses granted to You under this License for that Work shall
|
|
83
|
+
terminate as of the date such litigation is filed.
|
|
84
|
+
|
|
85
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
86
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
87
|
+
modifications, and in Source or Object form, provided that You
|
|
88
|
+
meet the following conditions:
|
|
89
|
+
|
|
90
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
91
|
+
Works a copy of this License; and
|
|
92
|
+
|
|
93
|
+
(b) You must cause any modified files to carry prominent notices
|
|
94
|
+
stating that You changed the files; and
|
|
95
|
+
|
|
96
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
97
|
+
that You distribute, all copyright, patent, trademark, and
|
|
98
|
+
attribution notices from the Source form of the Work,
|
|
99
|
+
excluding those notices that do not pertain to any part of
|
|
100
|
+
the Derivative Works; and
|
|
101
|
+
|
|
102
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
103
|
+
distribution, You must include a readable copy of the
|
|
104
|
+
attribution notices contained within such NOTICE file, in
|
|
105
|
+
at least one of the following places: within a NOTICE text
|
|
106
|
+
file distributed as part of the Derivative Works; within
|
|
107
|
+
the Source form or documentation, if provided along with the
|
|
108
|
+
Derivative Works; or, within a display generated by the
|
|
109
|
+
Derivative Works, if and wherever such third-party notices
|
|
110
|
+
normally appear. The contents of the NOTICE file are for
|
|
111
|
+
informational purposes only and do not modify the License.
|
|
112
|
+
You may add Your own attribution notices within Derivative
|
|
113
|
+
Works that You distribute, alongside or in addition to the
|
|
114
|
+
NOTICE text from the Work, provided that such additional
|
|
115
|
+
attribution notices cannot be construed as modifying the License.
|
|
116
|
+
|
|
117
|
+
You may add Your own license statement for Your modifications and
|
|
118
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
119
|
+
publish, distribute, sublicense, and/or sell copies of the
|
|
120
|
+
Contribution, either on its own or as part of the Work.
|
|
121
|
+
|
|
122
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
123
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
124
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
125
|
+
this License, without any additional terms or conditions.
|
|
126
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
127
|
+
the terms of any separate license agreement you may have executed
|
|
128
|
+
with Licensor regarding such Contributions.
|
|
129
|
+
|
|
130
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
131
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
132
|
+
except as required for reasonable and customary use in describing the
|
|
133
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
134
|
+
|
|
135
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
136
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
137
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
138
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
139
|
+
implied, including, without limitation, any conditions of TITLE,
|
|
140
|
+
NONINFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
141
|
+
PURPOSE. You are solely responsible for determining the
|
|
142
|
+
appropriateness of using or reproducing the Work and assume any
|
|
143
|
+
risks associated with Your exercise of permissions under this License.
|
|
144
|
+
|
|
145
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
146
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
147
|
+
unless required by applicable law (such as deliberate and grossly
|
|
148
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
149
|
+
liable to You for damages, including any direct, indirect, special,
|
|
150
|
+
incidental, or exemplary damages of any character arising as a
|
|
151
|
+
result of this License or out of the use or inability to use the
|
|
152
|
+
Work (even if such Contributor has been advised of the possibility
|
|
153
|
+
of such damages).
|
|
154
|
+
|
|
155
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
156
|
+
the Work or Derivative Works thereof, You may choose to offer, and
|
|
157
|
+
charge a fee for, acceptance of support, warranty, indemnity,
|
|
158
|
+
or other liability obligations and/or rights consistent with this
|
|
159
|
+
License. However, in accepting such obligations, You may offer only
|
|
160
|
+
conditions that are completely consistent with the terms of this
|
|
161
|
+
License and You indemnify each Contributor for any liability
|
|
162
|
+
incurred by such Contributor as a result of warranty or additional
|
|
163
|
+
liability obligations You accept.
|
|
164
|
+
|
|
165
|
+
END OF TERMS AND CONDITIONS
|
|
166
|
+
|
|
167
|
+
Copyright 2024 Graph Attention Engine Contributors
|
|
168
|
+
|
|
169
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
170
|
+
you may not use this file except in compliance with the License.
|
|
171
|
+
You may obtain a copy of the License at
|
|
172
|
+
|
|
173
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
174
|
+
|
|
175
|
+
Unless required by applicable law or agreed to in writing, software
|
|
176
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
177
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
178
|
+
See the License for the specific language governing permissions and
|
|
179
|
+
limitations under the License.
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: graph-attention-engine
|
|
3
|
+
Version: 0.7.25
|
|
4
|
+
Summary: Standalone numpy-only graph attention library (GAE v5)
|
|
5
|
+
Author-email: Arindam Banerji <banerji.arindam@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/ArindamBanerji/graph-attention-engine
|
|
8
|
+
Project-URL: Repository, https://github.com/ArindamBanerji/graph-attention-engine
|
|
9
|
+
Project-URL: Documentation, https://www.dakshineshwari.net
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: numpy>=1.24
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# Graph Attention Engine (GAE)
|
|
27
|
+
|
|
28
|
+
Graph Attention Engine is a standalone, NumPy-only scoring engine that implements Cross-Graph Attention for domain-independent decision systems. It is pure Python and requires no database, network access, or event loop. GAE is licensed under Apache 2.0.
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
Install the published package:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install graph-attention-engine
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For editable development installs:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install -e ".[dev]"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
### Scaled dot-product attention
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import numpy as np
|
|
50
|
+
from gae import scaled_dot_product_attention
|
|
51
|
+
|
|
52
|
+
rng = np.random.default_rng(7)
|
|
53
|
+
Q = rng.normal(size=(4, 8))
|
|
54
|
+
K = rng.normal(size=(6, 8))
|
|
55
|
+
V = rng.normal(size=(6, 16))
|
|
56
|
+
|
|
57
|
+
out, weights = scaled_dot_product_attention(Q, K, V)
|
|
58
|
+
|
|
59
|
+
assert out.shape == (4, 16)
|
|
60
|
+
assert weights.shape == (4, 6)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Profile scoring
|
|
64
|
+
|
|
65
|
+
`ProfileScorer` compares a factor vector with category-specific action centroids. The convenience factory accepts named categories and actions:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import numpy as np
|
|
69
|
+
from gae import ProfileScorer, build_profile_scorer
|
|
70
|
+
|
|
71
|
+
categories = ["routine", "critical"]
|
|
72
|
+
actions = ["accept", "review", "escalate"]
|
|
73
|
+
|
|
74
|
+
# Shape: (2 categories, 3 actions, 4 factors)
|
|
75
|
+
mu = np.array(
|
|
76
|
+
[
|
|
77
|
+
[
|
|
78
|
+
[0.2, 0.2, 0.1, 0.2],
|
|
79
|
+
[0.5, 0.4, 0.5, 0.4],
|
|
80
|
+
[0.8, 0.8, 0.9, 0.8],
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
[0.1, 0.2, 0.2, 0.1],
|
|
84
|
+
[0.5, 0.6, 0.5, 0.6],
|
|
85
|
+
[0.9, 0.9, 0.8, 0.9],
|
|
86
|
+
],
|
|
87
|
+
],
|
|
88
|
+
dtype=np.float64,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
centroids = {
|
|
92
|
+
category: {
|
|
93
|
+
action: mu[category_index, action_index].tolist()
|
|
94
|
+
for action_index, action in enumerate(actions)
|
|
95
|
+
}
|
|
96
|
+
for category_index, category in enumerate(categories)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
scorer: ProfileScorer = build_profile_scorer(
|
|
100
|
+
categories=categories,
|
|
101
|
+
actions=actions,
|
|
102
|
+
centroids=centroids,
|
|
103
|
+
n_factors=4,
|
|
104
|
+
)
|
|
105
|
+
result = scorer.score(np.array([0.85, 0.90, 0.80, 0.90]), category_index=1)
|
|
106
|
+
|
|
107
|
+
print(result.action_index)
|
|
108
|
+
print(result.confidence)
|
|
109
|
+
print(result.probabilities)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The returned `ScoringResult` contains the recommended `action_index`, `action_name`, calibrated `confidence`, full `probabilities`, distances, entropy, and confidence gap.
|
|
113
|
+
|
|
114
|
+
## Core API
|
|
115
|
+
|
|
116
|
+
### Core Scoring
|
|
117
|
+
|
|
118
|
+
| API | Description |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `ProfileScorer` | Scores factor vectors against category and action centroids. |
|
|
121
|
+
| `ScoringResult` | Contains the recommendation, confidence, probabilities, and diagnostics. |
|
|
122
|
+
| `KernelType` | Selects the distance kernel used for scoring. |
|
|
123
|
+
| `build_profile_scorer` | Builds a scorer from named categories, actions, and centroid mappings. |
|
|
124
|
+
|
|
125
|
+
### Oracle
|
|
126
|
+
|
|
127
|
+
| API | Description |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `OracleProvider` | Protocol for producing independent ground-truth outcomes. |
|
|
130
|
+
| `GTAlignedOracle` | Returns outcomes aligned with supplied ground truth. |
|
|
131
|
+
| `BernoulliOracle` | Samples deterministic-seeded Bernoulli outcomes. |
|
|
132
|
+
|
|
133
|
+
### Evaluation
|
|
134
|
+
|
|
135
|
+
| API | Description |
|
|
136
|
+
|---|---|
|
|
137
|
+
| `EvaluationScenario` | Defines one scored evaluation case and expected action. |
|
|
138
|
+
| `compute_ece` | Computes expected calibration error. |
|
|
139
|
+
| `run_evaluation` | Evaluates a scorer across a scenario collection. |
|
|
140
|
+
|
|
141
|
+
### Judgment
|
|
142
|
+
|
|
143
|
+
| API | Description |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `compute_judgment` | Converts a scoring result into an explained judgment. |
|
|
146
|
+
| `CONFIDENCE_HIGH` | Threshold for high-confidence judgments. |
|
|
147
|
+
| `CONFIDENCE_MEDIUM` | Threshold for medium-confidence judgments. |
|
|
148
|
+
|
|
149
|
+
### Calibration
|
|
150
|
+
|
|
151
|
+
| API | Description |
|
|
152
|
+
|---|---|
|
|
153
|
+
| `CalibrationProfile` | Holds scoring and learning calibration parameters. |
|
|
154
|
+
| `compute_theta_min` | Computes the deployment-aware conservation threshold. |
|
|
155
|
+
|
|
156
|
+
### Primitives
|
|
157
|
+
|
|
158
|
+
| API | Description |
|
|
159
|
+
|---|---|
|
|
160
|
+
| `scaled_dot_product_attention` | Computes scaled dot-product attention and its weights. |
|
|
161
|
+
| `softmax` | Computes a numerically stable probability distribution. |
|
|
162
|
+
|
|
163
|
+
### Learning
|
|
164
|
+
|
|
165
|
+
| API | Description |
|
|
166
|
+
|---|---|
|
|
167
|
+
| `LearningState` | Tracks centroids and learning metadata. |
|
|
168
|
+
| `WeightUpdate` | Describes a validated learning update. |
|
|
169
|
+
|
|
170
|
+
### Convergence
|
|
171
|
+
|
|
172
|
+
| API | Description |
|
|
173
|
+
|---|---|
|
|
174
|
+
| `get_convergence_metrics` | Reports centroid movement and convergence diagnostics. |
|
|
175
|
+
|
|
176
|
+
### Kernels
|
|
177
|
+
|
|
178
|
+
| API | Description |
|
|
179
|
+
|---|---|
|
|
180
|
+
| `L2Kernel` | Computes standard squared Euclidean distance. |
|
|
181
|
+
| `DiagonalKernel` | Applies per-factor diagonal weights. |
|
|
182
|
+
| `CovarianceEstimator` | Estimates covariance for adaptive distance calculations. |
|
|
183
|
+
| `KernelSelector` | Recommends a kernel from observed data properties. |
|
|
184
|
+
|
|
185
|
+
### Persistence
|
|
186
|
+
|
|
187
|
+
| API | Description |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `save_state` | Saves learning state to JSON. |
|
|
190
|
+
| `load_state` | Loads learning state from JSON. |
|
|
191
|
+
|
|
192
|
+
The complete public export list is available in [`gae/__init__.py`](gae/__init__.py).
|
|
193
|
+
|
|
194
|
+
## Conservation Law
|
|
195
|
+
|
|
196
|
+
GAE checks the constraint `alpha * q * V >= theta_min`, combining category coverage (`alpha`), observed quality (`q`), and verified volume (`V`). Meeting the threshold provides the operational guarantee that evidence is sufficient to maintain accuracy above the configured boundary; use [`compute_theta_min`](#calibration) to derive the deployment-aware threshold.
|
|
197
|
+
|
|
198
|
+
## Testing
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
pytest tests/ -v
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The current suite contains 1,244 passing tests.
|
|
205
|
+
|
|
206
|
+
## Documentation
|
|
207
|
+
|
|
208
|
+
- [Authoritative design document](docs/design/gae_design_v10_8.md)
|
|
209
|
+
- [Cross-Graph Attention mathematical foundation](https://www.dakshineshwari.net/post/cross-graph-attention-mathematical-foundation-with-experimental-validation)
|
|
210
|
+
- [Dakshineshwari](https://www.dakshineshwari.net)
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
Apache 2.0. See the [LICENSE](LICENSE) file.
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Graph Attention Engine (GAE)
|
|
2
|
+
|
|
3
|
+
Graph Attention Engine is a standalone, NumPy-only scoring engine that implements Cross-Graph Attention for domain-independent decision systems. It is pure Python and requires no database, network access, or event loop. GAE is licensed under Apache 2.0.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Install the published package:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install graph-attention-engine
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For editable development installs:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install -e ".[dev]"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### Scaled dot-product attention
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import numpy as np
|
|
25
|
+
from gae import scaled_dot_product_attention
|
|
26
|
+
|
|
27
|
+
rng = np.random.default_rng(7)
|
|
28
|
+
Q = rng.normal(size=(4, 8))
|
|
29
|
+
K = rng.normal(size=(6, 8))
|
|
30
|
+
V = rng.normal(size=(6, 16))
|
|
31
|
+
|
|
32
|
+
out, weights = scaled_dot_product_attention(Q, K, V)
|
|
33
|
+
|
|
34
|
+
assert out.shape == (4, 16)
|
|
35
|
+
assert weights.shape == (4, 6)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Profile scoring
|
|
39
|
+
|
|
40
|
+
`ProfileScorer` compares a factor vector with category-specific action centroids. The convenience factory accepts named categories and actions:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import numpy as np
|
|
44
|
+
from gae import ProfileScorer, build_profile_scorer
|
|
45
|
+
|
|
46
|
+
categories = ["routine", "critical"]
|
|
47
|
+
actions = ["accept", "review", "escalate"]
|
|
48
|
+
|
|
49
|
+
# Shape: (2 categories, 3 actions, 4 factors)
|
|
50
|
+
mu = np.array(
|
|
51
|
+
[
|
|
52
|
+
[
|
|
53
|
+
[0.2, 0.2, 0.1, 0.2],
|
|
54
|
+
[0.5, 0.4, 0.5, 0.4],
|
|
55
|
+
[0.8, 0.8, 0.9, 0.8],
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
[0.1, 0.2, 0.2, 0.1],
|
|
59
|
+
[0.5, 0.6, 0.5, 0.6],
|
|
60
|
+
[0.9, 0.9, 0.8, 0.9],
|
|
61
|
+
],
|
|
62
|
+
],
|
|
63
|
+
dtype=np.float64,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
centroids = {
|
|
67
|
+
category: {
|
|
68
|
+
action: mu[category_index, action_index].tolist()
|
|
69
|
+
for action_index, action in enumerate(actions)
|
|
70
|
+
}
|
|
71
|
+
for category_index, category in enumerate(categories)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
scorer: ProfileScorer = build_profile_scorer(
|
|
75
|
+
categories=categories,
|
|
76
|
+
actions=actions,
|
|
77
|
+
centroids=centroids,
|
|
78
|
+
n_factors=4,
|
|
79
|
+
)
|
|
80
|
+
result = scorer.score(np.array([0.85, 0.90, 0.80, 0.90]), category_index=1)
|
|
81
|
+
|
|
82
|
+
print(result.action_index)
|
|
83
|
+
print(result.confidence)
|
|
84
|
+
print(result.probabilities)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The returned `ScoringResult` contains the recommended `action_index`, `action_name`, calibrated `confidence`, full `probabilities`, distances, entropy, and confidence gap.
|
|
88
|
+
|
|
89
|
+
## Core API
|
|
90
|
+
|
|
91
|
+
### Core Scoring
|
|
92
|
+
|
|
93
|
+
| API | Description |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `ProfileScorer` | Scores factor vectors against category and action centroids. |
|
|
96
|
+
| `ScoringResult` | Contains the recommendation, confidence, probabilities, and diagnostics. |
|
|
97
|
+
| `KernelType` | Selects the distance kernel used for scoring. |
|
|
98
|
+
| `build_profile_scorer` | Builds a scorer from named categories, actions, and centroid mappings. |
|
|
99
|
+
|
|
100
|
+
### Oracle
|
|
101
|
+
|
|
102
|
+
| API | Description |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `OracleProvider` | Protocol for producing independent ground-truth outcomes. |
|
|
105
|
+
| `GTAlignedOracle` | Returns outcomes aligned with supplied ground truth. |
|
|
106
|
+
| `BernoulliOracle` | Samples deterministic-seeded Bernoulli outcomes. |
|
|
107
|
+
|
|
108
|
+
### Evaluation
|
|
109
|
+
|
|
110
|
+
| API | Description |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `EvaluationScenario` | Defines one scored evaluation case and expected action. |
|
|
113
|
+
| `compute_ece` | Computes expected calibration error. |
|
|
114
|
+
| `run_evaluation` | Evaluates a scorer across a scenario collection. |
|
|
115
|
+
|
|
116
|
+
### Judgment
|
|
117
|
+
|
|
118
|
+
| API | Description |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `compute_judgment` | Converts a scoring result into an explained judgment. |
|
|
121
|
+
| `CONFIDENCE_HIGH` | Threshold for high-confidence judgments. |
|
|
122
|
+
| `CONFIDENCE_MEDIUM` | Threshold for medium-confidence judgments. |
|
|
123
|
+
|
|
124
|
+
### Calibration
|
|
125
|
+
|
|
126
|
+
| API | Description |
|
|
127
|
+
|---|---|
|
|
128
|
+
| `CalibrationProfile` | Holds scoring and learning calibration parameters. |
|
|
129
|
+
| `compute_theta_min` | Computes the deployment-aware conservation threshold. |
|
|
130
|
+
|
|
131
|
+
### Primitives
|
|
132
|
+
|
|
133
|
+
| API | Description |
|
|
134
|
+
|---|---|
|
|
135
|
+
| `scaled_dot_product_attention` | Computes scaled dot-product attention and its weights. |
|
|
136
|
+
| `softmax` | Computes a numerically stable probability distribution. |
|
|
137
|
+
|
|
138
|
+
### Learning
|
|
139
|
+
|
|
140
|
+
| API | Description |
|
|
141
|
+
|---|---|
|
|
142
|
+
| `LearningState` | Tracks centroids and learning metadata. |
|
|
143
|
+
| `WeightUpdate` | Describes a validated learning update. |
|
|
144
|
+
|
|
145
|
+
### Convergence
|
|
146
|
+
|
|
147
|
+
| API | Description |
|
|
148
|
+
|---|---|
|
|
149
|
+
| `get_convergence_metrics` | Reports centroid movement and convergence diagnostics. |
|
|
150
|
+
|
|
151
|
+
### Kernels
|
|
152
|
+
|
|
153
|
+
| API | Description |
|
|
154
|
+
|---|---|
|
|
155
|
+
| `L2Kernel` | Computes standard squared Euclidean distance. |
|
|
156
|
+
| `DiagonalKernel` | Applies per-factor diagonal weights. |
|
|
157
|
+
| `CovarianceEstimator` | Estimates covariance for adaptive distance calculations. |
|
|
158
|
+
| `KernelSelector` | Recommends a kernel from observed data properties. |
|
|
159
|
+
|
|
160
|
+
### Persistence
|
|
161
|
+
|
|
162
|
+
| API | Description |
|
|
163
|
+
|---|---|
|
|
164
|
+
| `save_state` | Saves learning state to JSON. |
|
|
165
|
+
| `load_state` | Loads learning state from JSON. |
|
|
166
|
+
|
|
167
|
+
The complete public export list is available in [`gae/__init__.py`](gae/__init__.py).
|
|
168
|
+
|
|
169
|
+
## Conservation Law
|
|
170
|
+
|
|
171
|
+
GAE checks the constraint `alpha * q * V >= theta_min`, combining category coverage (`alpha`), observed quality (`q`), and verified volume (`V`). Meeting the threshold provides the operational guarantee that evidence is sufficient to maintain accuracy above the configured boundary; use [`compute_theta_min`](#calibration) to derive the deployment-aware threshold.
|
|
172
|
+
|
|
173
|
+
## Testing
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
pytest tests/ -v
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The current suite contains 1,244 passing tests.
|
|
180
|
+
|
|
181
|
+
## Documentation
|
|
182
|
+
|
|
183
|
+
- [Authoritative design document](docs/design/gae_design_v10_8.md)
|
|
184
|
+
- [Cross-Graph Attention mathematical foundation](https://www.dakshineshwari.net/post/cross-graph-attention-mathematical-foundation-with-experimental-validation)
|
|
185
|
+
- [Dakshineshwari](https://www.dakshineshwari.net)
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
Apache 2.0. See the [LICENSE](LICENSE) file.
|