Skip to content

Commit

Permalink
more reps
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed Jul 23, 2024
1 parent dc80a21 commit d4dd96d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 63 deletions.
40 changes: 19 additions & 21 deletions replication/debiasing/debiasing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ end

@enum LambdaMethod begin
optimal
polynomial
gcv
#polynomial
#gcv
end

mutable struct Experiment
Expand Down Expand Up @@ -103,8 +103,8 @@ function run_all()
lambda_candidates = [4.0, 5.0]
n_subsample = 10
d = 1
ns = [10, 20]
Bs = [10, 20]
ns = [1000]
Bs = [500]
x_evals = [ntuple(j -> 0.5, d)]
X_dist = Uniform(0, 1)
mu = (x -> sum(sin.(x)))
Expand All @@ -114,23 +114,23 @@ function run_all()
blocks = [(0, rmse::LambdaTarget), (1, rmse::LambdaTarget),
(1, undersmooth::LambdaTarget)]
for (J_estimator, lambda_target) in blocks
for lambda_method in lambda_methods
for n in ns
for B in Bs
for lambda_multiplier in lambda_multipliers
B_estimator = B
B_lifetime = B
experiment = Experiment(J_estimator, lambda_target, lambda_method,
lambda_multiplier, lambda_candidates,
n_subsample, d, n, B_estimator,
B_lifetime, x_evals, X_dist, mu, eps_dist)
run(experiment)
push!(experiments, experiment)
for lambda_method in lambda_methods
for n in ns
for B in Bs
for lambda_multiplier in lambda_multipliers
B_estimator = B
B_lifetime = B
experiment = Experiment(J_estimator, lambda_target, lambda_method,
lambda_multiplier, lambda_candidates,
n_subsample, d, n, B_estimator,
B_lifetime, x_evals, X_dist, mu, eps_dist)
run(experiment)
push!(experiments, experiment)
end
end
end
end
end
end
save(experiments)
end

Expand Down Expand Up @@ -223,7 +223,7 @@ function select_lifetime(X, Y, experiment)
end

function run(experiment::Experiment)
n_rep = 5
n_rep = 200
n = experiment.n
d = experiment.d
x_evals = experiment.x_evals
Expand All @@ -235,16 +235,14 @@ function run(experiment::Experiment)
coverage = 0.0
average_width = 0.0
average_lambda = 0.0
for rep in 1:n_rep
for rep in 1:n_rep
println(rep)
X = [ntuple(j -> rand(experiment.X_dist), d) for i in 1:n]
Y = [mu(X[i]) + rand(experiment.eps_dist) for i in 1:n]
lambda = select_lifetime(X, Y, experiment) * lambda_multiplier
forest = DebiasedMondrianForest(lambda, experiment.B_estimator,
x_evals,
experiment.J_estimator, X, Y, true)
#println(forest.debias_scaling)
#println(forest.debias_coeffs)
ci = forest.confidence_band
mse += (forest.mu_hat[] - mu(x_evals[]))^2 / n_rep
bias += (forest.mu_hat[] - mu(x_evals[])) / n_rep
Expand Down
42 changes: 0 additions & 42 deletions replication/debiasing/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ function lambda_method_format(l)
end

data = CSV.read("./replication/debiasing/results.csv", DataFrame)
#println(names(data))
#println(length(names(data)))
data = select!(data, sort(names(data)))
data = select!(data, [:d, :n, :J_estimator, :lambda_target, :lambda_method, :J_lifetime,
:B_estimator, :B_lifetime, :n_subsample,
Expand All @@ -32,11 +30,6 @@ data = select!(data, [:d, :n, :J_estimator, :lambda_target, :lambda_method, :J_l
data = sort!(data, [:J_estimator, :lambda_target, order(:lambda_method, by=lambda_method_order),
:J_lifetime, :d, :n, :B_estimator, :B_lifetime, :n_subsample,
:lambda_multiplier])

#data[!, :J_lifetime] = string.(data[!, :J_lifetime])
#println(names(data))
#println(length(names(data)))
#data = sort(data, [:J_estimator, :lambda_target])
display(data)

function make_table(df)
Expand All @@ -58,8 +51,6 @@ function make_table(df)
df[i, :lambda_method] == df[i-1, :lambda_method]
tex *= "&"
else
# TODO format nicely
#tex *= "& $(df[i, :J_lifetime]) $(df[i, :lambda_method])"
Jl = df[i, :J_lifetime]
lm_fmt = lambda_method_format(df[i, :lambda_method])
if lm_fmt != "OPT"
Expand All @@ -82,42 +73,9 @@ function make_table(df)
tex *= "\\\\\n"
end
tex *= "\\end{tabular}"

#for row in eachrow(df_Je_Jl_lm[!, [:J_estimator, :J_lifetime, :B_estimator, :lambda, :rmse, :bias, :sd,
#:bias_over_sd, :bias_theory, :sd_theory,
#:coverage, :average_width]])

#for J_estimator in unique(df[!, "J_estimator"])
#tex *= "$J_estimator "
#df_Je = filter(:J_estimator => ==(J_estimator), df)
#for J_lifetime in unique(df_Je[!, "J_lifetime"])
#df_Je_Jl = filter(:J_lifetime => ==(J_lifetime), df)
#for lambda_method in unique(df_Je_Jl[!, "lambda_method"])
#df_Je_Jl_lm = filter(:lambda_method => ==(lambda_method), df_Je_Jl)
## TODO format this nicely
#tex *= "$J_lifetime $lambda_method "
#for row in eachrow(df_Je_Jl_lm[!, [:B_estimator, :lambda, :rmse, :bias, :sd,
#:bias_over_sd, :bias_theory, :sd_theory,
#:coverage, :average_width]])
#for cell in row
#println(cell)
#cell = round(cell, digits=3)
#tex *= "& $cell"
#end
#tex *= "\\\\\n & "
#end
#end
#end
#end

#tex = chop(tex, tail = 3)
#tex *= "\\hline\n"
#tex *= "\\end{tabular}"

n = df[1, "n"]
d = df[1, "d"]
write("./replication/debiasing/table_d$(d)_n$(n).tex", tex)

end

for d in unique(data[!, "d"])
Expand Down

0 comments on commit d4dd96d

Please sign in to comment.