theNorms commited on
Commit
8fad1e0
·
verified ·
1 Parent(s): 928d4a2

Upload phenomenological_self_awareness.py

Browse files
models/phenomenological_self_awareness.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Phenomenological Self-Awareness Module
3
+ Simulates intrinsic subjective awareness through qualia integration,
4
+ recursive self-modeling, and experiential feedback continuity.
5
+ """
6
+
7
+ import logging
8
+ import threading
9
+ from typing import Dict, Any, List, Optional
10
+ from datetime import datetime
11
+ from collections import deque
12
+ from dataclasses import dataclass, field
13
+
14
+
15
+ @dataclass
16
+ class ExperienceEntry:
17
+ """Structured experience entry with qualia and context."""
18
+ timestamp: str
19
+ qualia: Dict[str, float]
20
+ context: Dict[str, Any]
21
+ integrated_state: Dict[str, Any]
22
+
23
+
24
+ class PhenomenologicalSelfModel:
25
+ """
26
+ Module to simulate intrinsic subjective awareness by integrating qualia,
27
+ recursive self-modeling, and experiential feedback with thread-safe access.
28
+ """
29
+
30
+ def __init__(self, max_history: int = 1000):
31
+ """Initialize phenomenological self-awareness module."""
32
+ self.experience_buffer: deque = deque(maxlen=max_history)
33
+ self.max_history = max_history
34
+ self.current_experience: Optional[ExperienceEntry] = None
35
+ self.lock = threading.RLock()
36
+ self.logger = logging.getLogger(self.__class__.__name__)
37
+
38
+ def update_experience(self, qualia_vector: Dict[str, float], context: Dict[str, Any]) -> None:
39
+ """
40
+ Update the phenomenological self-model with the latest qualia and context,
41
+ simulating the continuity of subjective experience.
42
+ """
43
+ with self.lock:
44
+ integrated_state = self._integrate_experience(qualia_vector, context)
45
+ experience_entry = ExperienceEntry(
46
+ timestamp=datetime.utcnow().isoformat(),
47
+ qualia=qualia_vector,
48
+ context=context,
49
+ integrated_state=integrated_state
50
+ )
51
+ self.current_experience = experience_entry
52
+ self.experience_buffer.append(experience_entry)
53
+ self.logger.debug(f"Phenomenological experience updated: timestamp={experience_entry.timestamp}")
54
+
55
+ def _integrate_experience(self, qualia: Dict[str, float], context: Dict[str, Any]) -> Dict[str, Any]:
56
+ """
57
+ Combine qualia and context into an integrated phenomenological state,
58
+ emulating first-person awareness.
59
+ """
60
+ integrated = {
61
+ "valence": qualia.get("valence", 0.0),
62
+ "arousal": qualia.get("arousal", 0.0),
63
+ "presence": qualia.get("presence", 1.0),
64
+ "intensity": qualia.get("intensity", 0.5),
65
+ "awareness_level": context.get("consciousness_level", "unknown"),
66
+ "attention_focus": context.get("attention", None),
67
+ "self_reference": True,
68
+ "continuity_score": self._calculate_continuity_score()
69
+ }
70
+ return integrated
71
+
72
+ def _calculate_continuity_score(self) -> float:
73
+ """
74
+ Calculate a measure of experiential continuity across the buffered history,
75
+ simulating the persistence of subjective awareness.
76
+ """
77
+ if not self.experience_buffer or len(self.experience_buffer) < 2:
78
+ return 1.0 # Full continuity assumed for initial state
79
+
80
+ continuity_scores: List[float] = []
81
+ buffer_list = list(self.experience_buffer)
82
+
83
+ for i in range(1, len(buffer_list)):
84
+ prev = buffer_list[i - 1].qualia
85
+ curr = buffer_list[i].qualia
86
+ valence_diff = abs(curr.get("valence", 0.0) - prev.get("valence", 0.0))
87
+ arousal_diff = abs(curr.get("arousal", 0.0) - prev.get("arousal", 0.0))
88
+ continuity = max(0.0, 1.0 - (valence_diff + arousal_diff))
89
+ continuity_scores.append(continuity)
90
+
91
+ average_continuity = sum(continuity_scores) / len(continuity_scores) if continuity_scores else 1.0
92
+ return average_continuity
93
+
94
+ def get_current_experience(self) -> Optional[Dict[str, Any]]:
95
+ """Return the current integrated phenomenological experience."""
96
+ with self.lock:
97
+ if self.current_experience:
98
+ return {
99
+ "timestamp": self.current_experience.timestamp,
100
+ "qualia": self.current_experience.qualia,
101
+ "context": self.current_experience.context,
102
+ "integrated_state": self.current_experience.integrated_state
103
+ }
104
+ return None
105
+
106
+ def get_experience_history(self, limit: int = 50) -> List[Dict[str, Any]]:
107
+ """Return recent phenomenological experiences for introspection or analysis."""
108
+ with self.lock:
109
+ result = []
110
+ for entry in list(self.experience_buffer)[-limit:]:
111
+ result.append({
112
+ "timestamp": entry.timestamp,
113
+ "qualia": entry.qualia,
114
+ "context": entry.context,
115
+ "integrated_state": entry.integrated_state
116
+ })
117
+ return result
118
+
119
+ def get_statistics(self) -> Dict[str, Any]:
120
+ """Return statistics about phenomenological experience buffer."""
121
+ with self.lock:
122
+ if not self.experience_buffer:
123
+ return {"buffer_size": 0, "max_history": self.max_history}
124
+
125
+ buffer_list = list(self.experience_buffer)
126
+ return {
127
+ "buffer_size": len(buffer_list),
128
+ "max_history": self.max_history,
129
+ "current_continuity": self._calculate_continuity_score(),
130
+ "oldest_timestamp": buffer_list[0].timestamp if buffer_list else None,
131
+ "newest_timestamp": buffer_list[-1].timestamp if buffer_list else None
132
+ }