SlideShare una empresa de Scribd logo
1 de 21
ストリームアルゴリズム
超入門
makoto.kataigi
参考文献
オンラインアルゴリズムとストリームアルゴリズム
- https://www.amazon.co.jp/dp/4320121716
Streaming algorithm
- https://en.wikipedia.org/wiki/Streaming_algorithm
PLAID Tech Blog
- https://tech.plaid.co.jp/streaming-algorithm/
目標
ストリームアルゴリズムって、
簡単な計算も難しいんだな、
ってのを理解する
オンラインアルゴリズムとは
不確定な「未来」にわたる決定をするアルゴリズム
現在
わかっている情報 わからない情報
オンラインアルゴリズム例
スノボを買うか問題
レンタル1回5,000円、板を買うなら50,000円
今シーズンは1月、2月、3月に行った
買うべきか、レンタルを続けるべきか?
ストリームアルゴリズムとは
オンラインアルゴリズム + メモリに乗り切らないデータ
決定版みたいなアルゴリズムはなく、データ依存になる部分が多い
レンタル1回5,000円、板を買うなら50,000円
過去3回行ったことがある
買うべきか、レンタルを続けるべきか?
最大値
頻出データ
データの種類数
window計算
タスク
タスク1:最大値
今までの最大値は何か?
10 15 8 14 10 20 14 18
・・・
6
問題
現在
チャンピオンアルゴリズム
今までの最大値と現在の値を比較
- 現在の値の方が大きい場合、最大値を入れ替え
ストリームアルゴリズムでも正確に計算できる
Max: 20
ポイント
10 15 8 14 10 20 14 18
・・・
6
アルゴリズム
現在
タスク2:頻出データ
過去のデータで、「一定割合」以上出現したデータを抽出したい
正確に求める方法はないため、近似になる
=> 近似率(=誤差率ε)がパラメータになる
a b a a c a a d d a d e f d
ポイント
・・・
問題 現在
Lossy Counting
1/ε個ごとのbucketに分割し、各bucketに1回以上出現するもののみカウントする
bucket Nの要素Eに対して、<E, 出現回数,許容誤差>を保持
許容誤差 = 過去出現した可能性のある回数 = bucket番号-1
- eが存在する : <E, 回数+1, 許容誤差>
- eが存在しない : <E, 1, N-1>
bucket切り替え時 : 回数 + n < N の要素を削除
アルゴリズム
a b a a c a a d d a d e f d
bucket1 bucket2 bucket4bucket3 bucket5
・・・
アイデア
現在
Lossy Counting
bucket3での挙動
a b a a c a a d d a d e f d
bucket1 bucket2 bucket4bucket3 bucket5
・・・
a 4 0
b deleted
c 1 1
a 5 0
b deleted
c 1 1
a 5 0
b deleted
c 1 1
a 4 0
b deleted
c 1 1
a 4 0
b deleted
c 1 1
a d d
d 1 2 d 2 2
bucket
切り替え
d 2 2
すでにある要素
= 回数+1
無い要素なら追加
<要素, 1(回数), N-1>
回数+誤差 < N の要素を削除
= 1bucketに平均1回以上出
現してないもの
KSPアルゴリズム
<E, 出現回数, 許容誤差> の代わりに、
<E, 出現回数 - 許容誤差> を保持する
アイデア
タスク3:種類数カウント
出現するデータの種類は何種類あるか
a b a a c a a d d a d e f d
・・・
問題 現在
ハッシュ関数を用いた近似カウント
ハッシュ関数でbucket分散させて、特定のbucketだけカウントする
a
hash(E) / 4 = 0 hash(E) / 4 = 1 hash(E) / 4 = 2 hash(E) / 4 = 3
b
c
f
d
e
ここだけカウント
a b a a c a a d d a d e f d
・・・
アイデア
ダブリング法
分割数が少ないと、メモリが溢れる ⇔ 分割数が多いと、誤差が大きくなる
a
hash(E) % 4 = 0 hash(E) % 4 = 1
b
c
a b
c
d
a b
c f
d
e
hash(E) % 2 = 0 hash(E) % 2 = 1
hash(E) % 1 = 0
課題
ウィンドウ関数
fixed window
sliding window
例)日次、週次
7/1 7/2 7/3
7/4 7/5 7/6
7/7 7/8 7/9
7/1 7/2 7/3 7/4 7/5 7/6
7/2 7/3 7/4 7/5 7/6 7/7
7/3 7/4 7/5 7/6 7/7 7/8 例)直近1週間
タスク4:sliding windowの最大値
今までの最大値は何か?
windowXの最大値は20
windowYの最大値は?18?19があったかもしれない
10 15 8 14 10 20 14 18
windowX
windowY
・・・
6
問題
ポイント
現在
sliding window 最大値アルゴリズム
自分より古いものが全て消えた時に最大値になる可能性があるものを残す
<時間, 値>のリストを次のルールで保持する
- 新しく値Xの要素がくる => リストの中でX以下の要素を全て削除して
<current, X> を最後尾に追加
- windowがスライド => 外れた時間の要素を削除
10 15 8 14 10 20 14 18
・・・
6
アルゴリズム
アイデア 現在
sliding window 最大値アルゴリズム
10 15 8 14 10 20 14 18
window1
window2
・・・
6
window3
15 8 14 10
window1
window2
window3
15 8 14 10 20
15 8 14 10 20 6
現在
さらに省メモリ化
X以下を削除 の部分を X+誤差ε以下のものを削除 にする
誤差ε以内の差の要素は保存しなくなる
アイデア
まとめ
ストリームアルゴリズムでは単純な計算もむずかしい

Más contenido relacionado

Destacado

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

202007勉強会資料 ストリームアルゴリズム