Skip to Content
学習アルゴリズム
book

学習アルゴリズム

by George Heineman
March 2025
Intermediate to advanced
280 pages
4h 16m
Japanese
O'Reilly Media, Inc.
Content preview from 学習アルゴリズム

第4章. 盛る

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

単に値のコレクションを格納するのではなく、エントリのコレクションを格納し、各エントリに値とそれに関連する優先度を数値で表すとしたらどうだろうか。 2つのエントリがあれば、優先順位が高い方が他よりも重要である。今回の課題は、新しい(値、優先度)エントリをコレクションに挿入し、最も優先度の高いエントリの値をコレクションから削除して戻せるようにすることだ。

この振る舞いは、enqueue(value, priority)dequeue() を効率的にサポートするデータ型であるプライオリティ・キューを定義しており、最も優先順位の高い値を削除する。プライオリティ・キューは、前章で説明したシンボル・テーブルとは異なり、最も優先順位の高い値の削除を要求する際に、事前に優先順位を知る必要がないからである。

混雑したナイトクラブが混雑しすぎると、図4-1のように外に人の列ができ る。 クラブに入ろうとする人が増えると、その人は列の最後尾で待たなければならな くなる。列から最初にナイトクラブに入るのは、最も長く待った人である。この振る舞いは、キュー抽象データ型の本質を表している。enqueue(value) の演算子は、value を追加してキューの最後にある最新の値にし、dequeue() はキューに残っている最も古いvalue を削除する。この経験を表現する別の方法は、"First in, first out"(FIFO)である。これは、"First [one] in [line is] first [taken] out [of line]"(最初に[行に]入ったものが、最初に[行から]取り出される)の略語である。

Patrons waiting in line at nightclub
図4-1. ナイトクラブでキューで待つ。

Node 前の章では、リンクリストのデータストアについて説明した。このデータストアを、キュー用のvalue

class Node:
  def __init__(self, val):
    self.value = val
    self.next = None

この構造を使用して、リスト4-1のQueue の実装では、リンクリストの末尾に値を追加するenqueue() 操作を行っている。図4-2は、"Joe"、"Jane"、"Jim "を(この順番で)ナイトクラブキューにエンキューした結果を示している。

"Joe "は最初の利用者からキューから外され、2人の利用者からなるキューとなり、"Jane ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

データサイエンスのための実践線形代数

データサイエンスのための実践線形代数

Mike X Cohen
データ分析によるネットワークセキュリティ

データ分析によるネットワークセキュリティ

Michael Collins, 中田 秀基, 木下 哲也

Publisher Resources

ISBN: 9798341626317