Overview
This REST API calculates the updated (posterior) probability using Bayes' Theorem. It accepts prior probability, likelihood, and false positive rate, then returns the computed probability in JSON format.
HTTP Method
The API supports both GET and POST requests.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
prior |
float (percent) | Yes | Initial probability (e.g., 1 for 1%). |
likelihood |
float (percent) | Yes | Probability of seeing evidence if hypothesis is true (e.g., 95 for 95%). |
altLikelihood |
float (percent) | Yes | Probability of seeing evidence if hypothesis is false (false positive rate, e.g., 5 for 5%). |
Example Request (GET)
https://www.promptbox.cn/api/bayes.php?prior=1&likelihood=95&altLikelihood=5
Example Request (cURL)
curl -X GET "https://www.promptbox.cn/api/bayes.php?prior=1&likelihood=95&altLikelihood=5"
Successful Response
{
"input": {
"prior_percent": 1,
"likelihood_percent": 95,
"altLikelihood_percent": 5
},
"result": {
"updated_probability_percent": 16.09
}
}
Error Response
{
"error": "Missing parameters. Required: prior, likelihood, altLikelihood (all in %).",
"example": "bayesian_api.php?prior=1&likelihood=95&altLikelihood=5"
}
Formula Used
Bayes' theorem is applied as:
P(H|E) = [ P(E|H) * P(H) ] / [ P(E|H) * P(H) + P(E|¬H) * (1 - P(H)) ]
- P(H): Prior probability (
prior). - P(E|H): Likelihood if hypothesis true (
likelihood). - P(E|¬H): False positive rate (
altLikelihood). - P(H|E): Updated (posterior) probability.