Beispiel #1
0
    def umbrella_sampling(self, tau, class_prob):
        us = usample.UmbrellaSampler(self.gumbel_softmax_fn,
                                     lpfargs=[tau, class_prob],
                                     debug=True,
                                     burn_acor=20)
        temps = np.linspace(1, 10, 8)
        us.add_umbrellas(temps,
                         ic=[0],
                         numwalkers=8,
                         sampler=emcee.EnsembleSampler)
        pos_us, _, _ = us.run(1000, freq=1000, repex=10, grstop=0.01)

        quant_splits = np.linspace(0, 1, len(class_prob) + 1)[1:]
        quant_splits[:-1] = quant_splits[:-1] + np.random.uniform(
            low=-1, high=1, size=(1, len(quant_splits) - 1)) * 0.001
        quant_val = np.quantile(pos_us[:, 0], quant_splits)
        sampled_classes = np.digitize(pos_us[:, 0], quant_val, right=True)

        return sampled_classes
Beispiel #2
0
    lpf = -0.5 * np.dot(pp, np.dot(icov, pp))

    return lpf


#
# Now create the umbrella sampler object
#

means = np.array([0.5, -0.25])

icov = np.array([[1, 0.5], [0.5, 1]])

us = usample.UmbrellaSampler(log_prob_fn,
                             lpfargs=[means, icov],
                             mpi=True,
                             debug=True,
                             burn_acor=20)

#
# Now add some umbrellas.
# First, define some temperatures to run with.
#

temps = np.linspace(1, 10, 8)

#
# Then add an umbrella at each temperature. Use four walkers, and give some initial conditions
# Can be added individually, or in bulk:
#
Beispiel #3
0
def log_prob_fn(p ):
    
    x=p[0]
    y=p[1]
    
    # Two Gaussian distributions, centered on +/- 1 
    lpf = np.log( np.exp(-16*(x-1)**2) + np.exp(-16*(x+1)**2  ))
    # And an independent Gaussian in another direction
    lpf -= 0.5*y*y
     
    
    return lpf 

#
# Now create the umbrella sampler object 
us = usample.UmbrellaSampler( log_prob_fn  , mpi=True, debug=True,  burn_acor=20 )

#
# Build umbrellas along a line between two points: the two peaks of the distribution.
# This line is a 1D "CV" or Collective Variable, embedded in the higher dimensions.
cvfn = ["line", [np.array([-1.0,0]), np.array([1.0,0])] ]

# The start of the line is "0", and the end is "1".
# We define the centers of the biasing distribution. Here we define four umbrellas:
centers = np.linspace( 0 , 1 , 4 ) 

# We may also make use of sampling using different temperatures within a window.
# Lets try sampling at a temperature of 1 and 5.
temps = [1,5]  

# Note that this gives a total of 4x2=8 umbrellas overall.
Beispiel #4
0
          (ndim, np.size(xmod)))
    print("active indices:", np.arange(np.size(xmod))[ia])
    print("initial values:", x0)
    print("initial scatter:", step)
    print(anames)

    nwalkers = 10

    pp = np.vstack([
        x0 + np.random.normal(scale=step, size=len(x0))
        for i in range(nwalkers)
    ])

    us = usample.UmbrellaSampler(sn_like_walk,
                                 lpfargs=args,
                                 lpfkwargs=kwargs,
                                 mpi=True,
                                 debug=True,
                                 burn_acor=20)

    if (us.is_master()):
        t0 = clock()

    #
    # Now add some umbrellas.
    # First, define some temperatures to run with.
    #

    temps = np.linspace(1, 10, 5.)

    #
    # Then add an umbrella at each temperature. Use numwalkers walkers, and give some initial conditions