2007.08.04

這是這禮拜去報告的隨機變數的設定,將會提到一開始使用隨機變數的寫法,以及 ns2 提供的五種分佈,而下禮拜則是要進行隨機變數的實際模擬應用,以及試著將隨機變數的數據用 Gnuplot 作圖出來證實曲線為何。


  set rng [new RNG]
# 隨機變數開始設定

  $rng seed 0
# 設定種子編號,就像是在ns2裡有著很多組編號的數據,
# 如今選一個編號的種子數據出來當隨機變數,接著再利用下面介紹的分佈去決定隨機變數
# 當需要亂數,亂數產生器會擷取此串數據的第一個數字,以此類推去往下擷取
# 所以假如所使用的隨機變數種子相同,分佈也相同的話,此時產生的隨機變數會相同
# ※當種子值為 0 的時候,表示每次執行程式擷取的變數都不同,就像是每次擷取不同的種子


# ===================== Pareto Distribution ======================

  puts "Testing Pareto Distribution"
# Pareto 分佈,柏拉圖分佈
  set r1 [new RandomVariable/Pareto]
  $r1 use-rng $rng
  $r1 set avg_ 10.0
  $r1 set shape_ 1.2
  for {set i 1} {$i<=3} {incr i} {
    puts [$r1 value]
  }
# 需設定兩個參數,expectation(avg_)、shaper parameter β(shape_)
# 從柏拉圖公式下去分析,shape_ 就是要給定它的 β ,至於 avg_ 就不是很清楚
# 不過我猜測是它的 α 吧 = ="

    以下為公式:


    Pareto Distribution:

http://probstat.nuk.edu.tw/Web/pdf21.htm
http://en.wikipedia.org/wiki/Pareto_distribution
[ Pareto Distribution ]

# ===================== Pareto Distribution ======================


# ==================== Constant Distribution =====================

  puts "\nTesting Constant Distribution"
# Constant 分佈,常數分佈
  set r2 [new RandomVariable/Constant]
  $r2 use-rng $rng
  $r2 set avg_ 5
  for {set i 1} {$i<=3} {incr i} {
    puts [$r2 value]
  }
# 需設定一個參數,avg_ 平均值,但是我測試的結果似乎 avg_ 不管設定任何值都沒啥影響
# 也就是每次執行都是固定值為 1

# ==================== Constant Distribution =====================


# ===================== Uniform Distribution ======================

  puts "\nTesting Uniform Distribution"
# Uniform 分佈,均勻的分佈
  set r3 [new RandomVariable/Uniform]
  $r3 use-rng $rng
  $r3 set min_ 0.0
  $r3 set max_ 10.0
  for {set i 1} {$i<=3} {incr i} {
    puts [$r3 value]
  }
# 需設定兩個參數,min_ 最小界定、max_ 最大界定
# 此亂數會均勻的在最小值與最大值之間分佈
# 阿彰哥的解釋是說,介於最大最小值之間的每個值會發生的機率都是平均的

    Uniform Distribution:

http://en.wikipedia.org/wiki/Uniform_distribution_(continuous)
http://www.riskglossary.com/link/uniform_distribution.htm
[ Uniform Distribution ]

# ===================== Uniform Distribution ======================


# ==================== Exponential Distribution =====================
  puts "\nTesting Exponential Distribution"
# Exponential 分佈,指數分佈
  set r4 [new RandomVariable/Exponential]
  $r4 use-rng $rng
  $r4 set avg_ 5.0
  for {set i 1} {$i<=3} {incr i} {
    puts [$r4 value]
  }
# 需設定一個參數,avg_ 平均值
# 至於有什麼差別,我就感覺不出來了
# 不過亂數產生的機率,會類似指數的函數所呈現的曲線一樣

    Exponential Distribution:


http://en.wikipedia.org/wiki/Exponential_distribution 
[ Exponential Distribution ]

# ==================== Exponential Distribution =====================


# ================== HyperExponential Distribution ===================

  puts "\nTesting HyperExponential Distribution"
# HyperExponential 分佈,高度的指數分佈!?
  set r5 [new RandomVariable/HyperExponential]
  $r5 use-rng $rng
  $r5 set avg_ 1.0
  $r5 set cov_ 4.0
  for {set i 1} {$i<=3} {incr i} {
    puts [$r5 value]
  }
# 需設定兩個參數,avg_ 平均值、cov_ (秘密...) 迷 : 其實是不知道
# 這個查到的只有一堆公式,所以不確定是呈現怎樣的曲線
# 以及兩個參數的用意也不太瞭解 = ="

http://en.wikipedia.org/wiki/Hyper-exponential_distribution
[ Hyper  Exponential ]

# ================== HyperExponential Distribution ===================
 
 

歡迎對於 NS2 有研究或見解的同學、朋友可以一起討論  by Yo PM 2:22

arrow
arrow
    全站熱搜

    NS2lab 發表在 痞客邦 留言(1) 人氣()