Skip to content

Instantly share code, notes, and snippets.

@LimHyungTae
Created January 9, 2023 16:01
Show Gist options
  • Save LimHyungTae/c447abf3f5e0ade5979844b55a5b2076 to your computer and use it in GitHub Desktop.
Save LimHyungTae/c447abf3f5e0ade5979844b55a5b2076 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
double prob2logOdds(double prob) {
return 2 * atanh(2 * prob - 1);
}
double logOdds2prob(double log_odds) {
return (tanh(log_odds / 2) + 1) / 2;
}
int main()
{
cout << prob2logOdds(0.000000) << endl;
cout << prob2logOdds(0.000001) << endl;
cout << prob2logOdds(0.75) << endl;
cout << prob2logOdds(0.80) << endl;
cout << prob2logOdds(0.90) << endl;
cout << prob2logOdds(0.95) << endl;
cout << prob2logOdds(0.99) << endl;
cout << prob2logOdds(1.0) << endl;
cout << " = = = = = = = = = = " << endl;
cout << logOdds2prob(-2.0) << endl;
cout << logOdds2prob(0.0) << endl;
cout << logOdds2prob(0.5) << endl;
cout << logOdds2prob(3.0) << endl;
cout << logOdds2prob(4.6) << endl;
cout << logOdds2prob(30) << endl;
cout << logOdds2prob(60) << endl;
return 0;
}
@LimHyungTae
Copy link
Author

-inf
-13.8155
1.09861
1.38629
2.19722
2.94444
4.59512
inf
= = = = = = = = = =
0.119203
0.5
0.622459
0.952574
0.990048
1
1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment