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 na
I think this is like an expert system, with B-Tree structure.
Main characteristics of algorithm:
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
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>
Akinator uses more of binary trees. So, the root node is the first question. This goes on inner and inner. Probably, Akinator also gets the location where you are and links the questions. I have developed my own Akinator named as Ankusha. I have used a pattern matching algorithm. It's quite complicated to say the way Ankusha works. You can get the source code from this github link. Ankusha-The Mind Reader Ankusha finishes the guess within five questions. He confirms the movie he guessed with you. If you click on 'No', next five questions are asked. This iteration continues up to twenty one questions. It is a Python 3.7 program, which requires the PIL and pygame module to be installed compulsorily. Please do try it out.
NOTE: Make sure that you read the file README.md before proceeding with the installation of the app. All licences are done under the GNU GPLv3 (GNU General Public Licence version 3.0).
This game is sometimes known as 20 Questions. There are some questions on SO on it, e.g.:
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.