theorem

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package theorem is an Bayes' theorem implementation.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bayes

func Bayes(priorPtoB, priorPfromAtoB, priorPNotFromAtoB float64) float64

Bayes returns the probability from the given probability based on Bayes' theorem. In other words, it returns the probability of event B occurring when event A occurred.

  • priorPtoB is the prior probability occurrence of event B.
  • priorPfromAtoB is the prior probability occurrence of event B when previous event A occurred.
  • priorPNotFromAtoB is the prior probability that did not occur event B when previous event A occurred.
Example
package main

import (
	"fmt"

	"github.com/KEINOS/go-bayes/pkg/theorem"
)

func main() {
	// Validation of figures
	// Bayes' theorem
	x := 0.3 * 0.4
	y := x + (1.-0.3)*0.5
	expect := x / y //nolint: ifshort // not using short syntax for readability

	// Prior probability to be B.
	PriorProbToB := 0.3
	// Prior probability to be B if the previous was A.
	PriorProbFromAtoB := 0.4
	// Prior probability not to be B if the previous was A.
	PriorProbNotFromAtoB := 0.5

	actual := theorem.Bayes(PriorProbToB, PriorProbFromAtoB, PriorProbNotFromAtoB)

	if expect == actual {
		fmt.Println("OK")
	}

}
Output:

OK

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL