Ë
    þÍ:j(J  ã                  ó@  — d Z ddlmZ ddlmZ ddlmZ ddlZddlm	Z	 ddl
mZ ddlmZ erdd	lmZ ddlZddlZndd
lmZ  ed«      Z ed«      Z ee«      Zdd„Z G d„ dej.                  j0                  «      Z G d„ d«      Z	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zy)a  Notations in this Gaussian process implementation

X_train: Observed parameter values with the shape of (len(trials), len(params)).
y_train: Observed objective values with the shape of (len(trials), ).
x: (Possibly batched) parameter value(s) to evaluate with the shape of (..., len(params)).
cov_fX_fX: Kernel matrix X = V[f(X)] with the shape of (len(trials), len(trials)).
cov_fx_fX: Kernel matrix Cov[f(x), f(X)] with the shape of (..., len(trials)).
cov_fx_fx: Kernel scalar value x = V[f(x)]. This value is constant for the Matern 5/2 kernel.
cov_Y_Y_inv:
    The inverse of the covariance matrix (V[f(X) + noise_var])^-1 with the shape of
    (len(trials), len(trials)).
cov_Y_Y_inv_Y: `cov_Y_Y_inv @ y` with the shape of (len(trials), ).
max_Y: The maximum of Y (Note that we transform the objective values such that it is maximized.)
sqd: The squared differences of each dimension between two points.
is_categorical:
    A boolean array with the shape of (len(params), ). If is_categorical[i] is True, the i-th
    parameter is categorical.
é    )Úannotations)ÚAny)ÚTYPE_CHECKINGN)Ú*single_blas_thread_if_scipy_v1_15_or_newer)Úoptuna_warn)Ú
get_logger)ÚCallable)Ú_LazyImportÚscipyÚtorchc                ó  — t        j                  | «      }t        j                  |«      r| S t        d«       t        j                  |d¬«      }t        j
                  | t        j                  |t        j                  t        j                  || t         j                  «      d¬«      d«      t        j                  |t        j                  t        j                  || t         j                   «      d¬«      d«      «      S )NzDClip non-finite values to the min/max finite values for GP fittings.r   )Úaxisç        )
ÚnpÚisfiniteÚallr   ÚanyÚclipÚwhereÚminÚinfÚmax)ÚvaluesÚis_values_finiteÚis_any_finites      úb/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/optuna/_gp/gp.pyÚwarn_and_convert_infr   .   s³   € Ü—{‘{ 6Ó*ÐÜ	‡v�vÐÔØˆäÐVÔWÜ—F‘FÐ+°!Ô4€Mô �7‰7ØÜ
�‰�¤§¡¤r§x¡xÐ0@À&Ì"Ï&É&Ó'QÐXYÔ ZÐ\_Ó`Ü
�‰�¤§¡¤r§x¡xÐ0@À&Ì2Ï6É6È'Ó'RÐYZÔ [Ð]`Óaóð ó    c                  ó0   — e Zd Zedd„«       Zedd„«       Zy)ÚMatern52Kernelc                ó¶   — t        j                  d|z  «      }t        j                  | «      }|d|z  |z   dz   z  }d|dz   z  |z  }| j                  |«       |S )aô  
        This method calculates `exp(-sqrt5d) * (1/3 * sqrt5d ** 2 + sqrt5d + 1)` where
        `sqrt5d = sqrt(5 * squared_distance)`.

        Please note that automatic differentiation by PyTorch does not work well at
        `squared_distance = 0` due to zero division, so we manually save the derivative, i.e.,
        `-5/6 * (1 + sqrt5d) * exp(-sqrt5d)`, for the exact derivative calculation.

        Notice that the derivative of this function is taken w.r.t. d**2, but not w.r.t. d.
        é   g«ªªªªªú?é   g«ªªªªªê¿)r   ÚsqrtÚexpÚsave_for_backward)ÚctxÚsquared_distanceÚsqrt5dÚexp_partÚvalÚderivs         r   ÚforwardzMatern52Kernel.forward?   sh   € ô —‘˜AÐ 0Ñ0Ó1ˆÜ—9‘9˜f˜WÓ%ˆØ˜5Ð$4Ñ4°vÑ=ÀÑAÑBˆØ˜F Q™JÑ'¨(Ñ2ˆØ×Ñ˜eÔ$Øˆ
r   c                ó(   — | j                   \  }||z  S )z¼
        Let x be squared_distance, f(x) be forward(ctx, x), and g(f) be a provided function, then
        deriv := df/dx, grad := dg/df, and deriv * grad = df/dx * dg/df = dg/dx.
        )Úsaved_tensors)r'   Úgradr,   s      r   ÚbackwardzMatern52Kernel.backwardR   s   € ð ×$Ñ$‰ˆØ�t‰|Ðr   N)r'   r   r(   útorch.TensorÚreturnr2   )r'   r   r0   r2   r3   r2   )Ú__name__Ú
__module__Ú__qualname__Ústaticmethodr-   r1   © r   r   r    r    >   s(   „ Øòó ðð$ òó ñr   r    c                  ó–   — e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
d„Zedd„«       Zdd„Zdd„Z	 d	 	 	 	 	 dd„Zddd„Z	dd„Z
	 	 	 	 	 	 	 	 	 	 dd	„Zy)ÚGPRegressorc                óØ  — || _         || _        || _        || _        || _        |j                  d«      |j                  d«      z
  j                  «       | _        | j                   j                  «       rT| j                  d| j                   f   dkD  j                  t        j                  «      | j                  d| j                   f<   d | _        d | _        || _        || _        || _        y )Néþÿÿÿéýÿÿÿ.r   )Ú_is_categoricalÚ_X_trainÚ_y_trainÚ_X_allÚ_y_allÚ	unsqueezeÚsquare_Ú_squared_X_diffr   Útyper   Úfloat64Ú_cov_Y_Y_cholÚ_cov_Y_Y_inv_YÚinverse_squared_lengthscalesÚkernel_scaleÚ	noise_var)ÚselfÚis_categoricalÚX_trainÚy_trainrJ   rK   rL   s          r   Ú__init__zGPRegressor.__init__]   sÖ   € ð  .ˆÔØˆŒØˆŒØˆŒØˆŒØ '× 1Ñ 1°"Ó 5¸×8IÑ8IÈ"Ó8MÑ M×VÑVÓXˆÔØ×Ñ×#Ñ#Ô%à×$Ñ$ S¨$×*>Ñ*>Ð%>Ñ?À#ÑEß‰d”5—=‘=Ó!ð × Ñ   d×&:Ñ&:Ð!:Ñ;ð 37ˆÔØ37ˆÔà,HˆÔ)Ø(ˆÔØ"ˆ�r   c                óš   — dt        j                  | j                  j                  «       j	                  «       j                  «       «      z  S )Ng      ð?)r   r$   rJ   ÚdetachÚcpuÚnumpy)rM   s    r   Úlength_scaleszGPRegressor.length_scalesw   s7   € à”R—W‘W˜T×>Ñ>×EÑEÓG×KÑKÓM×SÑSÓUÓVÑVÐVr   c                óR  — | j                   €| j                  �J d«       ‚t        j                  «       5  | j	                  «       j                  «       j                  «       j                  «       }d d d «       t        j                  | j                  j                  d   «      xx   | j                  j                  «       z  cc<   t        j                  j                  |«      }t         j                  j#                  |j$                  t         j                  j#                  || j&                  j                  «       j                  «       d¬«      d¬«      }t        j(                  |«      | _         t        j(                  |«      | _        | j*                  j                  «       | _        d | j*                  _        | j.                  j                  «       | _        d | j.                  _        | j                  j                  «       | _        d | j                  _        y # 1 sw Y   �Œ¯xY w)Nz(Cannot call cache_matrix more than once.r   T©ÚlowerF)rH   rI   r   Úno_gradÚkernelrS   rT   rU   r   Údiag_indicesr?   ÚshaperL   ÚitemÚlinalgÚcholeskyr   Úsolve_triangularÚTr@   Ú
from_numpyrJ   r0   rK   )rM   Úcov_Y_YÚcov_Y_Y_cholÚcov_Y_Y_inv_Ys       r   Ú_cache_matrixzGPRegressor._cache_matrix{   s¡  € Ø×!Ñ!Ð)¨d×.AÑ.AÐ.Ið 	
Ø6ó	
ÐIô �]‰]‹_ñ 	;Ø—k‘k“m×*Ñ*Ó,×0Ñ0Ó2×8Ñ8Ó:ˆG÷	;ð 	”—‘ §¡× 3Ñ 3°AÑ 6Ó7Ó8¸D¿N¹N×<OÑ<OÓ<QÑQÓ8Ü—y‘y×)Ñ)¨'Ó2ˆô Ÿ™×5Ñ5Ø�N‰NÜ�L‰L×)Ñ)¨,¸¿¹×8IÑ8IÓ8K×8QÑ8QÓ8SÐ[_Ð)Ó`Øð 6ó 
ˆô
 #×-Ñ-¨lÓ;ˆÔÜ#×.Ñ.¨}Ó=ˆÔØ,0×,MÑ,M×,TÑ,TÓ,VˆÔ)Ø15ˆ×)Ñ)Ô.Ø ×-Ñ-×4Ñ4Ó6ˆÔØ!%ˆ×ÑÔØŸ™×.Ñ.Ó0ˆŒØ"ˆ�‰Õ÷+	;ñ 	;ús   ´;HÈH&c                ó  — | j                   �| j                  €J d«       ‚| j                  j                  d   }|j                  d   }||z   }t	        j
                  ||ft        j                  ¬«      }| j                   j                  «       |d |…d |…f<   t        j                  «       5  | j                  |«      j                  «       j                  «       j                  «       }| j                  ||«      j                  «       j                  «       j                  «       }|t	        j                  |«      xx   | j                  j                  «       z  cc<   d d d «       t         j"                  j%                  | j                   j                  «       j                  «       j&                  d¬«      j&                  }	t        j"                  j)                  |	|	j&                  z  z
  «      ||d …|d …f<   |	||d …d |…f<   t        j*                  | j,                  |gd¬«      | _        t         j"                  j%                  |j&                  t         j"                  j%                  || j.                  j                  «       j                  «       d¬«      d¬«      }
t        j0                  |«      | _         t        j0                  |
«      | _        t        j*                  | j                  |gd¬«      | _        y # 1 sw Y   �Œ xY w)Nz-Call _cache_matrix before append_running_datar   ©ÚdtypeTrX   )ÚdimF)rH   rI   r?   r]   r   ÚzerosrG   rU   r   rZ   r[   rS   rT   r\   rL   r^   r   r_   ra   rb   r`   Úcatr@   rB   rc   rA   )rM   Ú	X_runningÚ	y_runningÚn_trainÚ	n_runningÚn_totalre   Úkernel_running_trainÚkernel_running_runningÚL21rf   s              r   Úappend_running_datazGPRegressor.append_running_data–   sz  € Ø×!Ñ!Ð-°$×2EÑ2EÐ2Qð 	
Ø;ó	
ÐQð —-‘-×%Ñ% aÑ(ˆØ—O‘O AÑ&ˆ	Ø˜IÑ%ˆô —x‘x ¨'Ð 2¼"¿*¹*ÔEˆØ+/×+=Ñ+=×+CÑ+CÓ+Eˆ�X�g�X˜x ˜xÐ'Ñ(Ü�]‰]‹_ñ 	XØ#'§;¡;¨yÓ#9×#@Ñ#@Ó#B×#FÑ#FÓ#H×#NÑ#NÓ#PÐ Ø%)§[¡[°¸IÓ%F×%MÑ%MÓ%O×%SÑ%SÓ%U×%[Ñ%[Ó%]Ð"Ø"¤2§?¡?°9Ó#=Ó>À$Ç.Á.×BUÑBUÓBWÑWÓ>÷	Xô �l‰l×+Ñ+Ø×Ñ×"Ñ"Ó$×*Ñ*Ó,Ð.B×.DÑ.DÈDð ,ó 
ç
‰!ð 	ô
 ,.¯9©9×+=Ñ+=Ð>TÐWZÐ]`×]bÑ]bÑWbÑ>bÓ+cˆ�W‘X˜w™xÐ'Ñ(Ø+.ˆ�W‘X˜x ˜xÐ'Ñ(Ü—i‘i §¡°	Ð :ÀÔBˆŒÜŸ™×5Ñ5Ø�N‰NÜ�L‰L×)Ñ)¨,¸¿¹¿¹Ó8I×8OÑ8OÓ8QÐY]Ð)Ó^Øð 6ó 
ˆô #×-Ñ-¨lÓ;ˆÔÜ#×.Ñ.¨}Ó=ˆÔÜ—i‘i §¡°	Ð :ÀÔBˆ�÷1	Xñ 	Xús   Â+B0K9Ë9LNc                óü  — |€|�J ‚| j                   }n­|€| j                  }|j                  dk(  r||z
  n"|j                  d«      |j                  d«      z
  j	                  «       }| j
                  j                  «       r@|d| j
                  f   dkD  j                  t        j                  «      |d| j
                  f<   |j                  | j                  «      }t        j                  |«      | j                  z  S )am  
        Return the kernel matrix with the shape of (..., n_A, n_B) given X1 and X2 each with the
        shapes of (..., n_A, len(params)) and (..., n_B, len(params)).

        If x1 and x2 have the shape of (len(params), ), kernel(x1, x2) is computed as:
            kernel_scale * Matern52Kernel.apply(
                sqd(x1, x2) @ inverse_squared_lengthscales
            )
        where if x1[i] is continuous, sqd(x1, x2)[i] = (x1[i] - x2[i]) ** 2 and if x1[i] is
        categorical, sqd(x1, x2)[i] = int(x1[i] != x2[i]).
        Note that the distance for categorical parameters is the Hamming distance.
        r#   r<   r=   .r   )rE   r?   ÚndimrC   rD   r>   r   rF   r   rG   ÚmatmulrJ   r    ÚapplyrK   )rM   ÚX1ÚX2ÚsqdÚsqdists        r   r[   zGPRegressor.kernel»   sã   € ð ˆ:Ø�:Ð�:Ø×&Ñ&‰CàˆzØ—]‘]�à Ÿg™g¨šl�2˜’7°·±¸RÓ0@À2Ç<Á<ÐPRÓCSÑ0S×\Ñ\Ó^ˆCØ×#Ñ#×'Ñ'Ô)Ø25°c¸4×;OÑ;OÐ6OÑ2PÐSVÑ2V×1\Ñ1\Ü—M‘Mó2��C˜×-Ñ-Ð-Ñ.ð —‘˜D×=Ñ=Ó>ˆÜ×#Ñ# FÓ+¨d×.?Ñ.?Ñ?Ð?r   c           	     óp  — | j                   �| j                  €J d«       ‚|j                  dk(  }|s|n|j                  d«      }t        j
                  j                  | j                  || j                  «      x}| j                  «      }t        j
                  j                  | j                   t        j
                  j                  | j                   j                  |dd¬«      dd¬«      }|rb|rJ d«       ‚| j                  ||«      }||j                  |j                  dd	«      «      z
  }	|	j                  d	d¬
«      j                  d«       n@| j                  }|t        j
                  j                  ||«      z
  }	|	j                  d«       |r"|j!                  d«      |	j!                  d«      fS ||	fS )a)  
        This method computes the posterior mean and variance given the points `x` where both mean
        and variance tensors will have the shape of x.shape[:-1].
        If ``joint=True``, the joint posterior will be computed.

        The posterior mean and variance are computed as:
            mean = cov_fx_fX @ inv(cov_fX_fX + noise_var * I) @ y, and
            var = cov_fx_fx - cov_fx_fX @ inv(cov_fX_fX + noise_var * I) @ cov_fx_fX.T.

        Please note that we clamp the variance to avoid negative values due to numerical errors.
        z+Call cache_matrix before calling posterior.r#   r   TF)ÚupperÚleftz3Call posterior with joint=False for a single point.éÿÿÿÿr<   )Údim1Údim2r   )rH   rI   rx   rC   r   r_   Úvecdotr[   rA   ra   rb   ry   Ú	transposeÚdiagonalÚ
clamp_min_rK   Úsqueeze)
rM   ÚxÚjointÚis_single_pointÚx_Ú	cov_fx_fXÚmeanÚVÚ	cov_fx_fxÚvar_s
             r   Ú	posteriorzGPRegressor.posteriorÙ   s„  € ð ×!Ñ!Ð-°$×2EÑ2EÐ2Qð 	
Ø9ó	
ÐQð Ÿ&™& A™+ˆÙ%‰Q¨1¯;©;°q«>ˆÜ�|‰|×"Ñ"°·±¸BÀÇÁÓ0LÐ#L 9Èd×NaÑNaÓbˆä�L‰L×)Ñ)Ø×ÑÜ�L‰L×)Ñ)¨$×*<Ñ*<×*>Ñ*>À	ÐQUÐ\aÐ)ÓbØØð	 *ó 
ˆñ Ù&Ð]Ð(]Ó]Ð&ØŸ™ B¨Ó+ˆIà˜qŸx™x¨	×(;Ñ(;¸BÀÓ(CÓDÑDˆDØ�M‰M˜r¨ˆMÓ+×6Ñ6°sÕ;à×)Ñ)ˆIØœuŸ|™|×2Ñ2°9¸aÓ@Ñ@ˆDØ�O‰O˜CÔ Ù5D�—‘˜Q“ §¡¨a£Ð1ÐVÈ4ÐQUÈ,ÐVr   c                óš  — | j                  «       }|j                  «       j                  | j                  «       t        j
                  j                  |«      }|j                  «       j                  «       j                  «        }t        j
                  j                  || j                  dd…df   d¬«      dd…df   }d||z  z  }||z   S )aÅ  
        This method computes the marginal log-likelihood of the kernel hyperparameters given the
        training dataset (X, y).
        Assume that N = len(X) in this method.

        Mathematically, the closed form is given as:
            -0.5 * log((2*pi)**N * det(C)) - 0.5 * y.T @ inv(C) @ y
            = -0.5 * log(det(C)) - 0.5 * y.T @ inv(C) @ y + const,
        where C = cov_Y_Y = cov_fX_fX + noise_var * I and inv(...) is the inverse operator.

        We exploit the full advantages of the Cholesky decomposition (C = L @ L.T) in this method:
            1. The determinant of a lower triangular matrix is the diagonal product, which can be
               computed with N flops where log(det(C)) = log(det(L.T @ L)) = 2 * log(det(L)).
            2. Solving linear system L @ u = y, which yields u = inv(L) @ y, costs N**2 flops.
        Note that given `u = inv(L) @ y` and `inv(C) = inv(L @ L.T) = inv(L).T @ inv(L)`,
        y.T @ inv(C) @ y is calculated as (inv(L) @ y) @ (inv(L) @ y).

        In principle, we could invert the matrix C first, but in this case, it costs:
            1. 1/3*N**3 flops for the determinant of inv(C).
            2. 2*N**2-N flops to solve C @ alpha = y, which is alpha = inv(C) @ y.

        Since the Cholesky decomposition costs 1/3*N**3 flops and the matrix inversion costs
        2/3*N**3 flops, the overall cost for the former is 1/3*N**3+N**2+N flops and that for the
        latter is N**3+2*N**2-N flops.
        NF)r€   r   g      à¿)r[   r‡   Úadd_rL   r   r_   r`   ÚlogÚsumra   r@   )rM   rd   ÚLÚlogdet_partÚinv_L_yÚ	quad_parts         r   Úmarginal_log_likelihoodz#GPRegressor.marginal_log_likelihoodþ   s­   € ð4 —+‘+“-ˆà×ÑÓ×Ñ §¡Ô/Ü�L‰L×!Ñ! 'Ó*ˆØ—z‘z“|×'Ñ'Ó)×-Ñ-Ó/Ð/ˆÜ—,‘,×/Ñ/°°4·=±=ÂÀDÀÑ3IÐQVÐ/ÓWÒXYÐ[\ÐX\Ñ]ˆØ˜G gÑ-Ñ.ˆ	à˜YÑ&Ð&r   c           	     ó  ‡ ‡‡‡‡	— ‰ j                   j                  d   Š	t        j                  t        j                  ‰ j
                  j                  «       j                  «       j                  «       «      t        j                  ‰ j                  j                  «       «      t        j                  ‰ j                  j                  «       d‰z  z
  «      gg«      }d
