Skip to content

Commit bd4958e

Browse files
Comments about functions
1 parent ddba6c0 commit bd4958e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

R/SmallFuncs.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# The functions in this file are all internal.
2+
3+
# Determine if a set of parameters is within the bounds.
14
checkBounds <- function(tab, bounds) {
25
return(
36
sapply(
@@ -9,6 +12,7 @@ checkBounds <- function(tab, bounds) {
912
)
1013
}
1114

15+
# Draw random parameters with LHS
1216
randParams <- function(boundsDT, rPoints, FAIL = TRUE) {
1317

1418
# Attempt to procure rPoints unique parameter sets by lhs.
@@ -37,6 +41,7 @@ randParams <- function(boundsDT, rPoints, FAIL = TRUE) {
3741

3842
}
3943

44+
# Scale parameters to 0-1 between their bounds.
4045
minMaxScale <- function(tabl, boundsDT) {
4146

4247
# tabl <- newD
@@ -49,6 +54,7 @@ minMaxScale <- function(tabl, boundsDT) {
4954

5055
}
5156

57+
# Do the reverse of minMaxScale
5258
unMMScale <- function(tabl, boundsDT) {
5359

5460
umms <- lapply(boundsDT$N, function(x) {
@@ -70,6 +76,7 @@ unMMScale <- function(tabl, boundsDT) {
7076

7177
}
7278

79+
# Scale a vector between 0-1
7380
zeroOneScale <- function(vec) {
7481

7582
r <- max(vec) - min(vec)
@@ -84,6 +91,7 @@ zeroOneScale <- function(vec) {
8491

8592
}
8693

94+
# Check to see if any rows from tab1 are exact duplicates of rows in tab2.
8795
checkDup <- function(tab1,tab2) {
8896

8997
sapply(1:nrow(tab1), function(i) {
@@ -93,6 +101,7 @@ checkDup <- function(tab1,tab2) {
93101

94102
}
95103

104+
# Return a data.table from a bounds list. Easier to work with.
96105
boundsToDT <- function(bounds) {
97106
data.table(
98107
N = names(bounds)
@@ -103,6 +112,7 @@ boundsToDT <- function(bounds) {
103112
)
104113
}
105114

115+
# Attempt to save bayesOpt object between optimization steps.
106116
saveSoFar <- function(optObj,verbose) {
107117
if (!is.null(optObj$saveFile)) {
108118
tryCatch(
@@ -117,8 +127,10 @@ saveSoFar <- function(optObj,verbose) {
117127
}
118128
}
119129

130+
# Cannot pass `%dopar%` so we recreate it with this function.
120131
ParMethod <- function(x) if(x) {`%dopar%`} else {`%do%`}
121132

133+
# Get information about the acquisition functions.
122134
getAcqInfo <- function(acq) {
123135
return(
124136
data.table(
@@ -129,6 +141,7 @@ getAcqInfo <- function(acq) {
129141
)
130142
}
131143

144+
# Early checks for parameters.
132145
checkParameters <- function(
133146
bounds
134147
, iters.n
@@ -154,24 +167,29 @@ checkParameters <- function(
154167
if (!errorHandling %in% c("stop","continue") & !is.numeric(errorHandling)) stop("errorHandling is malformed: Must be one of 'stop', 'continue', or an integer.")
155168
}
156169

170+
# Get the total time run of an object given the time it was started.
157171
totalTime <- function(optObj,startT) {
158172
optObj$elapsedTime + as.numeric(difftime(Sys.time(),startT,units = "secs"))
159173
}
160174

175+
# Fill in any missing elements of otherHalting we need.
161176
formatOtherHalting <- function(otherHalting) {
162177
if (is.null(otherHalting$timeLimit)) otherHalting$timeLimit <- Inf
163178
if (is.null(otherHalting$minUtility)) otherHalting$minUtility <- 0
164179
return(otherHalting)
165180
}
166181

182+
# When the process stops early it will print this color.
167183
#' @importFrom crayon make_style red
168184
returnEarly <- crayon::make_style("#FF6200")
169185

186+
# Constructor for stopEarlyMsg class.
170187
makeStopEarlyMessage <- function(msg) {
171188
class(msg) <- "stopEarlyMsg"
172189
return(msg)
173190
}
174191

192+
# Multiple places the process can stop early. This just prints the message.
175193
printStopStatus <- function(optObj,verbose) {
176194
if (verbose > 0) cat(returnEarly("\n",optObj$stopStatus,"\n"))
177195
}

0 commit comments

Comments
 (0)