forked from personal/squiggle.c
start adding nuclear probabilities
This commit is contained in:
parent
f8f8bc8de0
commit
8b32d2d9b6
BIN
examples/08_nuclear_war/example
Executable file
BIN
examples/08_nuclear_war/example
Executable file
Binary file not shown.
47
examples/08_nuclear_war/example.c
Normal file
47
examples/08_nuclear_war/example.c
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#include "../../squiggle.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
double probability_of_dying_nuno(uint64_t* seed){
|
||||||
|
double first_year_russian_nuclear_weapons = 1953;
|
||||||
|
double current_year = 2023;
|
||||||
|
double laplace_probability_nuclear_exchange_next_year = sample_beta(current_year-first_year_russian_nuclear_weapons, 0, seed);
|
||||||
|
|
||||||
|
double london_hit_conditional_on_russia_nuclear_weapon_usage = sample_beta(7.67, 69.65, seed);
|
||||||
|
// I.e., a beta distribution with a range of 0.05 to 0.16 into: https://nunosempere.com/blog/2023/03/15/fit-beta/
|
||||||
|
// 0.05 were my estimate and Samotsvety's estimate in March 2022, respectively:
|
||||||
|
// https://forum.effectivealtruism.org/posts/KRFXjCqqfGQAYirm5/samotsvety-nuclear-risk-forecasts-march-2022#Nu_o_Sempere
|
||||||
|
double informed_actor_not_able_to_escape = sample_beta(3.26212166586967, 3.26228162008564, seed);
|
||||||
|
// 0.2 to 0.8, i.e., 20% to 80%, again using the previous tool
|
||||||
|
double proportion_which_die_if_bomb_drops_in_london = sample_beta(10.00, 2.45, seed); // 60% to 95%
|
||||||
|
|
||||||
|
double probability_of_dying = laplace_probability_nuclear_exchange_next_year *
|
||||||
|
london_hit_conditional_on_russia_nuclear_weapon_usage *
|
||||||
|
informed_actor_not_able_to_escape *
|
||||||
|
proportion_which_die_if_bomb_drops_in_london;
|
||||||
|
return probability_of_dying;
|
||||||
|
}
|
||||||
|
|
||||||
|
double probability_of_dying_eli(uint64_t* seed){
|
||||||
|
double russia_nato_nuclear_exchange_in_next_month=sample_beta(1.30, 1182.99,seed); // .0001 to .003
|
||||||
|
double london_hit_conditional = sample_beta(3.47, 8.97, seed); // 0.1 to 0.5
|
||||||
|
double informed_actors_not_able_to_escape = sample_beta(2.73, 5.67, seed); // .1 to .6
|
||||||
|
double proportion_which_die_if_bomb_drops_in_london = sample_beta(3.00, 1.46, seed); // 0.3 to 0.95;
|
||||||
|
|
||||||
|
double probability_of_dying = russia_nato_nuclear_exchange_in_next_month*london_hit_conditional*informed_actors_not_able_to_escape*proportion_which_die_if_bomb_drops_in_london;
|
||||||
|
return probability_of_dying;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// set randomness seed
|
||||||
|
uint64_t* seed = malloc(sizeof(uint64_t));
|
||||||
|
*seed = 1000; // xorshift can't start with 0
|
||||||
|
|
||||||
|
|
||||||
|
free(seed);
|
||||||
|
}
|
53
examples/08_nuclear_war/makefile
Normal file
53
examples/08_nuclear_war/makefile
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c
|
||||||
|
OUTPUT=example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3 #-Ofast
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Formatter
|
||||||
|
STYLE_BLUEPRINT=webkit
|
||||||
|
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
||||||
|
|
||||||
|
## make build
|
||||||
|
build: $(SRC)
|
||||||
|
$(CC) $(OPTIMIZED) $(DEBUG) $(SRC) $(MATH) -o $(OUTPUT)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
OMP_NUM_THREADS=1 ./$(OUTPUT) && echo
|
||||||
|
|
||||||
|
time-linux:
|
||||||
|
@echo "Requires /bin/time, found on GNU/Linux systems" && echo
|
||||||
|
|
||||||
|
@echo "Running 100x and taking avg time $(OUTPUT)"
|
||||||
|
@t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(OUTPUT); done' 2>&1 >/dev/null | grep real | awk '{print $$2}' ); echo "scale=2; 1000 * $$t / 100" | bc | sed "s|^|Time using 1 thread: |" | sed 's|$$|ms|' && echo
|
||||||
|
|
||||||
|
## Profiling
|
||||||
|
|
||||||
|
profile-linux:
|
||||||
|
echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar"
|
||||||
|
echo "Must be run as sudo"
|
||||||
|
$(CC) $(SRC) $(MATH) -o $(OUTPUT)
|
||||||
|
sudo perf record ./$(OUTPUT)
|
||||||
|
sudo perf report
|
||||||
|
rm perf.data
|
BIN
examples/08_nuclear_war/scratchpad/example
Executable file
BIN
examples/08_nuclear_war/scratchpad/example
Executable file
Binary file not shown.
20
examples/08_nuclear_war/scratchpad/example.c
Normal file
20
examples/08_nuclear_war/scratchpad/example.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "../../../squiggle.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// set randomness seed
|
||||||
|
uint64_t* seed = malloc(sizeof(uint64_t));
|
||||||
|
*seed = 1000; // xorshift can't start with 0
|
||||||
|
double firstYearRussianNuclearWeapons = 1953;
|
||||||
|
double currentYear = 2023;
|
||||||
|
|
||||||
|
for(int i=0; i<10; i++){
|
||||||
|
double laplace_beta = sample_beta(currentYear-firstYearRussianNuclearWeapons + 1, 1, seed);
|
||||||
|
printf("%f\n", laplace_beta);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(seed);
|
||||||
|
}
|
53
examples/08_nuclear_war/scratchpad/makefile
Normal file
53
examples/08_nuclear_war/scratchpad/makefile
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../../squiggle.c
|
||||||
|
OUTPUT=example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3 #-Ofast
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Formatter
|
||||||
|
STYLE_BLUEPRINT=webkit
|
||||||
|
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
||||||
|
|
||||||
|
## make build
|
||||||
|
build: $(SRC)
|
||||||
|
$(CC) $(OPTIMIZED) $(DEBUG) $(SRC) $(MATH) -o $(OUTPUT)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
OMP_NUM_THREADS=1 ./$(OUTPUT) && echo
|
||||||
|
|
||||||
|
time-linux:
|
||||||
|
@echo "Requires /bin/time, found on GNU/Linux systems" && echo
|
||||||
|
|
||||||
|
@echo "Running 100x and taking avg time $(OUTPUT)"
|
||||||
|
@t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(OUTPUT); done' 2>&1 >/dev/null | grep real | awk '{print $$2}' ); echo "scale=2; 1000 * $$t / 100" | bc | sed "s|^|Time using 1 thread: |" | sed 's|$$|ms|' && echo
|
||||||
|
|
||||||
|
## Profiling
|
||||||
|
|
||||||
|
profile-linux:
|
||||||
|
echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar"
|
||||||
|
echo "Must be run as sudo"
|
||||||
|
$(CC) $(SRC) $(MATH) -o $(OUTPUT)
|
||||||
|
sudo perf record ./$(OUTPUT)
|
||||||
|
sudo perf report
|
||||||
|
rm perf.data
|
Loading…
Reference in New Issue
Block a user