modelFitting: fit a model minimizing the (symmetric) mean squared distance

View source: R/modelFitting.r

modelFittingR Documentation

fit a model minimizing the (symmetric) mean squared distance

Description

fit a model minimizing the (symmetric) mean squared distance

Usage

modelFitting(
  model,
  tarmesh,
  iterations = 5,
  lbfgs.iter = 5,
  lbfgs.orthantwise_c = 0,
  symmetric = c(0, 1, 2),
  refdist = 1e+05,
  tardist = 1e+05,
  rho = pi/2,
  sdmax = NULL,
  mahaprob = c("none", "chisq", "dist"),
  initparams = NULL,
  k = 50,
  threads = 0,
  method = "lbfgs",
  silent = FALSE,
  ...
)

Arguments

model

statistical model of class pPCA

tarmesh

a target mesh already aligned to the model

iterations

numbers of iterations to run

lbfgs.iter

integer:

lbfgs.orthantwise_c

integer or integer vector of length iterations. Contains coefficient(x) for the L1 norm of variables. This parameter should be set to zero for standard minimization problems. Setting this parameter to a positive value activates Orthant-Wise Limited-memory Quasi-Newton (OWL-QN) method, which minimizes the objective function F(x) combined with the L1 norm |x| of the variables, {F(x) + C |x|}. This parameter is the coefficient for the |x|, i.e., C. As the L1 norm |x| is not differentiable at zero, the library modifies function and gradient evaluations from a client program suitably. The default value is zero. Note that the objective function minimized by alternative packages (e.g., glmnet) is of the form : F(x)/N + C |x|, where N is the number of parameters. lbfgs does not divide the likelihood function by N. To achieve equivalence with glmnet result, take this difference of implementation into account.

symmetric

integer: specify which MSE to minimize. 0=search both ways, 1=model to target, 2=target to model.

refdist

maximal distance from model to reference to be considered

tardist

maximal distance from target to model to be considered

rho

numeric: allowed normal deviation of a point to be considered as corresponding.

sdmax

constrain parameters (normalized PC-scores) to be within +- sdmax

mahaprob

character: if != "none", use mahalanobis-distance to determine overall probability (of the shape projected into the model space."chisq" uses the Chi-Square distribution of the squared Mahalanobisdistance, while "dist" restricts the values to be within a multi-dimensional sphere of radius sdmax. If FALSE the probability will be determined per PC separately.

initparams

a vector with initial estimations of the model parameters. Set to zeros if NULL.

k

integer: amount of closest faces to consider during closest point search.

threads

integer: number of cores to use for closest point search

method

optimizer method. Can be one of "lbfgs", "BFGS", "CG", "L-BFGS-B", "SANN", "Brent". lbfgs calls the function from package lbfgs, while the others call optim.

silent

logical: if TRUE output will be suppressed.

...

additional parameters to be passed to lbfgs or optim.

Details

this function fits a statistical model to a target mesh using a l-bfgs optimizer to minimize the symmetric mean squared distance between meshes.

Value

par

the model's parameters

mesh

the fitted mesh

Note

needs RvtkStatismo installed

Examples

## Not run: 
require(RvtkStatismo)
download.file(url="https://github.com/marcelluethi/
statismo-shaperegistration/raw/master/data/VSD001_femur.vtk","./VSD001_femur.vtk",method = "w")
download.file(url="https://github.com/marcelluethi/
statismo-shaperegistration/raw/master/data/VSD002_femur.vtk","./VSD002_femur.vtk",method = "w")
download.file(url="https://github.com/marcelluethi/
statismo-shaperegistration/raw/master/data/VSD001-lm.csv","./VSD001-lm.csv",method = "w")
download.file(url="https://github.com/marcelluethi/
statismo-shaperegistration/raw/master/data/VSD002-lm.csv","./VSD002-lm.csv",method = "w")
ref <- read.vtk("VSD001_femur.vtk")
tar <- read.vtk("VSD002_femur.vtk")
ref.lm <- as.matrix(read.csv("VSD001-lm.csv",row.names=1,header = FALSE))
tar.lm <- as.matrix(read.csv("VSD002-lm.csv",row.names=1,header = FALSE))
Kernels <- SumKernels(GaussianKernel(50,50),IsoKernel(0.1,ref))
mymod <- statismoModelFromRepresenter(ref,kernel=Kernels)
mymodC <- RvtkStatismo::statismoConstrainModel(mymod,tar.lm,ref.lm,2)
fit <- modelFitting(mymodC,tar,iterations = 15)
#or without landmarks but instead with some icp steps
taricp <- icp(tar,ref,iterations = 50,type="s",getTransform = TRUE)
taricpAff <- icp(taricp$mesh,ref,iterations = 50,type="a",getTransform = TRUE)
##get affine transform
combotrafo <- taricpAff$transform%*%taricp$transform
fit2 <- modelFitting(mymod,taricpAff$mesh,iterations = 15)
## revert affine transforms
fit2aff <- applyTransform(fit2$mesh,combotrafo,inverse=TRUE)

## End(Not run)

zarquon42b/mesheR documentation built on Jan. 28, 2024, 2:17 p.m.