Skip to content

Commit

Permalink
Fix to MLE estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rucknium committed Feb 1, 2022
1 parent 54c62a9 commit fe2bcfe
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
16 changes: 8 additions & 8 deletions R/OSPEAD-dry-run.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# install.packages("readr")

xmr.Moser <- as.data.frame(readr::read_csv("data/log_spend_times.csv.xz"))
xmr.Moser <- as.data.frame(readr::read_csv("data-raw/log_spend_times.csv.xz"))
# Data from Moser et al. (2018) "An Empirical Analysis of Traceability in the Monero Blockchain"

xmr.Moser$spend_times_seconds <- exp(xmr.Moser$log_spend_times)
Expand All @@ -15,7 +15,7 @@ theta_i <- merge(data.frame(Var1 = 1:max(theta_i)), theta_i, all.x = TRUE)
theta_i <- theta_i$Freq
theta_i[is.na(theta_i)] <- 0
support <- 1:max(xmr.Moser$spend_times_blocks)
spend_times_blocks <- log(xmr.Moser$spend_times_blocks + 1)
spend_times_blocks <- xmr.Moser$spend_times_blocks
# offset is 2 to avoid zeroes later on


Expand Down Expand Up @@ -43,9 +43,9 @@ param.trans$f <- c(exp, exp, exp)

L_FGT <- function(param, f_D, support, flavor = 1) {
alpha <- flavor
a_i <- f_D(param, support)
a_i <- f_D(param, support + 1)
a_i <- a_i/sum(a_i)
sum( (a_i < theta_i & theta_i > 0) * theta_i * ((theta_i - a_i)/theta_i)^alpha , na.rm = TRUE )
sum( (theta_i * ((theta_i - a_i)/theta_i)^alpha)[a_i < theta_i & theta_i > 0] , na.rm = FALSE )
}


Expand All @@ -62,14 +62,14 @@ L_Welfare <- function(param, f_D, support, flavor = 1) {
a_i <- f_D(param, support + 1)
a_i <- a_i/sum(a_i)
(-1) * sum(
(theta_i > 0) * theta_i * u_CRRA(ifelse(a_i/theta_i < 1, a_i/theta_i, 1), eta = eta )
, na.rm = TRUE )
(theta_i * u_CRRA(ifelse(a_i/theta_i < 1, a_i/theta_i, 1), eta = eta ))[theta_i > 0]
, na.rm = FALSE )
}

L_MLE <- function(param, f_D, ...) {
(-1) * sum(
log( f_D(param, spend_times_blocks + 1) )
, na.rm = TRUE)
log( f_D(param, spend_times_blocks + 2) )
, na.rm = FALSE)
}


Expand Down
Binary file modified images/dry-run/L_FGT-flavor-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/dry-run/L_FGT-flavor-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/dry-run/L_MLE-flavor-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/dry-run/L_Welfare-flavor-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/dry-run/L_Welfare-flavor-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions tables/dry-run/minimizer-params.csv
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"f_D","L","flavor","param_1","param_2","param_3"
"f","L_FGT",1,7.73308554515871,118.063330027606,18.2981654946987
"f","L_FGT",2,11.5921594797106,53.2853002761615,27.3406960709529
"f","L_Welfare",1,11.9743452905718,59.1764924789675,29.717104784749
"f","L_FGT",1,8.05719252491297,109.952536784803,19.3046757980035
"f","L_FGT",2,12.5978958350072,51.0377153004329,30.2680011848127
"f","L_Welfare",1,11.9840267193704,59.1303303747434,29.7422478098935
"f","L_Welfare",5,12.8427809452998,33.244205814352,25.8240555862385
"f","L_MLE",0,48.4622052345434,3443646224.48591,51.0433803223784
"gamma","L_FGT",1,6.32941654097075,1.87163172217098,NA
"gamma","L_FGT",2,5.06661209503492,1.62582071865596,NA
"f","L_MLE",0,3.59628472609937,300481.358332403,22.5185453170164
"gamma","L_FGT",1,6.48456816194793,1.89456483637355,NA
"gamma","L_FGT",2,5.1506257459866,1.63896788952644,NA
"gamma","L_Welfare",1,5.79170334040451,1.76046364010705,NA
"gamma","L_Welfare",5,4.89150486745901,1.28402541668774,NA
"gamma","L_MLE",0,32.4413857250808,15.8015684774846,NA
"lnorm","L_FGT",1,1.32804852566472,0.295921100314083,NA
"lnorm","L_FGT",2,1.23371839168609,0.324481375069784,NA
"gamma","L_MLE",0,6.74707527626395,0.929026890047148,NA
"lnorm","L_FGT",1,1.32544578267069,0.296241359768276,NA
"lnorm","L_FGT",2,1.23800307568435,0.323337939579835,NA
"lnorm","L_Welfare",1,1.27141411713503,0.311455783458507,NA
"lnorm","L_Welfare",5,0.5250732421875,0.511099288016679,NA
"lnorm","L_MLE",0,0.703854078358836,0.18061269184726,NA
"lnorm","L_MLE",0,1.90675350659741,0.40122196894288,NA
10 changes: 5 additions & 5 deletions tables/dry-run/performance.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"L","flavor","f_D.gamma","f_D.lnorm","f_D.f"
"L_FGT",1,0.114593035422099,0.118442304051464,0.112173839576946
"L_FGT",2,0.0571138439873846,0.0497370994664305,0.0474519635595684
"L_Welfare",1,0.195514126489678,0.17438112408889,0.166604226378729
"L_Welfare",5,38.335672781811,9.80396337496936,2.43406002776894
"L_MLE",0,3072672.94314182,3255804.14458042,3036829.65623237
"L_FGT",1,0.113778893365453,0.117158303471642,0.110733297205176
"L_FGT",2,0.0574428929874666,0.0480854439291773,0.0461219760802895
"L_Welfare",1,0.195514126489678,0.174381904329582,0.16660468015691
"L_Welfare",5,38.3356738421929,9.80396820721904,2.43406074316384
"L_MLE",0,18968945.0299809,19097272.1691623,18974332.125762

0 comments on commit fe2bcfe

Please sign in to comment.