Skip to content

Latest commit

 

History

History

TopPushRankingAlgorithm

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

TopPush Python Code

本项目是对《Top Rank Optimization in Linear Time》 论文的python代码实现。实现过程参考了官方matlab和c代码,原论文以及代码见origin

纯python实现

主体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+C实现

用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,会生成新的数据)