import("coda")
import("mgcv")
import("Formula")
import("colorspace")

## importFrom("bit", "chunk", "chunk.default")
## importFrom("ff", "chunk.ff_vector", "chunk.ffdf", "chunk.bit", "read.table.ffdf",
##   "ff", "ffdf", "fforder", "as.ff", "ffapply", "nrow<-", "hi")
## importFrom("ffbase", "ffappend", "range.ff")

importFrom("parallel", "mclapply")
importFrom("sp", "bbox", "point.in.polygon", "polygons",
  "coordinates", "Polygon", "Polygons", "SpatialPolygons", "SpatialPoints",
  "CRS", "proj4string", "coordinates<-", "proj4string<-")
importFrom("splines", "splineDesign", "bs")
importFrom("MBA", "mba.points")
importFrom("survival", "Surv")
importFrom("mvtnorm", "rmvnorm", "dmvnorm")
importFrom("stats", "AIC", "BIC", "family")
importFrom("grDevices", "chull", "dev.interactive", "devAskNewPage",
  "gray", "gray.colors", "n2mfrow", "trans3d", "rgb", "dev.off", "png")
importFrom("graphics", "abline", "axis", "box", "contour", "hist",
  "layout", "lcm", "lines", "matplot", "mtext", "par",
  "points", "rect", "text", "plot.default", "barplot", "title", "legend", "grid")
importFrom("methods", "is", "as", "slot")
importFrom("stats", "acf", "as.formula", "coef", "complete.cases",
  "contrasts<-", "dbeta", "dbinom", "delete.response",
  "density", "dgamma", "dist", "dlnorm", "dlogis", "dnbinom",
  "dnorm", "dpois", "drop.terms", "dt", "dweibull", "end",
  "fitted", "formula", "gaussian", "integrate", "lm.wfit",
  "lowess", "make.link", "model.frame", "model.matrix",
  "model.offset", "model.response", "model.weights",
  "na.fail", "na.omit", "optim", "optimHess", "optimize",
  "pbeta", "pbinom", "pgamma", "plnorm", "plogis", "pnbinom",
  "pnorm", "ppois", "predict", "printCoefmat", "pt", "qnorm",
  "qqline", "qqnorm", "quantile", "rexp", "rgamma",
  "rmultinom", "rnorm", "runif", "rweibull", "sd", "start",
  "terms", "terms.formula", "time", "uniroot", "update",
  "var", "window", "median", "asOneSidedFormula", "ecdf",
  "pweibull", "qlogis", "rbeta", "rbinom", "rlnorm", "rpois",
  "qgamma", "qlnorm", "qweibull", "prcomp", "deviance", "cor",
  "lm.fit", "nls.control", "qbeta", "qbinom", "qpois", "na.pass", "relevel",
  ".getXlevels", "binomial", "glm", "glm.fit", "lm", "naresid", "residuals",
  "weights", "kmeans", "setNames")
importFrom("utils", "download.file", "flush.console", "getS3method",
  "head", "read.csv2", "read.table", "tail", "unzip",
  "write.table", "combn", "capture.output", "getFromNamespace")

import("Matrix")

