R上Hawkes点过程的参数优化

bmvo0sr5  于 2022-12-20  发布在  其他
关注(0)|答案(1)|浏览(179)

我有一个1,000人的数据集,其中一些人彼此认识,另一些人不认识。我试图用霍克斯点过程来预测(或节点)将采取一种行为。问题是我试图优化参数。我假设谁知道谁的边列表是到Hawkes的alpha输入,λ对于所有节点都是一个恒定的背景值,它就是我要计算的衰减函数β。
我有一个例子,它运行,但不确定这是正确的方法来计算这个参数?

library(hawkes)

#Multivariate Hawkes process - with 10 nodes
lambda0<-c(rep(0.2,10)) # set to constant to assume background intensity is equal for all nodes
alpha<-matrix(c(0.05,0.05,0,0.05,0,0.05,0.05,0,0,0.05, # matrix of who knows who 0.05 indicating a link 0 no link
                0.05,0.05,0,0,0,0,0,0,0,0,
                0,0,0.05,0,0,0,0,0,0,0,
                0.05,0,0,0.05,0,0,0,0,0,0,
                0,0,0,0,0.05,0,0,0,0,0,
                0.05,0,0,0,0,0.05,0,0,0,0,
                0.05,0,0,0,0,0,0.05,0,0,0,
                0,0,0,0,0,0,0,0.05,0,0,
                0,0,0,0,0,0,0,0,0.05,0,
                0.05,0,0,0,0,0,0,0,0,0.05
                ),byrow=TRUE,nrow=10) 
beta<-c(rep(0.7,10)) # set the initial values of beta to be able to generate some random history of events
history<-simulateHawkes(lambda0,alpha,beta,3600) # within 1 hour random generation of events for the 10 nodes

nloglik_bi_hawkes <- function(params, history){
beta <- c(params[1], params[2],params[3], params[4],params[5], params[6],params[7], params[8],params[9], params[10]) # in my real data I may have 1,000 of nodes so may need to optimise beta for more than 10.
return(likelihoodHawkes(lambda0, alpha, beta, history))
}


params_hawkes <- optim(c(rep(1,10)), nloglik_bi_hawkes, history = history) # to store the values of beta
djmepvbi

djmepvbi1#

有几点:

  • 当使用随机数时,使用set.seed使运行可重现
  • 问题中的beta <-行等效于beta <- params
  • nloglik_bi_hawkes函数实际上并不需要,因为你可以直接把likelihoodHawkes传递给optim。它的固定参数可以传递给optim,它会转发它们。
  • 当我尝试问题中的代码时,它在500次函数求值后停止,没有收敛。请改用method = "BFGS"

因此我们有

library(hawkes)
set.seed(123)

lambda0 <- rep(0.2,10)
alpha<-matrix(c(0.05,0.05,0,0.05,0,0.05,0.05,0,0,0.05, 
                0.05,0.05,0,0,0,0,0,0,0,0,
                0,0,0.05,0,0,0,0,0,0,0,
                0.05,0,0,0.05,0,0,0,0,0,0,
                0,0,0,0,0.05,0,0,0,0,0,
                0.05,0,0,0,0,0.05,0,0,0,0,
                0.05,0,0,0,0,0,0.05,0,0,0,
                0,0,0,0,0,0,0,0.05,0,0,
                0,0,0,0,0,0,0,0,0.05,0,
                0.05,0,0,0,0,0,0,0,0,0.05
                ),byrow=TRUE,nrow=10) 
beta <- rep(0.7,10)
history <- simulateHawkes(lambda0, alpha, beta, 3600)

fm <- optim(rep(1, 10), likelihoodHawkes, method = "BFGS",
  lambda0 = lambda0, alpha = alpha, history = history)
fm

给出:

$par
 [1] 0.2656976 0.1371221 0.6215783 0.1425127 0.4481591 0.1409979 0.1428707
 [8] 0.7836967 0.6930492 0.1490555

$value
[1] 15793.9

$counts
function gradient 
     105       26 

$convergence
[1] 0

$message
NULL

相关问题