def get_random_configuration(self): """make sure they're all inside the radius""" coords = np.zeros([self.natoms,3]) for i in range(self.natoms): coords[i,:] = vector_random_uniform_hypersphere(3) * self.radius assert(np.linalg.norm(coords[i,:]) <= self.radius) # test to make sure the configuration is good tests = self.get_config_tests() for test in tests: assert test.accept(coords.flatten()) return coords.flatten()
def get_random_configuration(self): """make sure they're all inside the radius""" coords = np.zeros([self.natoms, 3]) for i in range(self.natoms): coords[i, :] = vector_random_uniform_hypersphere(3) * self.radius assert (np.linalg.norm(coords[i, :]) <= self.radius) # test to make sure the configuration is good tests = self.get_config_tests() for test in tests: assert test.accept(coords.flatten()) return coords.flatten()
def do_nested_sampling(nreplicas=10, niter=200, mciter=1000, stepsize=.8, estop=-.9, x0=[1,1], r0=2, xlim=None, ylim=None, circle=False ): path = [] def mc_record_position_event(coords=None, **kwargs): if len(path) == 0 or not np.all(path[-1] == coords): path.append(coords) p = Pot() print p.get_energy(np.array([1,2.])) mc_walker = MonteCarloWalker(p, mciter=mciter, events=[mc_record_position_event]) # initialize the replicas with random positions replicas = [] for i in xrange(nreplicas): # choose points uniformly in a circle if circle: coords = vector_random_uniform_hypersphere(2) * r0 + x0 else: coords = np.zeros(2) coords[0] = np.random.uniform(xlim[0], xlim[1]) coords[1] = np.random.uniform(ylim[0], ylim[1]) # coords = np.random.uniform(-1,3,size=2) r = Replica(coords, p.get_energy(coords)) replicas.append(r) ns = NestedSampling(replicas, mc_walker, stepsize=stepsize) results = [Result()] results[0].replicas = [r.copy() for r in replicas] for i in xrange(niter): ns.one_iteration() new_res = Result() new_res.replicas = [r.copy() for r in replicas] new_res.starting_replica = ns.starting_replicas[0].copy() new_res.new_replica = ns.new_replicas[0].copy() path.insert(0, new_res.starting_replica.x) new_res.mc_path = path results.append(new_res) path = [] if ns.replicas[-1].energy < estop: break # plt.plot(ns.max_energies) # plt.show() return ns, results
def sample_coords_from_basin(self, m, Emax): """Returns a configuration with energy less than Emax sampled uniformly from the basin of a minimum this assumes the harmonic approximation and is exact in the harmonic approximation Parameters ---------- m : Minimum object normal mode frequencies and associated eigenvectors Emax : float energy upper bound k : integer number of degrees of freedom Notes ----- in real system, even ones that fit quite well to the harmonic approximation this very often generates configurations with energy greater than Emax. """ nm = m.normal_modes evals = nm.freqs vectors = nm.vectors k = self.k nzero = len(evals) - k # get uniform random k dimensional unit vector f = vector_random_uniform_hypersphere(k) # the target increase in energy is sampled from a power law distribution # js850 sep 13> dE_target = np.random.power(k-1) * (Emax - m.energy) dE_target = (Emax - m.energy) # scale f according to dE_target f *= np.sqrt(2. * dE_target) #TODO check prefactor # create the random displacement vector dx = np.zeros(m.coords.shape) for i in range(k): if evals[i+nzero] > 1e-4: dx += f[i] * vectors[:,i+nzero] / np.sqrt(evals[i+nzero]) return m.coords + dx
def get_random_configuration(self, radius=10.): """ return a random vector sampled uniformly from within a hypersphere of dimensions self.ndim""" x = vector_random_uniform_hypersphere(self.ndim) * radius return x
def get_random_configuration(self, radius=10.): """ return a random vector sampled uniformly from within a hypersphere of dimensions self.ndim""" x = vector_random_uniform_hypersphere(self.ndim) * radius return x
def get_random_configuration(self, radius=1.): """ """ x = vector_random_uniform_hypersphere(self.ndim * self.length) * radius return x.reshape(x, (self.ndim, self.length))