Skip to content

Commit

Permalink
Added more output to the scripts that generate results to SoftwareX
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolpantunes committed Jan 24, 2025
1 parent 0bddb64 commit 0e33113
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 42 deletions.
120 changes: 95 additions & 25 deletions examples/plot_journal_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import numpy as np
import matplotlib.pyplot as plt

from matplotlib import transforms
from matplotlib.patches import Rectangle
from matplotlib.patches import Ellipse

Expand All @@ -27,24 +28,80 @@
plt.rcParams['lines.linewidth'] = 2


def confidence_ellipse(x, y, ax, n_std=3.0, facecolor='none', **kwargs):
"""
Create a plot of the covariance confidence ellipse of *x* and *y*.
Parameters
----------
x, y : array-like, shape (n, )
Input data.
ax : matplotlib.axes.Axes
The axes object to draw the ellipse into.
n_std : float
The number of standard deviations to determine the ellipse's radiuses.
**kwargs
Forwarded to `~matplotlib.patches.Ellipse`
Returns
-------
matplotlib.patches.Ellipse
"""
if x.size != y.size:
raise ValueError("x and y must be the same size")

cov = np.cov(x, y)
pearson = cov[0, 1]/np.sqrt(cov[0, 0] * cov[1, 1])
## Using a special case to obtain the eigenvalues of this
## two-dimensional dataset.
ell_radius_x = np.sqrt(1 + pearson)
ell_radius_y = np.sqrt(1 - pearson)
ellipse = Ellipse((0, 0), width=ell_radius_x * 2, height=ell_radius_y * 2,
facecolor=facecolor, **kwargs)

## Calculating the standard deviation of x from
## the squareroot of the variance and multiplying
## with the given number of standard deviations.
scale_x = np.sqrt(cov[0, 0]) * n_std
mean_x = np.mean(x)

## calculating the standard deviation of y ...
scale_y = np.sqrt(cov[1, 1]) * n_std
mean_y = np.mean(y)

transf = transforms.Affine2D() \
.rotate_deg(45) \
.scale(scale_x, scale_y) \
.translate(mean_x, mean_y)

ellipse.set_transform(transf + ax.transData)
return ax.add_patch(ellipse)


def main():
# Color Blind adjusted colors and markers
colormap=['#377eb8', '#ff7f00', '#4daf4a', '#f781bf',
'#a65628', '#984ea3','#999999', '#e41a1c', '#dede00']
markers=['o', '*', '.', 'x', '+', 's', 'd', 'h', 'v']
lines=['-', ':', '--', '-.']

x1 = [0, 0.5, 3, 4, 4.25, 5]
y1 = [5, 1, 4, 4.25, 2, 0.5]
points = np.genfromtxt(f'traces/web0_reduced.csv', delimiter=',')

worst_knee = 20
x1 = points[worst_knee-5:worst_knee+3,0]
y1 = points[worst_knee-5:worst_knee+3,1]

# Plot 1
fg, ax = plt.subplots()
ax.plot(x1, y1, color=colormap[0], marker=markers[0], markersize=3)

ax.axhline(y = 1, color=colormap[1], linestyle=lines[2])
ax.axhline(y = 2, color=colormap[2], linestyle=lines[2])
ax.annotate('K0', (0.70, 1.1), color=colormap[1])
ax.annotate('K1', (4.30, 2.1), color=colormap[2])
ax.axhline(y = 0.5909, color=colormap[1], linestyle=lines[2])
ax.axhline(y = 0.6127, color=colormap[2], linestyle=lines[2])
ax.annotate('K0', (2.474E4, 0.5922), color=colormap[1])
ax.annotate('K1', (2.893E4, 0.6140), color=colormap[2])

ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
Expand All @@ -54,21 +111,30 @@ def main():
plt.savefig('out/knee_post_processing_00.pdf', bbox_inches='tight', transparent=True)
plt.show()

x2 = [0,2,2.1,2.2,3,5]
y2 = [5,4.5,4,1.5,.25,0]
corner_knee = 45
x2 = points[corner_knee-3:corner_knee+3,0]
y2 = points[corner_knee-3:corner_knee+3,1]
cop = (8.922E4, 0.4048)
prp = (7.32E4, 0.4057)
nep = (9.016E4, 0.3955)
arp = (prp[0], nep[1])
w1 = cop[0] - arp[0]
h1 = cop[1] - arp[1]
w2 = nep[0] - arp[0]
h2 = prp[1] - arp[1]

