Skip to content

Commit c84f95f

Browse files
committed
Not quite correct
1 parent 91522f2 commit c84f95f

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

scripts/regress.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
import sys
1313
from pathlib import Path
1414

15+
####
16+
# TODO:
17+
# [ ] - If the credential is two, I think we need to set it to zero. We probably want to remove
18+
# two with saturation (never going negative).
19+
#
20+
# [ ] - The port size should also be reduced by 1 with saturation (never going negative).
21+
#
22+
####
23+
1524

1625
if(len(sys.argv) == 1):
1726
print("Please provide a filename")
@@ -81,6 +90,82 @@ def explain_r2(r2):
8190

8291

8392

93+
for predicted_attribute,name in [("best_instr", "instructions"), ("best_cycles", "cycles")]:
94+
print("=====================================")
95+
print("predicting ", predicted_attribute, " (", name, ")", " without credentials" )
96+
regressor = LinearRegression(fit_intercept=False, positive=True)
97+
for protocol in range(8):
98+
print()
99+
thisframe = data[data["protocol"]==protocol]
100+
if thisframe.empty:
101+
continue
102+
thisframe = thisframe[thisframe["credential"]<=2]
103+
if thisframe.empty:
104+
continue
105+
print("protocol = ", protocol, " ", protocols[protocol])
106+
print("number of entries: ", len(thisframe.index))
107+
x = thisframe[predictors]
108+
y = thisframe[[predicted_attribute]]
109+
regressor.fit(x, y)
110+
r2 = regressor.score(x,y)
111+
print("R2 = ", r2, " (", explain_r2(r2), ")")
112+
print("Coefficients = ", regressor.coef_)
113+
for i in zip(predictors, regressor.coef_[0]):
114+
if i[1] > 0.000001:
115+
print("weight for ", i[0], " = ", i[1])
116+
print("Intercept = ", regressor.intercept_)
117+
118+
with PdfPages(dirname+protocols[protocol]+'_predicted_'+name+'_nocredentials.pdf') as pdf:
119+
fig,ax = plt.subplots()
120+
ax.plot(thisframe['input_size'], thisframe[predicted_attribute], label="measured", linestyle='none', marker='.', markerfacecolor='blue', markersize=4)
121+
ax.plot(thisframe['input_size'], regressor.predict(x), label="predicted", linestyle='none', marker='x', markerfacecolor='red', markersize=4)
122+
123+
ax.set_xlabel("URL size (bytes)")
124+
ax.set_ylabel(name)
125+
ax.spines[['right', 'top']].set_visible(False)
126+
ax.legend(loc='best', frameon=False)
127+
pdf.savefig(fig)
128+
129+
130+
131+
132+
for predicted_attribute,name in [("best_instr", "instructions"), ("best_cycles", "cycles")]:
133+
print("=====================================")
134+
print("predicting ", predicted_attribute, " (", name, ")", " with credentials" )
135+
regressor = LinearRegression(fit_intercept=False, positive=True)
136+
for protocol in range(8):
137+
print()
138+
thisframe = data[data["protocol"]==protocol]
139+
if thisframe.empty:
140+
continue
141+
thisframe = thisframe[thisframe["credential"]>2]
142+
if thisframe.empty:
143+
continue
144+
print("protocol = ", protocol, " ", protocols[protocol])
145+
print("number of entries: ", len(thisframe.index))
146+
x = thisframe[predictors]
147+
y = thisframe[[predicted_attribute]]
148+
regressor.fit(x, y)
149+
r2 = regressor.score(x,y)
150+
print("R2 = ", r2, " (", explain_r2(r2), ")")
151+
print("Coefficients = ", regressor.coef_)
152+
for i in zip(predictors, regressor.coef_[0]):
153+
if i[1] > 0.000001:
154+
print("weight for ", i[0], " = ", i[1])
155+
print("Intercept = ", regressor.intercept_)
156+
157+
with PdfPages(dirname+protocols[protocol]+'_predicted_'+name+'_withcredentials.pdf') as pdf:
158+
fig,ax = plt.subplots()
159+
ax.plot(thisframe['input_size'], thisframe[predicted_attribute], label="measured", linestyle='none', marker='.', markerfacecolor='blue', markersize=4)
160+
ax.plot(thisframe['input_size'], regressor.predict(x), label="predicted", linestyle='none', marker='x', markerfacecolor='red', markersize=4)
161+
162+
ax.set_xlabel("URL size (bytes)")
163+
ax.set_ylabel(name)
164+
ax.spines[['right', 'top']].set_visible(False)
165+
ax.legend(loc='best', frameon=False)
166+
pdf.savefig(fig)
167+
168+
84169
if plots:
85170
print ("Plotting...")
86171
data["best_instructions_per_cycle"] = data["best_instr"]/data["best_cycles"]

0 commit comments

Comments
 (0)