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_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)
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_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 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)
Beispiel #6
0
def exp_simulation():
    data = np.load(
        '../Spatio-Temporal-Point-Process-Simulator/results/spatial-variant-gaussian-b.npy'
    )
    params = np.load(
        '../Spatio-Temporal-Point-Process-Simulator/data/simulation-1-gcomp-b.npz'
    )
    mu = params['mu']
    beta = params['beta']
    kernel = GaussianMixtureDiffusionKernel(n_comp=1,
                                            layers=[10],
                                            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)
    # plot kernel parameters over the spatial region.
    utils.plot_spatial_kernel("results/learned-kernel-svgau-b.pdf",
                              kernel.gdks[0],
                              S=[[-1., 1.], [-1., 1.]],
                              grid_size=50)
Beispiel #7
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
Beispiel #8
0
def exp_real_with_1_comp():
    # REAL
    data = np.load('data/real/SCEDC-1999-2019-24hrs.npy')
    data = data[:, 1:, :3]
    params = np.load('results/real-24hrs-1-gcomp.npz')
    da = utils.DataAdapter(init_data=data)
    mu = params['mu']
    beta = params['beta']
    kernel = GaussianMixtureDiffusionKernel(n_comp=1,
                                            layers=[10],
                                            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)
    utils.plot_spatial_kernel(
        "results/learned-kernel-SCEDC-1999-2019-24hrs.pdf",
        kernel.gdks[0],
        S=[[-1., 1.], [-1., 1.]],
        grid_size=50)
    utils.spatial_intensity_on_map(
        "results/map-SCEDC-1999-2019-24hrs.html",
        da,
        lam,
        data,
        seq_ind=3000,
        t=8.0,
        # xlim=[-23.226, -22.621],
        # ylim=[-43.868, -43.050],
        # ngrid=200)
        xlim=da.xlim,
        ylim=da.ylim,
        ngrid=200)
Beispiel #9
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)
Beispiel #10
0
    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'])
    # kernel = GaussianMixtureDiffusionKernel(
    # 	n_comp=20, layers=[5], C=1., beta=.8,
    # 	SIGMA_SHIFT=.05, SIGMA_SCALE=.3, MU_SCALE=.03)
    # kernel = StdDiffusionKernel(C=1., beta=.15, sigma_x=.15, sigma_y=.15)
    lam = HawkesLam(mu, kernel, maximum=1e+3)

    # print(da.normalize(data)[0])
    print("mu", mu)
    print("beta", beta)

    # utils.spatial_intensity_on_map(
    # 	"results/ambulance_intensity_map-2.81.html", da, lam, data, seq_ind=0, t=2.81,
    # 	# # crime range
    # 	# xlim=[33.70, 33.87],
    # 	# ylim=[-84.50, -84.30],
    # 	# # earthquake range
    # 	# xlim=[25.692, 49.687],
    # 	# ylim=[-129.851, -111.094],
    # 	# ambulance range
    # 	xlim=[-23.226, -22.621],