指数分布(Exponential Distrubution):
f(x;rate) = rate*exp(-rate*x) when x>=0
0 when x<0
F(x,rate) = 1 - exp(-rate*x) when x>=0
0 when x<0
E(x) = 1/rate
V(x) = 1/rate**2
反变换法(Inverse transform method):
How does non transform a sample of the uniform[0,1] random variable into a sample of a given distribution?
Problem: Generate sample of random variable X with a given density f(x)?
Answer: Example exp(rate)?
1.Generate random umber U
2.Set X = -(1/rate)ln(1-U)
or X = -(1/rate)ln(U)
测试代码和结果:
test_exppdf.java
import java.util.Enumeration; import java.util.Random; import java.util.Vector;
public class test_exppdf {
public static void main(String args[]){ int i; float dly; float rate; float rnd; Random rndGen; rate = (float)1; rndGen = new Random(); for(i=0;i<1000;i++){ rnd = rndGen.nextFloat(); dly = (float)( (1/rate)*Math.log(1/rnd)); System.out.println(i+" "+dly+" "+rnd); } } }
|
javac test_exppdf.java
java test_exppdf >result.txt
start Dataplot GUI
READ result.txt X Y Z
4-PLOT Y
结果证明该方法能够产生相应的随机数.
为了扩展Dataplot的容量,需要使用以下命令:
DIMENSION 200 VARIABLES
DIMENSION 200 OBSERVATIONS
DIMENSION 200 200
DIMENSION 200 COLUMNS
DIMENSION 200 ROWS
取X的数学期望:
LET EX = MEAN X
阅读(1591) | 评论(0) | 转发(0) |