Saturday, November 4, 2017

Andrew Ng的AI新课程

Andrew Ng离开baidu后三件大事之一是成立deeplearning.ai,开设五门深度学习课程。网易云课堂搬运并翻译了前三门课。免费听一下,感觉课程内容虽然比较浅显偏engineering多一些,但总体还是质量颇高,收获不少,按照教学大纲总结如下 (慢慢更新)。

第一周  深度学习概论:

学习驱动神经网络兴起的主要技术趋势,了解现今深度学习在哪里应用、如何应用。

1.1  欢迎来到深度学习工程师微专业
ng秀中文,委托网易发布中文字幕版deeplearning.ai的课程。理念是希望培养成千上万人工智能人才,构建人工智能驱动的社会。
1.2  什么是神经网络?
介绍神经网络,house price prediction的例子,因为price不能为负所以曲线变成ReLU,很有意思的一个引出ReLU的方式,hiden unit 也称之为neuron。neural network就是stack neuron (like Lego brick) together toform a network.很直观。
1.3  用神经网络进行监督学习
几乎所有有价值的机器学习/神经网络技术都是supervised learning。也就是model一个x到y的映射函数。相对应的unsupervised learning,不存在y,只能指望data can tell something itself。
举了很多监督学习的例子
house price prediction用standard NN解决;image understanding,object detection这类问题用convolutional NN (CNN)解决;time series,or temporal sequence数据问题用Recurrent NN (RNN)解决;
structural data:房屋size等;unstructual data: audio/image/text, etc.

1.4  为什么深度学习会兴起?
因为数据量变大了,算法强了,计算资源强了。
举例:ReLU代替sigmoid。主要的优势在于sigmoid在两侧gradient几乎为0,导致gradient decent优化速度变慢。
interesting graph: idea ->code->experiments->idea... computation的提高导致这个iterative process加速,能带来更多更好结果。

1.5  关于这门课
简介五门课程和第一门课。
1.6  课程资源
鼓励上forum讨论问题。其他问题也可以联系deeplearning.ai。可以看出这个公司/机构的目的是培训为主,所以提到如果有公司需要培训hundreds of empolyees with deep learning expertise,可以联系他们,大学老师想开deep learning课的也可联系他们。



第二周  神经网络基础:

学习如何用神经网络的思维模式提出机器学习问题、如何使用向量化加速你的模型。

2.1  二分分类
2.2  logistic 回归
2.3  logistic 回归损失函数
2.4  梯度下降法
2.5  导数
2.6  更多导数的例子
2.7  计算图
2.8  计算图的导数计算
2.9  logistic 回归中的梯度下降法
2.10  m 个样本的梯度下降
2.11  向量化
2.12  向量化的更多例子
2.13  向量化 logistic 回归
2.14  向量化 logistic 回归的梯度输出
2.15  Python 中的广播
2.16  关于 python / numpy 向量的说明
2.17  Jupyter / Ipython 笔记本的快速指南
2.18  (选修)logistic 损失函数的解释


第三周  浅层神经网络:

学习使用前向传播和反向传播搭建出有一个隐藏层的神经网络。

3.1  神经网络概览
3.2  神经网络表示
3.3  计算神经网络的输出
3.4  多样本向量化
3.5  向量化实现的解释
3.6  激活函数
3.7  为什么需要非线性激活函数?
3.8  激活函数的导数
3.9  神经网络的梯度下降法
3.10  (选修)直观理解反向传播
3.11  随机初始化


第四周  深层神经网络:

理解深度学习中的关键计算,使用它们搭建并训练深层神经网络,并应用在计算机视觉中。

4.1  深层神经网络
4.2  深层网络中的前向传播
4.3  核对矩阵的维数
4.4  为什么使用深层表示
4.5  搭建深层神经网络块
4.6  前向和反向传播
4.7  参数 VS 超参数
4.8  这和大脑有什么关系?

Monday, June 30, 2014

How does Matlab calculate the eccentricity of a region

In matlab, there is a built-in function to calculate properties of a region.
http://www.mathworks.com/help/images/ref/regionprops.html#bqkf8jf

And as said in help message:
'Eccentricity' — Scalar that specifies the eccentricity of the ellipse that has the same second-moments as the region. The eccentricity is the ratio of the distance between the foci of the ellipse and its major axis length. The value is between 0 and 1. (0 and 1 are degenerate cases; an ellipse whose eccentricity is 0 is actually a circle, while an ellipse whose eccentricity is 1 is a line segment.) This property is supported only for 2-D input label matrices.

So, the idea is to fit using a ellipse with same second-moments as the region.
What does it mean?
The answer is in this thread:
http://stackoverflow.com/questions/1532168/what-are-the-second-moments-of-a-region

To simplify, the idea is to calculate the co-variance matrix, then do eign-value decomposition. Eigen-values are those axis length, minor and major one. While eigen-vectors are the directions of minor/major axis.

length of major axis = 2a, minor axis = 2b, then the foci = c, then:
eccentricity E = c/a = sqrt(1-(b/a)^2)
a^2-b^2 = c^2.


Wednesday, June 11, 2014

ML_general_talk.md

why this article

I am not a newbie for machine learning any more. But still sometimes I suspect what did I gain from learning “machine learning”. By applying some classical algorithms, I get some real feeling about this hot topic.

everything is about generalization

