forked from HyperCogWizard/plingua
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_rr_enhanced.cpp
More file actions
133 lines (108 loc) · 5.08 KB
/
test_rr_enhanced.cpp
File metadata and controls
133 lines (108 loc) · 5.08 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
#include <iostream>
#include <iomanip>
#include <relevance_realization.hpp>
#include <atomspace_integration.hpp>
using namespace plingua::rr;
using namespace plingua::atomspace;
void printRRState(const RRHypergraph* hypergraph) {
if (!hypergraph) return;
std::cout << "\n=== RR Hypergraph State ===" << std::endl;
std::cout << "Nodes: " << hypergraph->nodes.size() << std::endl;
for (auto it = hypergraph->nodes.begin(); it != hypergraph->nodes.end(); ++it) {
auto node = it->second;
std::cout << " Node " << node->id << " (" << node->label << "): "
<< "salience=" << std::fixed << std::setprecision(3) << node->salience
<< ", affordance=" << node->affordance_realization
<< ", coherence=" << node->computeTrialecticCoherence() << std::endl;
}
std::cout << "Edges: " << hypergraph->edges.size() << std::endl;
for (auto it = hypergraph->edges.begin(); it != hypergraph->edges.end(); ++it) {
auto edge = it->second;
std::cout << " Edge " << edge->id << ": " << edge->from_node
<< " -> " << edge->to_node
<< ", strength=" << edge->strength << std::endl;
}
}
void printAtomSpaceState(const AtomSpace* atomspace) {
if (!atomspace) return;
std::cout << "\n=== AtomSpace State ===" << std::endl;
std::cout << "Total atoms: " << atomspace->atoms.size() << std::endl;
auto concepts = atomspace->findAtomsOfType(Atom::CONCEPT_NODE);
std::cout << "Concept nodes: " << concepts.size() << std::endl;
for (unsigned id : concepts) {
auto atom = atomspace->getAtom(id);
if (atom) {
std::cout << " " << atom->name
<< " [strength=" << std::fixed << std::setprecision(3) << atom->strength
<< ", confidence=" << atom->confidence << "]" << std::endl;
}
}
auto evaluations = atomspace->findAtomsOfType(Atom::EVALUATION_LINK);
std::cout << "Evaluation links: " << evaluations.size() << std::endl;
for (unsigned id : evaluations) {
auto atom = atomspace->getAtom(id);
if (atom && atom->outgoing.size() >= 3) {
auto pred = atomspace->getAtom(atom->outgoing[0]);
auto arg1 = atomspace->getAtom(atom->outgoing[1]);
auto arg2 = atomspace->getAtom(atom->outgoing[2]);
if (pred && arg1 && arg2) {
std::cout << " " << pred->name << "(" << arg1->name << ", " << arg2->name << ")"
<< " [strength=" << atom->strength << "]" << std::endl;
}
}
}
}
int main() {
std::cout << "=== Enhanced RR Development & AtomSpace Integration Test ===" << std::endl;
// Create and initialize RR hypergraph directly
RRHypergraph hypergraph;
// Create test nodes
unsigned env_node = hypergraph.addMembraneNode(0, "environment", AARType::ARENA);
unsigned agent_node = hypergraph.addMembraneNode(1, "agent_membrane", AARType::AGENT);
unsigned arena_node = hypergraph.addMembraneNode(2, "arena_membrane", AARType::ARENA);
// Create test relations
hypergraph.addRelationEdge(agent_node, arena_node, RREdge::CO_CONSTRUCTION, 0.7);
std::cout << "\nInitial state:" << std::endl;
printRRState(&hypergraph);
// Set up AtomSpace integration
AtomSpace atomspace;
RRAtomSpaceIntegrator integrator(&hypergraph, &atomspace);
integrator.performIntegration();
printAtomSpaceState(&atomspace);
// Run simulation for several steps
std::cout << "\nRunning 50 simulation steps..." << std::endl;
for (int i = 0; i < 50; ++i) {
hypergraph.updateRelevanceRealization(0.1);
// Print intermediate state every 10 steps
if ((i + 1) % 10 == 0) {
std::cout << "\nStep " << (i + 1) << " state:" << std::endl;
printRRState(&hypergraph);
// Update AtomSpace
integrator.performIntegration();
// Show emergent patterns
auto patterns = integrator.findEmergentPatterns();
if (!patterns.empty()) {
std::cout << "Emergent patterns detected:" << std::endl;
for (const std::string& pattern : patterns) {
std::cout << " - " << pattern << std::endl;
}
}
}
}
// Final state with AtomSpace
std::cout << "\nFinal state:" << std::endl;
printRRState(&hypergraph);
printAtomSpaceState(&atomspace);
// Compute overall system relevance
double total_relevance = 0.0;
size_t node_count = 0;
for (auto it = hypergraph.nodes.begin(); it != hypergraph.nodes.end(); ++it) {
total_relevance += it->second->computeRelevanceGradient();
++node_count;
}
double system_relevance = node_count > 0 ? total_relevance / node_count : 0.0;
std::cout << "\nOverall system relevance: " << std::fixed << std::setprecision(3)
<< system_relevance << std::endl;
std::cout << "\n=== Test completed ===" << std::endl;
return 0;
}