
    yj                         d Z ddlmZmZ ddlmZmZ ddlZe G d d                      Z	e G d de	                      Z
e G d	 d
e	                      Z G d de          ZdS )z3
Base classes for tree-based surprisal estimation.
    )ABCabstractmethod)	dataclassfieldNc                   "    e Zd ZU dZdZeed<   dS )TreeNodezBase node for tree structures.r   countN)__name__
__module____qualname____doc__r	   int__annotations__     >/DATA/AppData/hermes/projects/honcho/src/dreamer/trees/base.pyr   r      s#         ((E3NNNNNr   r   c                   T    e Zd ZU dZ ee          Zeej                 e	d<   ddZ
dS )LeafNodez#Leaf node containing actual points.)default_factorypointsreturnNc                 R    | j         dk    rt          | j                  | _         d S d S Nr   )r	   lenr   )selfs    r   __post_init__zLeafNode.__post_init__   s)    :??!$+..DJJJ ?r   )r   N)r
   r   r   r   r   listr   npndarrayr   r   r   r   r   r   r      sT         --$uT:::FD:::/ / / / / /r   r   c                   0    e Zd ZU dZdZded<   dZded<   dS )InternalNodez'Internal node with splitting criterion.NzInternalNode | LeafNode | Noneleftright)r
   r   r   r   r"   r   r#   r   r   r   r!   r!      s:         11-1D
*111.2E+22222r   r!   c                       e Zd ZU dZeed<   eed<   ddeddfdZedej	        ddfd	            Z
edej	        defd
            Zdej	        ddfdZdS )SurprisalTreez
    Abstract base class for tree-based surprisal estimation.

    Subclasses implement different spatial indexing strategies.
    Not all implementations use a traditional tree structure.
    max_leaf_sizetotal_points
   r   Nc                 "    || _         d| _        d S r   )r&   r'   )r   r&   s     r   __init__zSurprisalTree.__init__0   s    *r   pointc                     dS )z"Insert a point into the structure.Nr   r   r+   s     r   insertzSurprisalTree.insert4         r   c                     dS )zCompute surprisal for a point.Nr   r-   s     r   	surprisalzSurprisalTree.surprisal8   r/   r   r   c                 :    |D ]}|                      |           dS )zInsert multiple points.N)r.   )r   r   r+   s      r   batch_insertzSurprisalTree.batch_insert<   s0     	 	EKK	 	r   )r(   )r
   r   r   r   r   r   r*   r   r   r   r.   floatr1   r3   r   r   r   r%   r%   %   s            c 4     1BJ 14 1 1 1 ^1 -rz -e - - - ^-2: $      r   r%   )r   abcr   r   dataclassesr   r   numpyr   r   r   r!   r%   r   r   r   <module>r8      s!    $ # # # # # # # ( ( ( ( ( ( ( (             / / / / /x / / / 3 3 3 3 38 3 3 3    C     r   