我有一个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
1条答案
按热度按时间djmepvbi1#
有几点:
set.seed
使运行可重现beta <-
行等效于beta <- params
nloglik_bi_hawkes
函数实际上并不需要,因为你可以直接把likelihoodHawkes
传递给optim
。它的固定参数可以传递给optim
,它会转发它们。method = "BFGS"
。因此我们有
给出: