/ core / theory_of_mind / __pycache__ / prediction_trainer.cpython-314.pyc
prediction_trainer.cpython-314.pyc
  1  +
  2  gi;�
  3  �^�Rt^RIHtHt^RIHt^RIHtHtHtH	t	H
  4  t
  5  ^RIt^RIH
t
HtHt^RIHtHtHt]!RR44t]!R	R
  6  44t!RR4t]R
8XEdG]!R4]
!RR7t]P5RR.R7O4]P5RR.R8O4]!]4tRt]!R4]P;]RR4t]!R]!]P@PB4R24]!R4]PE]^R7t#]$!]#^4F4wt%t&]!R]%R]&PNR
R ]&P8R!,R"24K6	.t(]P@PBF�t&R]&P8PS49g R#]&P8PS49d](PU]&PV4K^R$]&P8PS49d=R]&P8PS49d](PU]&PV4K�R%]&P8PS49gK�](PU]&PV4K�	]!R&]!](4R24]PY]](4]P[]4t.]!R'4]!R(].P^R)
24]!R*].P`R)
24]!R+].PbR)
24].Pd'd]!R,].Pd24].Pf'd]!R-].Pf24].Ph'd]!R.]!].Ph424]!R/4]Pk4t6]!R0]6R1,24]!R2]6R3,R)
24]!R4]6R5,24]!R64R#R#)9a^
  7  Prediction Trainer
  8  
  9  Implements the training loop for improving resonance predictions.
 10  
 11  The loop:
 12  1. Content is analyzed and predictions are made
 13  2. Operator reveals their actual selections
 14  3. Predictions are compared to actuals
 15  4. Cognitive fingerprint is updated based on the delta
 16  
 17  This is the core learning mechanism for building Theory of Mind.
 18  )�	dataclass�field)�datetime)�Optional�List�Dict�Any�SetN)�CognitiveFingerprint�GravityWell�PatternType)�ContentAnalyzer�ContentIdea�ResonancePredictionc�
 19  a�]tRt^toRt]!]PR7tRt	Rt
 20  ]!]R7t^t
^t^t^t]!]R7t]!]R7t]!]R7t]V3RlRl4t]V3RlRl4t]V3RlR	l4tV3R
 21  ltRtVtR#)�PredictionSessionz>
 22  A training session where predictions are made and validated.
 23  )�default_factoryNc� <�V^8�dQhRS[/#���return��float)�format�
__classdict__s"��I/Users/rcerf/repos/Sovereign_OS/core/theory_of_mind/prediction_trainer.py�__annotate__�PredictionSession.__annotate__8s���A�A�5�A�c�t�VPVP,pV^8�dVPV,#R#)zPrecision = TP / (TP + FP)�)�true_positives�false_positives��self�totals& r�	precision�PredictionSession.precision7�6���#�#�d�&:�&:�:��.3�a�i�t�"�"�U�*�@�S�@rc� <�V^8�dQhRS[/#rr)rrs"�rrr>s���A�A��Arc�t�VPVP,pV^8�dVPV,#R#)zRecall = TP / (TP + FN)r )r!�false_negativesr#s& r�recall�PredictionSession.recall=r(rc� <�V^8�dQhRS[/#rr)rrs"�rrrDs���S�S�%�Src���VPVP,^8XdR#^VPVP,,VPVP,,#)z4F1 = 2 * (precision * recall) / (precision + recall)r )r&r,)r$s&r�f1_score�PredictionSession.f1_scoreCsF���>�>�D�K�K�'�1�,���D�N�N�T�[�[�0�1�T�^�^�d�k�k�5Q�R�Rrc�<�V^8�dQh/S[;R&S[;R&S[;R&S[S[,;R&S[S[,;R&S[S[,;R&S[;R&S[;R&S[;R	&S[;R
 24  &S[S[,;R&S[S[,;R&S[S[,;R
&#)r�
 25  session_id�source_name�
 26  started_at�completed_at�
 27  prediction�actual_selectionsr!r"r+�true_negatives�new_gravity_wells�strengthened_patterns�weakened_patterns)�strrrrr	�intr)rrs"�rrrs�����
 28  �O����
��>���8�$�+���,�-�4���3�x�<��"��#�$��%�&��'�(��)�.�C�y�>�/�0 ��9�B�1�2�C�y�>�3r�)�__name__�
 29  __module__�__qualname__�__firstlineno__�__doc__rr�nowr5r6r7�setr8r!r"r+r9�listr:r;r<�propertyr&r,r0�__annotate_func__�__static_attributes__�__classdictcell__�rs@rrrs������
 30  !����>�J�'+�L�15�J�#(��"<���N��O��O��N�$)��#>��',�T�'B��#(��#>��
�A��A�
 31  �A��A�
 32  �S��S�Q�rrc�0a�]tRt^KtoRtV3RltRtVtR#)�TrainingResultz
 33  Result of a training session.
 34  c�<�V^8�dQh/S[;R&S[;R&S[;R&S[;R&S[S[,;R&S[S[,;R&S[S[,;R&S[S[S[S[3,,;R&S[S[S[S[3,,;R	&#)
 35  rr3r&r,r0r:r;r<�surprising_selections�surprising_ignores)r=rrrr)rrs"�rr�TrainingResult.__annotate__Ks�����
 36  �O����
�
�M���O���C�y� �� ��9�$���C�y� ��  ��S�#�X��/�/�!�"�T�#�s�(�^�,�,�#rr?N)r@rArBrCrDrIrJrKrLs@rrNrNKs������rrNc�a�]tRt^_toRtV3RlRltRV3RlRlltRV3RlRlltV3RlR	ltRV3R
 37  lRllt	V3RlR
lt
 38  V3RlRltRtVt
R#)�PredictionTrainerzG
 39  Trains the cognitive fingerprint through prediction-validation loops.
 40  c� <�V^8�dQhRS[/#)r�fingerprint)r
 41  )rrs"�rr�PredictionTrainer.__annotate__ds���	4�	4�$8�	4rc�@�Wn\V4Vn.VnR#)zT
 42  Initialize the trainer.
 43  
 44  Args:
 45      fingerprint: The cognitive fingerprint to train
 46  N)rVr
�analyzer�sessions)r$rVs&&r�__init__�PredictionTrainer.__init__ds��'��'��4��
�13��
rc�2<�V^8�dQhRS[RS[RS[RS[/#)r�contentr4�split_strategyr)r=r)rrs"�rrrWos3����������	�
 47  
 48  �rc���VPPWV4p\R\P!4PR42VVR7pVPPV4V#)z�
 49  Start a new prediction session by analyzing content.
 50  
 51  Args:
 52      content: Content to analyze
 53      source_name: Name of the source
 54      split_strategy: How to split content
 55  
 56  Returns:
 57      PredictionSession ready for validation
 58  �train_z
%Y%m%d_%H%M%S)r3r4r7)rY�analyze_contentrrrE�strftimerZ�append)r$r^r4r_r7�sessions&&&&  r�
start_session�PredictionTrainer.start_sessionosd��"�]�]�2�2��.�
 59 60  �$������ 7� 7�� H�I�J�#�!�
 61  ��	
�
�
���W�%��rc	�B<�V^8�dQhRS[RS[RS[RS[S[,/#)rre�top_k�	thresholdr)rr>rrr)rrs"�rrrW�s8���
 62  �
 63  �"�
 64  ��
 65  ��	
 66 67  
 68  �k�	�
 69  rc�z�VP'g.#VPPVPVVR7#)z�
 70  Get the predicted high-resonance ideas for a session.
 71  
 72  Args:
 73      session: The prediction session
 74      top_k: Maximum predictions to return
 75      threshold: Minimum resonance threshold
 76  
 77  Returns:
 78      List of predicted high-resonance ideas
 79  )rj�	max_count)r7rY�get_predicted_highlights)r$rerirjs&&&&r�get_predictions�!PredictionTrainer.get_predictions�s@��"�!�!�!��I��}�}�5�5������6�
 80  �	
 81  rc�6<�V^8�dQhRS[RS[S[,/#)rre�selected_idea_ids)rrr=)rrs"�rrrW�s'���P�P�"�P� ��9�Prc��\V4VnVPPF!pVPVP9VnK#	R#)z�
 82  Record the operator's actual selections.
 83  
 84  Args:
 85      session: The prediction session
 86      selected_idea_ids: IDs of ideas the operator actually selected
 87  N)rFr8r7�ideas�idea_id�actually_resonated)r$rerq�ideas&&& r�record_selections�#PredictionTrainer.record_selections�sA��%(�(9�$:��!��&�&�,�,�D�&*�l�l�g�6O�6O�&O�D�#�-rc�,<�V^8�dQhRS[RS[RS[/#�rre�
learning_rater)rrrN)rrs"�rrrW�s.���Q
 88  �Q
 89  �"�Q
 90  ��Q
 91  �
 92  �	Q
 93  rc�d�VP'dVP'g\R4h\VPPR,4p\W1P,4Vn\W1P,
 94  4Vn\VPV,
 95  4Vn\\RVPP44V,
 96  VP,
 97  4Vn
 98  .p.pVPPEFpVP'd�VPR8dpTPRVPRVPR,RVPR	VP R
 99  VP"Uu.uFqwP$NK	up/4K�VP'dK�VPR8�gK�VPRVPRVPR,RVPR	VP RVP&/4EK	VP)W4wr�p
100  W�nW�nW�n\0P2!4VnVP6;P8^,
unVPPFApVP6P;VPV9VP;'gR
R7KC	\=VP>VP@VPBVPDVV	V
101  VVR7	#uupi)a
102  Complete the session by comparing predictions to actuals and learning.
103  
104  Args:
105      session: The prediction session with actual selections recorded
106      learning_rate: How aggressively to update fingerprint
107  
108  Returns:
109      TrainingResult with metrics and insights
110  z,Session must have predictions and selections:N�
111  Nc3�8"�TFqPx�K	R#5i�N)rt)�.0�is& r�	<genexpr>�5PredictionTrainer.complete_session.<locals>.<genexpr>�s���<�#;�a�	�	�#;���皙�����?rtr^:N�dN�	predicted�topics�patternsg333333�?�factorsF)r��actual)	r3r&r,r0r:r;r<rPrQ)#r7r8�
112  ValueErrorrF�
predicted_top�lenr!r"r+rsr9ru�predicted_resonancerdrtr^r��
pattern_types�name�resonance_factors�_update_fingerprintr:r;r<rrEr6rV�training_sessions�record_prediction_resultrNr3r&r,r0)r$rer{�
predicted_setrPrQrv�p�	new_wells�strengthened�weakeneds&&&        r�complete_session�"PredictionTrainer.complete_session�s����!�!�!��)B�)B�)B��K�L�L��G�.�.�<�<�S�A�B�
�!$�]�5N�5N�%N�!O���"%�m�6O�6O�&O�"P���"%�g�&?�&?�-�&O�"P���!$��<�7�#5�#5�#;�#;�<�<��
�#�5�5�
6�"
113  ���!#�����&�&�,�,�D��&�&�&�4�+C�+C�c�+I�%�,�,��t�|�|��t�|�|�D�1���!9�!9��d�k�k���1C�1C� D�1C�A���1C� D�.���,�,�,��1I�1I�C�1O�"�)�)��t�|�|��t�|�|�D�1���!9�!9��d�k�k��t�5�5�+��-�*-1�,D�,D��-
114  �)�	��%.�!�(4�%�$,�!�'�|�|�~���	
���*�*�a�/�*��&�&�,�,�D����5�5��,�,�-�7��.�.�7�7�%�
6�
�-���)�)��'�'��>�>��%�%�'�".�&�"7�1�
115  
116117  	
118  ��=!Es�L-c�,<�V^8�dQhRS[RS[RS[/#rz)rr�tuple)rrs"�rrrWs.���<K�<K�"�<K��<K�
119  �	<Krc���.p.p.pVPPEF�pVP'Ed=VPF�pVP	4pW�P
120  P9d1VP
121  PVRR7VPV4K]VP
122  PV,P4K�	VPFNp	VP
123  PV	VR7V	PV9gK3VPV	P4KP	VP'd2VP
124  PVPRV,R7EKPEKSVPR8�gEKgVPFVp	VP
125  PV	V)^,R7V	PV9gK;VPV	P4KX	EK�	W4V3#)z�
126  Update the cognitive fingerprint based on session results.
127  
128  Returns (new_gravity_wells, strengthened_patterns, weakened_patterns)
129  g333333�?)�initial_mass)�strength_deltag�?)�weightg�?)r7rsrur��lowerrV�
gravity_wells�add_gravity_wellrd�activater��update_pattern_preferencer��altitude�update_altitude_distributionr�)
130  r$rer{r:r;r<rv�topic�topic_lower�patterns
131  &&&       rr��%PredictionTrainer._update_fingerprints����� "�����&�&�,�,�D��&�&�&�"�[�[�E�"'�+�+�-�K�"�*:�*:�*H�*H�H��(�(�9�9�'�),�:��*�0�0��=��(�(�6�6�{�C�L�L�N�)� $�1�1�G��$�$�>�>��'4�?���|�|�+@�@�-�4�4�W�\�\�B�
 2��=�=�=��$�$�A�A��
�
�"�]�2�B��!��+�+�c�1�#'�#5�#5���(�(�B�B�#�,9�>�A�+=�C��#�<�<�/@�@�-�4�4�W�\�\�B�
$6�K-�Z!�9J�J�Jrc�6<�V^8�dQhRS[S[S[3,/#r)rr=r)rrs"�rrrWJs���
132  �
133  �d�3��8�n�
134  rc�J�VP'gR^R^/#VPUu.uFqP'gKVNK	ppR\V4RVPPRVPP
135  RV'd#\
RV44\V4,M^RV'd#\
RV44\V4,M^RV'd#\
R	V44\V4,M^R
136  VPP^4Uu.uFpVPVP3NK	upRVPP4R,Uu.uF%pVPPVP3NK'	up/#uupiuupiuupi)
z'
137  Get summary of all training sessions.
138  rZ�
139  average_f1�total_predictions�overall_accuracy�average_precisionc3�8"�TFqPx�K	R#5ir)r&�r��ss& rr��9PredictionTrainer.get_training_summary.<locals>.<genexpr>Ws���$D�)�Q�[�[�)�r��average_recallc3�8"�TFqPx�K	R#5ir)r,r�s& rr�r�Xs���!>�I�q�(�(�I�r�c3�8"�TFqPx�K	R#5ir)r0r�s& rr�r�Ys���<�)�Q�j�j�)�r��top_gravity_wells�characteristic_patterns:N�N)rZr6r�rVr��prediction_accuracy�sum�get_top_gravity_wells�concept�mass�get_characteristic_patterns�pattern_typer��strength)r$r��	completed�wr�s&    r�get_training_summary�&PredictionTrainer.get_training_summaryJsa���}�}�}���<��3�3� $�
�
�@�
�1���Q�Q�
�	�@�
��I����!1�!1�!C�!C��� 0� 0� D� D��Yb��$D�)�$D�!D�s�9�~�!U�hi��S\�c�!>�I�!>�>��Y��O�bc��QZ�#�<�)�<�<�s�9�~�M�`a���)�)�?�?��B�"�B�A����A�F�F�#�B�"�
&��)�)�E�E�G��K�(�K�A����$�$�a�j�j�1�K�(�
140  �	
141  ��A��"��(s�F�F� !F�'+F ")rYrVrZN)�	paragraph)r}r�)g�������?)r@rArBrCrDr[rfrnrwr�r�r�rJrKrLs@rrTrT_sX�����	4�	4���<
142  �
143  �4P�P�$Q
144  �Q
145  �f<K�<K�|
146  �
147  rrT�__main__z === Prediction Trainer Test ===
148  �rick)�operator_id�survivalg�������?�compoundinggffffff�?a
149      Optimism always wins. Even in 1946 Japan, optimists like Morita built Sony.
150  
151      Jensen Huang's will to survive exceeds everyone's will to kill him. Nvidia
152      laid off 70% of the company but survived through determination.
153  
154      Let your winners ride. 99.98% of Amazon's growth happened after IPO.
155  
156      Strength leads to strength through reflexivity and compounding.
157  
158      Focus on what makes your beer taste better, not generating electricity.
159  
160      It's never too late - Morris Chang founded TSMC at 56.
161      zStarting prediction session...�
acquired_testr�z
162  
163  Analyzed z ideasz
164  Predicted top resonators:)riz  z. [z.2fz] :N�<Nz...�jensenr�zwinners ridez
165  Operator selected z
166  === Training Results ===zPrecision: z.2%zRecall: z
167  F1 Score: z
168  New gravity wells discovered: zStrengthened patterns: z
169  Surprising selections: z
170  === Training Summary ===z
171  Sessions: rZzOverall accuracy: r�zTop gravity wells: r�z
172  === Test Complete ===)�
173  resilience�will�
determination)�exponential�growth�leverage)7rD�dataclassesrrr�typingrrrrr	�json�cognitive_fingerprintr
174  rr�content_analyzerr
rrrrNrTr@�print�fpr��trainerr^rfrer�r7rsrn�predictions�	enumerater�rvr��selectedr�rdrtrwr��resultr&r,r0r:r;rPr��summaryr?rr�<module>r�s����)��1�1������
175  �+S�+S��+S�\�-�-��-�&C
176  �C
177  �N�z��	�
178  -�.�
179  �&�	1�B����
180  �C�)P�Q����
�s�,Q�R� ��#�G�
�G� 
181182  *�+��#�#�G�_�k�J�G�	�K��G�.�.�4�4�5�6�f�
183  =�>�
184185  '�(��)�)�'��)�;�K��[�!�,���4�
��1�#�S��1�1�#�6�b����c�9J�8K�3�O�P�-�
186  �H��"�"�(�(������+�+�-�-��T�\�\�=O�=O�=Q�1Q��O�O�D�L�L�)�
�4�<�<�-�-�/�
/�M�T�\�\�EW�EW�EY�4Y��O�O�D�L�L�)�
�t�|�|�1�1�3�
3��O�O�D�L�L�)�
)�
187  � ��X���v�
188  6�7����g�x�0�
�
%�
%�g�
.�F�	�
189  &�'�	�K��(�(��-�
190  .�/�	�H�V�]�]�3�'�
191  (�)�	�J�v���s�+�
192  ,�-�
����
�0��1I�1I�0J�K�L�
�#�#�#�
�'��(D�(D�'E�F�G�
�#�#�#�
�)�#�f�.J�.J�*K�)L�M�N�
193194  &�'��*�*�,�G�	�J�w�z�*�+�
195  ,�-�	��w�'9�:�3�?�
196  @�A�	���(;� <�=�
197  >�?�	�
198  #�$�Wr