Skip to content
Closed

Fbms #34

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
96b678f
Rebrand to FBMS and submitted to CRAN.
jonlachmann Sep 30, 2023
8c7ad1e
default R added for logistic regression
Oct 6, 2023
0a3b74a
1. diagnostics plot renamed for cran
Oct 9, 2023
0907b5c
Replace F and T with FALSE and TRUE.
jonlachmann Oct 29, 2023
2dbbcec
Add explanations of MJMCMC and GMJMCMC in docs.
jonlachmann Oct 29, 2023
427508a
Add explanations of MJMCMC and GMJMCMC in docs.
jonlachmann Oct 29, 2023
29a8e0b
Add references in DESCRIPTION
jonlachmann Oct 29, 2023
804337e
Add references in DESCRIPTION
jonlachmann Oct 29, 2023
1dee539
Add references in DESCRIPTION
jonlachmann Oct 29, 2023
9012462
Add return value documentation for all functions where it was missing.
jonlachmann Oct 29, 2023
0ee267f
More docs.
jonlachmann Oct 29, 2023
56e4429
More docs.
jonlachmann Oct 29, 2023
82e0931
Add verbose flags to be able to turn off console output.
jonlachmann Oct 29, 2023
8d4ffd4
examples added for CRAN
Oct 29, 2023
33c7ce6
added a simple call function FBMS
Nov 5, 2023
77611ea
updated fbms function
Nov 5, 2023
bb0acb5
simple FBMS funtion updated
Nov 5, 2023
f9f3c1f
Minor adjustments.
jonlachmann Nov 5, 2023
52ff8db
Line lengths in examples.
jonlachmann Nov 5, 2023
7463861
Minor CRAN fixes.
jonlachmann Nov 5, 2023
9440845
Minor CRAN fixes.
jonlachmann Nov 5, 2023
65ae75a
Improve run time for examples to satisfy CRAN requirements.
jonlachmann Nov 5, 2023
3e59a97
added a no run example for
Nov 6, 2023
e81048a
1. Effect sizes added
Nov 9, 2023
ac2e54f
effect sizes fixed for mjmcmc output
Nov 9, 2023
f9a6a9a
More CRAN fixes!
jonlachmann Nov 17, 2023
0e9a3dc
More CRAN fixes!!
jonlachmann Nov 20, 2023
14d66c7
More CRAN fixes...
jonlachmann Nov 22, 2023
52ade62
More CRAN fixes... date
jonlachmann Nov 28, 2023
57b4c2d
Included names of function after @export, which seems to make them vi…
Mar 20, 2024
b2b2217
added error handling if some chains faced problems
Jun 20, 2024
fdcc803
error messaging from within parallel chains added
Jun 20, 2024
1e441f0
documentation updated after NSM24 discussions
Jun 21, 2024
6d271a3
fixing the summary plotting issues with overriden base r commands
Jul 2, 2024
2856d0d
fixed pop = ... parameter in summaries, plots and predicts, also defa…
Jul 2, 2024
2ae4717
1. summaries moved back to pop = "best" by default
Jul 4, 2024
570a105
Trying to fix
Jul 5, 2024
e4ea9a5
trying to fix sample.int issues that very rarely but arrise
Jul 5, 2024
14109ce
fixed furhter sample int potential issues
Jul 5, 2024
78d3972
added population to printed output
Jul 18, 2024
8b111a3
fbms large data formula fix
Jul 18, 2024
496b952
fixing a rare proposal bug
Jul 19, 2024
3d3534e
verbose bug fixed in fbms wrapper
Aug 13, 2024
be2026a
setting default runs = 1
Aug 13, 2024
d10ff24
fbms function redesigned, method argument added, other parameters of …
Aug 13, 2024
b5010fa
verbose is set TRUE by default in fbms
Aug 13, 2024
838aa25
cosmetic changes in documentation following emails with Florian
Aug 14, 2024
62732d3
documentation for log.prior and ala added
Aug 19, 2024
2c106a5
* Refactor results filtration in merge results.
jonlachmann Sep 3, 2024
ecd08bd
* Fix to ensure that summary is using the correct transforms.
jonlachmann Sep 3, 2024
e225619
1 returning summary fixed
Sep 6, 2024
1f73e53
predict transforms fixed
Sep 19, 2024
5c6f4b4
parallel support for windows alfa version. test needed.
Sep 20, 2024
80e2c1e
parallel support for windows added
Sep 20, 2024
08a2fab
cthe parallels did not work yet on windows
Sep 21, 2024
db90914
removed for now rmclapply
Sep 21, 2024
5e4c86c
addinng mclapply hack for the package that imitates forking under win…
Sep 21, 2024
6505acc
exporting our new rmclapply to the global scope of the package to avo…
Sep 22, 2024
e23cb30
Included abalone data in the package, with documentation
Sep 24, 2024
27260f7
* Fix parallel run on windows
jonlachmann Sep 26, 2024
5191925
* Code style.
jonlachmann Sep 26, 2024
cb966a6
Script for reading Sanger data. Checked that it is equal to the data …
Sep 27, 2024
5cb38f1
Merge branch 'FBMS' of https://github.com/jonlachmann/GMJMCMC into FBMS
Sep 27, 2024
f2b32b0
sigmoid dixed
Sep 27, 2024
a8d429a
mising data handling added
Sep 28, 2024
b0e10cf
setting back global options after inference done, dfault, no impute set
Sep 29, 2024
f3c8feb
name in documentation updated
Sep 29, 2024
0841af5
commit na action
Sep 29, 2024
3c2c409
globally defined user specified transformation handling fixed in rmcl…
Oct 1, 2024
06ed3ea
Changed to use exoplanet object in package.
Oct 1, 2024
6964734
Merge branch 'FBMS' of https://github.com/jonlachmann/GMJMCMC into FBMS
Oct 1, 2024
965b2b4
Created
Oct 1, 2024
cb7a0ab
Updated Sanger data to not reshuffle columns (done in the analysis in…
Oct 1, 2024
6d62cb8
1. added gc() inside rmclapply function
Oct 3, 2024
023b24d
Merge branch 'FBMS' of https://github.com/jonlachmann/GMJMCMC into FBMS
Oct 3, 2024
281c854
Included names on individuals for SangerData and made the response th…
Oct 3, 2024
aa76aed
Merge branch 'FBMS' of https://github.com/jonlachmann/GMJMCMC into FBMS
Oct 3, 2024
302b1f6
seems to have fixed the seeds on parLapply!
Oct 3, 2024
e73dc3b
Merge branch 'FBMS' of https://github.com/jonlachmann/GMJMCMC into FBMS
Oct 3, 2024
58ab515
pop.max < p (init) bug fixed!
Oct 3, 2024
eba71e6
summary after prefiltering fixed
Oct 10, 2024
4ad35cc
Convertet SangerData2 to a data frame
Oct 11, 2024
946d31f
remerging issue fixed after parallel gmjmcmc
Oct 11, 2024
3f685d2
Merge branch 'FBMS' of https://github.com/jonlachmann/GMJMCMC into FBMS
Oct 11, 2024
522d0f2
docimentation after Geirs pull updated
Oct 11, 2024
2fc4a0f
Included example scripts from Florian (received 29.10.24) into the te…
Oct 29, 2024
761cde3
1d matrix to array conversion in newer R version causing a rare bug f…
Dec 13, 2024
c98f3e9
Included Sanger data
Dec 16, 2024
034cbeb
Updated script for making Sanger data
Dec 17, 2024
f36b36a
Updated script to use data in library and also only use reduced dataset
Dec 17, 2024
1ec3a1f
Changed to select variables by correlation
Dec 18, 2024
1f3fa0c
the warning message updated for too small population sizes
Dec 18, 2024
1478e05
examples from Florian with new names added
Dec 19, 2024
975088e
examples cleaned a bit
Dec 29, 2024
cf973e5
added ylim for diagn_plot
Dec 30, 2024
25889d0
Removed my local versions of examples in order to avoid conflict
Jan 28, 2025
1939a48
Merge branch 'FBMS' of https://github.com/jonlachmann/GMJMCMC into FBMS
Jan 28, 2025
a864ce3
Loaded data directly from package
Jan 28, 2025
686338c
mlik for other that unit variances added to gaussian.loglik calculations
Jan 29, 2025
5c7c004
Merge branch 'FBMS' of https://github.com/jonlachmann/GMJMCMC into FBMS
Jan 29, 2025
14551a8
params$var updated
Jan 29, 2025
e3bceb2
one more default setting corrections for gaussian mliks
Jan 29, 2025
30ab52c
unit variance as default for gaussian data
Jan 29, 2025
7409984
added detailed documentation for gen.probs.mjmcmc()
Jan 30, 2025
5221064
spelling corrected in sixes
Jan 30, 2025
fe8eb57
documentation for gen.propbs.gmjmcmc function updated with details fo…
Jan 30, 2025
0b9ff45
BIG fixes, many inconsistencies with the orgiginal EMJMCMC fixed.
Feb 3, 2025
1f00886
alpha generation type 4 (fully Bayesian) added,examples overviewed
Feb 5, 2025
1b29099
alpha strategies renamed to unit, deep, random
Feb 10, 2025
3502c79
* CRAN fixes
jonlachmann Feb 11, 2025
e649b2d
* Minor nitpicks.
jonlachmann Feb 11, 2025
9929b48
* Fix tests.
jonlachmann Feb 11, 2025
cd097da
Update README.md
jonlachmann Feb 11, 2025
b1ac51f
Made a new folder with scripts for making data. Currently only Sanger…
Feb 18, 2025
5782314
Included two SangerData sets, made by the Read_sanger_data.R script
Feb 18, 2025
9362cd7
Made result_parallel and result_parallel2 equal (except for seed)
Feb 18, 2025
37aa269
Model revisiting (#35)
jonlachmann Feb 18, 2025
337d70a
temp commit
Feb 19, 2025
af246aa
deleted wrongly added files
Feb 19, 2025
49f5eff
Deletet full sanger data, can be made running the script Make_Sanger_…
Feb 19, 2025
a370ce0
Merge branch 'FBMS' of https://github.com/jonlachmann/GMJMCMC into FBMS
Feb 19, 2025
b63d011
examples checked. new best pop message improved according to Geir's r…
Feb 19, 2025
79c368e
sanger data documentation and file updated for test passing
Feb 19, 2025
7277f4a
add get.best.model function
Feb 20, 2025
a606ae9
summary is automatically taking input data names now
Feb 20, 2025
14e1e4b
adding mpm and predictions for mpm and best model
Feb 20, 2025
42d78f5
object must be the first arg in predict function
Feb 20, 2025
70ea10b
predict model documentation updated
Feb 20, 2025
2fec79d
predict fixed
Feb 20, 2025
9ed52ca
adding ... in predict mpm or best to avoid warnings
Feb 20, 2025
cdb92a4
update predict documentation
Feb 20, 2025
c224373
describinng ... argument in predict best and mpm
Feb 20, 2025
dee027c
documentation updated
Feb 21, 2025
ae216df
Error in fbms(data = df, method = "gmjmcmc.parallel", transforms = tr…
Feb 21, 2025
9dbb046
added aa logic regression example number 5 as the new example for cus…
Feb 26, 2025
a590b85
logic regression example 5 added
Feb 26, 2025
f89d56e
tcch prior added for logic regression
Feb 26, 2025
a242675
potentially too big large jumps when pop size is smaller than the dat…
Feb 26, 2025
b1444a9
logic regression example alligned to the overleaf
Feb 26, 2025
e9427ac
* Break out a new file for summary
jonlachmann Feb 26, 2025
cb9f66e
* Polish before CRAN
jonlachmann Feb 26, 2025
cb46648
* Docs updates.
jonlachmann Feb 26, 2025
183ca37
* CRAN fixes.
jonlachmann Feb 26, 2025
77551ca
Included process time
Feb 27, 2025
4f5cd07
Renamed Ex3_Sec4_1.R related to merging Ex3+7
Mar 5, 2025
58963a5
Renamed Ex7_Sec5_1.R to Ex3_Sec4_1.R as part of merging these examples
Mar 5, 2025
a62a6d8
updated the database for kepler data to the most recent version
Mar 6, 2025
bf7aa00
Merge branch 'FBMS' of https://github.com/jonlachmann/GMJMCMC into FBMS
Mar 6, 2025
ad5abfb
added also the case with a fixed variance to example 1
Mar 6, 2025
4ca9efa
g prior added to example 1
Mar 6, 2025
139b76c
g prior based predictions added
Mar 6, 2025
1b7e59d
A lot of rearrangements on the script
Mar 7, 2025
7622dc6
Removed single runs from script,now only containing parallel runs.
Mar 19, 2025
2fc09f8
bas glm c .Call added
Mar 19, 2025
4af0f77
BAS linear models with all priors in
Mar 20, 2025
fd3b619
documentation added for rd files
Mar 20, 2025
6e2176c
a BAS log priors fixed examples with testing on Keppler all BAS prior…
Mar 20, 2025
b30d966
playing around with examples and all the new parameter priors
Mar 20, 2025
90f1a0c
tcch family of priors added for Gaussian responses
Mar 24, 2025
afc96a9
g prior under gaussian case added to likelihood. all documentation up…
Mar 24, 2025
61e0419
likelihoods file polished a bit
Mar 24, 2025
5398fde
master estimator added
Mar 24, 2025
9e719fb
master function fixed and updated. docs on master function added
Mar 24, 2025
b5dccd4
finally general master estimator added and polished
Mar 26, 2025
fa47531
updates from testing
Mar 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.idea
test
Make_data
tests_current
README.md
.DS_Store
^.*\.Rproj$
^\.Rproj\.user$
^CRAN-SUBMISSION$
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
inst/doc
run_algorithm.R
.Rproj.user
.idea
test
*.o
*.so
26 changes: 17 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
Package: GMJMCMC
Package: FBMS
Type: Package
Title: Genetically Modified Mode Jumping MCMC
Version: 1.0
Date: 2023-06-30
Title: Flexible Bayesian Model Selection and Model Averaging
Version: 1.1
Date: 2025-02-26
Encoding: UTF-8
Author: Jon Lachamnn
Maintainer: Jon Lachmann <[email protected]>
Description: Implements the GMJMCMC and MJMCMC algorithms used to fit Bayesian Generalized Non-Linear Models (BGNLM).
Language: en-US
Authors@R: c(
person("Jon", "Lachmann", email = "[email protected]", role = c("cre", "aut")),
person("Aliaksandr", "Hubin", email = "[email protected]", role = "aut")
)
Description: Implements the Mode Jumping Markov Chain Monte Carlo algorithm described in <doi:10.1016/j.csda.2018.05.020> and its Genetically Modified counterpart described in <doi:10.1613/jair.1.13047> as well as the sub-sampling versions described in <doi:10.1016/j.ijar.2022.08.018> for flexible Bayesian model selection and model averaging.
License: GPL-2
Depends:
R (>= 3.5.0),
fastglm,
GenSA,
parallel,
methods,
stats,
graphics
graphics,
r2r,
BAS,
tolerance
Imports:
Rcpp
LinkingTo:
Expand All @@ -24,6 +31,7 @@ Suggests:
knitr,
rmarkdown,
markdown
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
LazyData: true
51 changes: 51 additions & 0 deletions Make_data/Read_sanger_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#Read Sanger data
#Download first from https://ftp.sanger.ac.uk/pub/genevar/ the files
#https://ftp.sanger.ac.uk/pub/genevar/CEU_children_norm_march2007.zip
#https://ftp.sanger.ac.uk/pub/genevar/CHB_unrelated_norm_march2007.zip
#https://ftp.sanger.ac.uk/pub/genevar/JPT_unrelated_norm_march2007.zip
#https://ftp.sanger.ac.uk/pub/genevar/YRI_parents_norm_march2007.zip
#and unzip these

#Specify right path
path = "/mn/sarpanitu/ansatte-u2/geirs/prj/FBMS/data/"
x1 = t(read.table(paste(path,"CEU_parents_norm_march2007.txt",sep=""),header=T))
x2 = t(read.table(paste(path,"CHB_unrelated_norm_march2007.txt",sep=""),header=T))
x3 = t(read.table(paste(path,"JPT_unrelated_norm_march2007.txt",sep=""),header=T))
x4 = t(read.table(paste(path,"YRI_parents_norm_march2007.txt",sep=""),header=T))

rnames = c(rownames(x1)[-1],rownames(x2)[-1],rownames(x3)[-1],rownames(x4)[-1])
nam = x1[1,]
x1 = apply(x1[-1,],2,as.numeric)
x2 = apply(x2[-1,],2,as.numeric)
x3 = apply(x3[-1,],2,as.numeric)
x4 = apply(x4[-1,],2,as.numeric)
df = rbind(x1,x2,x3,x4)
colnames(df) = nam
rownames(df) = rnames

#Make columnn 24266 the first column, corresponding to CCT8
#(from the illumina_Human_WG-6_array_content.csv file)
df <- df[,c(24266,1:24265,24267:ncol(df))]

#Choose response variable
SangerData = df
usethis::use_data(SangerData,overwrite=TRUE)

#Rename columns
#colnames(df) = c("y",paste0("x",1:47292))

#Reduced dataset first by those having maximum expression levels below the
#25-th percentile of all measured expression levels
q = quantile(df[,-1],0.25)
foo = apply(df[,-1],2,max)
nC = ncol(df)-1
df = df[,c(1,1+c(1:nC)[foo>q])]

#Reduced dataset by deleting rows with range<2
drange = function(x){diff(range(x))}
foo2 = apply(df,2,drange)
nC = ncol(df)-1
df = df[,c(1,1+c(1:nC)[foo2>2])]
SangerData2 = as.data.frame(df)
usethis::use_data(SangerData2,overwrite=TRUE)

65 changes: 58 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ S3method(plot,gmjmcmc)
S3method(plot,gmjmcmc_merged)
S3method(plot,mjmcmc)
S3method(plot,mjmcmc_parallel)
S3method(predict,bgnlm_model)
S3method(predict,gmjmcmc)
S3method(predict,gmjmcmc_merged)
S3method(predict,gmjmcmc_parallel)
Expand All @@ -14,24 +15,34 @@ S3method(summary,gmjmcmc)
S3method(summary,gmjmcmc_merged)
S3method(summary,mjmcmc)
S3method(summary,mjmcmc_parallel)
export(cos.rad)
export(compute_effects)
export(cos_deg)
export(diagn_plot)
export(erf)
export(exp.dbl)
export(exp_dbl)
export(fbms)
export(fbms.mlik.master)
export(gauss)
export(gaussian.loglik)
export(gaussian.loglik.alpha)
export(gaussian.loglik.bic.irlssgd)
export(gaussian.loglik.g)
export(gaussian_tcch_log_likelihood)
export(gelu)
export(gen.params.gmjmcmc)
export(gen.params.mjmcmc)
export(gen.probs.gmjmcmc)
export(gen.probs.mjmcmc)
export(get.best.model)
export(get.mpm.model)
export(glm.loglik)
export(glm.logpost.bas)
export(gmjmcmc)
export(gmjmcmc.iact)
export(gmjmcmc.parallel)
export(hs)
export(linear.g.prior.loglik)
export(lm.logpost.bas)
export(log_prior)
export(logistic.loglik)
export(logistic.loglik.ala)
export(logistic.loglik.alpha)
export(marginal.probs)
export(merge_results)
Expand Down Expand Up @@ -60,27 +71,67 @@ export(pm2)
export(relu)
export(set.transforms)
export(sigmoid)
export(sin.rad)
export(sin_deg)
export(sqroot)
export(string.population)
export(string.population.models)
export(to23)
export(to25)
export(to35)
export(to72)
export(troot)
importFrom(BAS,CCH)
importFrom(BAS,EB.local)
importFrom(BAS,Jeffreys)
importFrom(BAS,TG)
importFrom(BAS,beta.prime)
importFrom(BAS,bic.prior)
importFrom(BAS,g.prior)
importFrom(BAS,hyper.g)
importFrom(BAS,hyper.g.n)
importFrom(BAS,hypergeometric1F1)
importFrom(BAS,hypergeometric2F1)
importFrom(BAS,intrinsic)
importFrom(BAS,phi1)
importFrom(BAS,tCCH)
importFrom(BAS,uniform)
importFrom(GenSA,GenSA)
importFrom(Rcpp,sourceCpp)
importFrom(fastglm,fastglm)
importFrom(graphics,barplot)
importFrom(graphics,lines)
importFrom(graphics,text)
importFrom(methods,is)
importFrom(parallel,clusterEvalQ)
importFrom(parallel,clusterExport)
importFrom(parallel,detectCores)
importFrom(parallel,makeCluster)
importFrom(parallel,mclapply)
importFrom(parallel,parLapply)
importFrom(parallel,stopCluster)
importFrom(r2r,has_key)
importFrom(r2r,hashmap)
importFrom(stats,Gamma)
importFrom(stats,acf)
importFrom(stats,as.formula)
importFrom(stats,binomial)
importFrom(stats,cor)
importFrom(stats,gaussian)
importFrom(stats,glm.control)
importFrom(stats,lm)
importFrom(stats,lm.fit)
importFrom(stats,median)
importFrom(stats,model.matrix)
importFrom(stats,model.response)
importFrom(stats,pnorm)
importFrom(stats,poisson)
importFrom(stats,predict)
importFrom(stats,qnorm)
importFrom(stats,rbinom)
importFrom(stats,rnorm)
importFrom(stats,runif)
importFrom(stats,sd)
importFrom(stats,var)
useDynLib(GMJMCMC)
importFrom(tolerance,F1)
importFrom(utils,sessionInfo)
useDynLib(FBMS)
4 changes: 2 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

set_alphas <- function(formula) {
.Call('_GMJMCMC_set_alphas', PACKAGE = 'GMJMCMC', formula)
.Call('_FBMS_set_alphas', PACKAGE = 'FBMS', formula)
}

vec_in_mat <- function(mat, vec, firstCol = 0L, lastCol = 0L) {
.Call('_GMJMCMC_vec_in_mat', PACKAGE = 'GMJMCMC', mat, vec, firstCol, lastCol)
.Call('_FBMS_vec_in_mat', PACKAGE = 'FBMS', mat, vec, firstCol, lastCol)
}

31 changes: 31 additions & 0 deletions R/abalone-data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' Physical measurements of 4177 abalones, a species of sea snail.
#'
#' %% ~~ A concise (1-5 lines) description of the dataset. ~~
#'
#' See the web page \url{https://archive.ics.uci.edu/ml/datasets/Abalone} for
#' more information about the data set.
#'
#' @name abalone
#' @docType data
#' @format A data frame with 4177 observations on the following 9 variables.
#' \describe{
#' \item{Diameter}{Diameter Perpendicular to length, continuous}
#' \item{Height}{Height with with meat in shell, continuous.}
#' \item{Length}{Longest shell measurement, continuous}
#' \item{Rings}{+1.5 gives the age in years, integer}
#' \item{Sex}{Sex of the abalone, \code{F} is female, \code{M} male, and \code{I} infant, categorical.}
#' \item{Weight_S}{Grams after being dried, continuous.}
#' \item{Weight_Sh}{Grams weight of meat, continuous.}
#' \item{Weight_V}{Grams gut weight (after bleeding), continuous.}
#' \item{Weight_W}{Grams whole abalone, continuous.} }
#' @source Dua, D. and Graff, C. (2019). UCI Machine Learning Repository
#' \url{https://archive.ics.uci.edu/ml/}. Irvine, CA: University of California,
#' School of Information and Computer Science.
#'
#' @keywords datasets
#' @examples
#'
#' data(abalone)
#' ## maybe str(abalone) ; plot(abalone) ...
#'
NULL
38 changes: 30 additions & 8 deletions R/alpha_generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
# Created by: jonlachmann
# Created on: 2021-03-16

gen.alphas <- function (strategy, feature, data, loglik) {
if (strategy == 1) stop("Not implemented.")
else if (strategy == 2) stop("Not implemented.")
else if (strategy == 3) feature <- alpha_3(feature, data, loglik)
gen.alphas <- function (strategy, feature, data, loglik, verbose) {

Check warning on line 6 in R/alpha_generation.R

View workflow job for this annotation

GitHub Actions / lint

file=R/alpha_generation.R,line=6,col=23,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function definition.
if (strategy == "deep") feature <- alpha_3(feature, data, loglik, verbose)
else if (strategy == "random") feature <- alpha_4(feature) else stop("Not implemented.")
return(feature)
}

#' Alpha generator using strategy 1 as per Hubin et. al.
#' TODO: This is just a placeholder.
#'
#' @noRd
#'
#' @param feature The feature to generate alphas for
alpha_1 <- function (feature) {

Check warning on line 18 in R/alpha_generation.R

View workflow job for this annotation

GitHub Actions / lint

file=R/alpha_generation.R,line=18,col=20,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function definition.
return(feature)
}

#' Alpha generator using strategy 2 as per Hubin et. al.
#' TODO: This is just a placeholder.
#'
#' @noRd
#'
#' @param feature The feature to generate alphas for
alpha_2 <- function (feature) {

Check warning on line 28 in R/alpha_generation.R

View workflow job for this annotation

GitHub Actions / lint

file=R/alpha_generation.R,line=28,col=20,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function definition.
return(feature)
}

Expand All @@ -29,31 +34,48 @@
#' @param feature The feature to generate alphas for
#' @param data The dataset used
#' @param loglik log likelihood function to use
alpha_3 <- function (feature, data, loglik) {
#'
#' @noRd
#'
alpha_3 <- function (feature, data, loglik, verbose) {

Check warning on line 40 in R/alpha_generation.R

View workflow job for this annotation

GitHub Actions / lint

file=R/alpha_generation.R,line=40,col=20,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function definition.
# Create the string representation of the feature with variable alphas
featfun <- print.feature(feature, dataset = TRUE, alphas = TRUE)
featfun <- set_alphas(featfun)
# Return if there are no alphas to set
if (featfun$count == 0) return(feature)

# Set initial range for Simulated Annealing
cat("Generating alphas\n")
range <- 10
done <- FALSE
while (!done) {
# Run simulated annealing on current range
sares <- GenSA::GenSA(rnorm(featfun$count), loglik,
rep(-range / 2, featfun$count), rep(range / 2, featfun$count),
control = list(max.call = 5e3), data, featfun$formula)
control = list(max.call = 5e3, maxit = 20,nb.stop.improvement = 5), data, featfun$formula)
# Check if any estimate is on the edge of the range, if so, extend the range and run again
if (sum((sares$par == (-range / 2)) + (sares$par == (range / 2))) != 0) range <- range*2
else done <- TRUE
}
if (sum(sares$par == 0) == featfun$count) {
cat("All zero feature occured.\n")
if (verbose) cat("All zero feature occured.\n")
return(NULL)
}
# Inject the new alphas into the feature
feature <- update.alphas(feature, sares$par)
return(feature)
}

#' Alpha generator using strategy 4 as per Hubin et. al.
#'
#' @param feature The feature to generate alphas for
#'
#' @noRd
#'
alpha_4 <- function (feature) {

Check warning on line 74 in R/alpha_generation.R

View workflow job for this annotation

GitHub Actions / lint

file=R/alpha_generation.R,line=74,col=20,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function definition.
# Create the string representation of the feature with variable alphas
featfun <- print.feature(feature, dataset = TRUE, alphas = TRUE)
featfun <- set_alphas(featfun)

Check warning on line 78 in R/alpha_generation.R

View workflow job for this annotation

GitHub Actions / lint

file=R/alpha_generation.R,line=78,col=1,[trailing_whitespace_linter] Remove trailing whitespace.
feature <- update.alphas(feature, rnorm(featfun$count,0,1))
return(feature)
}
Loading