So here's a typical group of friends in middle
school. And some of the people are popular, some of
them might not be. The first step to deciding
who's popular, is looking at who has a lot of
friends. So let's draw in some links, that show
who's a friend. And friendship links are one directional. Just
because Alice's friends with Bob, doesn't mean that Bob
is friend with Alice. So we'll draw our links as
arrows, so this means this person, we'll call him Bob, is
friends with Alice. And let's say, Alice
has many friends. And let's say Bob is also friends with
this person, they're friends with each other.
We have lots of friendship links. Some
of them are bi-directional but not all of them. So, we have lots of friendships.
So, is this enough to decide who's popular. So, if you
went to a school like I did, it's not. Just having a
lot of friends is not enough to make you popular, you
have to have the right friends. You have to be friends with
the popular people. So, it's not enough to have lots of
geeky friends say in high school, you've gotta have lots of friends
that are popular. So that means the definition of popular, isn't
just about having lots of friends, it's about having lots of friends,
who also have lots of friends. That's what
make some one popular, so we can define
popularity of a person is the number of
people who are friends with p. This means
the number of links from someone else to
that person is their popularity score. So here
is Charlie, so there are one, two, three
links into Charlie, so Charlie's popularity score would
be three. Alice also has three links, so her
popularity score would also be three. Bob only has one
arrow going to Bob, so his popularity score would be
one. So, this isn't a bad way to define popularity,
but it's not quite right. So, the definition of popularity
doesn't just depend on the number of friends you have,
it depends on, both, the number, and the popularity of
your friends. So, we can change the definition. Let's instead
define the popularity score of a person p. Now
it's going to be the sum of the popularities of
all of their friends. So we can write that in
a mathematical way, so using the sigma means to sum
up. We're going to take each friend, that is in
the friends of p. And we're going to sum up the
popularity score of the friends. If the mathematical notation is
unfamiliar to you, we could also write this as pseudo
Python code. We're thinking of the popularity of
a person p. Let's assume we have a
function that gives us the friends. So we're
going to start with a score of zero. We're going to
loop through the friends. And for each friend,
we're going to add to p score, the popularity score
of the friend. And we'll return the score
as the result. So now, you've seen a mathematical
definition of popularity, you've seen the same thing as code. I'm going to ask
you a very important quiz question next. Its an easy one to get
right if you try it twice because there's only two answers, but think
about it carefully. See if you can get it right the first time.
中学校でよく見られるグループがあります
人気者もいればそうでない人もいます
誰が人気者であるのかを決める最初のステップは
誰が多くの友達を持っているかということです
リンクを貼り友達を教えましょう
友情のリンクは一方通行です
アリスがボブの友達だからといって
ボブがアリスの友達というわけではないのです
認められたならばリンクを貼ります
これはボブと呼ばれる人が
アリスの友達であることを意味します
例えばアリスには多くの友達がいるとします
そしてボブはこの人の友達でもあり
彼らはお互いに友人同士です
多くの友情リンクがあります
中には双方向のものもありますが
すべてがそうであるわけではありません
そのため多くの友情があるのです
それではこれで人気者を決めるには十分でしょうか?
あなたが学校に行ったことがあれば
そうではないと分かるでしょう
単に友達が多いからといって
あなたが人気者になるわけではありません
正しい友達を持たなければなりません
人気者と友達になる必要があります
学校でオタク系の友人がたくさんいても
それでは十分ではありません
人気者である友人が必要です
人気があるということは
単に友人が多いという意味ではありません
すでに多くの友人を持つ人を
友人にすることです
これがある者を人気者にする方法です
ですから人気者の定義は
pの友人の数により決定できます
これは人から人へのリンク数が
人気度であることを意味します
ここにチャーリーがいます
チャーリーには3つのリンクがあります
この場合彼の人気度は3となります
アリスには3つのリンクがあるので
彼女の人気度も3です
ボブはわずか1つのリンクしか持っていません
ですから彼の人気度は1です
これは人気度を決定するには
悪い方法ではありませんが
あまり正しくはありません
つまり人気度の判定は
友人の数だけで決まるのではないのです
それは数とそして友人の人気により決定されます
ですから定義を変更します
代わりにpという人物の人気度を定義しましょう
友人すべての人気度の合計です
数学的な方法で書くことができますので
シグマを合計とします
各友人を取り上げます
つまりpの友人です
そして友人の人気度を合計しようとしています
数学的記法に馴染みがなければ
疑似Pythonコードで書くこともできます
pの人気度を考えています
私たちには友人を与えてくれる機能があるとします
まずscore = 0から開始します
友達の輪の中に入っていきます
各友人の名前pを加えます
これは友人の人気度で
そして結果として人気度を戻します
人気度を数学的に定義しました
コードでも同じものを記載しました
次回非常に重要な小テストを行います
2回行えば簡単に解けるでしょう
なぜなら正解は2つしかないからです
じっくり考えてください
1回目で正解が出せるようやってみましょう
Вот обычная компания друзей в средней
школе. И некоторые из школьников
популярные,некоторые
могут и не быть. Первый шаг к определению
кто популярный, посмотреть у кого много
друзей. Так что давайте нарисуем несколько
линий, которые покажут
这里是一组典型的中学朋友。
有些人非常受欢迎,有些可能
不受欢迎
第一步是决定谁受欢迎,是寻找谁有一些朋友
因此让我们画一些连接,这里显示了谁
的朋友。以及朋友关系是一个方向的。
就因为爱丽丝的朋友是鲍勃,并不意味着鲍勃
的朋友是爱丽丝。因此我们画出箭头的联系,
这个意味着这个人,我们叫他鲍勃是爱丽丝
的朋友。让我们说爱丽丝有许多
朋友。让我们说鲍勃也是
这个人的一个朋友,他们互相交朋友。
我们有许多朋友线,有些是
双向的,但是并不是所有的都是。因此,我们有一些友谊。
因此,这足够来确定谁更受欢迎。因此,假设你想要去
一家学校,像我一样,并不是,仅仅有一群朋友就可以
让你变得受欢迎,你必须有
正确的朋友。你必须有
受欢迎的朋友。因此在高中有许多奇怪的
朋友并不足够。你一定要有大量的受
欢迎的朋友。因此定义受欢迎,并不仅仅
是有许多朋友,而是有许多他们也有许多朋友的朋友 。
这是让人受欢迎,因此我们定义
一个人受欢迎的程度是一个代表一群人都和P
交朋友。这意味着
从其它人那里来的连线数目到这个人是
他们的受欢迎程度分数。因此
这是查理斯,而这里有一个,两个,三个
线路连接查理斯,因此查理斯的受欢迎程度是三。
爱丽丝也有三条线,因此
她的受欢迎程度也是三。鲍勃仅仅有一条
线连着,他的受欢迎程度就只是一了。
因此
这不是一个定义受欢迎程度的坏方式。
但是并不准确。因此定义受欢迎程度,并不取决于你
有多少数量的朋友。
它取决于,两者,数量,以及你朋友受欢迎的程度。
因此,你可以改变这个定义,让我们定义
一个人受欢迎程度的分数P。现在
我们要把他们所有朋友的受欢迎程度加起来。
因此我们可以写下一个数学式子,
用SIGM意味着加起来。
我们将会把每一个朋友,就是
P的朋友。我们将要把他们累加起来计算受欢迎
成都,数学符号是对你
不熟悉的的,我们将会写下这个 伪
python编码。我们在思考一个人的受欢迎程度
P。让我们假设我们有一个
关于朋友的公式。因此我们
将会
通过朋友循环。对于每一个朋友,我们
将会增加到P分数,受朋友欢迎分数。
我们把数值返回作为
结果。现在,我们看到了一个数学
定义受欢迎程度,我们在编程中也看到了相同的事情 。我将会接下来问你一个
重要的测试问题。如果尝试两次比较容易做对,
因为仅仅有两个答案,但是
仔细考虑,看是不是能够第一次答对。