-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuantitativeModel.cpp
134 lines (118 loc) · 4.26 KB
/
QuantitativeModel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
*
* QuantitativeModel.cpp
* ---------------------
*
* Author: Michael Dickens <[email protected]>
* Created: 2016-05-19
*
* Port of my quantitative model spreadsheet for people who don't have
* Excel.
*
*/
#include "QuantitativeModel.h"
using namespace std;
typedef map<string, Distribution> Table;
double Distribution::posterior(const Distribution& measurement) const
{
double c = integral(measurement, false);
return integral(measurement, true) / c;
}
/*
* Converts an 80% credence interval into a log-normal distribution.
*/
Distribution CI(double lo, double hi)
{
double p_m = sqrt(lo * hi);
double p_s = sqrt(log(hi / lo) / log(10) / 2 / NORMAL_90TH_PERCENTILE);
Distribution res(p_m, p_s);
return res;
}
Distribution CI(double val)
{
return CI(val, val);
}
Table read_input(string filename)
{
Table table;
ifstream file(filename);
string key, comments, low_CI, high_CI;
while (file.good()) {
getline(file, key, ',');
getline(file, low_CI, ',');
getline(file, high_CI, ',');
getline(file, comments);
table[key] = CI(stof(low_CI), stof(high_CI));
}
return table;
}
void globals(Table& table)
{
table["factory-farmed animal wellbeing"] = CI(6);
table["factory-farmed animal sentience adjustment"] = CI(0.3);
table["utility per factory-farmed animal"] =
table["factory-farmed animal wellbeing"]
* table["factory-farmed animal sentience adjustment"];
table["utility per cage removed"] = CI(0.3);
table["P(stay on earth)"] = CI(0.2);
table["P(we reduce WAS on balance)"] = CI(0.7);
table["P(fill universe with biology)"] = CI(0.4);
table["P(society doesn't care about animals)"] = CI(0.8);
table["P(we have factory farming)"] = CI(0.2);
table["P(we spread WAS)"] = CI(0.4);
table["P(we make suffering simulations)"] = CI(0.3);
table["P(fill universe with computers)"] = CI(0.4);
table["P(hedonium)"] = CI(0.05);
table["P(ems)"] = CI(0.3);
table["P(paperclip)"] = CI(0.649);
table["P(dolorium)"] = CI(0.001);
}
// TODO: not currently called
void ev_far_future(Table& table)
{
table["P(humans exist)"] = table["P(fill universe with biology)"];
table["P(hedonium exists)"] =
table["P(fill universe with computers)"] * table["P(hedonium)"];
table["p(ems exist)"] =
table["p(fill universe with computers)"] * table["p(ems)"];
table["p(paperclips exist)"] =
table["p(fill universe with computers)"] * table["p(paperclip)"];
table["p(dolorium exists)"] =
table["p(fill universe with computers)"] * table["p(dolorium)"];
}
double thl_posterior_direct(Table& table, const Distribution& prior)
{
table["THL years factory farming prevented per $1000"] = CI(700, 13000);
Distribution utility_estimate =
table["THL years factory farming prevented per $1000"]
* table["utility per factory-farmed animal"];
printf("%f %f\n", utility_estimate.p_m, pow(utility_estimate.p_s, 2));
return prior.posterior(utility_estimate);
}
double cage_free_posterior_direct(Table& table, const Distribution& prior)
{
table["cage-free total expenditures ($M)"] = CI(2, 3);
table["years until cage-free would have happened anyway"] = CI(5, 10);
table["millions of cages prevented"] = CI(100, 150);
table["proportion of change attributable to campaigns"] = CI(0.7, 1);
table["cage-free years per cage prevented"] = CI(1, 1);
Distribution utility_estimate =
table["cage-free total expenditures ($M)"].reciprocal()
* table["years until cage-free would have happened anyway"]
* table["millions of cages prevented"]
* table["proportion of change attributable to campaigns"]
* table["cage-free years per cage prevented"]
* table["utility per cage removed"]
* 1000;
Distribution r = table["cage-free total expenditures ($M)"].reciprocal();
printf("%f %f\n", utility_estimate.p_m, pow(utility_estimate.p_s, 2));
return prior.posterior(utility_estimate);
}
int main(int argc, char *argv[])
{
Table table;
globals(table);
printf("%f\n", thl_posterior_direct(table, Distribution(1, 0.75))); // 194.8
printf("%f\n", cage_free_posterior_direct(table, Distribution(1, 0.75))); // 2531
return 0;
}