Finished post://www.i494.com/articles/intuitive-convolution/

How To Understand Mathematical Convolution

比如让工程专业的学生局促不安?请他们解释卷积。当他们自己慢慢走向门的时候,他们会咕哝着滑动重叠部分。

Convolution is usually introduced with the formal definition:

$$ (f * g )(t)\ \ \stackrel{\mathrm{def}}{=}\ \int_{-\infty}^\infty f(\tau) g(t - \tau) d\tau $$

and we’re left to unwind this baffling integral ourselves. Ugh. Here’s the plain-English analogy that helped me:

卷积是累积效果的乘法。

A Quick Analogy: Hospital Treatment Plans

Imagine you’re treating patients with a rare disease. You have:

  • A treatment plan: Everyone gets 3 units of the cure. (Plan: [3])
  • 病人列表:周一见1人,周二见2人,周三见3人,周四见4人,周五见5人。(Patients: [1 2 3 4 5])

How much of the drug is used each day? Well, that’s a simple multiplication:

Plan * Patients = Total Daily Usage [3] * [1 2 3 4 5] = [3 6 9 12 15]

The plan can be multiplied with the patient list, giving the usage pattern[3 6 9 12 15].

Extend To Multi-Day Treatment Plans

Unsanitized ping-pong paddles have led to a mutated disease. After furious research, you devise a new treatment plan: 3 units the first day, 2 the next, and 1 on the final day.

Plan: [3 2 1]

Assume the same patient schedule:[1 2 3 4 5]. How much of the drug do you need each day?

Oh, that must be an easy multipl…wait a minute.

  • 周一:1个病人来了,她需要3个单位。
  • 周二:周一的那名患者得到2单位,但我们有两名周二的新患者,每人得到3单位。总数是2 +(3*2)= 8个单位。
  • 星期三:星期一的女孩得到1单位。两个周二的人每人得到2单位。但是有三个新的周三的人,啊…算了吧。每个人都拿些药。

细节被混在一起了。我们能更好地组织他们吗?

Here’s an idea: imagine flipping the list, forming a line where the first patient is at the front:

Start of line 5 4 3 2 1

Next, imagine we have 3 rooms where we apply the cure:

Rooms 3 2 1

第一天,你走进第一个房间,拿了3个单位的药。第二天,你搬到另一个房间(2个单元),第二天,你在最后一个房间(1个单元)。Then you’re done.

To work out the overall usage, imagine the patients are lined up and walk forward each day:

Monday ---------------------------- Rooms 3 2 1 Patients 5 4 3 2 1 Usage 3

Neat! On Monday, only the first patient is in a room. She gets 3 units, for a total usage of 3. Makes sense, right?

On Tuesday, everyone takes a step forward:

Tuesday ---------------------------- Rooms 3 2 1 Patients 5 4 3 2 1 Usage 6 2 = 8

Ah! This is simpler than the text description. The first patient is at the front of the line, but in the next room (2 units). We have two patients in the first room for their first day (2 * 3 = 6 units). The total is 8 units.

Imagine the list “walking forward” each day:

Wednesday ---------------------------- Rooms 3 2 1 Patients 5 4 3 2 1 Usage 9 4 1 = 14 Thursday ----------------------------- Rooms 3 2 1 Patients 5 4 3 2 1 Usage 12 6 2 = 20 Friday ----------------------------- Rooms 3 2 1 Patients 5 4 3 2 1 Usage 15 8 3 = 26

整洁的,对吧?我们有一个策略来预测任何一天的使用情况。只要翻动病人名单,“向前走”到你需要使用它的任何一天。

Here’s the daily usage:

计划*患者名单=每日总使用量[3 2 1]*[1 2 3 4 5]=[3 8 14 20 26…]

(Note: we’ll need drugs for Saturday and Sunday since the Friday patients have to finsih up.)

Discovering The Official Definition

两个函数的卷积是用$f * g$编写的,并带有一个星号(注意:星号通常意味着常规的乘法)。

The convolution gives the total usage when applying a plan to a set of patients. What did we do, exactly?

  • Get $f(x)$, the plan to use. In our case, the plan was[3 2 1]

  • 得到输入,$g(x)$。然而,我们想翻转它们,所以第一个输入在右边。这意味着我们需要$g(-x)$,它是$g(x)$的镜像。

  • We pick an amount of time to advance, call it t. This means we really want $g(-x + t)$.

So, we now have our setup:

  • f(x) : the plan to use
  • g(-x + t) : the inputs, in right-to-left order and slid to the correct position

Finally, we’re ready to compute how much “total medicine” is needed by multiplying each input by the part of the plan it’s on, and adding up the results.

This is a job for the integral, which is “piece by piece multiplication”.

Phew!

以下是官方定义:

[ ]

显示图像,并为其着色。

PS. “Simplifying” to $$ f(x) \cdot g(t - x)$$ hides what we are doing: we flip g(x), then we slide it over!

把数学看作是对你所知道的事物的描述,而不是一组符号,你知道,这些符号背后可能有也可能没有什么意义。


Convolution is seeing the result of a multi-step plan on your input.

Note:

  • We flip the patient list
  • We slide the plan forward the correct number of days.
  • 滑动之后,我们对重叠部分进行积分。

It’s written -g but its better written

$$g(\text{flip plus slide})$$
$$g(-t + T)$$