ˆˆˆˆ	ˆ fd„}t        «       5  t        j                  j                  ||ddd|i¬«      }d d d «       j                   st#        d|j$                  › �«      ‚t'        j(                  |j*                  «      }t'        j,                  |d ‰	 «      ‰ _        t'        j,                  |‰	   «      ‰ _	        ‰r%t'        j.                  ‰t&        j0                  ¬	«      n‰t'        j,                  |‰	dz      «      z   ‰ _        ‰ j3                  «        ‰ S # 1 sw Y   ŒâxY w)Nr#   g®Gáz®ï?c                ó¼  •— t        j                  | «      j                  d«      }t        j                  «       5  t        j                  |d ‰ «      ‰_        t        j                  |‰   «      ‰_        ‰r%t        j                  ‰t         j                  ¬«      nt        j                  |‰dz      «      ‰z   ‰_	        ‰j                  «         ‰‰«      z
  }|j                  «        |j                  ‰dz      }‰r|dk(  sJ ‚d d d «       j                  «       |j                  j                  «       j                  «       j!                  «       fS # 1 sw Y   ŒOxY w)NTri   r#   r   )r   rc   Úrequires_grad_Úenable_gradr%   rJ   rK   ÚtensorrG   rL   rœ   r1   r0   r^   rS   rT   rU   )	Ú
raw_paramsÚraw_params_tensorÚlossÚraw_noise_var_gradÚdeterministic_objectiveÚ	log_priorÚminimum_noiseÚn_paramsrM   s	       €€€€€r   Ú	loss_funcz1GPRegressor._fit_kernel_params.<locals>.loss_func;  s1  ø€ Ü %× 0Ñ 0°Ó <× KÑ KÈDÓ QÐÜ×"Ñ"Ó$ñ NÜ49·I±IÐ>OÐPYÐQYÐ>ZÓ4[�Ô1Ü$)§I¡IÐ.?ÀÑ.IÓ$J�Ô!ñ /ô —L‘L ´e·m±mÕDäŸ™Ð#4°XÀ±\Ñ#BÓCÀmÑSð ”ð
 ×4Ñ4Ó6Ð6¹À4»ÑH�Ø—‘”à%6×%;Ñ%;¸HÀq¹LÑ%IÐ"Ù2Ð6HÈAÒ6MÐMÐM÷Nð —9‘9“;Ð 1× 6Ñ 6× =Ñ =Ó ?× CÑ CÓ E× KÑ KÓ MÐMÐM÷Nð Nús   ºC
EÅETzl-bfgs-bÚgtol)ÚjacÚmethodÚoptionszOptimization failed: ri   )r¢   ú
np.ndarrayr3   ztuple[float, np.ndarray])r?   r]   r   Úconcatenater–   rJ   rS   rT   rU   rK   r^   rL   r   r   ÚoptimizeÚminimizeÚsuccessÚRuntimeErrorÚmessager   rc   rŠ   r%   r¡   rG   rg   )
rM   r§   r¨   r¦   r«   Úinitial_raw_paramsrª   ÚresÚraw_params_opt_tensorr©   s
   ````     @r   Ú_fit_kernel_paramszGPRegressor._fit_kernel_params"  s§  ü€ ð —=‘=×&Ñ& qÑ)ˆô  Ÿ^™^ä—‘�t×8Ñ8×?Ñ?ÓA×EÑEÓG×MÑMÓOÓPä—F‘F˜4×,Ñ,×1Ñ1Ó3Ó4ä—F‘F˜4Ÿ>™>×.Ñ.Ó0°4¸-Ñ3GÑGÓHððó	
Ð÷	Nñ 	Nô" 8Ó9ñ 		ä—.‘.×)Ñ)àØ"ØØ!Ø ˜ð *ó ˆC÷		ð �{Š{ÜÐ!6°s·{±{°mÐDÓEÐEä %× 0Ñ 0°·±Ó 7ÐÜ,1¯I©IÐ6KÈIÈXÐ6VÓ,WˆÔ)Ü!ŸI™IÐ&;¸HÑ&EÓFˆÔñ 'ô �L‰L˜¬e¯m©mÕ<à¤§¡Ð+@ÀÈAÁÑ+NÓ!OÑOð 	Œð
 	×ÑÔØˆ÷-		ð 		ús   Ã/'G7Ç7H )rN   r2   rO   r2   rP   r2   rJ   r2   rK   r2   rL   r2   r3   ÚNone)r3   r¯   )r3   rº   )rn   r2   ro   r2   r3   rº   )NN)r{   útorch.Tensor | Noner|   r»   r3   r2   )F)rŠ   r2   r‹   Úboolr3   z!tuple[torch.Tensor, torch.Tensor])r3   r2   )
r§   ú%Callable[[GPRegressor], torch.Tensor]r¨   Úfloatr¦   r¼   r«   r¾   r3   r:   )r4   r5   r6   rQ   ÚpropertyrV   rg   rv   r[   r“   rœ   r¹   r8   r   r   r:   r:   \   sÝ   „ ð#à$ð#ð ð#ð ð	#ð
 '3ð#ð #ð#ð  ð#ð 
ó#ð4 òWó ðWó#ó6#CðL IMð@Ø%ð@Ø2Eð@à	ó@ô<#WóJ"'ðH@à8ð@ð ð@ð "&ð	@ð
 ð@ð 
ô@r   r:   c           	     óJ  ‡ ‡‡‡— t        j                  ‰ j                  d   dz   t         j                  ¬«      Šd	ˆ ˆˆˆfd„} |«       }	|€ |«       }d }
||	fD ]  }	 t	        t        j
                  ‰«      t        j
                  ‰ «      t        j
                  ‰«      |j                  |j                  |j                  ¬«      j                  ||||¬«      c S  t        j                  d|
