本项目是对《Top Rank Optimization in Linear Time》 论文的python代码实现。实现过程参考了官方matlab和c代码,原论文以及代码见origin。
主体toppush函数以及epne函数都用python实现。
- toppush.py
直接调用toppush.py
中的topPush
函数即可。
例如:
w = topPush(X, y)
相关参数以全局变量形式定义:
lambdaa = 1 # radius of l2 ball
maxIter = 10000 # maximal number of iterations
tol = 1e-4 # the relative gap
debug = False # the flag whether it is for debugging
delta = 1e-6
用python实现toppush
函数,用C实现epne
函数。
- epne.c
- toppushWithC.py
1.编译epne.c
生成epne.so
动态链接库文件。
gcc -shared -o epne.so epne.c
2.直接调用toppushWithC.py
中的topPush
函数即可。
例如:
w = topPush(X, y)
相关参数以全局变量形式定义:
# load C func epne
mylib = cdll.LoadLibrary('epne.so')
epne = mylib.epne
# params
lambdaa = 1 # radius of l2 ball
maxIter = 10000 # maximal number of iterations
tol = 1e-4 # the relative gap
debug = False # the flag whether it is for debugging
delta = 1e-6
- test.py
topPush time: 19.8399107 s
topPushWithC time: 17.9153129 s
numpy.ndarray运算后会生成新的numpy.ndarray,不是在原数据上进行修改。例如(data = -data,会生成新的数据)