Automatic Differentiation, A.K.A please save me from backprop!

原文

With the release of Tensorflow [1] and Twitter’s torch-autograd [2] (inspired by autograd [3] originally written in Python) I think it’s time to take a look at automatic differentiation [4] and why it’s super awesome.

First, I’d like to differentiate symbolic differentiation (SD) and automatic differentiation (AD). SD is akin to the stuff you did in your calculus class, you take a math expression and return a math expression. AD is where you take code that computes some function and return code that computes the derivative of that function. Theano [5], for example, uses SD. This is precisely why it’s very difficult to express loops in Theano and models like RNNs take a long time to compile.

So why does AD even work?

The theory behind AD is all numeric computations are ultimately compositions of a finite set of elementary operations (+, -, *, /, exp, log, sin, cos, etc.) [6].

So the idea is if we can write the code to differentiate these basic operations, then when we encounter a complicated numeric computation we break it down into these elementary ops and deal with those as opposed to figuring out the derivative encapsulating the entire computation. No more fiddling around with backpropagation!
Ok, let’s tie this back in with Tensorflow and torch-autograd.
So far, there’s been two approaches to doing AD. Explicit vs. implicit graph construction.

Tensorflow

Construct a graph and have a compilation step to optimize the graph. Now, to be fair, Tensorflow uses the graph for much more than just AD. For our purposes we’ll just focus on the AD part.
You also can’t write arbitrary code, for example, you can’t use numpy to do computations. You have to use the Python Tensorflow library. This might not be case if you write in C++ since Tensorflow is a C++ program. Either way, the use of Tensorflow would most likely be in a higher-level language so it makes sense to have a language agnostic API.

torch-autograd

No compilation. Constructs a tape data structure on the fly that keeps track of computations and how to compute the backward pass (constucts the computation graph for you).
Here we can write arbitrary Torch/Lua code. Unlike Tensorflow there’s no concern to have a language agnostic API. If you buy into Torch you buy into Lua, so arbitrary code makes sense here.

So which approach is better?

I think both are right for what the each project’s goals are. Also, it doesn’t really matter! We should just be happy AD is taking off and we can avoid the dreaded friction of calculating the backward pass ourselves. Let the computer to the dirty work for you!
Sources:
[1] http://tensorflow.org/
[2] https://github.com/twitter/torch-autograd
[3] https://github.com/HIPS/autograd
[4] https://en.wikipedia.org/wiki/Automatic_differentiation
[5] http://deeplearning.net/software/theano/
[6] http://arxiv.org/abs/1502.05767

随着Tensorflow[1]和Twitter的发布火炬autograd[2](由autograd启发[3]最初用Python编写的),我认为现在是时候看看自动分化[4],以及为什么它的超级真棒。

首先,我想区分符号微分(SD)和自动微分(AD)。 SD类似于你在你的微积分类做了东西,你把一个数学表达式,并返回一个数学表达式。 AD是你采取一些计算功能,并返回代码,该计算函数的导数的代码。 Theano[5],例如,使用的SD。这正是为什么它是非常艰难的啮合来表达Theano循环和模型,如RNNs需要较长时间进行编译

那么,为什么AD甚至工作?

AD背后的理论是所有的数字计算最终都是有限的一系列基本操作的成分(+, - ,*,/,EXP,日志,正弦,余弦,等等)[6]。

这样的想法是,如果当我们遇到一个复杂的数值计算,我们把它分解成这些基本老年退休金计划,并与处理,而不是搞清楚衍生封装整个计算,我们可以编写代码来区分这些基本操作,然后。没有更多的反向传播摆弄周围!

好吧,让我们来配合这回在Tensorflow和火炬autograd。
到目前为止,已经两方法做AD。显性与隐性图施工。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 201,468评论 5 473
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,620评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 148,427评论 0 334
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,160评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,197评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,334评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,775评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,444评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,628评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,459评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,508评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,210评论 3 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,767评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,850评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,076评论 1 258
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,627评论 2 348
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,196评论 2 341

推荐阅读更多精彩内容