下面这道题出自于台大线上课程,Machine Learning Foundations,作业二 Question 6。其答案是
N^2 - N + 2
这道题目求一种Hypothesis Set的成长函数。这种Hypothesis Set称为positive-and-negative intervals。该成长函数为
N^2 - N + 2
如何求得?
要先了解,什么是positive-and-negative intervals。
题目有说明,h1是属于hypothesis set, H,而h2不属于H,为何?
如何理解下面这道式子?
h1(x) = sign (x(x-4))
其实我们将这导式子转成下面这道,有助于我们理解
f1(x) = x (x - 4)
用Python画出f1(x)如下:
![](https://i-blog.csdnimg.cn/blog_migrate/169d61e9cdeb49579605cd0a2357729b.png)
我们可以基于张图画出h1(x) = sign (x(x-4))如下:
![](https://i-blog.csdnimg.cn/blog_migrate/2ddc14d96417231c6b88527db43dcc3c.png)
所以h1(x)是一个Negative Intervals,属于H
同理
h2 (x) = sign ((x+1)(x)(x-1))
转成下面这道式子:
f2(x) = (x+1)(x)(x-1)
用Python画出f2(x)如下:
同理
h2 (x) = sign ((x+1)(x)(x-1))
转成下面这道式子:
f2(x) = (x+1)(x)(x-1)
用Python画出f2(x)如下:
![](https://i-blog.csdnimg.cn/blog_migrate/1d8786e160e704eeef8667e5f1c7ed5e.png)
我们可以基于张图画出
h2(x) = sign((x+1)(x)(x-1))
如下:
h2(x) = sign((x+1)(x)(x-1))
如下:
![](https://i-blog.csdnimg.cn/blog_migrate/e859116313810f7eef21175d49d3f9b0.png)
可以看出来,h2(x)不是一个Positive and Negative Intervals,所以不属于H。
现在有一个问题是,如何用一个式子表达positive and negative intervals?我们知道h1是negative interval,将它上下巅到,就成为positive interval
h3(x) = sign ((-1)x(x-4))
就用Python画f3(x),加上手绘的+-,表达h3(x)如下:
![](https://i-blog.csdnimg.cn/blog_migrate/5de9bcf6aad7f5ff7481704c21281a77.png)
可以看出来,h3(x)是一个Positive Interval,所以属于H。
我们将h1与h3结合在一起:
h(x) = sign (s * x * (x-4)), s = +1 or -1
再写成更通用一点,就是:
h(x) = sign (s * (x - a) (x - b)), s = +1 or -1
这就是用一个式子表达positive and negative intervals。
这个式子,也可以写成下面这道:
h(x) = s * sign ((x - a) (x - b)), s = +1 or -1
为何?我们将 h3改写成下面这道式子,来解释原因:
h4(x) = (-1) sign (x(x-4))
就用Python画f4(x)=x(x-4)如下,加上手绘的+-,表达h4(x)如下:
![](https://i-blog.csdnimg.cn/blog_migrate/5baeea91cfda910627e2541323d2355a.png)
在这里,我想表达的思路是,用来达达positive and negative intervals的式子:
h(x) = sign (s * (x - a) * (x - b)), s = +1 or -1
若将它视为一维空间的问题,会不太好理解,所以我将它转成二维空间,就是加上y轴,这样对这道式子会更好理解。甚至,可以用三维空间,理解这道式子:
h(x) = s * sign ((x - a) * (x - b)), s = +1 or -1
下图是s = 1的情况
![](https://i-blog.csdnimg.cn/blog_migrate/7ec1b4a3293ae314f17981f7339d06a4.png)
下图是s = -1的情况
所以这两张是鸟瞰图,+号代表高于水平面,-号代表低于水平面。这就是用3D的视角来看待这个问题。
f(x) = (x - a) (x - b)
h(x) = s * sign (f(x)), s = +1 or -1
这道式子的好处是,f(x)不变的情况下,只要切换s为+1或-1即可
回到正题,如何求positive and negative intervals的成长函数?
我们把这个问题拆成两个部份来看待:Positive Intervals和Negative Intervals,然后各别求这两个的成长函数:
Positive Intervals
红色的线段,代表positive interval。以5个点来表,可以从5+1的间隔选取两个位置,成为一个interval,共有C(5+1, 2)的情况,还要再加上全部为负的情况
![](https://i-blog.csdnimg.cn/blog_migrate/b4dc12156211b1d7b534eeeb2629b0d8.png)
从5个点推扩到n个点:
![](https://i-blog.csdnimg.cn/blog_migrate/a8c6d63cecd4639f13a3fd03131d08a8.png)
Negative Intervals
紫色的线段,代表negative interval
![](https://i-blog.csdnimg.cn/blog_migrate/202bf70e8fe2085a45e1859027a1b4d1.png)
其成长函数与postive interval 同:
![](https://i-blog.csdnimg.cn/blog_migrate/68c48e7d72b6c26f48de6c96ea6b7319.png)
我们设Positive Intervals的hypothesis set设为PI,Negative Intervals的hypothesis set设为NI。于是,求Positive and Negative Intervals的hypothesis set就是两个集合的联集。求它的成长函数,就是删除重覆的部份,如下图:
![](https://i-blog.csdnimg.cn/blog_migrate/86f5b07f44231cfc15ab1ba56fc5b51b.png)
接下来,开始思考如何删除重覆的部份。我们拿3个点观察postivie and negative intervals的hypothesis set长什么样子:
![](https://i-blog.csdnimg.cn/blog_migrate/2c57ef90c1ddad9197deafd37b931dab.png)
我们发现,灰色的线所连接的,代表重覆的hypothesis。这里重覆的有6个。进一步观察,这6个重覆的,有什么规律可寻,我们从PI对NI重覆的,列举如下:
![](https://i-blog.csdnimg.cn/blog_migrate/44f430ccea0bffa8ba99d7e8a26a87eb.png)
所以重覆的部份为2n,故我们推算,positive and negative intervals的成长函数如下:
![](https://i-blog.csdnimg.cn/blog_migrate/a5b42e5408db7a134b6ff0a0410e4990.png)
- Count