Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
xval-noise-models: Fit the models.
# Compute the SNR.
# Returns "high" values when the model variance is negative to
# hint the optimizer to get out of there.
snr <- function(mean, var) {
negatives <- which(var < 0)
result <- 20*log10(mean/sqrt(abs(var)))
result[negatives] <- result[negatives]*8
result;
}
# Fit the `Optim-SNR` model
fit.optim.snr <- function(sel.channel, param.init) {
training.pics <- read.csv('train-pics.csv', stringsAsFactors = FALSE, row.names=NULL)
training.pics <- as.vector(training.pics[,1])
data.df <- subset(data.frame(vvm.all$var.df),
channel == sel.channel &
pict %in% training.pics)
real.snr <- snr(data.df$mean, data.df$var)
target <- function(par) {
b0 <- par[1]
b1 <- par[2]
b2 <- par[3]
predicted.var <- (b2*data.df$mean + b1)*data.df$mean + b0
pred.snr <- snr(data.df$mean, predicted.var)
squared.avg <- mean((real.snr - pred.snr)^2)
squared.avg;
}
solve <- optim(par=param.init, fn=target, method='Nelder-Mead',
control = list(
trace=2,
maxit=1000))
}
# Fit the regular 'VVM' model
fit.w.robust <- function(sel.channel) {
training.pics <- read.csv('train-pics.csv', stringsAsFactors = FALSE, row.names=NULL)
training.pics <- as.vector(training.pics[,1])
data.df <- subset(data.frame(vvm.all$var.df),
channel == sel.channel &
pict %in% training.pics)
library(robustbase)
fit <- lmrob(var ~ mean + I(mean^2), weight=1/mean^2, data=data.df)
fit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.