Akinator 应用程序通过问几个问题就能猜出一个角色,这总是让我感到惊讶。所以我想知道什么样的算法或方法让它做到这一点?有没有这类算法的名称,我在哪里可以阅读更多关于它们的信息?
7 回答
这个游戏有时被称为20 Questions。关于它有一些关于SO的问题,例如:
算法的主要特点:
- 自学
- 错误放纵
- 下一题智能系统选择
Akinator 博弈算法模型被称为“基于模糊逻辑的专家系统”。
这不是决策树,因为决策树没有容错性。
我前段时间在 C# 上写过一篇,你可以通过链接找到它:https ://github.com/ukushu/AkinatorEngine
您可以在 wiki 上阅读的其他信息:
我不知道 Akinator 到底使用什么算法,但在这里我已经开源了一个实现相同效果的算法:https ://github.com/srogatch/ProbQA
基本上我们使用N(Questions)
乘以N(Answer Options)
时间的立方体N(Targets)
,请参阅https://github.com/srogatch/ProbQA/blob/master/ProbQA/PqaCore/CpuEngine.decl.h。
我们通过应用具有独立性假设的贝叶斯公式来训练立方体,请参阅https://github.com/srogatch/ProbQA/blob/master/ProbQA/PqaCore/CEEvalQsSubtaskConsider.cpp
由于代码针对 AVX2 和多线程进行了高度优化,因此可能难以阅读。阅读相同的 CUDA 代码可能更容易:https ://github.com/srogatch/ProbQA/blob/master/ProbQA/PqaCore/CudaEngineGpu.cu
该算法的应用程序也可用作推荐游戏的网站。
我认为这就像一个专家系统,具有 B-Tree 结构。
我有一个小项目来建立一个“找到你的品味”的动态测验,我想与你分享:
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 使用更多的二叉树。所以,根节点是第一个问题。这是内在和内在的。很可能,Akinator 还会获取您所在的位置并链接问题。我开发了自己的 Akinator,名为 Ankusha。我使用了模式匹配算法。说 Ankusha 的工作方式非常复杂。您可以从此 github 链接获取源代码。 Ankusha-The Mind Reader Ankusha 在五个问题内完成了猜想。他向你证实了他猜到的电影。如果您单击“否”,则会询问接下来的五个问题。此迭代持续到 21 个问题。它是一个 Python 3.7 程序,需要强制安装 PIL 和 pygame 模块。请尝试一下。
注意:确保在继续安装应用程序之前阅读文件 README.md。所有许可证均在 GNU GPLv3(GNU 通用公共许可证版本 3.0)下完成。