Skip to content

Commit

Permalink
Enhance cognition progress calculation with weighted metrics and impr…
Browse files Browse the repository at this point in the history
…ove reporting format; add unit tests for new functionality
  • Loading branch information
kasinadhsarma committed Dec 26, 2024
1 parent fdc596d commit a621223
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 30 deletions.
Binary file modified __pycache__/test_init.cpython-310-pytest-8.3.4.pyc
Binary file not shown.
Binary file modified models/__pycache__/consciousness_model.cpython-310.pyc
Binary file not shown.
67 changes: 43 additions & 24 deletions models/consciousness_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,32 @@ def adaptive_learning_step(self, state: torch.Tensor, error: float) -> torch.Ten

def calculate_cognition_progress(self, metrics):
"""
Calculate the percentage of cognition achieved based on metrics.
Calculate the percentage of cognition achieved based on multiple metrics.
"""
# Example calculation based on 'phi' metric
phi = metrics.get('phi', 0)
cognition_percentage = phi * 100
self.cognition_progress_history.append(cognition_percentage)
scores = {
'phi': metrics.get('phi', 0),
'coherence': metrics.get('coherence', 0),
'stability': metrics.get('stability', 0),
'adaptability': metrics.get('adaptability', 0),
'memory_retention': metrics.get('memory_retention', 0)
}

weights = {
'phi': 0.3,
'coherence': 0.2,
'stability': 0.15,
'adaptability': 0.15,
'memory_retention': 0.2
}

weighted_score = sum(weights[k] * scores[k] for k in weights)
cognition_percentage = weighted_score * 100

self.cognition_progress_history.append({
'total': cognition_percentage,
'breakdown': scores
})

return cognition_percentage

def report_cognition_progress(self):
Expand All @@ -223,25 +243,24 @@ def report_cognition_progress(self):
"""
if not self.cognition_progress_history:
return "No cognition progress data available."

avg_progress = sum(self.cognition_progress_history) / len(self.cognition_progress_history)
areas_to_improve = []

# Example criteria for identifying areas to improve
if avg_progress < 50:
areas_to_improve.append("Increase phi metric to improve cognition progress.")
if 'context_stability' in self.metrics and self.metrics['context_stability'] < 0.5:
areas_to_improve.append("Improve context stability.")
if 'coherence' in self.metrics and self.metrics['coherence'] < 0.5:
areas_to_improve.append("Enhance coherence in state transitions.")

report = f"Average Cognition Progress: {avg_progress}%\n"
if areas_to_improve:
report += "Areas to Improve:\n" + "\n".join(areas_to_improve)
else:
report += "All areas are performing well."

return report

latest = self.cognition_progress_history[-1]
report = [
f"Current Cognition Progress: {latest['total']:.2f}%\n",
"Breakdown:",
f"- Integrated Information (Phi): {latest['breakdown']['phi']*100:.2f}%",
f"- Thought Coherence: {latest['breakdown']['coherence']*100:.2f}%",
f"- Context Stability: {latest['breakdown']['stability']*100:.2f}%",
f"- Adaptability: {latest['breakdown']['adaptability']*100:.2f}%",
f"- Memory Retention: {latest['breakdown']['memory_retention']*100:.2f}%\n",
"Areas Needing Improvement:"
]

for metric, value in latest['breakdown'].items():
if value < 0.6:
report.append(f"- {metric.replace('_', ' ').title()}")

return "\n".join(report)

def forward(self, inputs, state=None, initial_state=None, deterministic=True, consciousness_threshold=0.5):
"""
Expand Down
12 changes: 6 additions & 6 deletions test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
platform linux -- Python 3.10.12, pytest-8.3.4, pluggy-1.5.0
rootdir: /home/kasinadhsarma/experiment/cognition-l3-experiment
plugins: cov-6.0.0, anyio-4.7.0
collected 114 items
collected 115 items

tests/benchmarks/test_arc_reasoning.py ....... [ 6%]
tests/benchmarks/test_bigbench_reasoning.py ..... [ 10%]
tests/test_consciousness.py ............................ [ 35%]
tests/test_environment.py .....s.. [ 42%]
tests/test_consciousness.py ............................ [ 34%]
tests/test_environment.py ......s.. [ 42%]
tests/test_error_correction.py ......... [ 50%]
tests/unit/attention/test_attention.py ...... [ 55%]
tests/unit/attention/test_attention_mechanisms.py ....... [ 61%]
tests/unit/integration/test_cognitive_integration.py ...... [ 66%]
tests/unit/integration/test_state_management.py ...... [ 71%]
tests/unit/integration/test_state_management.py ...... [ 72%]
tests/unit/memory/test_integration.py ...... [ 77%]
tests/unit/memory/test_memory.py .......... [ 85%]
tests/unit/memory/test_memory.py .......... [ 86%]
tests/unit/memory/test_memory_components.py .......... [ 94%]
tests/unit/state/test_consciousness_state_management.py ...... [100%]

Expand All @@ -24,4 +24,4 @@ tests/unit/state/test_consciousness_state_management.py ...... [100%]
_C._set_default_tensor_type(t)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================== 113 passed, 1 skipped, 1 warning in 8.94s ===================
================== 114 passed, 1 skipped, 1 warning in 10.78s ==================
Binary file not shown.
43 changes: 43 additions & 0 deletions tests/unit/test_cognition_progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

import pytest
import torch
from models.consciousness_model import ConsciousnessModel

class TestCognitionProgress:
@pytest.fixture
def model(self):
config = ConsciousnessModel.create_default_config()
return ConsciousnessModel(**config)

def test_cognition_progress_initial(self, model):
assert len(model.cognition_progress_history) == 0

def test_calculate_cognition_progress(self, model):
metrics = {
'phi': 0.7,
'coherence': 0.8,
'stability': 0.65,
'adaptability': 0.75,
'memory_retention': 0.85
}
progress = model.calculate_cognition_progress(metrics)
expected = (0.3 * 0.7) + (0.2 * 0.8) + (0.15 * 0.65) + (0.15 * 0.75) + (0.2 * 0.85)
assert progress == pytest.approx(expected * 100)
assert len(model.cognition_progress_history) == 1

def test_report_cognition_progress_no_data(self, model):
report = model.report_cognition_progress()
assert report == "No cognition progress data available."

def test_report_cognition_progress_with_data(self, model):
metrics = {
'phi': 0.7,
'coherence': 0.8,
'stability': 0.65,
'adaptability': 0.75,
'memory_retention': 0.85
}
model.calculate_cognition_progress(metrics)
report = model.report_cognition_progress()
assert "Current Cognition Progress: 75.00%" in report
assert "Areas Needing Improvement:" in report

0 comments on commit a621223

Please sign in to comment.