-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawThePlotAndEstimattion.py
48 lines (38 loc) · 1.25 KB
/
drawThePlotAndEstimattion.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
43
44
45
46
47
48
import math
import pickle
import numpy as np
from matplotlib import pyplot as plt
class pubMed:
def __init__(self):
self.rawData = []
def loadDocument(self, filename):
with open(filename, 'rb') as f:
self.rawData = pickle.load(f)[0:20000]
def DrawHeapLaw(self):
if len(self.rawData) < 2: # Need at least two points to fit
return None, None, None, None
x, y = [], []
for xAndy in self.rawData:
x.append(math.log10(xAndy[0]))
y.append(math.log10(xAndy[1]))
beta, logk = np.polyfit(x, y, 1)
return x, y, beta, logk
estimation = pubMed()
file = 'dataGenaration/result/heapLawData-selectedPromt.pkl'
estimation.loadDocument(file)
x, y, beta, logk = estimation.DrawHeapLaw()
print(beta)
print(logk)
# Check if data is sufficient for plotting
if x is not None and y is not None:
# Plotting the result
plt.figure(figsize=(10, 5))
plt.scatter(x, y, label='Data Points')
plt.plot([min(x), max(x)], [beta * min(x) + logk, beta * max(x) + logk], color='red', label='Fitted Line')
plt.xlabel('log10(X)')
plt.ylabel('log10(Y)')
plt.title('Heap\'s Law')
plt.legend()
plt.show()
else:
print("Insufficient data for plotting.")