#C3.txt: Math 640(RU), Spring 2020. Finite Random variables Help:=proc():print(` RSS(M,M) , RRV(N,M,K), AgeDS(), Av(X), PGF(X,t) `): end: AgeDS:=proc(): [[1/11,23],[1/11,23],[1/11,22],[1/11,21],[1/11,24],[1/11,24],[1/11,26],[1/11, 25], [1/11,22],[1/11,25], [1/11,69]]; end: #RSS(N,M): a random probability sample space on {1, ..., N} #with random probabilities (M is a pos. integer) #The output is a list of probabilities such L[i] is the #prob. of the "atomic" event i #M is an arbitrary artificial pos. integer>=1 to generate random prob. RSS:=proc(N,M) local i,ra,L: ra:=rand(1..M): L:=[seq(ra(),i=1..N)]: L/add(L): end: #RRV(N,M,K): A random random variable that takes (random) values from -K and to K #N and M are as in RSS(N,M) RRV:=proc(N,M,K) local ra,L,i: ra:=rand(-K..K): L:=RSS(N,M): [seq([L[i],ra()],i=1..nops(L))]: end: #inputs a finite r.v. outputs the expectation (aka average, aka mean) Av:=proc(X) local i: add(X[i][1]*X[i][2],i=1..nops(X)): end: #PGF(X,t): The probability generating function (a finite sum, or "generalized polynomial #t^(-3) is OK and t^(1/2) is OK PGF:=proc(X,t) local i: if not (type(t,symbol) and type(X,list) and {seq(nops(X[i]),i=1..nops(X))}={2} and {seq(type(X[i],list), i=1..nops(X))}={true}) then print(`Bad input`): RETURN(FAIL): fi: add(X[i][1]*t^X[i][2],i=1..nops(X)): end: #Moms(X,k): inputs a finite prob. dist. (with our data structre) and #a pos. integer k, outputs a list of size k whose first entry is #the mean (alias expectaion alias average), the second entry is #the variance and the i-th entry is the i-th moment ABOUT the mean Moms:=proc(X,k) local t, f,mu,f1,L,i: f:=PGF(X,t): mu:=subs(t=1,diff(f,t)): L:=[mu]: f:=t*diff(f/t^mu,t): for i from 2 to k do f:=t*diff(f,t): L:=[op(L), subs(t=1,f)]: od: L: end: