diff --git a/compound_random_variable/Makefile b/compound_random_variable/Makefile new file mode 100644 index 0000000..8de5e43 --- /dev/null +++ b/compound_random_variable/Makefile @@ -0,0 +1,27 @@ +example3_8:=example3_8.out +OBJS:=../utils/parse_arg.o ../utils/rand_gen.o +OBJS_3_8:=example3_8.o +OBJDIR:=output image +CXX=g++ +CXXFLAGS:=-std=c++14 + +.DEFAULT_GOAL:=all + +astyle: + astyle --style=google --indent=spaces=2 *.cc + +all: $(OBJDIR) example3_8 + +run: all + +example3_8: $(OBJS_3_8) $(OBJS) + $(CXX) $(CXXFLAGS) $^ -o $(example3_8) + +%.o: %.c %.h + $(CXX) $(CXXFLAGS) -c $^ + +$(OBJDIR): + mkdir -p $@ + +clean: + rm *.o $(OBJS) \ No newline at end of file diff --git a/compound_random_variable/example3_8.cc b/compound_random_variable/example3_8.cc new file mode 100644 index 0000000..95fe22e --- /dev/null +++ b/compound_random_variable/example3_8.cc @@ -0,0 +1,36 @@ +#include +#include "../utils/rand_gen.h" +#include + +int main(int argc,char *argv[]){ + // random number generator + rand_gen *gen = new rand_gen(); + + // upperbound: t = X1+X2 + double t=10000,counter=0.0,mu1=1,mu2=2; + // X1, X2 + std::map X1,X2; + + while(t--){ + // double ts = gen->exponential(mu1); + X1[(int)gen->exponential(mu1)]++; + X2[(int)gen->exponential(mu2)]++; + } + + double sum_X1=0.0,sum_X2=0.0; + for(auto&it: X1){ + sum_X1+=it.second; + } + for(auto&it: X2){ + sum_X2+=it.second; + } + + for(auto&it:X1){ + printf("[ %lf ]: %lf\n",it.first,it.second/sum_X1); + } + /*for(auto&it:X2){ + printf("[ %lf ]: %lf\n",it.first,it.second/sum_X2); + }*/ + + return 0; +} \ No newline at end of file