# Plot 2
fg, ax = plt.subplots()
ax.plot(x2, y2, color=colormap[0], marker=markers[0], markersize=3)
ax.add_patch(Rectangle((0, 4), 2, .5, fill=False, hatch='/', color=colormap[1], linewidth=2))
ax.add_patch(Rectangle((0, 4), 2.1, 1, fill=False, hatch='\\', color=colormap[2], linewidth=2))

ax.plot(0, 5, 'o', ms=7, color=colormap[2])
ax.annotate('P0', (0.1, 5.1), color=colormap[2])
ax.plot(2, 4.5, 'X', ms=7, color=colormap[1])
ax.annotate('C', (2.2, 4.6), color=colormap[1])
ax.plot(2.1, 4, 'o', ms=7, color=colormap[2])
ax.annotate('P1', (2.2, 4.1), color=colormap[2])
ax.add_patch(Rectangle(arp, w1, h1, fill=False, hatch='/', color=colormap[1], linewidth=2))
ax.add_patch(Rectangle(arp, w2, h2, fill=False, hatch='\\', color=colormap[2], linewidth=2))
ax.plot(prp[0], prp[1], 'o', ms=7, color=colormap[2])
ax.annotate('P0', (prp[0], prp[1]+0.0007), color=colormap[2])
ax.plot(cop[0], cop[1], 'X', ms=7, color=colormap[1])
ax.annotate('C', (cop[0]+2000, cop[1]), color=colormap[1])
ax.plot(nep[0], nep[1], 'o', ms=7, color=colormap[2])
ax.annotate('P1', (cop[0]+2000, nep[1]), color=colormap[2])

ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
Expand All @@ -79,18 +145,22 @@ def main():
plt.show()

# Plot 3
fg, ax = plt.subplots()
ax.plot(x2, y2, color=colormap[0], marker=markers[0], markersize=3)
cluster_knee = 37
x3 = points[cluster_knee:cluster_knee+6,0]
y3 = points[cluster_knee:cluster_knee+6,1]

ax.add_patch(Ellipse((2.2, 1.5), 4, 1.5, color=colormap[6], angle=-75, alpha=0.3))
fg, ax = plt.subplots()
ax.plot(x3, y3, color=colormap[0], marker=markers[0], markersize=3)

ax.plot(2.1, 3, 'x', mew=5, ms=10, color=colormap[1])
ax.plot(2.15, 2.25, 'x', mew=5, ms=10, color=colormap[1])
ecx = np.array([5.374e+04, 5.384e+04, 5.55e+04])
ecy = np.array([4.270992757584038957e-01, 4.263545367586771828e-01, 4.220090871822902434e-01])

ax.plot(2.2, 1.5, 'x', mew=5, ms=10, color=colormap[2])
confidence_ellipse(ecx, ecy, ax, n_std=2.5,
**{'color':colormap[6], 'angle':0, 'alpha':0.3})

ax.plot(2.5, 1.0315, 'x', mew=5, ms=10, color=colormap[1])
ax.plot(2.8, 0.5626, 'x', mew=5, ms=10, color=colormap[1])
ax.plot(5.374e+04,4.270992757584038957e-01, 'x', mew=5, ms=10, color=colormap[1])
ax.plot(5.384e+04,4.263545367586771828e-01, 'x', mew=5, ms=10, color=colormap[2])
ax.plot(5.55e+04,4.220090871822902434e-01, 'x', mew=5, ms=10, color=colormap[1])

ax.spines['left'].set_visible(True)
ax.spines['top'].set_visible(False)
Expand Down
1 change: 1 addition & 0 deletions examples/plot_journal_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
logging.getLogger('PIL').setLevel(logging.WARNING)
logger = logging.getLogger(__name__)


def main():
iris = datasets.load_iris()
X = iris.data
Expand Down
14 changes: 10 additions & 4 deletions examples/plot_journal_knees.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,20 @@ def main(args):
space_saving = round((1.0-(len(reduced)/len(points)))*100.0, 2)
logger.info('Number of data points after RDP: %s(%s %%)', len(reduced), space_saving)

# save points to CSV
# np.savetxt(f'traces/web0_reduced.csv', points_reduced, delimiter=",")

# Plot original trace and reduced version
x = points[:,0]
y = points[:,1]
plt.plot(x, y, color= colormap[0])
points_reduced = points[reduced]

