我是一个爱上F#的数学家。 .NET程序集使我感到悲痛。我不明白他们是如何纠缠和解决的。因此,我尝试运行an example from Infer.Net,并尝试将其转换为脚本时,在Visual Studio 2017中将其运行到FSI中时遇到以下错误:
Binding session to 'C:\Users\jdks\.nuget\packages\system.codedom\4.4.0\lib\netstandard2.0\System.CodeDom.dll'...
> System.PlatformNotSupportedException: Current platform is not supported by the current compiler choice Auto. Try a different one. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames)
at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.CompileWithCodeDom(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.Compile(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
--- End of inner exception stack trace ---
at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.Compile(List`1 filenames, List`1 sources, ICollection`1 referencedAssemblies)
at Microsoft.ML.Probabilistic.Compiler.CodeCompiler.WriteAndCompile(List`1 typeDeclarations)
at Microsoft.ML.Probabilistic.Compiler.ModelCompiler.CompileWithoutParams[T](List`1 itds)
at Microsoft.ML.Probabilistic.Models.InferenceEngine.Compile()
at Microsoft.ML.Probabilistic.Models.InferenceEngine.GetCompiledInferenceAlgorithm(Boolean inferOnlySpecifiedVars, IVariable var)
at Microsoft.ML.Probabilistic.Models.InferenceEngine.Infer[TReturn](IVariable var)
at <StartupCode$FSI_0003>.$FSI_0003.main@() in C:\Temp\Script1.fsx:line 24
Stopped due to error
这是脚本:
#r "netstandard.dll"
#r @"C:\Users\jdks\.nuget\packages\system.codedom\4.4.0\lib\netstandard2.0\System.CodeDom.dll"
#r @"C:\Users\jdks\.nuget\packages\microsoft.ml.probabilistic\0.3.1810.501\lib\netstandard2.0\Microsoft.ML.Probabilistic.dll"
#r @"C:\Users\jdks\.nuget\packages\microsoft.ml.probabilistic.compiler\0.3.1810.501\lib\netstandard2.0\Microsoft.ML.Probabilistic.Compiler.dll"
#r @"C:\Users\jdks\.nuget\packages\microsoft.ml.probabilistic.learners\0.3.1810.501\lib\netstandard2.0\Microsoft.ML.Probabilistic.Learners.dll"
#r @"C:\Users\jdks\.nuget\packages\microsoft.ml.probabilistic.visualizers.windows\0.3.1810.501\lib\net461\Microsoft.ML.Probabilistic.Compiler.Visualizers.Windows.dll"
#r @"C:\Users\jdks\Proto\infer-master\src\FSharpWrapper\bin\Debug\netstandard2.0\Microsoft.ML.Probabilistic.FSharp.dll"
open System
open Microsoft.ML.Probabilistic
open Microsoft.ML.Probabilistic.Distributions
open Microsoft.ML.Probabilistic.Models
let firstCoin = Variable.Bernoulli(0.5)
let secondCoin = Variable.Bernoulli(0.5)
let bothHeads = firstCoin &&& secondCoin
let engine = new InferenceEngine()
// this is the line that fails
let bothHeadsPost = engine.Infer<Bernoulli>(bothHeads)
printfn "Both heads posterior = %A" bothHeadsPost
bothHeads.ObservedValue <- false
如您所见,我为Infer.Net使用了nuget包,但下载了git repo并对其进行编译以获得FSharpWrapper.dll
。既然可以编译,我的猜测是该问题与程序集有关,但是还没有解决问题的第一要领。我应该在这里做什么?
相关信息:
-From the Infer.Net github repo:这些核心程序包以.NET Standard 2.0为目标,因此可以在以.NET Framework 4.6.1或.NET Core 2.1为目标的任何项目中使用。
奖金问题:
说Binding session to ...
是什么意思?我在Expert F#4.0或在线中找不到任何好的信息,它看起来可疑。
答案 0 :(得分:2)
有两个原因:
netstandard2.0
和net461
,这将解决此类问题。我建议将此软件包与您运行的.NET Core控制台应用程序一起使用(手动或通过dotnet-watch-run
工具)。