-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSynthetic_data_gen.py
More file actions
135 lines (89 loc) · 3.81 KB
/
Synthetic_data_gen.py
File metadata and controls
135 lines (89 loc) · 3.81 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import openpyxl
import array
import matplotlib.pylab as plt
import math
import random
import statistics
path = "Khanapur_Flows.xlsx"
column_name = "Discharge"
wb = openpyxl.load_workbook(path)
sheet = wb.active
discharge = array.array("f",[])
for j in range(1, sheet.max_column + 1):
if (sheet.cell(row=1, column=j).value == column_name):
for k in range(2, sheet.max_row + 1):
discharge.append(sheet.cell(k, j).value)
print(len(discharge))
########################################################################################################
def monthly_mean(discharge):
sum = [0]*12
for i in range(12):
count = 0
for j in range(i,len(discharge),12):
sum[i] += discharge[j]
count += 1
sum[i] = sum[i] / count
#print(sum[i])
return sum
#print(monthly_mean(discharge))
########################################################################################################
def standard_deviation(discharge, month_mean):
deviation = [0]*12
for i in range(12):
count = 0
for j in range(i, len(discharge), 12):
deviation[i] += (discharge[j] - month_mean[i])*(discharge[j] - month_mean[i])
count += 1
deviation[i] = math.sqrt(deviation[i] / count)
return deviation
#print(standard_deviation(discharge, monthly_mean(discharge)))
########################################################################################################
def correlation_coefficient(discharge, month_mean, monthly_deviation):
correlation = [0]*12
count = 0
for i in range(0, len(discharge), 12):
correlation[0] += ((discharge[i] - month_mean[0]) * (discharge[i + 11] - month_mean[11]))
count += 1
correlation[0] = correlation[0] / count
correlation[0] = correlation[0] / (monthly_deviation[0] * monthly_deviation[11])
for i in range(0, 11):
count = 0
for j in range(i , len(discharge), 12):
correlation[i+1] +=((discharge[j] - month_mean[i]) * (discharge[j +1] - month_mean[i+1]))
#correlation[i + 1] += ((discharge[j] - month_mean[i])*(discharge[j+1] - month_mean[i+1]))/((monthly_deviation[i])*(monthly_deviation[i+1]))
count += 1
correlation[i+1] = correlation[i+1]/ count
correlation[i+1] = correlation[i+1]/ (monthly_deviation[i]*monthly_deviation[i+1])
return correlation
#print(correlation_coefficient(discharge,monthly_mean(discharge),standard_deviation(discharge,monthly_mean(discharge))))
###############################################################################################
def regression_coefficient(correlation, deviation):
b = [0] * 12
b[0] = correlation[0] * deviation[0]/deviation[11]
for i in range(11):
b[i+1] += correlation[i+1]* deviation[i+1]/deviation[i]
return b
###################################################################################################
p = correlation_coefficient(discharge,monthly_mean(discharge),standard_deviation(discharge,monthly_mean(discharge)))
q = standard_deviation(discharge,monthly_mean(discharge))
r = monthly_mean(discharge)
s = regression_coefficient(p,q)
#print(regression_coefficient(p,q))
#print(random.normalvariate(0,1))
def synthetic_data(r,s,q,p, discharge, n):
previous_data = discharge[len(discharge) - 12: len(discharge)]
#print(previous_data)
data = [0]*n
for i in range(n):
x = i % 12
data[i] = r[x]+ s[x]*(previous_data[x-1]- r[x-1])+ random.normalvariate(0,1)*q[x]* math.sqrt(1- p[x]*p[x])
previous_data[x] = data[i]
return data
n = int(input("Enter no. of data points: "))
print(synthetic_data(r,s,q,p, discharge, n))
w = synthetic_data(r,s,q,p, discharge, n)
k = statistics.mean(w)
l = statistics.stdev(w,k)
print(f"""
Mean: {k}
Standard Deviation: {l}""")