From a621223d40c9cbdfb186a098036aef38596cf928 Mon Sep 17 00:00:00 2001 From: kasinadhsarma Date: Thu, 26 Dec 2024 13:44:39 +0530 Subject: [PATCH] Enhance cognition progress calculation with weighted metrics and improve reporting format; add unit tests for new functionality --- .../test_init.cpython-310-pytest-8.3.4.pyc | Bin 160 -> 160 bytes .../consciousness_model.cpython-310.pyc | Bin 18370 -> 18935 bytes models/consciousness_model.py | 67 +++++++++++------- test.txt | 12 ++-- ...tion_progress.cpython-310-pytest-8.3.4.pyc | Bin 0 -> 4009 bytes tests/unit/test_cognition_progress.py | 43 +++++++++++ 6 files changed, 92 insertions(+), 30 deletions(-) create mode 100644 tests/unit/__pycache__/test_cognition_progress.cpython-310-pytest-8.3.4.pyc create mode 100644 tests/unit/test_cognition_progress.py diff --git a/__pycache__/test_init.cpython-310-pytest-8.3.4.pyc b/__pycache__/test_init.cpython-310-pytest-8.3.4.pyc index fef8b03ef8009ece88914c48510b60fa7051861f..a98e303f9dce5dc6f5c6ec2779bba78b414c63cf 100644 GIT binary patch delta 18 YcmZ3$xPXx>pO=@50SIhpO=@50SFGuPUM;f03*-?@c;k- diff --git a/models/__pycache__/consciousness_model.cpython-310.pyc b/models/__pycache__/consciousness_model.cpython-310.pyc index e42aae8b0f1c93312d8c3cb050ab80f94daa25b5..b320274489dd9746e243aa47336cb87ceb67ecd9 100644 GIT binary patch delta 2509 zcmZ`*YiwK99lz)L-s@MAx~=WTAx%w79(H3x8dB1vYMNI|RuNH(s!a?9$LG{>WBa=2 zUbkQzTtr3N4-`#j`#>MVL87A)-G(x>2V2=%!Pczs0X}TKUpAhl2oQWgY+;)C|F0d> zB5|+o&;Rp(ob!L3bA0h>@|7S>dSjzUf+yt5rf&bqOHKWOvI~X|_>9K@N~9uDLgjhc zrW|!jsZ(m5(vYIg)9P`Fx~Q9a;C0($Vv?iMQL;~_UfOWPb&QNjPmm|boLrJ=qhFeH zl%)M~#Zht`lYF%4v^-CURC4T*A}fjyh(`k>&O*ja=QB*a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?G^N#~(-U2lgf*I8*GR6w)pbEK zGhN#KfnZ%W6Ta%1tu>|5P;^9HAdQ|vI)`iggcw1*g}_fVore#5+m~CH(UNMN;*aoW zZxMSVq(BpqVQpXqxed<;YS>+SEwGB*fn$N{ycO8n6Nr_Fe>s>7$P)H>9Toz!?T-W$ z<2;_&q7(tGR}hN_hL#&cmNZt7ucvc1K27Q?ncKtDeJsQz{U>-@jKNlm+tAvM*w5gH ziA|p_TZ>gJAMRNT^lbLq?qbLcq&5#Ubl|kL=CA1N#Np4(VxKSkI4z!obxePA;Owim z#B_tNZ%t<_Hj+()81`6UkCRhUk;U?wneGJMcn4QTs$3L(o+?@dSNnqXHQ37#R^N 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): @@ -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): """ diff --git a/test.txt b/test.txt index 7ec6b48..1e82498 100644 --- a/test.txt +++ b/test.txt @@ -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%] @@ -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 ================== 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 new file mode 100644 index 0000000000000000000000000000000000000000..7833243d4e7f857fdcd86766e2e74b6e3aabe008 GIT binary patch literal 4009 zcmbVP&2QYs73c74x!e!g@<(hZZPsq=iYcN`D{>4ua;l_pP-GFHJrqIzGbj{#N0CF zNM);nry5$l>Q%Qb(o&mj^y;ym&r8b= zIWf5`D0EBzKZlaCyUJKiSgJl?V~w-1o@%N7sX8`NBmPOE?rU64jV|LF^>@_+o$HCd zZyYH1l=uydn+ZE$!hu#HtdS)^oflPpMsg&}qIfXSy;JoN*{%}2(0Wo*(1 zPR)QpuOt?%s%hnbJz&2AICbn7w}#so>s-OtsHv0M1xxwD56WhNm zl-8{lX^T!gN6(eX5R_tQ$%*H``o7)WAWkB&XOA6w+`5&|a>I!;E%f`MN^2UKhKWfm zkys(IO5(=T8841~k;tW&uy&@yXwk8=OD|qYG%#sq-yZBq2zVkp?RLB{bcH_~0T(FbVo`W`+?g;_QMO??%IrOH+3zjJCbd?Rz~xtGcn*^=XEz`JUVp;^PA$ zB9WbOyAj}-xWHlP^*xFl#}X!XA^pp0v{vrOa=CH6+*m6&-p(8Oyzk_j%^OQg&!R*S z471l?0CYE?AojvKjA8=t=WMikJjh=%!*lRIg_-E9N%(&O%n-*AyAZQHGRA7k_LUUC zL?~3odcy7^5V$oqQ$01$0*tAVRuCu_g26(NRMTplCfdHvp&>|Y>X$)MON@O}2FV)6 zD=9!O)}i5_G6ZV8KDD?*7BY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ition_progress.py new file mode 100644 index 0000000..1675321 --- /dev/null +++ b/tests/unit/test_cognition_progress.py @@ -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 \ No newline at end of file