Skip to content

Commit

Permalink
added "ck filter_2d math.frontier"
Browse files Browse the repository at this point in the history
  • Loading branch information
gfursin committed Jul 10, 2021
1 parent 2fe75ef commit 68e229e
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* v2.5.6.1
* added 'ck_html_end_note' key to customize CK result dashboard
* fixed Pareto frontier filter
* added "ck filter_2d math.frontier"

* v2.5.6
* added --j flag to "ck install package" to update CK_HOST_CPU_NUMBER_OF_PROCESSORS env
Expand Down
6 changes: 6 additions & 0 deletions ck/repo/module/math.frontier/.cm/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
"actions": {
"filter": {
"desc": "filter experiments with multiple characteristics (performance, energy, accuracy, size, etc) to leave only points on a (Pareto) frontier"
},
"filter_2d": {
"desc": "Leave points on 2D frontier"
}
},
"actions_redirect": {
"filter": "xfilter"
},
"copyright": "See CK COPYRIGHT.txt for copyright details",
"desc": "detecting (Pareto) frontier for multi-objective optimizations",
"developer": "Grigori Fursin",
Expand Down
18 changes: 18 additions & 0 deletions ck/repo/module/math.frontier/.cm/updates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"control": [
{
"author": "Grigori Fursin",
"author_email": "Grigori.Fursin@cTuning.org",
"author_webpage": "http://fursin.net",
"copyright": "See CK COPYRIGHT.txt for copyright details",
"engine": "CK",
"iso_datetime": "2021-07-10T11:16:14.957032",
"license": "See CK LICENSE.txt for licensing details",
"version": [
"2",
"5",
"6"
]
}
]
}
81 changes: 80 additions & 1 deletion ck/repo/module/math.frontier/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def init(i):
#
# HELP IS APPRECIATED!

def filter(i):
def xfilter(i):
"""
Input: {
points - dict with points, each has dict with optimization dimensions (should have the same names)
Expand Down Expand Up @@ -148,3 +148,82 @@ def filter(i):
ck.out('Number of points after filtering: '+str(lp))

return {'return':0, 'points':points, 'deleted_points':dpoints}

##############################################################################
# Leave points on 2D frontier
# TBD: need to redesign to support any number of dimensions

def filter_2d(i):
"""
Input: {
points (list) : [{"dim1":value11, "dim2":value12, ...},
{"dim1":value21, "dim2":value22, ...}]
frontier_keys (list) : ["dim1", "dim2"] - which keys to use for the frontier
(reverse_keys) (list) : ["dim2"] - which keys to reverse (smaller is better)
(plot) (str) : if "yes", plot graph with a frontier using matplotlib
}
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
frontier [list] - list of points on a 2D frontier
}
"""

plot=i.get('plot','')=='yes'

points=i['points']

frontier_keys=i['frontier_keys']
assert len(frontier_keys)==2, 'must be 2 frontier keys'

reverse_keys=i.get('reverse_keys',[])

kx=frontier_keys[0]
ky=frontier_keys[1]

revx=True if kx in reverse_keys else False
revy=True if ky in reverse_keys else False


if len(points)<3:
frontier=points
else:
# Sort by 0 dim
spoints=sorted(points, key=lambda x: x.get(kx,0), reverse=revx)

frontier=[spoints[0]]

for p in spoints[1:]:
if revy:
if p.get(ky,0)>=frontier[-1].get(ky,0):
frontier.append(p)
elif p.get(ky,0)<=frontier[-1].get(ky,0):
frontier.append(p)

if plot:
import matplotlib.pyplot as plt

x1=[]
y1=[]
for v in points:
x1.append(v.get(kx,0))
y1.append(v.get(ky,0))

plt.scatter(x1,y1)

x2=[]
y2=[]
for v in frontier:
x2.append(v.get(kx,0))
y2.append(v.get(ky,0))

plt.plot(x2,y2)

plt.show()

return {'return':0, 'frontier':frontier}

0 comments on commit 68e229e

Please sign in to comment.