export(
  ## main user interface
  "bamlss",               
  "bamlss.frame",
  "bamlss.formula",
  "bamlss.family",
  "opt_bfit",
  "opt_bbfit",
  "opt_bbfitp",
  "bfit",
  "bbfit",
  "bbfitp",
  "contribplot",
  "bfit_iwls",
  "bfit_iwls_Matrix",
  "bfit_lm",
  "bfit_optim",
  "bfit_glmnet",
  "sam_GMCMC",
  "GMCMC",
  "GMCMC_iwls",
  "GMCMC_iwlsC",
  "GMCMC_iwlsC_gp",
  "GMCMC_slice",
  "sam_JAGS",
  "sam_BayesX",
  "JAGS",
  "BayesX",
  "BayesX.control",
  "get_BayesXsrc",
  "sam_MVNORM",
  "MVNORM",
  "surv_transform",
  "opt_Cox",
  "sam_Cox",
  "cox_mode",
  "cox_mcmc",
  "cox_predict",

  ## engine setup functions
  "randomize",
  "trans_random",
  "trans_AR1",
  "AR1",
  "set.starting.values",
  "bamlss.engine.setup",
  "get.state",
  "get.par",
  "set.par",

  ## families,
  "ALD_bamlss",
  "AR1_bamlss",
  "beta_bamlss",
  "beta1_bamlss",
  "binomial_bamlss",
  "cnorm_bamlss",
  "cox_bamlss",
  "dirichlet_bamlss",
  "dw_bamlss",
  "ELF_bamlss",
  "gaussian_bamlss",
  "gaussian2_bamlss",
  "Gaussian_bamlss",
  "gamma_bamlss",
  "logNN_bamlss",
  "multinomial_bamlss",
  "mvnorm_bamlss",
  "poisson_bamlss",
  "quant_bamlss",
  "gpareto_bamlss",
  "glogis_bamlss",
  "nbinom_bamlss",
  "ztnbinom_bamlss",
  "lognormal_bamlss",
  "weibull_bamlss",
  "gumbel_bamlss",
  "gF",
  "Sichel_bamlss",
  "GEV_bamlss",
  "mix_bamlss",
  "DGP_bamlss",
  "ZANBI_bamlss",

  ## extractor functions
  "DIC",
  "samples",
  "samplestats",
  "results.bamlss.default",
  "parameters",
  "WAIC",

  ## vis functions
  "plot2d",
  "plot3d",
  "plotmap",
  "plotblock",
  "sliceplot",
  "colorlegend",

  ## JM
  "jm_bamlss",
  "opt_JM",
  "sam_JM",
  "jm_mcmc",
  "jm_mode",
  "simJM",
  "rJM",
  "jm_survplot",
  "jm_predict",

  ## others
  "GAMart",
  "Volcano",
  "Crazy",
  "Surv2",
  "c95",
  "s2",
  "sx",
  "rSurvTime2",
  "simSurv",
  "scale2",
  "continue",
  "homstart_data",
  "tx",
  "tx2",
  "tx3",
  "tx4",
  "rmf",
  "smooth.construct",
  "smooth.construct.tensorX.smooth.spec",
  "Predict.matrix.tensorX.smooth",
  "smooth.construct.tensorX3.smooth.spec",
  "Predict.matrix.tensorX3.smooth",
  "BUGSeta",
  "BUGSmodel",
  "neighbormatrix",
  "plotneighbors",
  "bamlss.model.frame",
  
  ## boosting/lasso
  "opt_boost",
  "opt_boostm",
  "boost",
  "boostm",
  "boost_summary",
  "boost_plot",
  "boost_frame",
  "la",
  "opt_lasso",
  "lasso",
  "lasso_plot",
  "lasso_stop",
  "lasso_coef",
  "lasso_transform",

  ## neural nets
  "n",
  "n.weights",
  "predictn",
  "ddnn",
  "predict.ddnn",
  "cv_ddnn",
  "make_weights",

  ## linear effects
  "lin",
  "smooth.construct.linear.smooth.spec",

  ## random bits
  "rb",
  "smooth.construct.randombits.smooth.spec",

  ## monotone P-splines
  "smooth.construct.ms.smooth.spec",

  ## stability selection
  "stabsel",

  ## kriging
  "smooth.construct.kr.smooth.spec",
  "Predict.matrix.kriging.smooth",

  ## shortcuts
  "boost2",
  "lasso2",
  "bayesx2",
  "bboost",
  "predict.bboost",
  "bboost_plot",
  "pathplot",

  ## misc
  "response_name",
  "smooth_check",
  "engines",
  "gamlss_distributions",
  "CRPS",

  ## mvnchol
  "dist_mvnchol",
  "make_formula",
  "mvn_chol",
  "mvn_modchol",
  "mvnchol_bamlss"
)

