tnfr 4.5.2__py3-none-any.whl → 8.5.0__py3-none-any.whl

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.

Potentially problematic release.


This version of tnfr might be problematic. Click here for more details.

Files changed (365) hide show
  1. tnfr/__init__.py +334 -50
  2. tnfr/__init__.pyi +33 -0
  3. tnfr/_compat.py +10 -0
  4. tnfr/_generated_version.py +34 -0
  5. tnfr/_version.py +49 -0
  6. tnfr/_version.pyi +7 -0
  7. tnfr/alias.py +214 -37
  8. tnfr/alias.pyi +108 -0
  9. tnfr/backends/__init__.py +354 -0
  10. tnfr/backends/jax_backend.py +173 -0
  11. tnfr/backends/numpy_backend.py +238 -0
  12. tnfr/backends/optimized_numpy.py +420 -0
  13. tnfr/backends/torch_backend.py +408 -0
  14. tnfr/cache.py +149 -556
  15. tnfr/cache.pyi +13 -0
  16. tnfr/cli/__init__.py +51 -16
  17. tnfr/cli/__init__.pyi +26 -0
  18. tnfr/cli/arguments.py +344 -32
  19. tnfr/cli/arguments.pyi +29 -0
  20. tnfr/cli/execution.py +676 -50
  21. tnfr/cli/execution.pyi +70 -0
  22. tnfr/cli/interactive_validator.py +614 -0
  23. tnfr/cli/utils.py +18 -3
  24. tnfr/cli/utils.pyi +7 -0
  25. tnfr/cli/validate.py +236 -0
  26. tnfr/compat/__init__.py +85 -0
  27. tnfr/compat/dataclass.py +136 -0
  28. tnfr/compat/jsonschema_stub.py +61 -0
  29. tnfr/compat/matplotlib_stub.py +73 -0
  30. tnfr/compat/numpy_stub.py +155 -0
  31. tnfr/config/__init__.py +224 -0
  32. tnfr/config/__init__.pyi +10 -0
  33. tnfr/{constants_glyphs.py → config/constants.py} +26 -20
  34. tnfr/config/constants.pyi +12 -0
  35. tnfr/config/defaults.py +54 -0
  36. tnfr/{constants/core.py → config/defaults_core.py} +59 -6
  37. tnfr/config/defaults_init.py +33 -0
  38. tnfr/config/defaults_metric.py +104 -0
  39. tnfr/config/feature_flags.py +81 -0
  40. tnfr/config/feature_flags.pyi +16 -0
  41. tnfr/config/glyph_constants.py +31 -0
  42. tnfr/config/init.py +77 -0
  43. tnfr/config/init.pyi +8 -0
  44. tnfr/config/operator_names.py +254 -0
  45. tnfr/config/operator_names.pyi +36 -0
  46. tnfr/config/physics_derivation.py +354 -0
  47. tnfr/config/presets.py +83 -0
  48. tnfr/config/presets.pyi +7 -0
  49. tnfr/config/security.py +927 -0
  50. tnfr/config/thresholds.py +114 -0
  51. tnfr/config/tnfr_config.py +498 -0
  52. tnfr/constants/__init__.py +51 -133
  53. tnfr/constants/__init__.pyi +92 -0
  54. tnfr/constants/aliases.py +33 -0
  55. tnfr/constants/aliases.pyi +27 -0
  56. tnfr/constants/init.py +3 -1
  57. tnfr/constants/init.pyi +12 -0
  58. tnfr/constants/metric.py +9 -15
  59. tnfr/constants/metric.pyi +19 -0
  60. tnfr/core/__init__.py +33 -0
  61. tnfr/core/container.py +226 -0
  62. tnfr/core/default_implementations.py +329 -0
  63. tnfr/core/interfaces.py +279 -0
  64. tnfr/dynamics/__init__.py +213 -633
  65. tnfr/dynamics/__init__.pyi +83 -0
  66. tnfr/dynamics/adaptation.py +267 -0
  67. tnfr/dynamics/adaptation.pyi +7 -0
  68. tnfr/dynamics/adaptive_sequences.py +189 -0
  69. tnfr/dynamics/adaptive_sequences.pyi +14 -0
  70. tnfr/dynamics/aliases.py +23 -0
  71. tnfr/dynamics/aliases.pyi +19 -0
  72. tnfr/dynamics/bifurcation.py +232 -0
  73. tnfr/dynamics/canonical.py +229 -0
  74. tnfr/dynamics/canonical.pyi +48 -0
  75. tnfr/dynamics/coordination.py +385 -0
  76. tnfr/dynamics/coordination.pyi +25 -0
  77. tnfr/dynamics/dnfr.py +2699 -398
  78. tnfr/dynamics/dnfr.pyi +26 -0
  79. tnfr/dynamics/dynamic_limits.py +225 -0
  80. tnfr/dynamics/feedback.py +252 -0
  81. tnfr/dynamics/feedback.pyi +24 -0
  82. tnfr/dynamics/fused_dnfr.py +454 -0
  83. tnfr/dynamics/homeostasis.py +157 -0
  84. tnfr/dynamics/homeostasis.pyi +14 -0
  85. tnfr/dynamics/integrators.py +496 -102
  86. tnfr/dynamics/integrators.pyi +36 -0
  87. tnfr/dynamics/learning.py +310 -0
  88. tnfr/dynamics/learning.pyi +33 -0
  89. tnfr/dynamics/metabolism.py +254 -0
  90. tnfr/dynamics/nbody.py +796 -0
  91. tnfr/dynamics/nbody_tnfr.py +783 -0
  92. tnfr/dynamics/propagation.py +326 -0
  93. tnfr/dynamics/runtime.py +908 -0
  94. tnfr/dynamics/runtime.pyi +77 -0
  95. tnfr/dynamics/sampling.py +10 -5
  96. tnfr/dynamics/sampling.pyi +7 -0
  97. tnfr/dynamics/selectors.py +711 -0
  98. tnfr/dynamics/selectors.pyi +85 -0
  99. tnfr/dynamics/structural_clip.py +207 -0
  100. tnfr/errors/__init__.py +37 -0
  101. tnfr/errors/contextual.py +492 -0
  102. tnfr/execution.py +77 -55
  103. tnfr/execution.pyi +45 -0
  104. tnfr/extensions/__init__.py +205 -0
  105. tnfr/extensions/__init__.pyi +18 -0
  106. tnfr/extensions/base.py +173 -0
  107. tnfr/extensions/base.pyi +35 -0
  108. tnfr/extensions/business/__init__.py +71 -0
  109. tnfr/extensions/business/__init__.pyi +11 -0
  110. tnfr/extensions/business/cookbook.py +88 -0
  111. tnfr/extensions/business/cookbook.pyi +8 -0
  112. tnfr/extensions/business/health_analyzers.py +202 -0
  113. tnfr/extensions/business/health_analyzers.pyi +9 -0
  114. tnfr/extensions/business/patterns.py +183 -0
  115. tnfr/extensions/business/patterns.pyi +8 -0
  116. tnfr/extensions/medical/__init__.py +73 -0
  117. tnfr/extensions/medical/__init__.pyi +11 -0
  118. tnfr/extensions/medical/cookbook.py +88 -0
  119. tnfr/extensions/medical/cookbook.pyi +8 -0
  120. tnfr/extensions/medical/health_analyzers.py +181 -0
  121. tnfr/extensions/medical/health_analyzers.pyi +9 -0
  122. tnfr/extensions/medical/patterns.py +163 -0
  123. tnfr/extensions/medical/patterns.pyi +8 -0
  124. tnfr/flatten.py +29 -50
  125. tnfr/flatten.pyi +21 -0
  126. tnfr/gamma.py +66 -53
  127. tnfr/gamma.pyi +36 -0
  128. tnfr/glyph_history.py +144 -57
  129. tnfr/glyph_history.pyi +35 -0
  130. tnfr/glyph_runtime.py +19 -0
  131. tnfr/glyph_runtime.pyi +8 -0
  132. tnfr/immutable.py +70 -30
  133. tnfr/immutable.pyi +36 -0
  134. tnfr/initialization.py +22 -16
  135. tnfr/initialization.pyi +65 -0
  136. tnfr/io.py +5 -241
  137. tnfr/io.pyi +13 -0
  138. tnfr/locking.pyi +7 -0
  139. tnfr/mathematics/__init__.py +79 -0
  140. tnfr/mathematics/backend.py +453 -0
  141. tnfr/mathematics/backend.pyi +99 -0
  142. tnfr/mathematics/dynamics.py +408 -0
  143. tnfr/mathematics/dynamics.pyi +90 -0
  144. tnfr/mathematics/epi.py +391 -0
  145. tnfr/mathematics/epi.pyi +65 -0
  146. tnfr/mathematics/generators.py +242 -0
  147. tnfr/mathematics/generators.pyi +29 -0
  148. tnfr/mathematics/metrics.py +119 -0
  149. tnfr/mathematics/metrics.pyi +16 -0
  150. tnfr/mathematics/operators.py +239 -0
  151. tnfr/mathematics/operators.pyi +59 -0
  152. tnfr/mathematics/operators_factory.py +124 -0
  153. tnfr/mathematics/operators_factory.pyi +11 -0
  154. tnfr/mathematics/projection.py +87 -0
  155. tnfr/mathematics/projection.pyi +33 -0
  156. tnfr/mathematics/runtime.py +182 -0
  157. tnfr/mathematics/runtime.pyi +64 -0
  158. tnfr/mathematics/spaces.py +256 -0
  159. tnfr/mathematics/spaces.pyi +83 -0
  160. tnfr/mathematics/transforms.py +305 -0
  161. tnfr/mathematics/transforms.pyi +62 -0
  162. tnfr/metrics/__init__.py +47 -9
  163. tnfr/metrics/__init__.pyi +20 -0
  164. tnfr/metrics/buffer_cache.py +163 -0
  165. tnfr/metrics/buffer_cache.pyi +24 -0
  166. tnfr/metrics/cache_utils.py +214 -0
  167. tnfr/metrics/coherence.py +1510 -330
  168. tnfr/metrics/coherence.pyi +129 -0
  169. tnfr/metrics/common.py +23 -16
  170. tnfr/metrics/common.pyi +35 -0
  171. tnfr/metrics/core.py +251 -36
  172. tnfr/metrics/core.pyi +13 -0
  173. tnfr/metrics/diagnosis.py +709 -110
  174. tnfr/metrics/diagnosis.pyi +86 -0
  175. tnfr/metrics/emergence.py +245 -0
  176. tnfr/metrics/export.py +60 -18
  177. tnfr/metrics/export.pyi +7 -0
  178. tnfr/metrics/glyph_timing.py +233 -43
  179. tnfr/metrics/glyph_timing.pyi +81 -0
  180. tnfr/metrics/learning_metrics.py +280 -0
  181. tnfr/metrics/learning_metrics.pyi +21 -0
  182. tnfr/metrics/phase_coherence.py +351 -0
  183. tnfr/metrics/phase_compatibility.py +349 -0
  184. tnfr/metrics/reporting.py +63 -28
  185. tnfr/metrics/reporting.pyi +25 -0
  186. tnfr/metrics/sense_index.py +1126 -43
  187. tnfr/metrics/sense_index.pyi +9 -0
  188. tnfr/metrics/trig.py +215 -23
  189. tnfr/metrics/trig.pyi +13 -0
  190. tnfr/metrics/trig_cache.py +148 -24
  191. tnfr/metrics/trig_cache.pyi +10 -0
  192. tnfr/multiscale/__init__.py +32 -0
  193. tnfr/multiscale/hierarchical.py +517 -0
  194. tnfr/node.py +646 -140
  195. tnfr/node.pyi +139 -0
  196. tnfr/observers.py +160 -45
  197. tnfr/observers.pyi +31 -0
  198. tnfr/ontosim.py +23 -19
  199. tnfr/ontosim.pyi +28 -0
  200. tnfr/operators/__init__.py +1358 -106
  201. tnfr/operators/__init__.pyi +31 -0
  202. tnfr/operators/algebra.py +277 -0
  203. tnfr/operators/canonical_patterns.py +420 -0
  204. tnfr/operators/cascade.py +267 -0
  205. tnfr/operators/cycle_detection.py +358 -0
  206. tnfr/operators/definitions.py +4108 -0
  207. tnfr/operators/definitions.pyi +78 -0
  208. tnfr/operators/grammar.py +1164 -0
  209. tnfr/operators/grammar.pyi +140 -0
  210. tnfr/operators/hamiltonian.py +710 -0
  211. tnfr/operators/health_analyzer.py +809 -0
  212. tnfr/operators/jitter.py +107 -38
  213. tnfr/operators/jitter.pyi +11 -0
  214. tnfr/operators/lifecycle.py +314 -0
  215. tnfr/operators/metabolism.py +618 -0
  216. tnfr/operators/metrics.py +2138 -0
  217. tnfr/operators/network_analysis/__init__.py +27 -0
  218. tnfr/operators/network_analysis/source_detection.py +186 -0
  219. tnfr/operators/nodal_equation.py +395 -0
  220. tnfr/operators/pattern_detection.py +660 -0
  221. tnfr/operators/patterns.py +669 -0
  222. tnfr/operators/postconditions/__init__.py +38 -0
  223. tnfr/operators/postconditions/mutation.py +236 -0
  224. tnfr/operators/preconditions/__init__.py +1226 -0
  225. tnfr/operators/preconditions/coherence.py +305 -0
  226. tnfr/operators/preconditions/dissonance.py +236 -0
  227. tnfr/operators/preconditions/emission.py +128 -0
  228. tnfr/operators/preconditions/mutation.py +580 -0
  229. tnfr/operators/preconditions/reception.py +125 -0
  230. tnfr/operators/preconditions/resonance.py +364 -0
  231. tnfr/operators/registry.py +74 -0
  232. tnfr/operators/registry.pyi +9 -0
  233. tnfr/operators/remesh.py +1415 -91
  234. tnfr/operators/remesh.pyi +26 -0
  235. tnfr/operators/structural_units.py +268 -0
  236. tnfr/operators/unified_grammar.py +105 -0
  237. tnfr/parallel/__init__.py +54 -0
  238. tnfr/parallel/auto_scaler.py +234 -0
  239. tnfr/parallel/distributed.py +384 -0
  240. tnfr/parallel/engine.py +238 -0
  241. tnfr/parallel/gpu_engine.py +420 -0
  242. tnfr/parallel/monitoring.py +248 -0
  243. tnfr/parallel/partitioner.py +459 -0
  244. tnfr/py.typed +0 -0
  245. tnfr/recipes/__init__.py +22 -0
  246. tnfr/recipes/cookbook.py +743 -0
  247. tnfr/rng.py +75 -151
  248. tnfr/rng.pyi +26 -0
  249. tnfr/schemas/__init__.py +8 -0
  250. tnfr/schemas/grammar.json +94 -0
  251. tnfr/sdk/__init__.py +107 -0
  252. tnfr/sdk/__init__.pyi +19 -0
  253. tnfr/sdk/adaptive_system.py +173 -0
  254. tnfr/sdk/adaptive_system.pyi +21 -0
  255. tnfr/sdk/builders.py +370 -0
  256. tnfr/sdk/builders.pyi +51 -0
  257. tnfr/sdk/fluent.py +1121 -0
  258. tnfr/sdk/fluent.pyi +74 -0
  259. tnfr/sdk/templates.py +342 -0
  260. tnfr/sdk/templates.pyi +41 -0
  261. tnfr/sdk/utils.py +341 -0
  262. tnfr/secure_config.py +46 -0
  263. tnfr/security/__init__.py +70 -0
  264. tnfr/security/database.py +514 -0
  265. tnfr/security/subprocess.py +503 -0
  266. tnfr/security/validation.py +290 -0
  267. tnfr/selector.py +59 -22
  268. tnfr/selector.pyi +19 -0
  269. tnfr/sense.py +92 -67
  270. tnfr/sense.pyi +23 -0
  271. tnfr/services/__init__.py +17 -0
  272. tnfr/services/orchestrator.py +325 -0
  273. tnfr/sparse/__init__.py +39 -0
  274. tnfr/sparse/representations.py +492 -0
  275. tnfr/structural.py +639 -263
  276. tnfr/structural.pyi +83 -0
  277. tnfr/telemetry/__init__.py +35 -0
  278. tnfr/telemetry/cache_metrics.py +226 -0
  279. tnfr/telemetry/cache_metrics.pyi +64 -0
  280. tnfr/telemetry/nu_f.py +422 -0
  281. tnfr/telemetry/nu_f.pyi +108 -0
  282. tnfr/telemetry/verbosity.py +36 -0
  283. tnfr/telemetry/verbosity.pyi +15 -0
  284. tnfr/tokens.py +2 -4
  285. tnfr/tokens.pyi +36 -0
  286. tnfr/tools/__init__.py +20 -0
  287. tnfr/tools/domain_templates.py +478 -0
  288. tnfr/tools/sequence_generator.py +846 -0
  289. tnfr/topology/__init__.py +13 -0
  290. tnfr/topology/asymmetry.py +151 -0
  291. tnfr/trace.py +300 -126
  292. tnfr/trace.pyi +42 -0
  293. tnfr/tutorials/__init__.py +38 -0
  294. tnfr/tutorials/autonomous_evolution.py +285 -0
  295. tnfr/tutorials/interactive.py +1576 -0
  296. tnfr/tutorials/structural_metabolism.py +238 -0
  297. tnfr/types.py +743 -12
  298. tnfr/types.pyi +357 -0
  299. tnfr/units.py +68 -0
  300. tnfr/units.pyi +13 -0
  301. tnfr/utils/__init__.py +282 -0
  302. tnfr/utils/__init__.pyi +215 -0
  303. tnfr/utils/cache.py +4223 -0
  304. tnfr/utils/cache.pyi +470 -0
  305. tnfr/{callback_utils.py → utils/callbacks.py} +26 -39
  306. tnfr/utils/callbacks.pyi +49 -0
  307. tnfr/utils/chunks.py +108 -0
  308. tnfr/utils/chunks.pyi +22 -0
  309. tnfr/utils/data.py +428 -0
  310. tnfr/utils/data.pyi +74 -0
  311. tnfr/utils/graph.py +85 -0
  312. tnfr/utils/graph.pyi +10 -0
  313. tnfr/utils/init.py +821 -0
  314. tnfr/utils/init.pyi +80 -0
  315. tnfr/utils/io.py +559 -0
  316. tnfr/utils/io.pyi +66 -0
  317. tnfr/{helpers → utils}/numeric.py +51 -24
  318. tnfr/utils/numeric.pyi +21 -0
  319. tnfr/validation/__init__.py +257 -0
  320. tnfr/validation/__init__.pyi +85 -0
  321. tnfr/validation/compatibility.py +460 -0
  322. tnfr/validation/compatibility.pyi +6 -0
  323. tnfr/validation/config.py +73 -0
  324. tnfr/validation/graph.py +139 -0
  325. tnfr/validation/graph.pyi +18 -0
  326. tnfr/validation/input_validation.py +755 -0
  327. tnfr/validation/invariants.py +712 -0
  328. tnfr/validation/rules.py +253 -0
  329. tnfr/validation/rules.pyi +44 -0
  330. tnfr/validation/runtime.py +279 -0
  331. tnfr/validation/runtime.pyi +28 -0
  332. tnfr/validation/sequence_validator.py +162 -0
  333. tnfr/validation/soft_filters.py +170 -0
  334. tnfr/validation/soft_filters.pyi +32 -0
  335. tnfr/validation/spectral.py +164 -0
  336. tnfr/validation/spectral.pyi +42 -0
  337. tnfr/validation/validator.py +1266 -0
  338. tnfr/validation/window.py +39 -0
  339. tnfr/validation/window.pyi +1 -0
  340. tnfr/visualization/__init__.py +98 -0
  341. tnfr/visualization/cascade_viz.py +256 -0
  342. tnfr/visualization/hierarchy.py +284 -0
  343. tnfr/visualization/sequence_plotter.py +784 -0
  344. tnfr/viz/__init__.py +60 -0
  345. tnfr/viz/matplotlib.py +278 -0
  346. tnfr/viz/matplotlib.pyi +35 -0
  347. tnfr-8.5.0.dist-info/METADATA +573 -0
  348. tnfr-8.5.0.dist-info/RECORD +353 -0
  349. {tnfr-4.5.2.dist-info → tnfr-8.5.0.dist-info}/entry_points.txt +1 -0
  350. {tnfr-4.5.2.dist-info → tnfr-8.5.0.dist-info}/licenses/LICENSE.md +1 -1
  351. tnfr/collections_utils.py +0 -300
  352. tnfr/config.py +0 -32
  353. tnfr/grammar.py +0 -344
  354. tnfr/graph_utils.py +0 -84
  355. tnfr/helpers/__init__.py +0 -71
  356. tnfr/import_utils.py +0 -228
  357. tnfr/json_utils.py +0 -162
  358. tnfr/logging_utils.py +0 -116
  359. tnfr/presets.py +0 -60
  360. tnfr/validators.py +0 -84
  361. tnfr/value_utils.py +0 -59
  362. tnfr-4.5.2.dist-info/METADATA +0 -379
  363. tnfr-4.5.2.dist-info/RECORD +0 -67
  364. {tnfr-4.5.2.dist-info → tnfr-8.5.0.dist-info}/WHEEL +0 -0
  365. {tnfr-4.5.2.dist-info → tnfr-8.5.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,36 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Literal
4
+
5
+ from tnfr.types import TNFRGraph
6
+
7
+ __all__: tuple[str, ...]
8
+
9
+ class AbstractIntegrator:
10
+ def integrate(
11
+ self,
12
+ graph: TNFRGraph,
13
+ *,
14
+ dt: float | None = ...,
15
+ t: float | None = ...,
16
+ method: str | None = ...,
17
+ n_jobs: int | None = ...,
18
+ ) -> None: ...
19
+
20
+ class DefaultIntegrator(AbstractIntegrator):
21
+ def __init__(self) -> None: ...
22
+
23
+ def prepare_integration_params(
24
+ G: TNFRGraph,
25
+ dt: float | None = ...,
26
+ t: float | None = ...,
27
+ method: Literal["euler", "rk4"] | None = ...,
28
+ ) -> tuple[float, int, float, Literal["euler", "rk4"]]: ...
29
+ def update_epi_via_nodal_equation(
30
+ G: TNFRGraph,
31
+ *,
32
+ dt: float | None = ...,
33
+ t: float | None = ...,
34
+ method: Literal["euler", "rk4"] | None = ...,
35
+ n_jobs: int | None = ...,
36
+ ) -> None: ...
@@ -0,0 +1,310 @@
1
+ """Adaptive learning system for TNFR.
2
+
3
+ This module implements high-level adaptive learning dynamics combining
4
+ emission (AL) and self-organization (T'HOL) operators into canonical
5
+ learning cycles. All functionality reuses existing TNFR infrastructure.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any, Sequence
11
+
12
+ from ..alias import get_attr
13
+ from ..constants.aliases import ALIAS_EPI, ALIAS_DNFR
14
+ from ..operators.definitions import (
15
+ Coherence,
16
+ Contraction,
17
+ Dissonance,
18
+ Emission,
19
+ Mutation,
20
+ Operator,
21
+ Reception,
22
+ Recursivity,
23
+ Resonance,
24
+ SelfOrganization,
25
+ Silence,
26
+ Transition,
27
+ )
28
+ from ..structural import run_sequence
29
+ from ..types import TNFRGraph
30
+
31
+ __all__ = ["AdaptiveLearningSystem"]
32
+
33
+
34
+ class AdaptiveLearningSystem:
35
+ """System for adaptive learning using TNFR operators.
36
+
37
+ This class orchestrates adaptive learning cycles combining emission (AL),
38
+ reception (EN), self-organization (T'HOL), and stabilization (IL) operators.
39
+ It implements the canonical learning sequences defined in the TNFR manual.
40
+
41
+ All methods reuse existing operators and run_sequence infrastructure.
42
+
43
+ Parameters
44
+ ----------
45
+ graph : TNFRGraph
46
+ Graph containing the learning node.
47
+ node : Any
48
+ Node identifier for the learning entity.
49
+ learning_rate : float, default=1.0
50
+ Sensitivity to dissonance that triggers reorganization. Higher values
51
+ make the system more responsive to novel stimuli.
52
+ consolidation_threshold : float, default=0.7
53
+ ΔNFR threshold below which the system stabilizes. Lower values mean
54
+ earlier consolidation.
55
+
56
+ Attributes
57
+ ----------
58
+ G : TNFRGraph
59
+ Reference to the graph.
60
+ node : Any
61
+ Node being managed.
62
+ learning_rate : float
63
+ Configured learning sensitivity.
64
+ consolidation_threshold : float
65
+ Configured consolidation trigger.
66
+
67
+ Examples
68
+ --------
69
+ >>> from tnfr.structural import create_nfr
70
+ >>> from tnfr.dynamics.learning import AdaptiveLearningSystem
71
+ >>> G, node = create_nfr("learner", epi=0.3, vf=1.0)
72
+ >>> system = AdaptiveLearningSystem(G, node, learning_rate=0.8)
73
+ >>> # Basic learning cycle
74
+ >>> system.learn_from_input(stimulus=0.5, consolidate=True)
75
+ >>> # Consolidate memory
76
+ >>> system.consolidate_memory()
77
+ """
78
+
79
+ def __init__(
80
+ self,
81
+ graph: TNFRGraph,
82
+ node: Any,
83
+ learning_rate: float = 1.0,
84
+ consolidation_threshold: float = 0.7,
85
+ ) -> None:
86
+ """Initialize adaptive learning system."""
87
+ self.G = graph
88
+ self.node = node
89
+ self.learning_rate = learning_rate
90
+ self.consolidation_threshold = consolidation_threshold
91
+
92
+ def learn_from_input(
93
+ self,
94
+ stimulus: float,
95
+ consolidate: bool = True,
96
+ ) -> None:
97
+ """Execute learning cycle from external stimulus.
98
+
99
+ Implements canonical learning sequence following TNFR grammar:
100
+ - AL (Emission): Activate learning readiness
101
+ - EN (Reception): Receive stimulus
102
+ - IL (Coherence): Stabilize before dissonance (grammar requirement)
103
+ - OZ (Dissonance): If stimulus is dissonant
104
+ - T'HOL (SelfOrganization): Reorganize if needed
105
+ - NUL (Contraction): Close T'HOL block (grammar requirement)
106
+ - IL (Coherence): Consolidate if requested
107
+ - SHA (Silence): End sequence properly
108
+
109
+ Parameters
110
+ ----------
111
+ stimulus : float
112
+ External input value to learn from.
113
+ consolidate : bool, default=True
114
+ Whether to stabilize after learning.
115
+
116
+ Notes
117
+ -----
118
+ Reuses run_sequence and existing operators for all transformations.
119
+ Dissonance detection uses current EPI from node attributes.
120
+ Sequences must follow TNFR grammar rules including T'HOL closure.
121
+
122
+ **Grammar compliance:**
123
+
124
+ - T'HOL (SelfOrganization) blocks require closure with NUL (Contraction) or SHA (Silence)
125
+ - Dissonance should be preceded by stabilization (Coherence)
126
+ """
127
+ sequence: list[Operator] = [Emission(), Reception()]
128
+
129
+ # Check if stimulus is dissonant (requires reorganization)
130
+ if self._is_dissonant(stimulus):
131
+ # For dissonant input, follow grammar-compliant reorganization
132
+ # T'HOL block must be closed with SILENCE or CONTRACTION
133
+ sequence.extend(
134
+ [
135
+ Coherence(), # Stabilize before dissonance (grammar)
136
+ Dissonance(), # Introduce controlled instability
137
+ SelfOrganization(), # Autonomous reorganization
138
+ Silence(), # Close T'HOL block and end sequence (grammar requirement)
139
+ ]
140
+ )
141
+ else:
142
+ # Non-dissonant: simpler path with optional consolidation
143
+ if consolidate:
144
+ sequence.append(Coherence())
145
+ sequence.append(Silence()) # Always end with terminal operator
146
+
147
+ # Execute using canonical run_sequence
148
+ run_sequence(self.G, self.node, sequence)
149
+
150
+ def _is_dissonant(self, stimulus: float) -> bool:
151
+ """Determine if stimulus requires reorganization.
152
+
153
+ Parameters
154
+ ----------
155
+ stimulus : float
156
+ External stimulus value.
157
+
158
+ Returns
159
+ -------
160
+ bool
161
+ True if stimulus differs significantly from current EPI.
162
+
163
+ Notes
164
+ -----
165
+ Reuses get_attr for accessing node EPI canonically.
166
+ """
167
+ current_epi = float(get_attr(self.G.nodes[self.node], ALIAS_EPI, 0.0))
168
+ return abs(stimulus - current_epi) > self.learning_rate
169
+
170
+ def consolidate_memory(self) -> None:
171
+ """Execute memory consolidation cycle.
172
+
173
+ Implements canonical consolidation sequence:
174
+ - AL (Emission): Reactivate for consolidation
175
+ - EN (Reception): Integrate memory
176
+ - IL (Coherence): Stabilize structure
177
+ - REMESH (Recursivity): Recursive consolidation
178
+
179
+ Notes
180
+ -----
181
+ Reuses run_sequence and existing operators for consolidation.
182
+ This sequence is useful for post-learning stabilization.
183
+ Follows TNFR grammar: must start with emission and include reception->coherence.
184
+ """
185
+ sequence = [Emission(), Reception(), Coherence(), Recursivity()]
186
+ run_sequence(self.G, self.node, sequence)
187
+
188
+ def adaptive_cycle(self, num_iterations: int = 10) -> None:
189
+ """Execute full adaptive learning cycle with exploration.
190
+
191
+ Implements iterative learning with conditional stabilization:
192
+ - Each iteration: AL -> EN -> IL -> THOL with closure
193
+ - Stabilizes with SILENCE if ΔNFR below threshold
194
+ - Continues exploring with DISSONANCE if ΔNFR above threshold
195
+
196
+ Parameters
197
+ ----------
198
+ num_iterations : int, default=10
199
+ Number of learning iterations to execute.
200
+
201
+ Notes
202
+ -----
203
+ Reuses operators and _should_stabilize logic for adaptive behavior.
204
+ Each iteration applies a grammar-compliant sequence.
205
+ T'HOL requires proper context (AL -> EN -> IL) and closure (SILENCE/CONTRACTION).
206
+ """
207
+ for _ in range(num_iterations):
208
+ # Grammar-compliant activation sequence
209
+ Emission()(self.G, self.node)
210
+ Reception()(self.G, self.node)
211
+ Coherence()(self.G, self.node)
212
+
213
+ # Self-organization: autonomous reorganization
214
+ SelfOrganization()(self.G, self.node)
215
+
216
+ # T'HOL requires closure
217
+ Silence()(self.G, self.node)
218
+
219
+ def _should_stabilize(self) -> bool:
220
+ """Decide whether to stabilize based on current ΔNFR.
221
+
222
+ Returns
223
+ -------
224
+ bool
225
+ True if ΔNFR is below consolidation threshold.
226
+
227
+ Notes
228
+ -----
229
+ Reuses get_attr for accessing ΔNFR canonically.
230
+ Low ΔNFR indicates structure is settling and ready for consolidation.
231
+ """
232
+ dnfr = abs(float(get_attr(self.G.nodes[self.node], ALIAS_DNFR, 0.0)))
233
+ return dnfr < self.consolidation_threshold
234
+
235
+ def deep_learning_cycle(self) -> None:
236
+ """Execute deep learning with crisis and reorganization.
237
+
238
+ Implements canonical deep learning sequence:
239
+ AL -> EN -> IL -> OZ -> THOL -> IL -> (SHA or NUL)
240
+
241
+ The final operator (SHA/SILENCE or NUL/CONTRACTION) is selected by
242
+ the TNFR grammar based on structural conditions:
243
+ - SHA (SILENCE) if Si >= si_high (high sense index)
244
+ - NUL (CONTRACTION) if Si < si_high (low sense index)
245
+
246
+ This is canonical THOL closure behavior per TNFR sec.4.
247
+
248
+ Notes
249
+ -----
250
+ Reuses run_sequence with predefined deep learning pattern.
251
+ Grammar may adaptively select the appropriate THOL closure.
252
+ """
253
+ sequence = [
254
+ Emission(),
255
+ Reception(),
256
+ Coherence(),
257
+ Dissonance(),
258
+ SelfOrganization(),
259
+ Coherence(),
260
+ Silence(), # Grammar may replace with Contraction if Si < si_high
261
+ ]
262
+ run_sequence(self.G, self.node, sequence)
263
+
264
+ def exploratory_learning_cycle(self) -> None:
265
+ """Execute exploratory learning with enhanced propagation.
266
+
267
+ Implements canonical exploratory learning sequence:
268
+ AL -> EN -> IL -> OZ -> THOL -> IL -> SHA
269
+
270
+ After self-organization, coherence stabilizes and closes T'HOL,
271
+ then silence terminates.
272
+
273
+ Notes
274
+ -----
275
+ Reuses run_sequence with predefined exploratory pattern.
276
+ This is similar to deep_learning_cycle but focuses on consolidation.
277
+ Supports operational fractality (nested THOL allowed per sec.3.7).
278
+ """
279
+ sequence = [
280
+ Emission(),
281
+ Reception(),
282
+ Coherence(),
283
+ Dissonance(),
284
+ SelfOrganization(),
285
+ Coherence(), # Stabilize and close T'HOL
286
+ Silence(), # Terminal operator
287
+ ]
288
+ run_sequence(self.G, self.node, sequence)
289
+
290
+ def adaptive_mutation_cycle(self) -> None:
291
+ """Execute transformative learning with mutation.
292
+
293
+ Implements canonical adaptive mutation sequence:
294
+ AL -> EN -> IL -> OZ -> ZHIR -> NAV
295
+
296
+ Notes
297
+ -----
298
+ Reuses run_sequence with predefined mutation pattern.
299
+ This represents transformative learning with phase transitions.
300
+ Follows TNFR grammar: dissonance before mutation, ends with transition.
301
+ """
302
+ sequence = [
303
+ Emission(),
304
+ Reception(),
305
+ Coherence(),
306
+ Dissonance(),
307
+ Mutation(),
308
+ Transition(),
309
+ ]
310
+ run_sequence(self.G, self.node, sequence)
@@ -0,0 +1,33 @@
1
+ """Type stubs for adaptive learning module."""
2
+
3
+ from typing import Any
4
+
5
+ from ..types import TNFRGraph
6
+
7
+ class AdaptiveLearningSystem:
8
+ """System for adaptive learning using TNFR operators."""
9
+
10
+ G: TNFRGraph
11
+ node: Any
12
+ learning_rate: float
13
+ consolidation_threshold: float
14
+
15
+ def __init__(
16
+ self,
17
+ graph: TNFRGraph,
18
+ node: Any,
19
+ learning_rate: float = ...,
20
+ consolidation_threshold: float = ...,
21
+ ) -> None: ...
22
+ def learn_from_input(
23
+ self,
24
+ stimulus: float,
25
+ consolidate: bool = ...,
26
+ ) -> None: ...
27
+ def _is_dissonant(self, stimulus: float) -> bool: ...
28
+ def consolidate_memory(self) -> None: ...
29
+ def adaptive_cycle(self, num_iterations: int = ...) -> None: ...
30
+ def _should_stabilize(self) -> bool: ...
31
+ def deep_learning_cycle(self) -> None: ...
32
+ def exploratory_learning_cycle(self) -> None: ...
33
+ def adaptive_mutation_cycle(self) -> None: ...
@@ -0,0 +1,254 @@
1
+ """Structural metabolism implementation for TNFR.
2
+
3
+ T'HOL (Self-Organization) as metabolic process: receiving external stimuli,
4
+ reorganizing them autonomously into internal structure, and stabilizing results.
5
+
6
+ This module implements metabolic cycles that use T'HOL as the engine of
7
+ structural transformation and adaptation.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import TYPE_CHECKING, Any
13
+
14
+ if TYPE_CHECKING:
15
+ from ..types import NodeId, TNFRGraph
16
+
17
+ from ..alias import get_attr
18
+ from ..constants.aliases import ALIAS_DNFR
19
+
20
+ __all__ = [
21
+ "StructuralMetabolism",
22
+ "digest_stimulus",
23
+ "adaptive_metabolism",
24
+ "cascading_reorganization",
25
+ ]
26
+
27
+
28
+ class StructuralMetabolism:
29
+ """Implements T'HOL-based structural metabolism cycles.
30
+
31
+ T'HOL is not just self-organization - it's **structural metabolism**:
32
+ the capacity to digest external experience and reorganize it into
33
+ internal structure without external instruction.
34
+
35
+ **Metabolic Characteristics:**
36
+
37
+ - **Reception (EN)**: Ingests external stimulus
38
+ - **Reorganization (THOL)**: Autonomously transforms stimulus to structure
39
+ - **Stabilization (IL)**: Consolidates new structural configuration
40
+
41
+ This creates a complete metabolic cycle: EN → THOL → IL
42
+
43
+ Parameters
44
+ ----------
45
+ graph : TNFRGraph
46
+ Graph containing the metabolizing node
47
+ node : NodeId
48
+ Identifier of the node performing metabolism
49
+
50
+ Attributes
51
+ ----------
52
+ G : TNFRGraph
53
+ Reference to the graph
54
+ node : NodeId
55
+ Reference to the node identifier
56
+ metabolic_rate : float
57
+ Scaling factor for metabolic intensity (default 1.0)
58
+
59
+ Examples
60
+ --------
61
+ >>> from tnfr.structural import create_nfr
62
+ >>> from tnfr.dynamics.metabolism import StructuralMetabolism
63
+ >>> G, node = create_nfr("cell", epi=0.5, vf=1.0)
64
+ >>> metabolism = StructuralMetabolism(G, node)
65
+ >>> # Digest external stimulus
66
+ >>> metabolism.digest(0.3) # doctest: +SKIP
67
+ >>> # Result: stimulus integrated and reorganized structurally
68
+ """
69
+
70
+ def __init__(self, graph: TNFRGraph, node: NodeId) -> None:
71
+ """Initialize structural metabolism for a node.
72
+
73
+ Parameters
74
+ ----------
75
+ graph : TNFRGraph
76
+ Graph containing the node
77
+ node : NodeId
78
+ Node identifier
79
+ """
80
+ self.G = graph
81
+ self.node = node
82
+ self.metabolic_rate = 1.0
83
+
84
+ def digest(self, tau: float = 0.08) -> None:
85
+ """Metabolize external stimulus through complete metabolic cycle.
86
+
87
+ Implements the canonical metabolic sequence: EN → THOL → IL
88
+
89
+ 1. Reception (EN): Receives external stimulus from neighbors
90
+ 2. Reorganization (THOL): Autonomously transforms into structure
91
+ 3. Stabilization (IL): Consolidates the result
92
+
93
+ Parameters
94
+ ----------
95
+ tau : float
96
+ Bifurcation threshold for THOL (default 0.08)
97
+
98
+ Notes
99
+ -----
100
+ The metabolic rate modulates the intensity of each operation.
101
+ Lower tau increases likelihood of bifurcation during reorganization.
102
+ """
103
+ from ..operators.definitions import Reception, SelfOrganization, Coherence
104
+
105
+ # 1. Receive external stimulus
106
+ Reception()(self.G, self.node)
107
+
108
+ # 2. Reorganize metabolically (T'HOL with controlled bifurcation)
109
+ SelfOrganization()(self.G, self.node, tau=tau)
110
+
111
+ # 3. Stabilize result
112
+ Coherence()(self.G, self.node)
113
+
114
+ def adaptive_metabolism(self, stress_level: float) -> None:
115
+ """Adapt metabolic response to stress level.
116
+
117
+ High stress (dissonance) triggers deeper reorganization with
118
+ increased bifurcation probability. Low stress allows gentler
119
+ metabolic cycles.
120
+
121
+ Parameters
122
+ ----------
123
+ stress_level : float
124
+ Level of structural stress/dissonance (0.0 to 1.0+)
125
+ - < 0.5: Moderate stress, gentle reorganization
126
+ - >= 0.5: High stress, deep reorganization with dissonance
127
+
128
+ Notes
129
+ -----
130
+ This implements adaptive structural metabolism where the depth
131
+ of reorganization scales with environmental pressure.
132
+ """
133
+ from ..operators.definitions import (
134
+ Dissonance,
135
+ SelfOrganization,
136
+ Coherence,
137
+ )
138
+
139
+ if stress_level >= 0.5:
140
+ # High stress: dissonance + deep reorganization
141
+ # Apply operators individually to avoid grammar restrictions
142
+ Dissonance()(self.G, self.node) # Introduce controlled instability
143
+ SelfOrganization()(
144
+ self.G, self.node, tau=0.08
145
+ ) # Deep reorganization (likely bifurcates)
146
+ Coherence()(self.G, self.node) # Stabilize new configuration
147
+ else:
148
+ # Moderate stress: gentle reorganization
149
+ # Higher tau reduces bifurcation probability
150
+ SelfOrganization()(self.G, self.node, tau=0.15)
151
+
152
+ def cascading_reorganization(self, depth: int = 3) -> None:
153
+ """Execute recursive T'HOL cascade.
154
+
155
+ Applies T'HOL multiple times with progressively decreasing
156
+ bifurcation thresholds, creating nested structural reorganization.
157
+
158
+ This implements operational fractality: reorganization at multiple
159
+ scales simultaneously.
160
+
161
+ Parameters
162
+ ----------
163
+ depth : int
164
+ Number of cascade levels (default 3)
165
+
166
+ Notes
167
+ -----
168
+ Each level uses tau = 0.1 * (0.8 ^ level), creating progressively
169
+ more sensitive bifurcation at deeper levels.
170
+
171
+ **Warning**: Deep cascades (depth > 5) may create highly complex
172
+ nested structures. Monitor structural complexity metrics.
173
+ """
174
+ from ..operators.definitions import SelfOrganization
175
+
176
+ for level in range(depth):
177
+ # Decreasing threshold: deeper levels bifurcate more easily
178
+ tau = 0.1 * (0.8**level)
179
+ SelfOrganization()(self.G, self.node, tau=tau)
180
+
181
+
182
+ def digest_stimulus(G: TNFRGraph, node: NodeId, tau: float = 0.08) -> None:
183
+ """Functional interface for single metabolic cycle.
184
+
185
+ Equivalent to `StructuralMetabolism(G, node).digest(tau)`.
186
+
187
+ Parameters
188
+ ----------
189
+ G : TNFRGraph
190
+ Graph containing the node
191
+ node : NodeId
192
+ Node identifier
193
+ tau : float
194
+ Bifurcation threshold
195
+
196
+ Examples
197
+ --------
198
+ >>> from tnfr.structural import create_nfr
199
+ >>> from tnfr.dynamics.metabolism import digest_stimulus
200
+ >>> G, node = create_nfr("neuron", epi=0.4, vf=1.2)
201
+ >>> digest_stimulus(G, node, tau=0.1) # doctest: +SKIP
202
+ """
203
+ metabolism = StructuralMetabolism(G, node)
204
+ metabolism.digest(tau)
205
+
206
+
207
+ def adaptive_metabolism(G: TNFRGraph, node: NodeId, stress: float) -> None:
208
+ """Functional interface for adaptive metabolic response.
209
+
210
+ Equivalent to `StructuralMetabolism(G, node).adaptive_metabolism(stress)`.
211
+
212
+ Parameters
213
+ ----------
214
+ G : TNFRGraph
215
+ Graph containing the node
216
+ node : NodeId
217
+ Node identifier
218
+ stress : float
219
+ Stress level (0.0 to 1.0+)
220
+
221
+ Examples
222
+ --------
223
+ >>> from tnfr.structural import create_nfr
224
+ >>> from tnfr.dynamics.metabolism import adaptive_metabolism
225
+ >>> G, node = create_nfr("organism", epi=0.6, vf=1.0)
226
+ >>> adaptive_metabolism(G, node, stress=0.7) # doctest: +SKIP
227
+ """
228
+ metabolism = StructuralMetabolism(G, node)
229
+ metabolism.adaptive_metabolism(stress)
230
+
231
+
232
+ def cascading_reorganization(G: TNFRGraph, node: NodeId, depth: int = 3) -> None:
233
+ """Functional interface for cascading reorganization.
234
+
235
+ Equivalent to `StructuralMetabolism(G, node).cascading_reorganization(depth)`.
236
+
237
+ Parameters
238
+ ----------
239
+ G : TNFRGraph
240
+ Graph containing the node
241
+ node : NodeId
242
+ Node identifier
243
+ depth : int
244
+ Cascade depth
245
+
246
+ Examples
247
+ --------
248
+ >>> from tnfr.structural import create_nfr
249
+ >>> from tnfr.dynamics.metabolism import cascading_reorganization
250
+ >>> G, node = create_nfr("system", epi=0.7, vf=1.1)
251
+ >>> cascading_reorganization(G, node, depth=3) # doctest: +SKIP
252
+ """
253
+ metabolism = StructuralMetabolism(G, node)
254
+ metabolism.cascading_reorganization(depth)