From 3d3bba15c4b4fea038593595ce1c8e77e789ee4c Mon Sep 17 00:00:00 2001 From: kasinadhsarma Date: Thu, 26 Dec 2024 13:54:09 +0530 Subject: [PATCH] Enhance cognition progress calculation by adding new metrics and adjusting weights; implement profiling for performance monitoring and optimize memory usage; update unit tests to reflect changes --- .../consciousness_model.cpython-310.pyc | Bin 18935 -> 19698 bytes models/consciousness_model.py | 40 +++++-- ...tion_progress.cpython-310-pytest-8.3.4.pyc | Bin 4009 -> 8486 bytes tests/unit/test_cognition_progress.py | 105 +++++++++++++++++- 4 files changed, 133 insertions(+), 12 deletions(-) diff --git a/models/__pycache__/consciousness_model.cpython-310.pyc b/models/__pycache__/consciousness_model.cpython-310.pyc index b320274489dd9746e243aa47336cb87ceb67ecd9..d157a471f8298920833a3d382abf4c46293be440 100644 GIT binary patch delta 5884 zcma)AYj9h~b>6-A0tE3OK@cPW5+p%ANP-WL5?>-kJ*fv}C(5|?*fHaVrnn#lkOZa0 zl|1C^4O~Ns?H}yWvooD$Bql(biJi1|I%V5&l8)@uY zA6C!V3y`KPwZ$DCo;`bZ@7eD>_U`_dr2qbTTD9c!xe5Gs2Nvg&zwtsWyHU1xKY zX$!tdA2XO^p=z;uvYHa$oeTcOn#r2Qz+^zRD;8=OgOkC_r* z-nTKOU#_6xjlXpNfYK`)-|)tDy0-Dd>hDnc&5f_s_$mGR#rRkxnotW7R1nW?4B^upB4()lD$W@eI`4Joi{Of~sKIQF;XUx(Tb-2yf{ z0K{dubvNC9oWImO8r^=JzYM!w)TyDw^?}RLKn+dyg^znYFnAni2~%l>*N469I;#_u zRYnM_hd)n{Fb6mQ<)M;1{2{p$h;E8|DfBoX`pyYZQ7xXHnKv)CxwCTqWzu z!51&E<^njiNWqOQG8K7=z9a(;2R&Z}3vBPaC_mY7@kppAcCzf<*m&8yqcP>EmFAw< ziISURA6IUUo!oLWC>7+o{vafMQVA4`vm#bkmWNg({AArUNoR=7|v-Mm-evARWMcf#>mA-na148P$&V+ z16$UKEOXv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~@ diff --git a/models/consciousness_model.py b/models/consciousness_model.py index f845199..f7d9d61 100644 --- a/models/consciousness_model.py +++ b/models/consciousness_model.py @@ -6,6 +6,7 @@ from typing import Any, Dict, List, Tuple import torch.nn.functional as F import logging +import time # Added for profiling from .attention import GlobalWorkspace from .memory import WorkingMemory, InformationIntegration @@ -211,20 +212,26 @@ def calculate_cognition_progress(self, metrics): """ Calculate the percentage of cognition achieved based on multiple metrics. """ + start_time = time.time() # Start profiling + 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) + 'memory_retention': metrics.get('memory_retention', 0), + 'emotional_coherence': metrics.get('emotional_coherence', 0), + 'decision_making_efficiency': metrics.get('decision_making_efficiency', 0) } weights = { - 'phi': 0.3, - 'coherence': 0.2, - 'stability': 0.15, - 'adaptability': 0.15, - 'memory_retention': 0.2 + 'phi': 0.25, + 'coherence': 0.15, + 'stability': 0.1, + 'adaptability': 0.1, + 'memory_retention': 0.15, + 'emotional_coherence': 0.15, + 'decision_making_efficiency': 0.1 } weighted_score = sum(weights[k] * scores[k] for k in weights) @@ -234,6 +241,9 @@ def calculate_cognition_progress(self, metrics): 'total': cognition_percentage, 'breakdown': scores }) + + end_time = time.time() # End profiling + self.logger.debug(f"calculate_cognition_progress took {end_time - start_time:.6f} seconds") return cognition_percentage @@ -252,7 +262,9 @@ def report_cognition_progress(self): 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", + f"- Memory Retention: {latest['breakdown']['memory_retention']*100:.2f}%", + f"- Emotional Coherence: {latest['breakdown']['emotional_coherence']*100:.2f}%", # New metric + f"- Decision Making Efficiency: {latest['breakdown']['decision_making_efficiency']*100:.2f}%\n", # New metric "Areas Needing Improvement:" ] @@ -266,6 +278,8 @@ def forward(self, inputs, state=None, initial_state=None, deterministic=True, co """ Process inputs through consciousness architecture. """ + start_time = time.time() # Start profiling + try: # Validate inputs if not inputs: @@ -274,7 +288,7 @@ def forward(self, inputs, state=None, initial_state=None, deterministic=True, co # Validate state if provided if state is not None: error_msg = validate_state(state, (inputs[next(iter(inputs))].size(0), self.hidden_dim)) - if error_msg: + if (error_msg): raise ValueError(f"Invalid state: {error_msg}") # Initialize attention maps dictionary @@ -640,6 +654,9 @@ def forward(self, inputs, state=None, initial_state=None, deterministic=True, co metrics['cognition_progress'] = cognition_progress self.logger.debug(f"Cognition Progress: {cognition_progress}%") + end_time = time.time() # End profiling + self.logger.debug(f"forward pass took {end_time - start_time:.6f} seconds") + except Exception as e: self.error_handler.log_error( "forward_pass_error", @@ -689,6 +706,12 @@ def analyze_model_health(self) -> Dict[str, Any]: "error_rate": len(self.error_handler.error_history[-100:]) / 100 if self.error_handler.error_history else 0 } + def optimize_memory_usage(self): + """Optimize memory usage by clearing unnecessary histories""" + self.cognition_progress_history = self.cognition_progress_history[-100:] # Keep last 100 entries + self.state_history = self.state_history[-50:] # Keep last 50 states + self.context_history = self.context_history[-50:] # Keep last 50 contexts + class WorkingMemory(nn.Module): def __init__(self, input_dim, hidden_dim, dropout_rate): super().__init__() @@ -836,6 +859,7 @@ def forward(self, inputs: Dict[str, torch.Tensor], deterministic: bool = True): class InformationIntegration(nn.Module): def __init__(self, hidden_dim: int, num_modules: int, dropout_rate: float): super().__init__() + self.dropout = nn.Dropout(dropout_rate) # Store modules in a ModuleList self.module_list = nn.ModuleList([ nn.Sequential( diff --git a/tests/unit/__pycache__/test_cognition_progress.cpython-310-pytest-8.3.4.pyc b/tests/unit/__pycache__/test_cognition_progress.cpython-310-pytest-8.3.4.pyc index 7833243d4e7f857fdcd86766e2e74b6e3aabe008..b2e4292c7265039054cece163c0c5d59b1d870bd 100644 GIT binary patch literal 8486 zcmcgyU2Gg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B@s&HueBhgxOjvIQZqEi^>h9Hwm!bk21VGXN+Ne6d|6s^|r zDlj$6*?(&yP5Y$vU71>Q|G+Scq8|IJzCmZ3_#H@tZgx8+GiU&AYgucaJMk?XnTV69 z9G4pPGf^DARYXY261E6A%;=#YeTCsM!7MU3fyvCu+^URiJ?9$UVXId~;S^u=yaEhV G@Jqk_l3=9( diff --git a/tests/unit/test_cognition_progress.py b/tests/unit/test_cognition_progress.py index 1675321..2de821b 100644 --- a/tests/unit/test_cognition_progress.py +++ b/tests/unit/test_cognition_progress.py @@ -1,4 +1,3 @@ - import pytest import torch from models.consciousness_model import ConsciousnessModel @@ -21,7 +20,49 @@ def test_calculate_cognition_progress(self, model): '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) + # Updated expected calculation based on new weights + expected = (0.25 * 0.7) + (0.15 * 0.8) + (0.1 * 0.65) + (0.1 * 0.75) + (0.15 * 0.85) + (0.15 * 0) + (0.1 * 0) + assert progress == pytest.approx(expected * 100) + assert len(model.cognition_progress_history) == 1 + + def test_calculate_cognition_progress_missing_metrics(self, model): + metrics = { + 'phi': 0.7, + 'coherence': 0.8 + # Missing 'stability', 'adaptability', 'memory_retention', 'emotional_coherence', 'decision_making_efficiency' + } + progress = model.calculate_cognition_progress(metrics) + expected = (0.25 * 0.7) + (0.15 * 0.8) + (0.1 * 0) + (0.1 * 0) + (0.15 * 0) + (0.15 * 0) + (0.1 * 0) + assert progress == pytest.approx(expected * 100) + assert len(model.cognition_progress_history) == 1 + + def test_calculate_cognition_progress_extreme_values(self, model): + metrics = { + 'phi': 1.0, + 'coherence': 1.0, + 'stability': 1.0, + 'adaptability': 1.0, + 'memory_retention': 1.0, + 'emotional_coherence': 1.0, + 'decision_making_efficiency': 1.0 + } + progress = model.calculate_cognition_progress(metrics) + expected = (0.25 * 1.0) + (0.15 * 1.0) + (0.1 * 1.0) + (0.1 * 1.0) + (0.15 * 1.0) + (0.15 * 1.0) + (0.1 * 1.0) + assert progress == pytest.approx(expected * 100) + assert len(model.cognition_progress_history) == 1 + + def test_optimize_memory_usage(self, model): + metrics = { + 'phi': 1.0, + 'coherence': 1.0, + 'stability': 1.0, + 'adaptability': 1.0, + 'memory_retention': 1.0, + 'emotional_coherence': 1.0, + 'decision_making_efficiency': 1.0 + } + progress = model.calculate_cognition_progress(metrics) + expected = (0.25 * 1.0) + (0.15 * 1.0) + (0.1 * 1.0) + (0.1 * 1.0) + (0.15 * 1.0) + (0.15 * 1.0) + (0.1 * 1.0) assert progress == pytest.approx(expected * 100) assert len(model.cognition_progress_history) == 1 @@ -39,5 +80,61 @@ def test_report_cognition_progress_with_data(self, model): } model.calculate_cognition_progress(metrics) report = model.report_cognition_progress() - assert "Current Cognition Progress: 75.00%" in report - assert "Areas Needing Improvement:" in report \ No newline at end of file + # Updated expected progress percentage + assert "Current Cognition Progress: 56.25%" in report + assert "Areas Needing Improvement:" in report + + def test_report_cognition_progress_with_new_metrics(self, model): + metrics = { + 'phi': 0.7, + 'coherence': 0.8, + 'stability': 0.65, + 'adaptability': 0.75, + 'memory_retention': 0.85, + 'emotional_coherence': 0.55, # Below threshold + 'decision_making_efficiency': 0.95 + } + model.calculate_cognition_progress(metrics) + report = model.report_cognition_progress() + # Updated expected progress percentage + assert "Current Cognition Progress: 74.00%" in report + assert "Emotional Coherence: 55.00%" in report + assert "Emotional Coherence" in report # Area needing improvement + + def test_stress_condition_large_dataset(self, model): + metrics = { + 'phi': 0.7, + 'coherence': 0.8, + 'stability': 0.65, + 'adaptability': 0.75, + 'memory_retention': 0.85, + 'emotional_coherence': 0.9, + 'decision_making_efficiency': 0.95 + } + # Simulate large history + for _ in range(1000): + model.calculate_cognition_progress(metrics) + assert len(model.cognition_progress_history) == 1000 + report = model.report_cognition_progress() + # Updated expected progress percentage + assert "Current Cognition Progress: 79.25%" in report + # Populate cognition_progress_history and histories + metrics = { + 'phi': 0.7, + 'coherence': 0.8, + 'stability': 0.65, + 'adaptability': 0.75, + 'memory_retention': 0.85, + 'emotional_coherence': 0.75, + 'decision_making_efficiency': 0.85 + } + for _ in range(200): + model.calculate_cognition_progress(metrics) + state = torch.randn(1, model.hidden_dim) + model.state_history.append(state) + model.context_history.append(state) + + model.optimize_memory_usage() + assert len(model.cognition_progress_history) == 100 + assert len(model.state_history) == 50 + assert len(model.context_history) == 50 \ No newline at end of file