首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Unity 2017中使用微软Infer.net

如何在Unity 2017中使用微软Infer.net
EN

Stack Overflow用户
提问于 2017-12-11 07:51:37
回答 1查看 79关注 0票数 0

我使用的是Unity 2017.2。Infer.Net框架需要Unity4.0,并且.NET只能使用面向.NET 3.5的程序集。我该怎么做?

EN

回答 1

Stack Overflow用户

发布于 2017-12-11 07:51:37

在Unity 2017.2中,您可以转到:

编辑->项目设置-> Player ->其他设置-> Configuration -> API兼容级别

并切换到“实验.NET 4.6”。

这是你的测试代码:

代码语言:javascript
复制
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using System;
using System.Text;
using MicrosoftResearch.Infer.Models;
using MicrosoftResearch.Infer;

public class TestInferNet : MonoBehaviour {

    // Use this for initialization
    void Start () {

        Debug.Log("Start Infer.net");

        Variable<bool> firstCoin = Variable.Bernoulli(0.5).Named("firstCoin");
        Variable<bool> secondCoin = Variable.Bernoulli(0.5).Named("secondCoin");
        Variable<bool> bothHeads  = (firstCoin & secondCoin).Named("bothHeads");

        InferenceEngine ie = new InferenceEngine();

        if (!(ie.Algorithm is VariationalMessagePassing))
        {
            Debug.Log("Probability both coins are heads: "+ie.Infer(bothHeads));
            bothHeads.ObservedValue=false;
            Debug.Log("Probability distribution over firstCoin: " + ie.Infer(firstCoin));
        }
        else
            Debug.Log("This example does not run with Variational Message Passing");

        Debug.Log("Done start");

    }

    // Update is called once per frame
    void Update () {

    }
} 

您只需要将Infer.Compiler.dll和FSharp.Core 4.3.0添加到Unity的Assembly-CSharp项目中。对于FSharp程序集,请在Visual Studio中安装F#语言包。然后从以下位置复制程序集:

代码语言:javascript
复制
C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.0.0

添加到您的Assets文件夹,并在C#项目中引用它。将上面的脚本添加到您选择的游戏对象中。

检查Unity中的控制台,查看上面程序的输出消息。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47744737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档