This Go library implements a number of Subjective Logic operators. Subjective Logic is a type of probabilistic logic that uses subjective opinions instead of probabilities. To learn more about Subjective Logic please refer to "Subjective Logic, A Formalism for Reasoning under Uncertainty" book by Audun Jøsang.
Subjective Logic is a type of probabilistic logic that uses subjective opinions instead of probabilities. A binomial opinion about the truth of the proposition
-
$b_x$ : belief mass in support of the proposition$x$ being true. -
$d_x$ : disbelief mass in support of the proposition$x$ being false. -
$u_x$ : uncertainty mass representing lack of evidence. -
$a_x$ : base rate i.e. the prior probability of$x$ being true without any evidence.
type Opinion struct {
belief float64
disbelief float64
uncertainty float64
baseRate float64
}
The following methods have been implemented for the opinion:
- NewOpinion()
- GetBelief()
- GetDisbelief()
- GetUncertainty()
- GetBaseRate()
- Modify()
- ProjProb()
- Compare()
- ToString
- ToStringE()
The NewOpinion()
method takes in four float64
values and outputs an Opinion
as well as an Error. In case a valid Opinion
can be formed, it will be returned and the error will be nil
. If the input values violate the requirements for a valid Opinion
, the Opinion
would be initialized with zeroes and an error will be returned.
For a valid Opinion
, each input value
opinion, err := subjectivelogic.NewOpinion(.5, .25, .25, .5)
if err != nil {
println(err.Error())
} else {
belief := opinion.GetBelief()
disbelief := opinion.GetDisbelief()
uncertainty := opinion.GetUncertainty()
baseRate := opinion.GetBaseRate()
println(fmt.Sprintf("Opinion: %.2f, %.2f, %.2f, %.2f", belief, disbelief, uncertainty, baseRate))
}
This code generates the following output:
Opinion: 0.50, 0.25, 0.25, 0.50
This implements the Addition Operator as defined in Subjective Logic:
func Addition(opinion1 *Opinion, opinion2 *Opinion) (Opinion, error)
Inputs
Moreover, the Addition Operator will attempt to divide through
func main() {
opinion1, _ := subjectivelogic.NewOpinion(0.2, 0.8, 0, 0.5)
opinion2, _ := subjectivelogic.NewOpinion(0.4, 0, 0.6, 0.5)
opinion3, _ := subjectivelogic.NewOpinion(1, 0, 0, 0.5)
out1, err1 := subjectivelogic.Addition(&opinion1, &opinion2) //Case 1
out2, err2 := subjectivelogic.Addition(&opinion1, &opinion3) //Case 2
fmt.Println("Case 1:", "Opinion = ", out1.ToString(), "Error:", err1)
fmt.Println("Case 2:", "Opinion = ", out2.ToString(), "Error:", err2)
}
The above code snippet shows the usage of the Addition operator. Case 1 uses two Opinions that are not problematic for the Addition operator, resulting in a valid output Opinion and no error:
Case 1: Opinion = 0.6000000000000001, 0.1, 0.3, 1 Error: <nil>
Case 2 uses two valid Opinions that are problematic for the Addition operator as the sum of their belief masses exceeds
Case 2: Opinion = 0, 0, 0, 0 Error: Addition: Check the validity of your input values
This implements the Complement Operator as defined in Subjective Logic:
func Complement(opinion *Opinion) (Opinion, error)
There are no problematic inputs for this operator, as long as they are valid opinions.
func main() {
opinion, _ := subjectivelogic.NewOpinion(0.2, 0.8, 0, 0.5)
out, err := subjectivelogic.Complement(&opinion)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Output:", out, err)
}
}
The code snippet above shows the usage of the Complement operator. This specific example will result in the following output:
Output: {0.8 0.2 0 0.5} <nil>
This implements the Binomial Multiplication Operator as defined in Subjective Logic:
func Multiplication(opinion1 *Opinion, opinion2 *Opinion) (Opinion, error)
The Binomial Multiplication Operator will try to divide through
func main() {
opinion1, _ := subjectivelogic.NewOpinion(0.2, 0.8, 0, 0.5)
opinion2, _ := subjectivelogic.NewOpinion(0.4, 0, 0.6, 0.5)
out, err := subjectivelogic.Multiplication(&opinion1, &opinion2)
if err != nil {
fmt.PrintlnImplementation("Error:", err)
} else {
fmt.Println("Output:", out, err)
}
}
The code snippet above shows the usage of the Multiplication operator. This specific example will result in the following output:
Output: {0.12000000000000002 0.8 0.08 0.25} <nil>
This implements the Comultiplication Operator as defined in Subjective Logic:
func Comultiplication(opinion1 *Opinion, opinion2 *Opinion) (Opinion, error)
The Binomial Comultiplication Operator will try to divide through
func main() {
opinion1, _ := subjectivelogic.NewOpinion(0.2, 0.8, 0, 0.5)
opinion2, _ := subjectivelogic.NewOpinion(0.4, 0, 0.6, 0.5)
out, err := subjectivelogic.Comultiplication(&opinion1, &opinion2)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Output:", out, err)
}
}
The code snippet above shows the usage of the Comultiplication operator. This specific example will result in the following output:
Output: {0.52 0.16 0.32 0.75} <nil>
==This implements the Belief Constraint Fusion Operator as defined in Subjective Logic:==
NEEDS TO BE EDITED
func ConstraintFusion(opinion1 *Opinion, opinion2 *Opinion) (Opinion, error)
The Belief Constraint Fusion Operator will try to divide through
func main() {
opinion1, _ := subjectivelogic.NewOpinion(0.2, 0.8, 0, 0.5)
opinion2, _ := subjectivelogic.NewOpinion(0.4, 0, 0.6, 0.5)
out, err := subjectivelogic.ConstraintFusion(&opinion1, &opinion2)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Output:", out, err)
}
}
The code snippet above shows the usage of the Belief Constraint operator. This specific example will result in the following output:
Output: {0.2941176470588236 0.7058823529411764 0 0.5} <nil>
This implements the Aleatory Cumulative Fusion Operator as defined in Subjective Logic:
Case I: For
Case II: For
func CumulativeFusion(opinion1 *Opinion, opinion2 *Opinion) (Opinion, error)
There are no problematic inputs for this operator, as long as they are valid opinions.
func main() {
opinion1, _ := subjectivelogic.NewOpinion(0.2, 0.8, 0, 0.5)
opinion2, _ := subjectivelogic.NewOpinion(0.4, 0, 0.6, 0.5)
out, err := subjectivelogic.CumulativeFusion(&opinion1, &opinion2)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Output:", out, err)
}
}
The code snippet above shows the usage of the Cumulative fusion operator. This specific example will result in the following output:
Output: {0.2 0.8 0 0.5} <nil>
This implements the Averaging Fusion Operator as defined in Subjective Logic:
Case I: For
Case II: For
func AveragingFusion(opinion1 *Opinion, opinion2 *Opinion) (Opinion, error)
There are no problematic inputs for this operator, as long as they are valid opinions.
func main() {
opinion1, _ := subjectivelogic.NewOpinion(0.2, 0.8, 0, 0.5)
opinion2, _ := subjectivelogic.NewOpinion(0.4, 0, 0.6, 0.5)
out, err := subjectivelogic.AveragingFusion(&opinion1, &opinion2)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Output:", out, err)
}
}
The code snippet above shows the usage of the Averaging fusion operator. This specific example will result in the following output:
Output: {0.2 0.8 0 0.5} <nil>
This implements the Weighted Fusion Operator as defined in Subjective Logic:
Case I: For
Case II: For
Case III:
func WeightedFusion(opinion1 *Opinion, opinion2 *Opinion) (Opinion, error)
There are no problematic inputs for this operator, as long as they are valid opinions.
func main() {
opinion1, _ := subjectivelogic.NewOpinion(0.2, 0.8, 0, 0.5)
opinion2, _ := subjectivelogic.NewOpinion(0.4, 0, 0.6, 0.5)
out, err := subjectivelogic.WeightedFusion(&opinion1, &opinion2)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Output:", out, err)
}
}
The code snippet above shows the usage of the Weighted fusion operator. This specific example will result in the following output:
Output: {0.2 0.8 0 0.5} <nil>
This implements the Trust Discounting Operator as defined in Subjective Logic:
func TrustDiscounting(opinion1 *Opinion, opinion2 *Opinion) (Opinion, error)
There are no problematic inputs for this operator, as long as they are valid opinions.
func main() {
opinion1, _ := subjectivelogic.NewOpinion(0.2, 0.8, 0, 0.5)
opinion2, _ := subjectivelogic.NewOpinion(0.4, 0, 0.6, 0.5)
out, err := subjectivelogic.TrustDiscounting(&opinion1, &opinion2)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Output:", out, err)
}
}
The code snippet above shows the usage of the Trust discounting operator. This specific example will result in the following output:
Output: {0.08000000000000002 0 0.9199999999999999 0.5} <nil>
This implements the Trust Discounting Operator for Multi-edge Paths as defined in Subjective Logic.
If
and:
TBD
TBD
TBD
Contributions are very welcome! Please let us know if you find an issue and have ideas for improvement. Alternately, open an issue or submit a pull request on GitHub.
This project is licensed under the Apache License, Verion 2.0 - see the LICENSE file for details.
In case of problems or issues, please open an issue on GitHub.