⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inference.bas

📁 用VB和MSBN实现线的一个贝叶斯网络的简单例子
💻 BAS
字号:
Attribute VB_Name = "Inference"

Option Explicit

' Inference: an Overview
Sub InferenceExample()
    
    Dim aMSBN As New MSBN3Lib.MSBN
    
    'Load the Auto model
    Dim modelAuto As MSBN3Lib.Model
    Set modelAuto = aMSBN.Models.Add("Auto", FileName:="auto.dsc", ErrorFilename:="loaderror.log")
     
    'Call the model's inference engine "inferAuto"
    Dim inferAuto As MSBN3Lib.Engine
    Set inferAuto = modelAuto.Engine
    
    ' Check a probability
    Debug.Print "The probability that the car will start is "
    Debug.Print inferAuto.Belief("EngineStart", "yes")
    Debug.Print
    
    
    
    ' Add some evidence and check some probabilities
    Debug.Print "Tell it that the car, in fact, doesn't start."
    inferAuto.Evidence.Add "EngineStart", "no"
    
    Debug.Print "The probability that the car will start is "
    Debug.Print inferAuto.Belief("EngineStart", "yes")
    Debug.Print "The probability that the battery is good is "
    Debug.Print inferAuto.Belief("Battery", "good")
    Debug.Print
    
    ' Add some more evidence and check some probabilities
    Debug.Print "Tell it the lights don't work"
    inferAuto.Evidence.Add "LightsShine", "don't work"
    Debug.Print "The probability that the battery is good is "
    Debug.Print inferAuto.Belief("Battery", "good")
    Debug.Print
    
    
    ' Change some evidence and check some probabilities
    Debug.Print "Tell it the lights do work"
    inferAuto.Evidence.Set "LightsShine", "work"
    Debug.Print "The probability that the battery is good is "
    Debug.Print inferAuto.Belief("Battery", "good")
    Debug.Print

    'For every node and every state, show the probability
    Dim aNode As MSBN3Lib.Node
    Dim aState As MSBN3Lib.state
    Debug.Print "Nodes and probabilities"
    For Each aNode In modelAuto.ModelNodes
        Debug.Print aNode.Name,
        For Each aState In aNode.States
            Debug.Print "P("; aState.Name; ")="; inferAuto.Belief(aNode, aState),
        Next aState
        Debug.Print
    Next aNode
    Debug.Print
    
    'Show a recommendation
    Debug.Print "Knowing the state of "; inferAuto.Recommendations.Keys(0); "would be most useful."
    Debug.Print
    
    'List all recommendations
    Debug.Print "Node", "Utility"
    For Each aNode In inferAuto.Recommendations.KeyObjects
        Debug.Print aNode.Name, inferAuto.Recommendations(aNode)
    Next aNode

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -