Skip to content

Commit

Permalink
Enhance cognition progress calculation in ConsciousnessModel by integ…
Browse files Browse the repository at this point in the history
…rating emotional coherence; add unit tests for memory retrieval and goal state updates
  • Loading branch information
kasinadhsarma committed Dec 26, 2024
1 parent 5e22241 commit ffadb0f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
Binary file modified models/__pycache__/consciousness.cpython-310.pyc
Binary file not shown.
Binary file not shown.
27 changes: 17 additions & 10 deletions models/consciousness.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,23 @@ def forward(self, inputs: Dict[str, torch.Tensor],

return aware_state, metrics

def calculate_cognition_progress(self, metrics: Dict[str, float]) -> float:
# ...existing code...

# Add emotional coherence to progress calculation
if 'emotion_intensities' in metrics:
emotional_balance = torch.mean(metrics['emotion_intensities']).item()
metrics['emotional_coherence'] = emotional_balance

# Continue with existing progress calculation
# ...existing code...
def calculate_cognition_progress(self, metrics):
"""
Calculate cognitive progress based on metrics.
Returns a value between 0 and 100.
"""
# Calculate emotional coherence
emotional_coherence = torch.mean(metrics['emotion_intensities']).item()
metrics['emotional_coherence'] = emotional_coherence

# Calculate overall progress using phi, coherence and emotional_coherence
progress = (
0.4 * metrics['phi'] +
0.3 * metrics['coherence'] +
0.3 * emotional_coherence
) * 100

return max(0, min(100, progress)) # Ensure result is between 0 and 100

def create_consciousness_module(hidden_dim: int = 512,
num_cognitive_processes: int = 4) -> ConsciousnessModel:
Expand Down
Empty file added models/global_workspace.py
Empty file.
Binary file not shown.
Binary file not shown.
12 changes: 11 additions & 1 deletion tests/unit/test_consciousness.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ def test_emotional_integration(self, model, sample_input):
assert metrics['emotional_influence'].shape == output.shape
assert torch.any(metrics['emotional_influence'] != 0)

def test_emotion_cognition_progress(self, model):
def test_memory_retrieval_shape(self, model, sample_input):
"""Test if memory retrieval produces correct shapes"""
output, metrics = model(sample_input)

# Check if retrieved_memory exists and has correct shape
assert 'retrieved_memory' in metrics
retrieved_memory = metrics['retrieved_memory']
assert retrieved_memory.shape == (sample_input['attention'].size(0), model.hidden_dim)

def test_goal_state_updates(self, model, sample_input):
"""Test if goal state updates properly"""
"""Test if emotional states affect cognition progress."""
metrics = {
'phi': 0.8,
Expand Down
Empty file.

0 comments on commit ffadb0f

Please sign in to comment.