2016-09-07 22 views
0

使用以下data.framesR:轉換試驗和錯誤校正自動化

#df is data.frame to be used to get the simulated values 
df <- read.csv(url("https://www.dropbox.com/s/j1jyrxlinyql0d8/df_simu2.csv?raw=1")) 
head(df) 
#  ID loss  area param1 param2 
#1 well5 8.62 0.3430550 High High 
#2 well5 8.62 0.1643353 High High 
#3 well5 8.62 4.2321602 High High 
#4 well5 8.62 0.0349235 Medium High 
#5 well5 8.62 0.0648697 Medium High 
#6 well5 8.62 0.0444421 Medium High 

#df_measured is the data.frame that have the measured values to be compared with the simulated values later 
df_measured <- read.csv(url("https://www.dropbox.com/s/77v6ysdi1ziqq6i/df_measured.csv?raw=1")) 
head(df_measured) 
#  ID measured 
#1 well1 29.7513 
#2 well2 21.7710 
#3 well3 191.6334 
#4 well4 260.2431 
#5 well5 532.3491 

這個代碼來獲取模擬值,並將其與實測值

library(dplyr) 
df_simulated <- df %>% 
    dplyr::mutate(loss1 = loss/1e3,            #convert the units 
       param1_no = ifelse(param1 == "High", 0.7,       #convert param1 values to numbers 
            ifelse(param1 == "Medium", 0.5, 
              ifelse(param1 == "Low", 0.3, NA))), 
       param2_no = ifelse(param2 == "High", 0.9,       #convert param2 values to numbers 
             ifelse(param2 == "Medium", 0.5, 
               ifelse(param2 == "Low", 0.3, NA)))) %>% 
    dplyr::group_by(ID) %>% 
    dplyr::summarise(simulated = sum(loss1 * area * (1- param1_no) * (1 - param2_no), na.rm =T)) %>% 
    #merge it with df_measured to comapre simulated with measured 
    dplyr::full_join(., df_measured, by = "ID") %>%         
    dplyr::select(ID, simulated, measured) 

我得到這個結果比較

#df_simulated 
# A tibble: 5 × 3 
#  ID simulated measured 
# <fctr>  <dbl> <dbl> 
#1 well1 115.90577 29.7513 
#2 well2 31.68084 21.7710 
#3 well3 299.77588 191.6334 
#4 well4 387.15474 260.2431 
#5 well5 519.88316 532.3491 

simulated值不接近除well5以外的值爲。 爲了儘可能接近得到simulated值到measured,我需要改變值的param1_no水平和param2_no

對於這兩種param1_no和「param2_no」

  1. high可以從改變0.67〜0.99
  2. medium可以從0.34變化到0.66
  3. low可以變化從0.01到0.33

在校準過程中,我可以不斷更改這些值「試錯」,直到我的simulated值儘可能接近measured

但是,手動執行此操作需要時間。 我會高度讚賞,如果您可以建議任何更快的方法來獲得param1_noparam2_nohigh,mediumlow)的最佳值,使模擬值更接近測量值。

回答

0

您是否檢查過hydromad()包和SCEoptim函數?您可以養活你的公式和參數限制到優化,並返回校準參數值(根據你必須定義一個目標函數)Link

BTW:這個問題的題目的心不是那麼好......

+0

感謝您的時間和幫助。我還沒有檢查過它。 – aelwan

+0

任何改善標題的建議? – aelwan