I'm optimizing some various models, one of which is radialSVM using the caret
package. I'm creating a tuning grid in preparation to cycle through a loop to find the best parameters to use for the model.
One thing that would be extremely helpful is some sort of varying increment sequence. For example, I'd like to start with small parameter values incremented in small steps. The larger I go, the bigger steps I can take. I've found that small parameters do change the model quite a bit, so I'd like to explore them more carefully.
It would be fantastic to have the sequence increment by some multiplier of the current step, say x <- x+5*x
. Is this possible with something that already exists, (like a creative use of seq()
), or do I need to use a loop?
The simplest way to create a sequence of numbers in R is by using the : operator. Type 1:20 to see how it works. That gave us every integer between (and including) 1 and 20 (an integer is a positive or negative counting number, including 0).
seq() function in R Language is used to create a sequence of elements in a Vector. It takes the length and difference between values as optional argument. Syntax: seq(from, to, by, length.out)
The function rep() in R will repeate a number or a sequence of numbers n times. For example, typing rep(5, 5) wiull print the number 5 five times.
A sequence vector is created by using the sequence of numbers such as 1 to 15, 21 to 51, 101 to 150, -5 to 10. The length of this type of vectors can be found only by using the length function.
How about something like this:
0.0001 * 6^(0:10)
# [1] 0.0001 0.0006 0.0036 0.0216 0.1296 0.7776 4.6656
# [8] 27.9936 167.9616 1007.7696 6046.6176
You could use the exponential distribution:
qexp((1:100)/100)
> qexp((1:100)/100)
[1] 0.01005034 0.02020271 0.03045921 0.04082199 0.05129329 0.06187540 0.07257069 0.08338161
[9] 0.09431068 0.10536052 0.11653382 0.12783337 0.13926207 0.15082289 0.16251893 0.17435339
Adjust it to have differences that meet you needs:
diff( 20* qexp((1:100)/100) )
[1] 0.2030474 0.2051300 0.2072557 0.2094260 0.2116422 0.2139058 0.2162183 0.2185814
[9] 0.2209967 0.2234660 0.2259911 0.2285739 0.2312164 0.2339208 0.2366892 0.2395238
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With