-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCMTest.py
42 lines (32 loc) · 1.11 KB
/
MCMTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
#
# MCMTest.py is a program for testing the Markov-chain Mixture Distribution
# (MCM) model for forecasting a time-series. It utilizes MCM.py as main model
# file and as a test data set TestData.m as input for forecasting.
#
# Import the MCM file
import numpy as np
import matplotlib.pyplot as plt
from MCM import MCMFit, MCMForecast, MCMRnd
# Load the files
testFilename = "TestData.txt"
data = np.loadtxt(testFilename).transpose()
# Set the number of bins
n = 50
# Number of sampled points from predictive distribution
num = 2000
# Number of steps ahead forecast
steps = 1
# Observed point, from which to forecast
obsPoint = 0.5
# Obtain the NxN transition matrix P from the data
# and Num number of steps ahead
p = MCMFit(data, n, steps)
# Obtain X and Y for the piecewise uniform distribution
binStarts, transProbs = MCMForecast(p, data.min(), data.max(), obsPoint)
# Generate Num random numbers of samples from the forecasted distribution
fcstSamples = MCMRnd(binStarts, transProbs, num)
plt.hist(fcstSamples, 30)
plt.plot(binStarts, num*transProbs)
plt.axis([0.3, 0.8, 0, 800])
plt.show()