def test_std_diffusion():
    '''
    Test Spatio-Temporal Point Process Generator equipped with 
    standard diffusion kernel
    '''
    # parameters initialization
    mu     = .1
    kernel = StdDiffusionKernel(C=1., beta=1., sigma_x=.1, sigma_y=.1)
    lam    = HawkesLam(mu, kernel, maximum=1e+3)
    pp     = SpatialTemporalPointProcess(lam)

    # generate points
    points, sizes = pp.generate(
        T=[0., 10.], S=[[-1., 1.], [-1., 1.]], 
        batch_size=100, verbose=True)
    print(points)
    print(sizes)

    # read or save to local npy file.
    # points = np.load('results/tf_thining_samples.npy')
    np.save('results/hpp_Feb_25.npy', points)

    # plot intensity of the process over the time
    plot_spatial_intensity(lam, points[0], S=[[0., 10.], [-1., 1.], [-1., 1.]],
        t_slots=1000, grid_size=50, interval=50)
 def sampling(self, sess, batch_size):
     """fetch model parameters, and generate samples accordingly."""
     # get current model parameters
     mu, beta = sess.run([self.mu, self.beta])
     Wss = sess.run(self.Wss)
     bss = sess.run(self.bss)
     Wphis = sess.run(self.Wphis)
     # construct kernel function and conditional intensity lambda
     kernel = GaussianMixtureDiffusionKernel(self.n_comp,
                                             layers=self.layers[1:-1],
                                             beta=beta,
                                             C=self.C,
                                             SIGMA_SHIFT=self.SIGMA_SHIFT,
                                             SIGMA_SCALE=self.SIGMA_SCALE,
                                             MU_SCALE=self.MU_SCALE,
                                             Wss=Wss,
                                             bss=bss,
                                             Wphis=Wphis)
     lam = HawkesLam(mu, kernel, maximum=self.maximum)
     # sampling points given model parameters
     pp = SpatialTemporalPointProcess(lam)
     seqs, sizes = pp.generate(T=self.T,
                               S=self.S,
                               batch_size=batch_size,
                               verbose=self.verbose)
     return seqs
def test_random_gaussian_mixture_diffusion():
    '''
    Test Spatio-Temporal Point Process Generator equipped with 
    random Gaussian mixture diffusion kernel
    '''
    mu     = .2
    kernel = GaussianMixtureDiffusionKernel(
        n_comp=5, layers=[5, 5], C=1., beta=1., 
        SIGMA_SHIFT=.2, SIGMA_SCALE=.05, MU_SCALE=.05)
    lam    = HawkesLam(mu, kernel, maximum=1e+3)
    pp     = SpatialTemporalPointProcess(lam)

    # generate points
    points, sizes = pp.generate(
        T=[0., 10.], S=[[-1., 1.], [-1., 1.]], 
        batch_size=2, verbose=True)
    print(points.shape)
    print(sizes)

    # read or save to local npy file.
    # points = np.load('results/free_hpp_Mar_15_layer_5.npy')
    # np.save('results/gaussian_hpp_Mar_15_layer_5.npy', points)

    # plot intensity of the process over the time
    plot_spatial_intensity(lam, points[0], S=[[0., 10.], [-1., 1.], [-1., 1.]],
        t_slots=1000, grid_size=50, interval=50)
def test_gaussian_diffusion():
    '''
    Test Spatio-Temporal Point Process Generator equipped with 
    Gaussian diffusion kernel
    '''
    mu     = .1
    kernel = GaussianDiffusionKernel(
        layers=[5, 5], C=1., beta=1., 
        SIGMA_SHIFT=.2, SIGMA_SCALE=.05, MU_SCALE=.1, is_centered=True)
    lam    = HawkesLam(mu, kernel, maximum=1e+3)
    pp     = SpatialTemporalPointProcess(lam)
    print(kernel.Ws)
    print(kernel.bs)

    # plot kernel parameters over the spatial region.
    plot_spatial_kernel("results/kernel.pdf", kernel, S=[[-1., 1.], [-1., 1.]], grid_size=50)

    # generate points
    points, sizes = pp.generate(
        T=[0., 10.], S=[[-1., 1.], [-1., 1.]], 
        batch_size=2, verbose=True)
    print(points)
    print(sizes)

    # read or save to local npy file.
    # points = np.load('results/free_hpp_Mar_15_layer_5.npy')
    # np.save('results/gaussian_hpp_Mar_15_layer_5.npy', points)

    # plot intensity of the process over the time
    plot_spatial_intensity(lam, points[0], S=[[0., 10.], [-1., 1.], [-1., 1.]],
        t_slots=1000, grid_size=50, interval=50)
