-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark_base.py
More file actions
29 lines (26 loc) · 902 Bytes
/
benchmark_base.py
File metadata and controls
29 lines (26 loc) · 902 Bytes
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
import numpy as np
import pandas as pd
def _check_constraints(A, b, coef_, eps=1e-5):
return all(A @ coef_ + b <= eps)
def obj(C, y, out, loss={'name': 'svm'}):
if loss['name']=='svm':
return np.sum(C*np.maximum(1 - y*out, 0))
elif loss['name']=='QR':
kappa = loss['qt']
loss_mat = np.zeros((len(y), len(kappa)))
for i, kappa_tmp in enumerate(kappa):
loss_mat[:,i] = kappa_tmp * np.maximum(y - out, 0) + (1 - kappa_tmp) * np.maximum(out - y, 0)
return np.sum(loss_mat)
elif loss['name']=='TV':
return C*np.sum(abs(y - out))
else:
pass
def _append_result(df, n, d, C, err, method, time):
df['method'].append(method)
df['time'].append(time)
df['err'].append(err)
df['neg_log_err'].append(-np.log10(abs(err)+1e-10))
df['n'].append(n)
df['dim'].append(d)
df['C'].append(C)
return df