-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCognitiveEngine.cpp
More file actions
148 lines (123 loc) · 5.27 KB
/
Copy pathCognitiveEngine.cpp
File metadata and controls
148 lines (123 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "CognitiveEngine.h"
#include <iostream>
#include <iomanip>
#include <cmath>
void CognitiveEngine::recordTrace(const std::string& entry) {
sessionLog.push_back(entry);
}
CognitiveEngine::CognitiveEngine()
: engineTag("CE-DEFAULT"),
currentLocus(0),
currentState(Triad{.T = 1.0, .S = 0.5, .E = 0.4}) {
manifold.AddNode(0, "Stillness / Open Observation", Rational(1, 1));
manifold.AddNode(1, "Deliberation / The Crucible", Rational(3, 2));
manifold.AddNode(2, "Committed Action / The Crossing", Rational(1, 2));
manifold.Connect(0, 1, Rational(1, 2));
manifold.Connect(1, 2, Rational(3, 4));
manifold.Connect(2, 0, Rational(1, 1));
recordTrace("[INIT] CognitiveEngine default instance constructed.");
}
CognitiveEngine::CognitiveEngine(const std::string& tag, uint32_t initialLocus, const Triad& initialState)
: engineTag(tag),
currentLocus(initialLocus),
currentState(initialState) {
manifold.AddNode(0, "Stillness / Open Observation", Rational(1, 1));
manifold.AddNode(1, "Deliberation / The Crucible", Rational(3, 2));
manifold.AddNode(2, "Committed Action / The Crossing", Rational(1, 2));
manifold.Connect(0, 1, Rational(1, 2));
manifold.Connect(1, 2, Rational(3, 4));
manifold.Connect(2, 0, Rational(1, 1));
recordTrace("[INIT] CognitiveEngine parameterized instance: " + tag);
}
std::string CognitiveEngine::getEngineTag() const {
return engineTag;
}
uint32_t CognitiveEngine::getCurrentLocus() const {
return currentLocus;
}
Triad CognitiveEngine::getCurrentState() const {
return currentState;
}
double CognitiveEngine::getMetricEnergy() const {
return currentState.E;
}
std::string CognitiveEngine::getCurrentNodeLabel() const {
const GraphNode* nodePtr = manifold.GetNode(currentLocus);
if (nodePtr != nullptr) {
return nodePtr->label;
}
return "UNKNOWN_LOCUS";
}
std::vector<std::string> CognitiveEngine::getSessionLog() const {
return sessionLog;
}
void CognitiveEngine::setEngineTag(const std::string& newTag) {
engineTag = newTag;
recordTrace("[MUTATE] Engine tag updated to: " + newTag);
}
bool CognitiveEngine::setCurrentLocus(uint32_t targetNodeId) {
if (manifold.GetNode(targetNodeId) != nullptr) {
currentLocus = targetNodeId;
recordTrace("[MUTATE] Locus forced to node ID: " + std::to_string(targetNodeId));
return true;
}
recordTrace("[ERR] Failed to set invalid locus: " + std::to_string(targetNodeId));
return false;
}
void CognitiveEngine::setCurrentState(const Triad& nextState) {
currentState = nextState;
recordTrace("[MUTATE] Triad coordinate modified directly.");
}
void CognitiveEngine::applyKinematicRotation() {
currentState = rotator.Rotate(currentState);
recordTrace("[KINEMATICS] SO(3) conservative rotation applied.");
}
void CognitiveEngine::applyDissipationDecay(double rate) {
double decay = rate * std::tanh(currentState.E + 0.05);
currentState.E = std::max(0.0, currentState.E - decay);
currentState.T += 0.05;
recordTrace("[DISSIPATION] Tension dissipated by rate " + std::to_string(rate));
}
bool CognitiveEngine::transitionTo(uint32_t targetNodeId) {
if (manifold.GetNode(targetNodeId) == nullptr) {
recordTrace("[TRAVERSAL_REJECTED] Destination does not exist: " + std::to_string(targetNodeId));
return false;
}
const std::vector<GraphEdge>* edges = manifold.GetEdges(currentLocus);
bool connected = false;
if (edges != nullptr) {
for (const auto& edge : *edges) {
if (edge.target_node_id == targetNodeId) {
connected = true;
break;
}
}
}
if (connected) {
currentLocus = targetNodeId;
currentState.T += 0.10;
currentState.E += 0.20;
recordTrace("[TRAVERSAL] Transitioned to locus: " + getCurrentNodeLabel());
return true;
}
recordTrace("[TRAVERSAL_BLOCKED] No admittance edge from " + std::to_string(currentLocus) + " to " + std::to_string(targetNodeId));
return false;
}
void CognitiveEngine::emitTelemetryReport() const {
std::cout << std::endl;
std::cout << "================================================================================" << std::endl;
std::cout << "COGNITIVE ENGINE INSTANCE REPORT: " << engineTag << std::endl;
std::cout << "================================================================================" << std::endl;
std::cout << "Current Node: [" << currentLocus << "] " << getCurrentNodeLabel() << std::endl;
std::cout << "State Vector: T: " << std::fixed << std::setprecision(2) << currentState.T
<< " | S: " << currentState.S << " | E: " << currentState.E << std::endl;
std::cout << "Total Energy E: " << getMetricEnergy() << std::endl;
std::cout << "L2 Norm: " << currentState.Norm() << std::endl;
std::cout << "--------------------------------------------------------------------------------" << std::endl;
std::cout << "Journal Entries (" << sessionLog.size() << " logged):" << std::endl;
for (const auto& line : sessionLog) {
std::cout << " " << line << std::endl;
}
std::cout << "================================================================================" << std::endl;
std::cout << std::endl;
}