0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

基礎から学ぶ 人工知能の教科書 第4章 章末問題

Posted at

はじめに

機械学習の勉強として、「基礎から学ぶ 人工知能の教科書」 を読んでいます。

この本の特徴は、章末問題にPythonの簡単なプログラムが載っていてるところです。

ここでは、それをRubyにて写経しています。

第4章 章末問題

isa.rb
semnet = {"portable terminal"=>"computer",
          "laptop PC"=>"computer",
          "stationary PC"=>"computer",
          "smartphone"=>"portable terminal",
          "tablet"=>"portable terminal",
          "desktop PC"=>"stationary PC",
          "server PC"=>"stationary PC"}
while true
  puts "「AはBですか?」という質問を扱います。AとBを入力してください"
  print "Aを入力:"
  a = gets.chomp
  print "Bを入力:"
  b = gets.chomp
  puts "質問:「#{a}#{b}ですか?」"
  puts "推論を開始します"
  if semnet[a].nil?
    puts "「#{a}」がわかりません"
    next
  end
  obj = a
  while obj != b
    puts "#{obj}#{semnet[obj]}です"
    if semnet[obj] == b
      puts "結論:#{a}#{b}です"
      break
    end
    unless semnet.keys.include?(semnet[obj])
      puts "結論:#{a}#{b}ではありません"
      break
    end
    obj = semnet[obj]
  end
  puts "推論終了"
end

意味ネットワーク(semantic network)におけるリンクの一つであるis-aリンクを用いた推論を実装する問題です。

is-a - wikipedia

pythonは日本語入力でもうまくいくのですが、rubyではうまくいかなかったので英単語に変更しています。

「AはBですか?」という質問を扱います。AとBを入力してください
Aを入力:smartphone
Bを入力:computer
質問:「smartphoneはcomputerですか?」
推論を開始します
smartphoneはportable terminalです
portable terminalはcomputerです
結論:smartphoneはcomputerです
推論終了

まとめ

  • 第4章まで読んだ
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?