# save points to CSV
np.savetxt(f'traces/web0_reduced.csv', points_reduced, delimiter=",")
plt.savefig('out/knees_trace_original.png', bbox_inches='tight', transparent=True)
plt.savefig('out/knees_trace_original.pdf', bbox_inches='tight', transparent=True)
plt.savefig('out/knees_trace_original.svg', bbox_inches='tight', transparent=True)
plt.show()

plt.plot(x, y, color= colormap[0])
points_reduced = points[reduced]
plt.plot(points_reduced[:, 0], points_reduced[:, 1], linestyle=lines[2], marker='o', markersize=3, color=colormap[1])
plt.savefig('out/knees_trace_reduced.png', bbox_inches='tight', transparent=True)
plt.savefig('out/knees_trace_reduced.pdf', bbox_inches='tight', transparent=True)
Expand Down Expand Up @@ -133,6 +138,7 @@ def main(args):
plt.plot(x[knees], y[knees], 'o', markersize=7, color=colormap[7])
plt.savefig('out/knees_final_plot.png', bbox_inches='tight', transparent=True)
plt.savefig('out/knees_final_plot.pdf', bbox_inches='tight', transparent=True)
plt.savefig('out/knees_final_plot.svg', bbox_inches='tight', transparent=True)
plt.show()


Expand Down
31 changes: 18 additions & 13 deletions examples/plot_journal_mrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
Copyright (c) 2021-2023 The Research Foundation of SUNY
'''


import tqdm
import logging
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt

from sklearn import datasets
from sklearn.cluster import KMeans

import kneeliverse.rdp as rdp
import kneeliverse.kneedle as kneedle
Expand Down Expand Up @@ -71,27 +70,33 @@ def main():
markers=['o', '*', '.', 'x', '+', 's', 'd', 'h', 'v']
lines=['-', ':', '--', '-.']

points = np.genfromtxt('traces/rsrch1-minisim1.csv', delimiter=',')
points = np.genfromtxt('traces/web0.csv', delimiter=',')

# Plot original trace and reduced version
x = points[:,0]/1000
y = points[:,1]

plt.plot(x, y, color= colormap[0])
plt.legend(['MRC (LRU)'])
plt.legend(['MRC (ARC)'])

plt.xlabel('Cache Size (GB)')
plt.ylabel('Miss Ratio')

# Points
pa = (36.4, 0.5417)
pb = (53.7, 0.4508)
pc = (90.2, 0.3956)
pd = (162.9, 0.3469)

# Arrows
plt.annotate('A', xy=(1.29E4/1000, 0.796), weight='bold', color=colormap[7],
xytext=(2.29E4/1000,.82), arrowprops=dict(arrowstyle='->', lw=1.5, color=colormap[6]))
plt.annotate('B', xy=(3.10E4/1000, 0.786), weight='bold', color=colormap[7],
xytext=(4.10E4/1000,.82), arrowprops=dict(arrowstyle='->', lw=1.5, color=colormap[6]))
plt.annotate('C', xy=(4.25E4/1000, 0.753), weight='bold', color=colormap[7],
xytext=(5.25E4/1000,.80), arrowprops=dict(arrowstyle='->', lw=1.5, color=colormap[6]))
plt.annotate('D', xy=(9.82E4/1000, 0.706), weight='bold', color=colormap[7],
xytext=(1.08E5/1000,.75), arrowprops=dict(arrowstyle='->', lw=1.5, color=colormap[6]))
plt.annotate('A', xy=pa, weight='bold', color=colormap[7],
xytext=(pa[0]+10, pa[1]+0.05), arrowprops=dict(arrowstyle='->', lw=1.5, color=colormap[6]))
plt.annotate('B', xy=pb, weight='bold', color=colormap[7],
xytext=(pb[0]+10, pb[1]+0.05), arrowprops=dict(arrowstyle='->', lw=1.5, color=colormap[6]))
plt.annotate('C', xy=pc, weight='bold', color=colormap[7],
xytext=(pc[0]+10, pc[1]+0.05), arrowprops=dict(arrowstyle='->', lw=1.5, color=colormap[6]))
plt.annotate('D', xy=pd, weight='bold', color=colormap[7],
xytext=(pd[0]+10, pd[1]+0.05), arrowprops=dict(arrowstyle='->', lw=1.5, color=colormap[6]))

# Bracket
#ax = plt.gca()
Expand Down

0 comments on commit 0e33113

Please sign in to comment.