Пример #5
0
 def _sampling(self, sess, T, S, batch_size):
     """
     """
     # get current model parameters
     mu, beta, sigma_x, sigma_y = sess.run([self.mu, self.beta, self.sigma_x, self.sigma_y])
     print("[%s] mu=%.2f, beta=%.2f, sigma_x=%.2f, sigma_y=%.2f." % (arrow.now(), mu, beta, sigma_x, sigma_y), file=sys.stderr)
     # sampling points given model parameters
     kernel        = DiffusionKernel(beta=beta, sigma_x=sigma_x, sigma_y=sigma_y)
     lam           = HawkesLam(mu, kernel, maximum=self.maximum)
     pp            = SpatialTemporalPointProcess(lam)
     points, sizes = pp.generate(T=T, S=S, batch_size=batch_size)
     return points, sizes
def test_pretrain_gaussian_mixture_diffusion():
    '''
    Test Spatio-Temporal Point Process Generator equipped with 
    pretrained Gaussian mixture diffusion kernel
    '''
    params = np.load('data/mle_gaussian_mixture_params.npz')
    mu     = params['mu']
    beta   = params['beta']
    kernel = GaussianMixtureDiffusionKernel(
        n_comp=5, layers=[5], C=1., beta=beta, 
        SIGMA_SHIFT=.05, SIGMA_SCALE=.2, MU_SCALE=.01,
        Wss=params['Wss'], bss=params['bss'], Wphis=params['Wphis'])
    lam    = HawkesLam(mu, kernel, maximum=1e+3)
    pp     = SpatialTemporalPointProcess(lam)

    # # generate points
    # points, sizes = pp.generate(
    #     T=[0., 10.], S=[[-1., 1.], [-1., 1.]], 
    #     batch_size=2, verbose=True)
    # print(points.shape)
    # print(sizes)

    # read or save to local npy file.
    points = np.load('data/apd.robbery.permonth.npy')
    da     = DataAdapter(init_data=points)
    points = da.normalize(points)
    # np.save('results/gaussian_hpp_Mar_15_layer_5.npy', points)

    # plot intensity of the process over the time
    plot_spatial_intensity(lam, points[0], S=[[0., 10.], [-1., 1.], [-1., 1.]],
        t_slots=1000, grid_size=50, interval=50)
Пример #7
0
def exp_real_with_2_comp():
    # REAL
    data = np.load(
        '../Spatio-Temporal-Point-Process-Simulator/data/rescale.ambulance.perday.npy'
    )
    data = data[:, 1:, :3]
    params = np.load(
        '../Spatio-Temporal-Point-Process-Simulator/data/rescale_ambulance_mle_gaussian_mixture_params.npz'
    )
    da = utils.DataAdapter(init_data=data)
    mu = .1  # params['mu']
    beta = params['beta']
    kernel = GaussianMixtureDiffusionKernel(n_comp=1,
                                            layers=[5],
                                            C=1.,
                                            beta=beta,
                                            SIGMA_SHIFT=.1,
                                            SIGMA_SCALE=.5,
                                            MU_SCALE=.01,
                                            Wss=params['Wss'],
                                            bss=params['bss'],
                                            Wphis=params['Wphis'])
    lam = HawkesLam(mu, kernel, maximum=1e+3)
    print("mu", mu)
    print("beta", beta)
    print(params['Wphis'].shape)
    pp = SpatialTemporalPointProcess(lam)
    # generate points
    points, sizes = pp.generate(T=[0., 10.],
                                S=[[-1., 1.], [-1., 1.]],
                                batch_size=100,
                                verbose=True)
    results = da.restore(points)
    print(results)
    print(sizes)
    np.save('results/ambulance-simulation.npy', results)