S3method("plot", "bamlss")
S3method("plot", "bnd")
S3method("plot", "bamlss.results")
S3method("plot", "bamlss.residuals")
S3method("c", "bamlss.residuals")
S3method("plot", "bamlss.residuals.list")
S3method("plot", "stabsel")
S3method("summary", "bamlss")
S3method("summary", "stabsel")
S3method("family", "bamlss")
S3method("family", "bamlss.frame")
S3method("family", "stabsel")
S3method("print", "summary.bamlss")
S3method("print", "family.bamlss")
S3method("print", "bamlss.frame")
S3method("print", "bamlss")
S3method("print", "boost_summary")
S3method("print", "bamlss.formula")
S3method("print", "stabsel")
S3method("print", "summary.stabsel")
S3method("plot", "boost_summary")
S3method("predict", "bamlss")
S3method("predict", "boost_frame")
S3method("fitted", "bamlss")
S3method("logLik", "bamlss")
S3method("DIC", "bamlss")
S3method("DIC", "gmcmc")
S3method("coef", "bamlss")
S3method("confint", "bamlss")
S3method("residuals", "bamlss")
S3method("model.matrix", "bamlss.frame")
S3method("model.matrix", "bamlss.terms")
S3method("model.matrix", "bamlss.formula")
S3method("smooth.construct", "bamlss.frame")
S3method("smooth.construct", "bamlss.formula")
S3method("smooth.construct", "bamlss.terms")
S3method("smooth.construct", "kr.smooth.spec")
S3method("smooth.construct", "tensorX.smooth.spec")
S3method("smooth.construct", "tensorX3.smooth.spec")
S3method("smooth.construct", "la.smooth.spec")
S3method("smooth.construct", "nnet.smooth.spec")
S3method("smooth.construct", "nnet2.smooth.spec")
S3method("smooth.construct", "linear.smooth.spec")
S3method("smooth.construct", "randombits.smooth.spec")
S3method("smooth.construct", "sr.smooth.spec")
S3method("smooth.construct", "ms.smooth.spec")
S3method("Predict.matrix", "kriging.smooth")
S3method("Predict.matrix", "deriv.smooth")
S3method("Predict.matrix", "tensorX.smooth")
S3method("Predict.matrix", "tensorX3.smooth")
S3method("Predict.matrix", "lasso.smooth")
S3method("Predict.matrix", "nnet.smooth")
S3method("Predict.matrix", "nnet2.smooth")
S3method("Predict.matrix", "nnet3.smooth")
S3method("Predict.matrix", "linear.smooth")
S3method("Predict.matrix", "randombits.smooth")
S3method("Predict.matrix", "srand.smooth")
S3method("Predict.matrix", "ff_smooth.smooth.spec")
S3method("bamlss.engine.setup.smooth", "default")
S3method("sx.construct", "tensorX.smooth")
S3method("terms", "bamlss")
S3method("terms", "bamlss.frame")
S3method("terms", "bamlss.formula")
S3method("samples", "bamlss")
S3method("samples", "bamlss.frame")
S3method("model.frame", "bamlss")
S3method("model.frame", "bamlss.frame")
S3method("predict", "ddnn")
S3method("predict", "bboost")
S3method("fitted", "ddnn")
S3method("residuals", "ddnn")
S3method("formula", "bamlss.formula.character")
S3method("formula", "bamlss.formula")
S3method("formula", "stabsel")
S3method("as.character", "bamlss.formula")
S3method("as.character", "bamlss.terms")
S3method("prodist", "bamlss")

S3method("smooth.construct", "Re.smooth.spec")
S3method("smooth.construct", "Re2.smooth.spec")
S3method("smooth.construct", "fdl.smooth.spec")
S3method("smooth.construct", "ha.smooth.spec")
S3method("smooth.construct", "ispline.smooth.spec")
S3method("smooth.construct", "mlt.smooth.spec")
S3method("smooth.construct", "nnet0.smooth.spec")
S3method("smooth.construct", "re2.smooth.spec")
S3method("smooth.construct", "rs.smooth.spec")
S3method("smooth.construct", "rsc.smooth.spec")
S3method("smooth.construct", "str.smooth.spec")

## For topmodels.
import("distributions3")
export(BAMLSS)
S3method(cdf, BAMLSS)
S3method(family, BAMLSS)
S3method(format, BAMLSS)
S3method(is_continuous, BAMLSS)
S3method(is_discrete, BAMLSS)
S3method(kurtosis, BAMLSS)
S3method(log_pdf, BAMLSS)
S3method(mean, BAMLSS)
S3method(pdf, BAMLSS)
S3method(print, BAMLSS)
S3method(quantile, BAMLSS)
S3method(random, BAMLSS)
S3method(scoringRules::crps, BAMLSS)
S3method(skewness, BAMLSS)
S3method(support, BAMLSS)
S3method(variance, BAMLSS)

useDynLib(bamlss, .registration = TRUE)

