o
    z“©iš  ã                   @   sp   d dl mZmZ d dlmZ d dlmZ d dlmZm	Z	 ddl
mZ ddlmZ ddlmZ G d	d
„ d
eƒZdS )é    )ÚCallableÚUnion)ÚTensor)ÚModule)ÚvjpÚjacrevé   )ÚSDE)ÚSLIC)ÚDEVICEc                       sb   e Zd Z				ddededeeef dede	f
‡ fdd	„Z
d
edeedf defdd„Z‡  ZS )Ú
KernelSLICNçü©ñÒMbP?ÚkernelÚforward_modelÚmodelÚsdeÚtikhonov_regularisationc           	         s@   t ƒ j|f||dœ|¤Ž t|jƒdksJ dƒ‚|| _|| _dS )aË  
        This clas overwrites DSM loss to include correlation from the forward model. We use the approximation 
        that the forward model can be represented as a convolution. The kerel of this convolution
        is provided by the user. 

        This approximation is useful because it can be used in the case where the Jacobian is quite large 
        or does not fit into memory. It allows us to use the convolution theorem to simplify the 
        Gaussian transition score function used as target for DSM. 
        
        In this class, I assume that kernel has the same shape as the output of the forward model. See 
        the method to construct an effective kernel from the forward model.
        )r   Úcheckpoints_directoryé   z.Kernel should be an image with channels first.N)ÚsuperÚ__init__ÚlenÚshaper   r   )	Úselfr   Úinput_dimensionsr   r   r   r   r   Úhyperparameters©Ú	__class__© úL/home/ubuntu/.local/lib/python3.10/site-packages/score_models/kernel_slic.pyr      s   
zKernelSLIC.__init__ÚsamplesÚargs.Úreturnc                 G   s   d S )Nr   )r   r    r!   r   r   r   Úloss_fn'   s   zKernelSLIC.loss_fn)NNNr   )Ú__name__Ú
__module__Ú__qualname__r   r   r   Ústrr   r	   Úfloatr   Úlistr#   Ú__classcell__r   r   r   r   r   
   s"    øþü
ûúø&r   N)Útypingr   r   Útorchr   Útorch.nnr   Ú
torch.funcr   r   r   r	   Úscore_modelr
   Úutilsr   r   r   r   r   r   Ú<module>   s    