Translating SoRec: Social Recommendation Using Probabilistic Matrix Factorization
SoRec: 基于概率矩阵分解的社交化推荐
1. 介绍
推荐系统(Recommender Systems)的职责是尝试为用户(User)提议他们可能会感兴趣的项目(Item, 譬如电影、书籍、音乐、新闻、网页、图片,等等)。一类典型的推荐系统是基于协同过滤(Collaborative Filtering,以下简称CF)构建的,即一种通过收集与目标相似的其他用户(或其他的商品)的评分信息,来自动预测某位活跃用户的兴趣倾向的技术手段。构成CF的理论基础的一个重要假设是,活跃用户们会更倾向于喜爱那些与他们相似的用户也喜爱的项目 [13]。基于这个简洁有效的直觉,CF被应用于许多大型、著名的商业系统中,如Amazon。然而,受限于CF技术的本质,基于它的推荐系统存在以下一系列的固有弱点:
-
(1) 由于User-Item的打分矩阵经常十分稀疏(商业推荐系统中的有效评分数据的密度通常占不到1% [19]),基于记忆(Memory-based,或称启发式 [10],[12],[13],[24] )的CF算法常常无法为目标用户找到类似用户的配对,因为各种计算相似程度的方法,如PCC(the Pearson Correlation Coefficient)和余弦方法(Cosine Method),都假设被计算的一对用户至少有对一些相同的项目或物品进行过打分;更有甚者,几乎所有基于记忆或基于模型(Model-based [8],[9],[18],[20])的CF算法都无法处理那些从未给任何项目评分的用户的情况。
-
(2) 在现实中,我们经常向我们信得过的朋友询问电影、音乐和书籍等的推荐,并且我们的口味与个性很容易就受到身边人的影响。因此,那些传统的只挖掘“用户-项目”打分矩阵(User-item Rating Matrix,以下简称“U-I矩阵”)来给出推荐的推荐系统的输出就显得有些不切实际了。
Issues When Converting Python2.x Code to Python3.x
收藏的原文网址貌似在地震中无法打开了 0 0 转载一下。
使用2to3将代码移植到Python 3
0. 概述
几乎所有的Python 2程序都需要一些修改才能正常地运行在Python 3的环境下。为了简化这个转换过程,Python 3自带了一个叫做2to3的实用脚本(Utility Script),这个脚本会将你的Python 2程序源文件作为输入,然后自动将其转换到Python 3的形式。案例研究:将chardet移植到Python 3(porting chardet to Python 3)描述了如何运行这个脚本,然后展示了一些它不能自动修复的情况。这篇附录描述了它能够自动修复的内容。
1. print语句
在Python 2里,print是一个语句。无论你想输出什么,只要将它们放在print关键字后边就可以。在Python 3里,print()是一个函数。就像其他的函数一样,print()需要你将想要输出的东西作为参数传给它。
My Notes of Python 3
1. 函数参数
1) 默认参数
Python函数在定义的时候,默认参数(比如L
)的值就被计算出来了;每次调用该函数,如果改变了L
的内容,则下次调用时,默认参数的内容就变了,不再是函数定义时的值了。所以,定义默认参数时,必须指向不变对象。
2. 继承与多态
1) 实例属性与类属性
相同名称的实例属性将屏蔽掉类属性,但是当你删除实例属性后,再使用相同的名称,访问到的将是类属性。
2) 动态语言的鸭子类型
3. 函数式编程
1) 装饰器
一个完整的decorator的写法如下:
import functools def log(func): @functools.wraps(func) def wrapper(*args, **kw): print('call %s():' % func.__name__) return func(*args, **kw) return wrapper
或者针对带参数的decorator:
My JavaScript Notes
1. 作用域问题
1)隐式全局变量声明
function func1() { var a1 = b1 = 1; return b1; } func1(); console.log(b1); function func2() { var a2 = b2 = 2; return a2; } func2(); console.log(a2);
以上输出的结果分别是"1"和"null"(或"a2 is not defined"),乍一看觉得匪夷所思,但是了解了JS的作用域知识以后,迎刃而解:
用var声明后,a1是func1的本地变量,而中间变量b1没有被声明地直接拿来使用,相当于创造了一个全局变量。本地变量在外部作用域中无法访问是几乎所有编程语言共同的,而根据JS闭包原则,全局变量b1则可以被访问到。
How to Redirect with Context in Django
The following question on StackOverflow :
I have a view that validates and saves a form. After the form is saved, I'd like redirect back to a list_object view with a success message "form for customer
xyz
was successfully updated..."
HttpResponseRedirect
doesn't seem like it would work, because it only has an argument for the url, no way to pass dictionary with it.I've tried modifying my wrapper for object_list to take a dict as a parameter that has the necessary context. I the return a call to this wrapper from inside the view that saves the form. However, when the page is rendered, the url is '/customer_form/' rather than '/list_customers/'. I tried modifying the request object, before passing it to the object_list wrapper, but that did not work.
用Django Form做登录出错信息处理的Sample
这个学期用基于Python的Django 1.8.2 后端开发框架做了不少活儿,感觉这真是一个为程序员包办各种脏活累活儿的省心Framework :) 使用django.forms提供的API做表单输入的后端验证时遇到了一些坑,大多是因为不了解API的设计哲学所致,基本通过查阅官方文档+搜索StackOverflow解决。这里呈现一个比较通用的登录界面错误信息提示功能的代码片段作为Sample,来归纳一下使用forms时一些需要注意的细节。
这是一个多APP的教务系统工程,其中登录验证在层次上写到了“基础信息管理子系统(IMS)”中;每个APP都(理应)把自己所辖的URL放到一个固定的前缀下,在顶层的urls.py
中include每个APP的urls,并对应相应的匹配前缀(比如/ims/login/
在顶层被前缀/ims/匹配,在IMS APP中的urls里只要匹配login/
即可)。示例如下:
#djcode/urls.py urlpatterns += [ url(r'^ims/', include('IMS.urls')), ] #IMS/urls.py from IMS import views #... urlpatterns += [ url(r'^login/$', views.loggingin), url(r'^user_auth/', views.user_auth), url(r'^home/$', views.home), ]
Raspberry Pi 无线网卡配置
用root权限修改 /etc/network/interfaces
文件:
$ sudo vim /etc/network/interfaces
修改后文件内容如下:
auto lo iface lo inet loopback iface eth0 inet dhcp auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "JoStudio" wpa-psk "password" #wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
若一直没用VNC等进过图形化界面,就请把原来的最后一行注释掉(如上)。
为MIPS指令集的WRTnode添加系统调用
Embedded System Lab 5 on WRTnode
1. 实验准备
- WRTnode核心板直插手机充电线作为供电,通过Macbook的终端ssh登录操作,通过浏览器端的Luci配置界面刷固件;
- 交叉编译环境搭建参照
http://adward-r.github.io/posts/samba-and-cross-compile-toolchain-on-wrtnode.html
,我在之前这一步的时候已经下载好了WRTnode定制版本的OpenWRT源码,并编译了固件,中间文件和配置文件都放在了自己的VPS上,编译起来会比较快,也不需要修改配置了。
2. 添加系统调用
以下{$linux-src}
路径指的是sdk目录下的build_dir/target-*/linux-ramips_mt7620n/linux-*/
,内部文件目录结构即与一般Linux Kernel版本源码相似。
例如,在我的VPS上是~/OpenWrt/wrtnode-sdk/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620n/linux-3.10.49/
。注意编译需要在非root用户下进行。
2.1 mysyscall.c
$ cd {$linux-src}/arch/mips/kernel/
,新建mysyscall.c
文件作为新增的系统调用的实现代码,效果是在日志中输出一行文字:
#include <linux/kernel.h> void mysyscall(void) { printk("New syscall!\n"); }
My RSS Subscriptions
存档一下我目前Feedly上的RSS订阅源集合;虽然它家的Android客户端做得不算大气好看、Material Design,但是内容抓取还是比大多数客户端要靠谱,于是乎依然在用。Mac上用的则是Reeder 2,真的很棒。
<?xml version="1.0" encoding="UTF-8"?> <opml version="1.0"> <head> <title>Subscriptions - RSS</title> </head> <body> <outline text="Friends" title="Friends"> <outline htmlUrl="http://blog.littleaprilfool.me/" title="April Pie" xmlUrl="http://blog.littleaprilfool.me/rss" type="rss" text="April Pie"/> <outline htmlUrl="http://rockidog.com/" title="一本正经地瞎扯淡" xmlUrl="http://rockidog.com/feed.xml" type="rss" text="一本正经地瞎扯淡"/> <outline htmlUrl="http://www.xsjxmx.com" title="开拖拉机的熊猫" xmlUrl="http://www.xsjxmx.com/index.php/feed/" type="rss" text="开拖拉机的熊猫"/> </outline> <outline text="Music" title="Music"> <outline htmlUrl="http://blog.sina.com.cn/hughke" title="hughke的博客" xmlUrl="http://blog.sina.com.cn/rss/1436337665.xml" type="rss" text="hughke的博客"/> <outline htmlUrl="http://www.5friend.cn" title="一碟沉香 » 古典" xmlUrl="http://www.5friend.cn/archives/category/classic/feed" type="rss" text="一碟沉香 » 古典"/> <outline htmlUrl="http://www.5friend.cn" title="一碟沉香 » 爵士" xmlUrl="http://www.5friend.cn/archives/category/uncategorized/feed" type="rss" text="一碟沉香 » 爵士"/> <outline htmlUrl="http://blog.sina.com.cn/headphoneclub" title="耳机俱乐部小白的BLOG" xmlUrl="http://blog.sina.com.cn/rss/1311376432.xml" type="rss" text="耳机俱乐部小白的BLOG"/> <outline htmlUrl="http://naomafei.blog.163.com" title="脑吗啡的博客" xmlUrl="http://naomafei.blog.163.com/rss/" type="rss" text="脑吗啡的博客"/> <outline htmlUrl="http://blog.sina.com.cn/yyjj" title="静介" xmlUrl="http://blog.sina.com.cn/rss/1228233583.xml" type="rss" text="静介"/> </outline> <outline text="Other" title="Other"> <outline htmlUrl="http://www.kanzhihu.com" title="看知乎" xmlUrl="http://www.kanzhihu.com/feed" type="rss" text="看知乎"/> <outline htmlUrl="http://daily.zhihu.com/" title="知乎日报" xmlUrl="http://zhihurss.miantiao.me/dailyrss" type="rss" text="知乎日报"/> <outline htmlUrl="http://daily.zhihu.com/" title="知乎日报2" xmlUrl="http://zhihudaily.dev.malash.net/" type="rss" text="知乎日报2"/> <outline htmlUrl="http://wp.minyueguo.com" title="闽越国" xmlUrl="http://wp.minyueguo.com/feed/" type="rss" text="闽越国"/> </outline> <outline text="Tech" title="Tech"> <outline htmlUrl="http://blog.binchen.org/" title="Chen's blog" xmlUrl="http://blog.binchen.org/rss.xml" type="rss" text="Chen's blog"/> <outline htmlUrl="http://blog.pluskid.org" title="Free Mind" xmlUrl="http://blog.pluskid.org/?feed=rss2" type="rss" text="Free Mind"/> <outline htmlUrl="http://freemind.pluskid.org" title="Free Mind" xmlUrl="http://freemind.pluskid.org/rss.xml" type="rss" text="Free Mind"/> <outline htmlUrl="http://lucifr.com" title="Lucifr" xmlUrl="http://lucifr.com/atom.xml" type="rss" text="Lucifr"/> <outline htmlUrl="http://macshuo.com" title="MacTalk-池建强的随想录" xmlUrl="http://macshuo.com/?feed=rss2" type="rss" text="MacTalk-池建强的随想录"/> <outline htmlUrl="http://www.isofts.org" title="Mac志" xmlUrl="http://www.isofts.org/feed/" type="rss" text="Mac志"/> <outline htmlUrl="http://rednaxelafx.iteye.com" title="Script Ahead, Code Behind" xmlUrl="http://rednaxelafx.iteye.com/rss" type="rss" text="Script Ahead, Code Behind"/> <outline title="winter" xmlUrl="http://feed.cnblogs.com/blog/u/37697/rss" type="rss" text="winter"/> <outline htmlUrl="http://rockidog.com/" title="一本正经地瞎扯淡" xmlUrl="http://rockidog.com/feed.xml" type="rss" text="一本正经地瞎扯淡"/> <outline title="刘未鹏 | Mind Hacks" xmlUrl="http://mindhacks.cn/feed/" type="rss" text="刘未鹏 | Mind Hacks"/> <outline title="南极光的专栏" xmlUrl="http://blog.csdn.net/rk2900/rss/list" type="rss" text="南极光的专栏"/> <outline title="博学无忧" xmlUrl="http://www.bo56.com/feed/" type="rss" text="博学无忧"/> <outline title="大茶园丁 - Openwrt" xmlUrl="http://www.wuqiong.info/feed/category/Openwrt/" type="rss" text="大茶园丁 - Openwrt"/> <outline title="少数派" xmlUrl="http://sspai.com/feed" type="rss" text="少数派"/> <outline title="灵犀志趣" xmlUrl="http://www.lingcc.com/feed/" type="rss" text="灵犀志趣"/> <outline title="老赵点滴" xmlUrl="http://blog.zhaojie.me/rss" type="rss" text="老赵点滴"/> <outline htmlUrl="http://coolshell.cn" title="酷 壳 - CoolShell.cn" xmlUrl="http://coolshell.cn/feed" type="rss" text="酷 壳 - CoolShell.cn"/> </outline> </body> </opml>
Samba and Cross-Compile Toolchain on WRTnode
Embedded System Lab 2 on WRTnode
1. 器材列表
- WRTnode核心板,专用USB线,USB-to-TTL串口线
2. 接线方法
- 电插座\<->手机充电头\<->专用USB线的单个USB头\<->专用USB的OTG头\<->WRTnode核心板\<->GND、RXD2、TXD2三个针脚\<->USB-to-TTL线的杜邦线头\<-> USB-to-TTL线的USB头\<->电脑USB口;
- 针脚具体接线方法同第一次实验报告,可在WRTnode Wiki找到,细节不再作冗余说明;
- 实验的大部分流程都是通过
$ ssh root@192.168.8.1
在Mac OS X的终端中以root身份完成的,WRTnode的作用相当于局域网路由器,通过它使得Macbook、手机等终端可以连接Internet。
3. Samba配置
-
Samba Server Port的安装: