我正在尝试在 Python 3.6中使用 infer.net ( https://dotnet.github.io/infer/ )。为此,我安装了 pythonnet 包,并下载了我需要使用 infer.net 的 dll 文件。文件/包的导入,新类型的使用正在工作,但是当我试图推断一个基本模型时,我得到了一个 PlatformNotSupportedException 并且我不知道如何处理这种错误。有人可以帮助我吗?我在这里使用 Jupyter Notebook 这是我使用的代码。
import clr
import System
import numpy as np
from System import Console
from System import Array
from System import IO
from System import Array, Double, Type
clr.AddReference("Microsoft.ML.Probabilistic")
clr.AddReference("Microsoft.ML.Probabilistic.Compiler")
clr.AddReference("Microsoft.ML.Probabilistic.Learners")
clr.AddReference("System.CodeDom")
#---------import all classes and methods from above namespaces-----------
from Microsoft.ML.Probabilistic.Distributions import *
from Microsoft.ML.Probabilistic.Models import *
from Microsoft.ML.Probabilistic.Collections import *
from Microsoft.ML.Probabilistic.Factors import *
from Microsoft.ML.Probabilistic.Math import *
from Microsoft.ML.Probabilistic.Models import Variable, VariableArray, Range, InferenceEngine
from Microsoft.ML.Probabilistic.Distributions import Gaussian, Gamma
len = Variable.New[int]()
dataRange = Range(len)
x = Variable.Array[float](dataRange)
mean = Variable.GaussianFromMeanAndVariance(0.0, 100.0).Named('mean')
precision = Variable.GammaFromShapeAndScale(1.0, 1.0).Named('precision')
x.set_Item(dataRange,
Variable.GaussianFromMeanAndPrecision(mean,
precision).ForEach(dataRange))
data = [] # System.Array.CreateInstance(float, 100)
for i in range(0, 100):
data.append(np.random.normal(42, 1))
ie = InferenceEngine()
len.ObservedValue = 100
x.ObservedValue = data
engine = InferenceEngine()
engine.ModelName = 'Gaussian_priors'
engine.Infer(mean)
---------------------------------------------------------------------------
PlatformNotSupportedException Traceback (most recent call last)
PlatformNotSupportedException: L'opération n'est pas prise en charge sur cette plateforme.
à Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
à Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames)
à Microsoft.ML.Probabilistic.Compiler.CodeCompiler.CompileWithCodeDom(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
à Microsoft.ML.Probabilistic.Compiler.CodeCompiler.Compile(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
The above exception was the direct cause of the following exception:
PlatformNotSupportedException Traceback (most recent call last)
<ipython-input-1-c6ab7cf71833> in <module>()
47 engine.ModelName = 'Gaussian_priors'
48
---> 49 engine.Infer(mean)
PlatformNotSupportedException: Current platform is not supported by the current compiler choice Auto. Try a different one.
à Microsoft.ML.Probabilistic.Compiler.CodeCompiler.Compile(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
à Microsoft.ML.Probabilistic.Compiler.CodeCompiler.WriteAndCompile(List`1 typeDeclarations)
à Microsoft.ML.Probabilistic.Compiler.ModelCompiler.CompileWithoutParams[T](List`1 itds)
à Microsoft.ML.Probabilistic.Models.InferenceEngine.Compile()
à Microsoft.ML.Probabilistic.Models.InferenceEngine.GetCompiledInferenceAlgorithm(Boolean inferOnlySpecifiedVars, IVariable var)
à Microsoft.ML.Probabilistic.Models.InferenceEngine.Infer(IVariable var)