Exemplo n.º 1
0
def test_samepoints(n):
    """Given exactly 2^n-1 samples, all series produce exactly the same
    points in different order
    """
    s = sobol((2**n - 1, max_dimensions()), chunks=(2**n - 1, 2000))
    s = s.map_blocks(np.sort, axis=0)
    s = s.T - s[:, 0]
    assert not s.any()
Exemplo n.º 2
0
 def get_weight_bias_sobol(self):
     """
     Weight are obtained with Sobol Sequence
     :return:
     """
     # w_sobol = np.zeros((self.hidden_neurons, self.dim))
     # w_sobol[1:self.hidden_neurons] = sobol((self.hidden_neurons - 1,
     #                                         self.dim))
     return sobol((self.hidden_neurons, self.dim))
Exemplo n.º 3
0
def test_max_dimensions():
    assert max_dimensions() == 21201
    assert sobol((4, 21201)).shape == (4, 21201)
    assert sobol((4, 201), d0=21000).shape == (4, 201)
    with pytest.raises(ValueError):
        sobol((4, 202), d0=21000)
    assert sobol(4, d0=21200).shape == (4, )
    with pytest.raises(ValueError):
        sobol(4, d0=21201)
Exemplo n.º 4
0
def test_bad_samples(n):
    with pytest.raises(ValueError) as e:
        sobol(n)
    assert str(e.value) == "samples must be between 1 and 2^32"
Exemplo n.º 5
0
def test_dask_2d():
    output = sobol((15, 4), d0=123, chunks=(10, 3))
    assert output.chunks == ((10, 5), (3, 1))
    assert_array_equal(EXPECT, output.compute())
Exemplo n.º 6
0
def test_numpy_2d():
    output = sobol((15, 4), d0=123)
    assert_array_equal(EXPECT, output)
Exemplo n.º 7
0
def test_dask_1d():
    output = sobol(15, d0=123, chunks=(10, 3))
    assert output.chunks == ((10, 5), )
    assert_array_equal(EXPECT[:, 0], output.compute())
Exemplo n.º 8
0
def test_numpy_1d():
    output = sobol(15, d0=123)
    assert_array_equal(EXPECT[:, 0], output)
Exemplo n.º 9
0
    def bind(self, ens, beads, nm, cell, bforce, prng, omaker):

        super(SCPhononsMover, self).bind(ens, beads, nm, cell, bforce, prng,
                                         omaker)

        # Raises error if nparallel is not a factor of max_steps
        if self.max_steps % self.nparallel != 0:
            raise ValueError(
                "Number of parallel force evaluations is not a factor of the maximum number of Monte Carlo steps."
            )

        # Raises error for nbeads not equal to 1.
        if self.beads.nbeads > 1:
            raise ValueError(
                "Calculation not possible for number of beads greater than one"
            )

        # Initialises a 3*number of atoms X 3*number of atoms dynamic matrix.
        if self.dynmatrix.size != (beads.q.size * beads.q.size):
            if self.dynmatrix.size == 0:
                self.dynmatrix = np.zeros((beads.q.size, beads.q.size), float)
                self.dynmatrix_r = np.zeros((beads.q.size, beads.q.size),
                                            float)
            else:
                raise ValueError(
                    "Force constant matrix size does not match system size")
        self.dynmatrix = self.dynmatrix.reshape((beads.q.size, beads.q.size))
        self.atol = self.chop

        # Creates duplicate classes to simplify computation of forces.
        self.dof = 3 * self.beads.natoms
        self.dbeads = self.beads.copy(nbeads=self.nparallel)
        self.dcell = self.cell.copy()
        self.dforces = self.forces.copy(self.dbeads, self.dcell)

        # Sets temperature.
        self.temp = self.ensemble.temp
        self.m = dstrip(self.beads.m).copy()

        # Initializes mass related arrays.
        self.m3 = dstrip(self.beads.m3[-1])
        self.im3 = np.divide(1.0, self.m3)
        self.sqm3 = np.sqrt(self.m3)
        self.isqm3 = np.sqrt(self.im3)

        # Initializes mass related diagonal matrices.
        self.M = np.diag(self.m3)
        self.iM = np.diag(self.im3)
        self.sqM = np.diag(self.sqm3)
        self.isqM = np.diag(self.isqm3)

        # Initializes variables specific to sc phonons.
        self.isc = 0
        self.imc = 0
        self.phononator = SCPhononator()
        self.phononator.bind(self)

        # a random shuffle to allow some randomness in the sobol-like PRNGs
        self.prng = prng
        self.random_shuffle = np.asarray(list(range(self.dof)))

        # defines function to perform a Gaussian transformation.
        self.fginv = np.vectorize(gaussian_inv)

        # TODO implement an option to give the file name to fetch the random samples. Also implement check of dimensionality, and raise an error if it runs out of random numbers
        # reads sobol points from file!
        if self.random_type == "file":
            self.random_sequence = np.loadtxt("SOBOL-RNG")
        elif self.random_type == "pseudo":
            self.random_sequence = self.prng.rng.rand(
                self.max_steps * self.max_iter, self.dof)
        elif self.random_type == "sobol":
            self.random_sequence = np.asarray([
                sobol(self.dof, i)
                for i in range(0, self.max_steps * self.max_iter + 1)
            ])

        # Shuffles the
        self.prng.rng.shuffle(self.random_shuffle)