o
    }oi                     @  s   d dl mZ d dlm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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 )    )annotations)TYPE_CHECKING)_SearchSpaceTransform)BaseSampler)LazyRandomState)Any)distributions)BaseDistribution)Study)FrozenTrialc                   @  sD   e Zd ZdZddddZdd	d
Zd ddZd!ddZd"ddZdS )#RandomSampleraS  Sampler using random sampling.

    This sampler is based on *independent sampling*.
    See also :class:`~optuna.samplers.BaseSampler` for more details of 'independent sampling'.

    Example:

        .. testcode::

            import optuna
            from optuna.samplers import RandomSampler


            def objective(trial):
                x = trial.suggest_float("x", -5, 5)
                return x**2


            study = optuna.create_study(sampler=RandomSampler())
            study.optimize(objective, n_trials=10)

    Args:
        seed: Seed for random number generator.
    Nseed
int | NonereturnNonec                 C  s   t || _d S N)r   _rng)selfr    r   K/home/ubuntu/.local/lib/python3.10/site-packages/optuna/samplers/_random.py__init__-   s   zRandomSampler.__init__c                 C  s   | j j  d S r   )r   rngr   )r   r   r   r   
reseed_rng0   s   zRandomSampler.reseed_rngstudyr
   trialr   dict[str, BaseDistribution]c                 C     i S r   r   )r   r   r   r   r   r   infer_relative_search_space3      z)RandomSampler.infer_relative_search_spacesearch_spacedict[str, Any]c                 C  r   r   r   )r   r   r   r   r   r   r   sample_relative8   r   zRandomSampler.sample_relative
param_namestrparam_distributiondistributions.BaseDistributionr   c                 C  sJ   ||i}t |}| jj|jd d df |jd d df }||| S )Nr      )r   r   r   uniformboundsuntransform)r   r   r   r"   r$   r   transtrans_paramsr   r   r   sample_independent=   s   ,z RandomSampler.sample_independentr   )r   r   r   r   )r   r   )r   r
   r   r   r   r   )r   r
   r   r   r   r   r   r    )
r   r
   r   r   r"   r#   r$   r%   r   r   )	__name__
__module____qualname____doc__r   r   r   r!   r,   r   r   r   r   r      s    


r   N)
__future__r   typingr   optuna._transformr   optuna.samplersr   "optuna.samplers._lazy_random_stater   r   optunar   optuna.distributionsr	   optuna.studyr
   optuna.trialr   r   r   r   r   r   <module>   s    