› d�«        |«       }|j                  «        |S # t        $ r}|}
Y d }~ŒÄd }~ww xY w)
Nr#   é   ri   c            	     óþ   •— t        t        j                  ‰«      t        j                  ‰ «      t        j                  ‰«      ‰d d j                  «       ‰d   j                  «       ‰d   j                  «       ¬«      S )Nr<   r‚   ©rN   rO   rP   rJ   rK   rL   )r:   r   rc   Úclone)ÚXÚYÚdefault_kernel_paramsrN   s   €€€€r   Ú_default_gprz'fit_kernel_params.<locals>._default_gprr  so   ø€ ÜÜ ×+Ñ+¨NÓ;Ü×$Ñ$ QÓ'Ü×$Ñ$ QÓ'Ø)>¸sÀÐ)C×)IÑ)IÓ)KØ.¨rÑ2×8Ñ8Ó:Ø+¨BÑ/×5Ñ5Ó7ô
ð 	
r   rÃ   )r§   r¨   r¦   r«   z/The optimization of kernel parameters failed: 
z<
The default initial kernel parameters will be used instead.)r3   r:   )r   Úonesr]   rG   r:   rc   rJ   rK   rL   r¹   r´   ÚloggerÚwarningrg   )rÅ   rÆ   rN   r§   r¨   r¦   Ú	gpr_cacher«   rÈ   Údefault_gpr_cacheÚerrorÚgpr_cache_to_useÚeÚdefault_gprrÇ   s   ```           @r   Úfit_kernel_paramsrÒ   e  s-  û€ ô "ŸJ™J q§w¡w¨q¡z°A¡~¼U¿]¹]ÔKÐ÷
ð 
ñ %›ÐØÐÙ “Nˆ	à€Eð 'Ð(9Ð:ò Ðð	ÜÜ$×/Ñ/°Ó?Ü×(Ñ(¨Ó+Ü×(Ñ(¨Ó+Ø-=×-ZÑ-ZØ-×:Ñ:Ø*×4Ñ4ô÷ !Ñ Ø#Ø+Ø(?Øð	 !ó òðô$ ‡N�NØ
:¸5¸'ð BFð 	Fôñ “.€KØ×ÑÔØÐøô ò 	Ø�Eûð	ús   ÁA:DÄ	D"ÄDÄD")r   r¯   r3   r¯   )Ng{®Gáz„?)rÅ   r¯   rÆ   r¯   rN   r¯   r§   r½   r¨   r¾   r¦   r¼   rÌ   zGPRegressor | Noner«   r¾   r3   r:   )Ú__doc__Ú
__future__r   Útypingr   r   rU   r   Ú"optuna._gp.scipy_blas_thread_patchr   Úoptuna._warningsr   Úoptuna.loggingr   Úcollections.abcr	   r   r   Úoptuna._importsr
   r4   rÊ   r   ÚautogradÚFunctionr    r:   rÒ   r8   r   r   ú<module>rÝ      sÛ   ðñõ& #å Ý  ã å YÝ (Ý %ñ Ý(ãÜå+á˜Ó €EÙ˜Ó €Eá	�HÓ	€óô �U—^‘^×,Ñ,ô ÷<Fñ Fð` %)Øð7Øð7àð7ð ð7ð 5ð	7ð
 ð7ð "ð7ð "ð7ð ð7ð ô7r   