Chinaunix首页 | 论坛 | 博客
  • 博客访问: 136090
  • 博文数量: 34
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 600
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-14 03:26
文章分类

全部博文(34)

文章存档

2011年(6)

2010年(2)

2009年(4)

2008年(22)

我的朋友

分类:

2008-09-27 10:00:19

 
指数分布(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) |
给主人留下些什么吧!~~