Open OrdinarySK opened 4 years ago
The SSA code here is implemented in the function ssaMap. The source code can be seen in R, and is visible here in GitHub: https://github.com/jskoien/intamapInteractive/blob/master/R/ssaMap.R Or did you mean something else than this?
Thank you very much. My object function is the weighting of multi-mkv. could you give me some advices to programming the function. Before this, I used the "ssaOptim“ function finshed calculation of single mkv. I also added some points to fix the suitable number of points. Can I define my own objective function based on your package to achieve my needs? Because the preparation before optimization based on the objective function is applicable based on the intamapInteractive package.
The package as it is now is probably not flexible enough to achieve what I think you would like to do. What you could do is download the source code, then you could either:
I modified the code of CalculateMukv . Here are my object function code:
**__**`calculateMukv` <-
function (observations, predGrid, model, formulaString, fun, ...)
{
if (!missing(fun) && is.function(fun)) {
return(do.call(fun, list(observations, predGrid, model, formulaString, ...)))
}
if(length(model) !=3){
stop("model must contain three variogram")
}else{
model1 = model[[1]]
model2 = model[[2]]
model3 = model[[3]]
}
prG = predGrid
obs = observations_**
if (missing(formulaString) || is.null(formulaString)) {
eq1 = dum ~ 1
eq2 = dum ~ 1
eq3 = dum ~ 1
}
if(length(formulaString) == 3){
eq1 = formulaString[[1]] #lst
eq2 = formulaString[[2]] #pre
eq3 = formulaString[[3]] #twi
}else{
stop("must input three parameter")
}
############ changed following 'if statement'
if (!"data.frame" %in% getSlots(class(obs)) & all(all.vars(eq1)[-1] %in% dimnames(coordinates(obs))[[2]])
& all(all.vars(eq2)[-1] %in% dimnames(coordinates(obs))[[2]])
& all(all.vars(eq3)[-1] %in% dimnames(coordinates(obs))[[2]])) {
obs = SpatialPointsDataFrame(obs, data = data.frame(dum = rep(1,
dim(coordinates(obs))[1])))
names(obs) = as.character("mutil-MKV")
}
lst_krige = krige(eq1, obs, prG, model1)
pre_krige = krige(eq2, obs, preG, model2)
soil_krige = krige(eq3, obs, preG, model3)
lst_mkv = mean(lst_krige$var1.var)
pre_mkv = mean(pre_krige$var1.var)
soil_mkv = mean(pre_krige$var1.var)
mutil_obj = lst_mkv / (3 * model1$psill[2]) + pre_mkv / (3 * model2$psill[2])
+ soil_mkv / (3 * model3$psill[2])
'red_ann_gam_krig = krige(eq, obs, prG, model)'
return(mutil_obj)
}**_
My mutil-Mukv need three models and formulas. The parameter of model and formulaString I pass by default is a list containing three objects. But I meet new problem. I modified the parameter number of calculateMukv so that need to modify ssaOptim and ssaMap. Because of ssaOptim and ssaMap also used calculateMukv. ``
I want to ask you some questions. counld you tell me how to achieve “spatial simulated annealing(SSA)”algorithm? I want to programmatically achieve ssa optimization of MKV for multiple goals. I hope you can tell us about the source code or website of SSA implementation.