Learning from the basics Artificial intelligence textbook Chapter 4 Chapter end problems

Introduction

As a study of machine learning, I am reading "* Learning from the basics: Artificial intelligence textbook *".

The feature of this book is that the end-of-chapter problem contains a simple program of Python.

Here, it is copied with Ruby.

Chapter 4 End of Chapter Problem

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 "Handles the question "Is A a B?" Please enter A and B"
  print "Enter A:"
  a = gets.chomp
  print "Enter B:"
  b = gets.chomp
  puts "Question: "#{a}Is#{b}Is it? ""
  puts "Start inference"
  if semnet[a].nil?
    puts "「#{a}"I do not know"
    next
  end
  obj = a
  while obj != b
    puts "#{obj}Is#{semnet[obj]}is"
    if semnet[obj] == b
      puts "Conclusion:#{a}Is#{b}is"
      break
    end
    unless semnet.keys.include?(semnet[obj])
      puts "Conclusion:#{a}Is#{b}でIsありません"
      break
    end
    obj = semnet[obj]
  end
  puts "Inference end"
end

It is a problem to implement inference using ʻis-a link` which is one of the links in the semantic network.

is-a - wikipedia

python works well with Japanese input, but it didn't work with ruby, so I changed it to English words.

Handles the question "Is A a B?" Please enter A and B
Enter A: smartphone
Enter B: computer
Question: "Is your smartphone a computer?"
Start inference
smartphone is a portable terminal
portable terminal is computer
Conclusion: smartphone is computer
Inference end

Summary

Recommended Posts

Learning from the basics Artificial intelligence textbook Chapter 4 Chapter end problems
Learning from the basics Artificial intelligence textbook Chapter 5 Chapter end problems
Learning from the basics Artificial intelligence textbook Chapter 2 Chapter end problems
Learning from the basics Artificial intelligence textbook Chapter 3 End-of-chapter problems
Othello ~ From the tic-tac-toe of "Implementation Deep Learning" (4) [End]
Pip the machine learning library from one end (Ubuntu)
Deep Learning from the mathematical basics Part 2 (during attendance)
Creating artificial intelligence by machine learning using TensorFlow from zero knowledge-Introduction 1
Deep Learning / Deep Learning from Zero Chapter 5 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 7 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 3 Memo
Deep Learning / Deep Learning from Zero Chapter 4 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 4 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 6 Memo
From the beginning of the basics of gcc
Deep Learning / Deep Learning from Zero 2 Chapter 8 Memo
Deep Learning / Deep Learning from Zero Chapter 3 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 5 Memo
Python learning memo for machine learning by Chainer until the end of Chapter 2
[Challenge CircleCI from 0] Learn the basics of CircleCI
[Learning memo] Deep Learning made from scratch [Chapter 5]
Deep learning / Deep learning made from scratch Chapter 6 Memo
[Learning memo] Deep Learning made from scratch [Chapter 7]
[Learning memo] Deep Learning made from scratch [Chapter 6]
Deep learning / Deep learning made from scratch Chapter 7 Memo
[Ruby] From the basics to the inject method
Deep Learning Java from scratch Chapter 2 Perceptron
Learning notes from the beginning of Python 1
Deep Learning from mathematical basics (during attendance)
Learning notes from the beginning of Python 2
Deep Learning Java from scratch Chapter 1 Introduction
Deep Learning from scratch The theory and implementation of deep learning learned with Python Chapter 3
Deep Learning from scratch Java Chapter 4 Neural network learning
Deep Learning Java from scratch Chapter 3 Neural networks
Python Machine Learning Programming Chapter 1 Gives Computers the Ability to Learn from Data Summary
Deep Learning from scratch ① Chapter 6 "Techniques related to learning"
Deep Learning from scratch Chapter 2 Perceptron (reading memo)
A fledgling engineer learned JUnit from the basics
"Deep Learning from scratch" Self-study memo (Part 8) I drew the graph in Chapter 6 with matplotlib
Chapter 2 Implementation of Perceptron Cut out only the good points of deep learning made from scratch
Chapter 3 Neural Network Cut out only the good points of deep learning made from scratch
"Deep Learning from scratch" Self-study memo (No. 14) Run the program in Chapter 4 on Google Colaboratory
Artificial intelligence, machine learning, deep learning to implement and understand
Python learning memo for machine learning by Chainer from Chapter 2
Can artificial intelligence predict the price of Yu-Gi-Oh! Cards?
Try to solve the problems / problems of "Matrix Programmer" (Chapter 1)
[Deep Learning from scratch] I implemented the Affine layer
Unsupervised learning 1 Basics
Chapter 1 Introduction to Python Cut out only the good points of deep learning made from scratch
[Part 2] Use Deep Learning to forecast the weather from weather images
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 1
[Java] Delete the specified number of characters from the end of StringBuilder
An amateur stumbled in Deep Learning from scratch Note: Chapter 6
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 4
[Introduction to matplotlib] Read the end time from COVID-19 data ♬
Deep Learning Java from scratch Chapter 5 Error back propagation method
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 2
[Part 1] Use Deep Learning to forecast the weather from weather images
An amateur stumbled in Deep Learning from scratch Note: Chapter 2
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 5
Try to solve the problems / problems of "Matrix Programmer" (Chapter 0 Functions)