It always amazed me how the Akinator app could guess a character by asking just several questions. So I wonder what kind of algorithm or method let it do that? Is there a name for that class of algorithms and where can I read more about them?
问题:
回答1:
Yes, there is a name for these class of algorithms - it is called classification algorithms in the field of machine learning. Decision trees is one example for classification algorithm.
In this classification problem, the features for the algorithm are the answers to the question.
Deciding which question should be asked next can be done in various ways - for example by trying to maximize the predicted (or mean) entropy from the next question.
回答2:
This game is sometimes known as 20 Questions. There are some questions on SO on it, e.g.:
- How do 20 questions AI algorithms work?
- Designing a twenty questions algorithm
- the akinator is running with a database?
回答3:
Main characteristics of algorithm:
- Self-educating
- Mistakes-indulgence
- Intelligent system of next question choose
Akinator game algorithm model is called "Expert system based on Fuzzy logic".
And this is NOT Decision trees, because it's have no mistakes-indulgence.
I had wrote one some time ago on C#, you can find it by link: https://github.com/ukushu/AkinatorEngine
回答4:
I don't know what exactly algorithm Akinator uses, but here I have put open-source an algorithm that achieves the same effect: https://github.com/srogatch/ProbQA
Basically we use a cube of N(Questions)
times N(Answer Options)
times N(Targets)
, see https://github.com/srogatch/ProbQA/blob/master/ProbQA/PqaCore/CpuEngine.decl.h .
We train the cube by applying Bayesian formula with independence assumption, see https://github.com/srogatch/ProbQA/blob/master/ProbQA/PqaCore/CEEvalQsSubtaskConsider.cpp
Because the code is highly optimized for AVX2 and multi-threading, it may be hard to read. It may be easier to read the CUDA code for the same: https://github.com/srogatch/ProbQA/blob/master/ProbQA/PqaCore/CudaEngineGpu.cu
An application of this algorithm is also available as a website to recommend a game.
回答5:
I think this is like an expert system, with B-Tree structure.
回答6:
i have a small project to build a dynamic quiz for 'find your taste' and i want to share it with you :
const quizData =
{
"title": "Quiz about Foo", "questions": [
{ "text": "Tea or Coffee ?", "answers": [["Coffee","coffee"], ["Tea","tea"]] },
{ "text": "What type of coffee do you like ?", "parentanswer": "coffee", "answers": [["Arabic","arabic_coffee"], ["Turkish","turkish-coffee"], ["Espresso","espresso-coffee"], ["Black","black-coffee"]] },
{ "text": "What type of tea do you like ?", "parentanswer": "tea", "answers": [["Green","green-tea"], ["Red","red-tea"], ["Earl","earl-tea"]] },
{ "text": "Do you like it stronge ?", "parentanswer": "black-coffee", "answers": [["Yes","stronge-coffee"], ["No","notstronge-coffee"]] },
{ "text": "Do you like it light ?", "parentanswer": "stronge-coffee", "answers": [["Yes","light-coffee"], ["No","notlight-coffee"]] },
],
"products":[
{ "name": "Japanese Green Tea" , "characteristic": "tea,green-tea"},
{"name":"Organic Sencha Green Tea" , "characteristic": "tea,green-tea"},
{"name":"Yogi Tea" , "characteristic": "tea,green-tea"},
{"name":"South African Rooibos" , "characteristic": "tea,red-tea"},
{"name":"Lipton" , "characteristic": "tea,red-tea"},
{"name":"Alrifai" , "characteristic": "coffee,arabic-coffee"},
{"name":"Baja" , "characteristic": "coffee,arabic-coffee"},
{"name":"Tim Hortons" , "characteristic": "coffee,black-coffee,stronge-coffee"},
{"name":"Starbucks" , "characteristic": "coffee,black-coffee,light-coffee"},
{"name":"Espresso Craft Blend" , "characteristic": "coffee, espresso-coffee"},
{"name":"Baja" , "characteristic": "coffee, turkish-coffee"},
]
};
Vue.component('question', {
template: `
<div v-if="question" class=" m-2" >
<h3 class="text-primary">Find your taste</h3> <br/>
<h4>Question {{ questionNumber }} :</h4><br/>
<h3 class="text-primary">{{ question.text }} </h3> <br/>
<div @change="submitAnswer" class=" btn-group-toggle" >
<label class="btn btn-outline-primary m-2" v-for="(mcanswer,index) in question.answers" >
<input :value="mcanswer" type="radio" name="currentQuestion" :id="'answer'+index" v-model="answer" > {{mcanswer[0]}}
</label>
</div>
</div>
`,
data() {
return {
answer: ''
}
},
props: ['question', 'question-number'],
methods: {
submitAnswer: function (e) {
app.handleAnswer(this);
}
},
});
const app = new Vue({
el: '#quiz',
data() {
return {
resultsStage: false,
title: '',
questions: [],
products:[],
currentQuestion: 0,
answers: [],
correct: 0,
result: '',
counter: 0
}
},
created() {
this.title = quizData.title;
this.questions = quizData.questions;
this.products = quizData.products;
},
methods: {
handleAnswer(e) {
this.answers[this.currentQuestion] = e.answer[0];
var i ;
for(i=0; this.currentQuestion < this.questions.length; i++)
{
//find child question for selected answer
if(typeof(this.questions[i].parentanswer)!='undefined')
{
if(e.answer[1] === this.questions[i].parentanswer)
{
this.result += e.answer[1] + ',';
this.currentQuestion=i;
this.counter++;
break;
}
}
//no child for this question => end of quiz
if(i+1 == this.questions.length)
{
this.result += e.answer[1];
this.handleResults();
this.resultsStage = true;
break;
}
}
},
handleResults() {
// window.location.href = "http://hadict.com"+this.result + "/?sl=ar";
var i ;
var hasResult=false;
for(i=0; i < this.products.length; i++)
{
if( this.products[i].characteristic==this.result)
{
this.result = this.products[i].name;
hasResult=true;
break;
}
}
if(!hasResult)
{
this.result="no result";
}
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="quiz">
<div v-if="!resultsStage">
<question :question="questions[currentQuestion]" :question-number="counter+1"></question>
</div>
<div v-if="resultsStage">
<div
style="justify-content: space-between;display: flex;flex-direction: column;align-items: center;margin: 10px;">
<h3 class="text-primary">Done</h3>
<h3 class="text-primary">Your best drink is : </h3>
<h3 class="text-primary">{{result}}</h3>
</div>
</div>
</div>