Skip to content

Commit e9bce92

Browse files
committed
Improvement:
Add new metric for complexity - area under learning curve
1 parent 1d22700 commit e9bce92

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

utilities/plot_learning_rate.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ def run(cls, path, _data):
6767

6868
print("Graph Plotted: {}".format(path), flush=True)
6969

70+
area = cls.trapezium_rule(_data['x'], _data['y'])
71+
7072
return dict(coefficients=coefficient,
71-
r_square=r_square)
73+
r_square=r_square,
74+
area_inverse=(1 / area))
7275

7376
@classmethod
7477
def title_generation(cls, path, **kwargs):
@@ -241,6 +244,20 @@ def lsq_logistic_fit(cls, _x, _y):
241244
return (k, c), "y = 1 / (1 + e^(({})x + ({})))".format(
242245
k, c), __x.tolist(), __y.tolist(), predicted_y.tolist()
243246

247+
@classmethod
248+
def trapezium_rule(cls, _x, _y):
249+
"""Use trapezium rule to estimate the area under curve"""
250+
# As x is percentage, use x / 100
251+
data = [(_x[i] / 100, _y[i]) for i in range(len(_x))]
252+
data.sort(key=lambda x: x[0])
253+
254+
area = 0
255+
for i in range(len(data) - 1):
256+
area += ((data[i][1] + data[i + 1][1]) *
257+
(data[i + 1][0] - data[i][0]) / 2)
258+
259+
return area
260+
244261

245262
def plot(name, data):
246263
_data = collections.defaultdict(list)
@@ -267,9 +284,10 @@ def main(path):
267284
printing_data[key] = plot("{}.{}".format(
268285
path, key.replace(' ', '_')), value)
269286

270-
return (path[path.rfind('/') + 1:].replace(
271-
'.learning_rate.result.json', ''),
272-
printing_data)
287+
return {
288+
'dataset': path[path.rfind('/') + 1:].replace(
289+
'.learning_rate.result.json', ''),
290+
'result': printing_data}
273291

274292

275293
def traverse(paths):

0 commit comments

Comments
 (0)