Пример #1
0
    def save(self, group):
        """
        Save the state of the node into a HDF5 file.

        group can be the root
        """
        ## if name is None:
        ##     name = self.name
        ## subgroup = group.create_group(name)

        for i in range(len(self.u)):
            utils.write_to_hdf5(group, self.u[i], "u%d" % i)
        utils.write_to_hdf5(group, self.observed, "observed")
Пример #2
0
    def save(self, group):
        """
        Save the state of the node into a HDF5 file.

        group can be the root
        """
        ## if name is None:
        ##     name = self.name
        ## subgroup = group.create_group(name)

        for i in range(len(self.u)):
            utils.write_to_hdf5(group, self.u[i], 'u%d' % i)
        utils.write_to_hdf5(group, self.observed, 'observed')
Пример #3
0
    def save(self, group):
        """
        Save the state of the node into a HDF5 file.

        group can be the root
        """
        ## if name is None:
        ##     name = self.name
        ## subgroup = group.create_group(name)

        for i in range(len(self.phi)):
            utils.write_to_hdf5(group, self.phi[i], 'phi%d' % i)
        utils.write_to_hdf5(group, self.f, 'f')
        utils.write_to_hdf5(group, self.g, 'g')
        super().save(group)
Пример #4
0
    def save(self, group):
        """
        Save the state of the node into a HDF5 file.

        group can be the root
        """
        ## if name is None:
        ##     name = self.name
        ## subgroup = group.create_group(name)
        
        for i in range(len(self.phi)):
            utils.write_to_hdf5(group, self.phi[i], 'phi%d' % i)
        utils.write_to_hdf5(group, self.f, 'f')
        utils.write_to_hdf5(group, self.g, 'g')
        super().save(group)
Пример #5
0
def simulate_data(filename=None, 
                  resolution=30,
                  M=50,
                  N=1000, 
                  diffusion=1e-6,
                  velocity=4e-3,
                  innovation_noise=1e-3,
                  innovation_lengthscale=0.6,
                  noise_ratio=1e-1,
                  decay=0.9997,
                  burnin=1000,
                  thin=20):

    # Simulate the process

    # Because simulate_process simulates a unit square over unit time step we
    # have to multiply parameters by the time length in order to get the effect
    # of a long time :)
    #
    # Thin-parameter affects the temporal resolution.
    diffusion *= (N + burnin/thin)
    velocity *= (N + burnin/thin)
    decay = decay ** (1/thin)
    innovation_noise *= np.sqrt(N)
    U = simulate_process(resolution,
                         resolution,
                         burnin+N*thin, 
                         diffusion=diffusion,
                         velocity=velocity,
                         noise=innovation_noise,
                         lengthscale=innovation_lengthscale,
                         decay=decay)

    # Put some stations randomly
    x1x2 = np.random.permutation(resolution*resolution)[:M]
    x1 = np.arange(resolution)[np.mod(x1x2, resolution)]
    x2 = np.arange(resolution)[(x1x2/resolution).astype(int)]
    #x1 = np.random.randint(0, resolution, M)
    #x2 = np.random.randint(0, resolution, M)

    # Get noisy observations
    U = U[burnin::thin]
    F = U[:, x1, x2].T
    std = np.std(F)
    Y = F + noise_ratio*std*np.random.randn(*np.shape(F))
    X = np.array([x1, x2]).T

    # Save data
    if filename is not None:
        f = h5py.File(filename, 'w')
        try:
            utils.write_to_hdf5(f, U, 'U')
            utils.write_to_hdf5(f, diffusion/T, 'diffusion')
            utils.write_to_hdf5(f, velocity/T, 'velocity')
            utils.write_to_hdf5(f, decay, 'decay')
            utils.write_to_hdf5(f, innovation_noise/np.sqrt(T), 'innovation_noise')
            utils.write_to_hdf5(f, noise_ratio, 'noise_ratio')
            utils.write_to_hdf5(f, Y, 'Y')
            utils.write_to_hdf5(f, F, 'F')
            utils.write_to_hdf5(f, X, 'X')
        finally:
            f.close()

    return (U, Y, F, X)