Skip to content

Instantly share code, notes, and snippets.

@oscardelama
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscardelama/ff0ec450d783913e4a44 to your computer and use it in GitHub Desktop.
Save oscardelama/ff0ec450d783913e4a44 to your computer and use it in GitHub Desktop.
xval-noise-models: The main routine
execute.tests <- function(n) {
# A place-holder for the test results
result.df <- data.frame()
# Initial values for snr model optimization
param.init <- c(2, 0.4, 5e-06)
# Iterate n times
for (n in 1:n) {
split.data()
# Model each channel per iteration
for (sel.channel in imgnoiser.option('RGGB.channel.labels')) {
solve <- fit.optim.snr(sel.channel, param.init)
wv <- test.error.weighted.var(sel.channel, solve$par)
se <- test.error.snr(sel.channel, solve$par)
result.df <- rbind(result.df,
data.frame(
'model' = 'optim.snr',
'channel' = sel.channel,
'w.var.error' = wv$w.var,
'w.mean.error' = wv$w.mean,
'snr.error' = se,
'coeff1' = solve$par[1],
'coeff2' = solve$par[2],
'coeff3' = solve$par[3]
))
lfit <- fit.w.robust(sel.channel)
wv <- test.error.weighted.var(sel.channel, lfit$coefficients)
se <- test.error.snr(sel.channel, lfit$coefficients)
result.df <- rbind(result.df,
data.frame(
'model' = 'w.robust',
'channel' = sel.channel,
'w.var.error' = wv$w.var,
'w.mean.error' = wv$w.mean,
'snr.error' = se,
'coeff1' = lfit$coefficients[1],
'coeff2' = lfit$coefficients[2],
'coeff3' = lfit$coefficients[3]
))
}
}
# Summarize the results per model an channel
result.df <-
tbl_df(result.df) %>%
group_by(method, channel) %>%
summarize(var.weighted.avg = mean(var.weighted),
mean.weighted.avg = mean(mean.weighted),
SNR.error.avg = mean(SNR.Error),
coeff1.avg = mean(coeff1),
coeff2.avg = mean(coeff2),
coeff3.avg = mean(coeff3)
)
# return the result
result.df;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment