python求残差_在python中如何计算点过程的残差

好的,你首先要做的就是绘制数据。为了简单起见,我复制了this figure,因为它只有8个事件发生,所以很容易看到系统的行为。以下代码:import numpy as np

import math, matplotlib

import matplotlib.pyplot

import matplotlib.lines

mu = 0.1 # Parameter values as found in the article http://jheusser.github.io/2013/09/08/hawkes.html Hawkes Process section.

alpha = 1.0

beta = 0.5

EventTimes = np.array([0.7, 1.2, 2.0, 3.8, 7.1, 8.2, 8.9, 9.0])

" Compute conditional intensities for all times using the Hawkes process. "

timesOfInterest = np.linspace(0.0, 10.0, 100) # Times where the intensity will be sampled.

conditionalIntensities = [] # Conditional intensity for every epoch of interest.

for t in timesOfInterest:

conditionalIntensities.append( mu + np.array( [alpha*math.exp(-beta*(t-ti)) if t > ti else 0.0 for ti in EventTimes] ).sum() ) # Find the contributions of all preceding events to the overall chance of another one occurring. All events that occur after t have no contribution.

" Plot the conditional intensity time history. "

fig = matplotlib.pyplot.figure()

ax = fig.gca()

labelsFontSize = 16

ticksFontSize = 14

fig.suptitle(r"$Conditional\ intensity\ VS\ time$", fontsize=20)

ax.grid(True)

ax.set_xlabel(r'$Time$',fontsize=labelsFontSize)

ax.set_ylabel(r'$\lambda$',fontsize=labelsFontSize)

matplotlib

你可能感兴趣的:(python求残差)