Generalization means the ability to have good prediction on novel data samples. In other words, when you make prediction on testing data given the model you trained on training data.
You can easily get a 100% accuracy on training data, except for some ambiguous data point (same data points, but different label). This is meaningless since your decision boundary is too complex. The terminology is over-training. Instead of record every training data sample by taking photo, you need to loss the decision boundary. Some technologies play this role essentially, like margin in SVM, regularization in general optimization.
Another this is features goes first. You cannot do magic on bad features. This means spend more time on feature extraction/selection/design is worthy. In some sense, deep learning or sparse coding/representation is to put efforts on the steps before classification.

Do Preprocessing

Some simple preprocessing, e.g. normalization, whitening, etc. can really benefit your classification.

select correct classification algorithm

Linear or not, svm or lda.
I always try four algorithm to have baseline:
1. Support Vector Machine (SVM)
2. Linear Discriminant Analysis (LDA)
3. Random Forest (RF)
4. K Nearest Neighbor (KNN)


Written with StackEdit.

Tuesday, June 10, 2014

git_notes

Git 笔记

Some basic concepts

repository 仓库,存储code的单元。
branch 分支,同一个代码库的不同版本控制路径,默认的主线是master,可以分叉出来开发测试新功能,完成后merge到master上。
commit 提交修改。
push推送到远程,默认推到original的repository。
pull 从远程repository取回代码。
一般远程的repository默认是origin, 另一个常用的名字是upstream,这个用于从一个已有的repository fork了一个副本后,自己的副本作为origin,原始的版本作为upstream。参加open source project常用到upstream。

文件状态

untracked 即没有加入到git的index
unmodified 没有个修改过的文件
modified 修改但尚未提交
staged 已经提交,上了舞台了。。

常用命令

git status检查所有文件的状态
git diff 检查文件修改前后差异
git branch 创建新分支
git checkout 切换分支
删除和ignore不同:
ignore只是忽略跟踪,但文件保留,删除是彻底删除,先删除文件再用git -rm xx.xx 实现彻底git上的删除。

深入

关于配置:
/etc/gitconfig 针对系统 git config –system
~/gitconfig 针对当前用户 git config –global
.git/config 针对当前 repository
git config –list列出当前所有配置。
提交代码最常用的配置是信息是用户名和邮箱。当你需要提交并push的时候会要求输user pwd验证身份。另一种选择是可以直接在本地产生一对公钥私钥 (ssh-keygen -t rsa -C “your_email_address”)。
所谓分布式版本控制。事实上是说没有一个主线处于支配地位。我的理解,在远程服务器比如github上也是一个类似本地的一个repository。所以你的机器如果在线,也能直接被clone。
.git文件下存储所有配置。(比如忽略某些文件,index等)

References:

GitHub详细教程
collaborate using git
git user guide
简单明了的一个教程:廖雪峰的git教程
Written with StackEdit.

Monday, June 9, 2014

java integer pool

Here in this post, I record a bug in my project(Java).
The problem is when compare two integers, it works well only when integer is of one-byte length.
This is caused by "Integer constant pool". To avoid extra memory cost, Java will return a already-created Integer object if it's between -128 and 127. This means:
Integer i = Integer(10); Integer j = Integer(10);
bool flag = (i==j); //return true; directly check the address
bool flagE = i.equals(j);//return true; directly check the values, what we expect here.
For the Object class, which is the root class of all classes in java, these two method (or operator) are the same. But for a certain derived class, it is not necessary depends on the logic.

So if the logic of your program is to check whether two integers are equally valued, then you need to use equals instead of == operator.

You may imply that java override the equals function for Integer class. this gives us another topic to discuss, that is, when you override equals function you need override hashCode(). One naturally raised question is "why always override hashcode() given equals() overrided". Here is a good article for this question:
http://www.xyzws.com/javafaq/why-always-override-hashcode-if-overriding-equals/20
To simplify it, you have to guarantee that:
if equals(Object o) gives true, hashCode() output same integer. This means you need to generate hash code from attributes which are used to decide whether two objects are equal (equals() function).

Thursday, May 29, 2014

[Python] fundamental of Python

introduction

Python is a interpreting script language, which is very popular these years. This post will summarize some fundamentals of this language.
I installed python(x,y) as my python environment. To run a python script, type in “python xx.py”, or run it in IDE, just same as running matlab script in matlab IDE.
fundamental syntax:
http://wiki.woodpecker.org.cn/moin/PyAbsolutelyZipManual
import (same as Java)
string <=> int
str(i)
string.atoi(s,[,base]) #convert to int, base is the base of the number, 10, 16, or 8
string.atof(s) #convert to float
change dir:
import os
chdir(strDir)
statement (loop/if/else)
if x<0:
x++ # note that all code-block structure is defined by indent
else:
x–

no end

for i in range(10,0,-3): # range(10,0,-3) means 10:-3:0, while 0 is excluded
print “the output num is %d”%(i)
read/write file:
http://www.cnblogs.com/allenblogs/archive/2010/09/13/1824842.html
fid = open(“xx.txt”,”r”)
line = fid.readline()
fid.close()
fid = open(“xx.txt”,”w+”)
fid.write(line) # automatically return to a new line
fid.close()

List if mutable, while tuple is immutable.


How to check the structure of a variable?
You can call type(var) to know the type of the variable. Then dir() and getattr() to check the structure.

List comprehensions
x = list([0 1 2 3 4 5])
y = [x_i for x_i in x]
y = [x_i+1 for x_i in x if x>1]
y = [x_i+1 if x_i%2==0 else x_i for x_i in x if x>1]

how to sum up a list?
sum(x)

pandas DataFrame



Written with StackEdit.