Convolution represented with asterisk (*), which gets confusing since in most cases, people (informally) mean regular multiplication. But you can see why: convolution is a turbocharged multiplication.

Convolution steps in when multiplication can’t handle the job.

Technically, we can flip convolution around. In practice, we have the “plan” (called a kernel) and the “patients” (the data). We apply the plan to each patient and want to know the total outcome.

Properties of Convolution

  • Backwards and forwards
  • Total integral (total usage)
  • Fourier Transform

Properties Of Convolution

  • reversing the order

Imagine the patients are immoble. So, we have vans that drive

The patients are lined up:

Vans 1 2 3 1 2 3 4 5

每天货车都向前开,为他们看到的病人治疗。

  • We flip the patient list, and they walk into the rooms (earliest patient first)
  • We flip the treatment plan, and the vans drive to the patients (earliest van first)

整洁的,对吧?Sof * g = g * f.

The patients walk through the hospital, or the vans move and attend each patient.

Examples

Blurring an image
Taking an average
Taking a moving average

Total Usage

Slide It By

Here’s a few ways to imagine it

  1. Line everyone up.

病人们排好队。你有一辆货车,沿着线开下去。每天你都要往下移动一个单位。

  1. Have patients walk through.

You have a static van. The patients walk through. Each day, they get up and move one room to the right.

The convolution ishow much medicine is being used that day. It’s a combinatino of how many patients are being treated, and what stage of the plan they’re on.

Useful, right? Can also work backwards.


What is convolution? Given a sequence of incoming patients, and a known multi-day antibiotic treatment plan, convolution finds the total daily usage pattern.

怎么做?每天统计治疗每一阶段的患者人数,乘以该阶段的剂量,然后加起来。

Why? The overall usage is eye-opening compared to just analyzing the sequence of patients and the treatment plan.

In Math-English:

  • 卷积将输入序列应用到输出是一个函数而不是单个点的系统中。因为输出可能会持续(昨天开始的处理仍然会影响今天的使用),我们必须考虑以前输入的变化。

In the math world, inputs return instantaneous outputs. When y = f(x), we put in x, get y, and that’s it. A single output was made, nothing more!

现实世界的系统不是瞬时的。拍拍你的手,声波就会上升,达到峰值,然后下降。输出的是一种糊状的、模糊的波,而不是完美的咔嚓声。

当允许输出在一段时间内“模糊”时,卷积获得总体效果。

====
例子:什么东西是模糊的?

literal blurring of images

if we apply a PERFECT spike … then we can extract the original.

Fourier / LaPlace overlap

Just intuit the reasons why.

I want you to INTUITIVELY see how convolution is EXTREMELY useful.

You have monthly customer numbers: 100, 200, 300

and you have their monthly average spend

$20, $10, $10, $10, $5

卷积得到收益图。

How many customers at what stage of the lifecycle?

使用它无处不在。

Continuous version? Probably not. Go for the discrete.

Wolfram alpha example.

===
Work through properties:

  • integral totals

  • Fourier/LaPlace transform

  • reversible

  • 的身份。有没有一种“治疗方案”可以只计算病人的数量?是啊!(1 0 0 0)狄拉克函数。或者离散的。这是一个完美的尖峰。一个输入,一个输出。

  • require linear, time-invariant systems. linear: pieces just add up, no interaction. time-invariant: it doesn’t matter when a signal shows up (Monday, Friday, etc. Labor Day, Thanksgiving). Same treatment plan applies.

  • 可以“像对数一样”使用它。对数将指数转化为乘法。Multiplication into addition.

Convolution turns Fourier Transforms into multiplications. So you can solve it, then undo.

Can see it as an ACTUAL TOOL (“applying one to another”) or just some intermediate representation which is more useful to manipulate things with. Solve, then undo.

Fourier breaks interaction into frequency components. Only inputs and outputs of the same frequency overlap and make a contribution. So convolution can be written with point wise multiplication (convolution theorem).

卷积的傅里叶变换是另一个积分,这个二重积分可以分成两点积分。只有相同的频率有重叠之处。


Use linear algebra terms here…

for inverse convolution, need to REDUCE the area that was added [right?]

convolve arrays… have a js demo


Inverse convolution: restore original. Have the blurry, remove the effect of the camera lens. Bad focus? Inverse convolve.

Neat!!!


(Do a transcription! Just write as I speak. See what I can write here.)

Technical Appendix

  1. Impulse response

Sounds so fancy. “A LTI system is characterized by its impulse response.” Translation: Send a SINGLE patient through to figure out what the baseline treatment plan is. Now that you have the plan, you can scale it up to any number of patients. [Imagine a rival hospital sending a patient in and taking notes about the treatment.]

Send the “impulse” which is just [1]. A single patient. If you send a single patient through, you’ll get a copy of the treatment plan back out! [What happens to them each day].

  1. Linear and Time-invariant systems

If a system is linear [double the patients, double the treatment] and time-invariant [Your treatment just depends on when YOU show up, not a global time. I.e., whether your first day is Monday or Thursday, it doesn’t matter – you get the same dose]. We only care that it’s your first day, not whether it’s Monday or Thursday.

[你可以想象一个系统,你的治疗取决于你哪天来上班,哪位工作人员在工作,等等。To make it simpler, we assume everything is identical (non-variant) no matter the date you ask for treatment.]

Reference:http://www.onmyphd.com/?p=convolution