Skip to content

Commit

Permalink
Some unfinished work.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbird61 committed Apr 26, 2018
1 parent a06dbeb commit c0f1cb1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
27 changes: 27 additions & 0 deletions compound_random_variable/Makefile
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 36 additions & 0 deletions compound_random_variable/example3_8.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <cstdio>
#include "../utils/rand_gen.h"
#include <map>

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<double,int> 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;
}

0 comments on commit c0f1cb1

Please sign in to comment.