Raw File
util.pyc
ó
‡oŠ\c@s‰ddlZddlZddlmZddlmZddd„Zdefd„ƒYZ	d	„Z
dd
„Zdd
d„ƒYZ
dS(iÿÿÿÿN(tnorm(tminimizei †iúcs|j|dd…df|dd…dfd||jdfƒ}ˆ|dˆdˆƒ}||jƒ}	|jƒ}
|j|dd…df|dd…dfd||jdfƒ}x|D]…}t‡‡‡fd†|jddƒd	|d
dƒ}
|
jsqÅn|
dks0|
jd|
krÅ|
j	}	|
jd}
qÅqÅWt
j|	|dd…df|dd…dfƒS(sÓ
    A function to find the maximum of the acquisition function

    It uses a combination of random sampling (cheap) and the 'L-BFGS-B'
    optimization method. First by sampling `n_warmup` (1e5) points at random,
    and then running L-BFGS-B from `n_iter` (250) random starting points.

    Parameters
    ----------
    :param ac:
        The acquisition function object that return its point-wise value.

    :param gp:
        A gaussian process fitted to the relevant data.

    :param y_max:
        The current maximum known value of the target function.

    :param bounds:
        The variables bounds to limit the search of the acq max.

    :param random_state:
        instance of np.RandomState random number generator

    :param n_warmup:
        number of times to randomly sample the aquisition function

    :param n_iter:
        number of times to run scipy.minimize

    Returns
    -------
    :return: x_max, The arg max of the acquisition function.
    Niitsizetgpty_maxcs#ˆ|jddƒdˆdˆƒS(NiiÿÿÿÿRR(treshape(tx(tacRR(sN:\TCAD\SLALOM\Bayes\util.pyt<lambda>7siÿÿÿÿtboundstmethodsL-BFGS-B(tuniformtshapetargmaxtmaxRRtsuccesstNonetfunRtnptclip(RRRR	trandom_statetn_warmuptn_itertx_triestystx_maxtmax_acqtx_seedstx_trytres((RRRsN:\TCAD\SLALOM\Bayes\util.pytacq_maxs$%//
		 	tUtilityFunctioncBsMeZdZd„Zd„Zed„ƒZed„ƒZed„ƒZRS(s9
    An object to compute the acquisition functions.
    cCsI||_||_|dkr<dj|ƒ}t|ƒ‚n	||_dS(sC
        If UCB is to be used, a constant kappa is needed.
        tucbteitpoisWThe utility function {} has not been implemented, please choose one of ucb, ei, or poi.N(sucbseiR"(tkappatxitformattNotImplementedErrortkind(tselfR'R#R$terr((sN:\TCAD\SLALOM\Bayes\util.pyt__init__Os			cCsy|jdkr%|j|||jƒS|jdkrM|j||||jƒS|jdkru|j||||jƒSdS(NR R!R"(R't_ucbR#t_eiR$t_poi(R(RRR((sN:\TCAD\SLALOM\Bayes\util.pytutility_scCsGtjƒ-tjdƒ|j|dtƒ\}}WdQX|||S(Ntignoret
return_std(twarningstcatch_warningstsimplefiltertpredicttTrue(RRR#tmeantstd((sN:\TCAD\SLALOM\Bayes\util.pyR+gs

!cCswtjƒ-tjdƒ|j|dtƒ\}}WdQX||||}|||tj|ƒ|tj|ƒS(NR/R0(R1R2R3R4R5Rtcdftpdf(RRRR$R6R7tz((sN:\TCAD\SLALOM\Bayes\util.pyR,os


!cCsZtjƒ-tjdƒ|j|dtƒ\}}WdQX||||}tj|ƒS(NR/R0(R1R2R3R4R5RR8(RRRR$R6R7R:((sN:\TCAD\SLALOM\Bayes\util.pyR-xs


!(	t__name__t
__module__t__doc__R*R.tstaticmethodR+R,R-(((sN:\TCAD\SLALOM\Bayes\util.pyRJs			cCsËddl}t|tƒr'|g}nx|D]•}t|dƒ~}xttr¼yt|ƒ}Wntk
rsPnX|j|ƒ}y"|jd|dd|dƒWqIt	k
r¸qIXqIWWdQXq.W|S(sLoad previous ...

    iÿÿÿÿNtrtparamsttarget(
tjsont
isinstancetstrtopenR5tnextt
StopIterationtloadstregistertKeyError(t	optimizertlogsRBtlogtjt	iteration((sN:\TCAD\SLALOM\Bayes\util.pyt	load_logs‚s$
	
	

cCsa|dkrtjjƒ}n?t|tƒrBtjj|ƒ}nt|tjjƒs]t‚|S(s­
    Creates a random number generator based on an optional seed.  This can be
    an integer or another random state for a seeded rng, or None for an
    unseeded rng.
    N(RRtrandomtRandomStateRCtinttAssertionError(R((sN:\TCAD\SLALOM\Bayes\util.pyt
ensure_rngŸstColourscBsïeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
Ze
d„ƒZe
d„ƒZe
d
„ƒZe
d„ƒZe
d„ƒZe
d„ƒZe
d„ƒZe
d„ƒZe
d„ƒZe
d„ƒZe
d„ƒZRS(sPrint in nice colours.sssssssssscCs|||jS(N(tEND(tclststcolour((sN:\TCAD\SLALOM\Bayes\util.pyt_wrap_colour¼scCs|j||jƒS(sWrap text in black.(R[RW(RXRY((sN:\TCAD\SLALOM\Bayes\util.pytblackÀscCs|j||jƒS(sWrap text in blue.(R[tBLUE(RXRY((sN:\TCAD\SLALOM\Bayes\util.pytblueÅscCs|j||jƒS(sWrap text in bold.(R[tBOLD(RXRY((sN:\TCAD\SLALOM\Bayes\util.pytboldÊscCs|j||jƒS(sWrap text in cyan.(R[tCYAN(RXRY((sN:\TCAD\SLALOM\Bayes\util.pytcyanÏscCs|j||jƒS(sWrap text in darkcyan.(R[tDARKCYAN(RXRY((sN:\TCAD\SLALOM\Bayes\util.pytdarkcyanÔscCs|j||jƒS(sWrap text in green.(R[tGREEN(RXRY((sN:\TCAD\SLALOM\Bayes\util.pytgreenÙscCs|j||jƒS(sWrap text in purple.(R[tPURPLE(RXRY((sN:\TCAD\SLALOM\Bayes\util.pytpurpleÞscCs|j||jƒS(sWrap text in red.(R[tRED(RXRY((sN:\TCAD\SLALOM\Bayes\util.pytredãscCs|j||jƒS(sWrap text in underline.(R[t	UNDERLINE(RXRY((sN:\TCAD\SLALOM\Bayes\util.pyt	underlineèscCs|j||jƒS(sWrap text in yellow.(R[tYELLOW(RXRY((sN:\TCAD\SLALOM\Bayes\util.pytyellowís(R;R<R=R]R_RaRcRWReRgRiRkRmtclassmethodR[R\R^R`RbRdRfRhRjRlRn(((sN:\TCAD\SLALOM\Bayes\util.pyRV®s,((R1tnumpyRtscipy.statsRtscipy.optimizeRRtobjectRRPRRURV(((sN:\TCAD\SLALOM\Bayes\util.pyt<module>sC8	
back to top