|
204 | 204 | }) |
205 | 205 | } |
206 | 206 |
|
207 | | -`rform` <- function(terms=9, k=3, n=7, coeffs, ensure=TRUE){ |
208 | | - if(missing(coeffs)){coeffs <- seq_len(terms)} |
| 207 | +`rform` <- function(terms=9, k=3, n=7, ensure=TRUE, integer=TRUE){ |
209 | 208 | ind <- t(replicate(terms,sample(seq_len(n),k))) |
210 | 209 | if(ensure & all(ind)<n){ind[sample(which(ind==max(ind)),1)] <- n} |
211 | | - kform(spray(ind,coeffs,addrepeats=TRUE)) |
| 210 | + if(integer){ |
| 211 | + coeffs <- seq_len(terms) |
| 212 | + } else { |
| 213 | + coeffs <- runif(terms) |
| 214 | + } |
| 215 | + kform(spray(ind, coeffs, addrepeats=TRUE)) |
212 | 216 | } |
213 | 217 |
|
214 | | -`rformm` <- function(terms=30, k=7, n=20, coeffs, ensure=TRUE){ |
215 | | - rform(terms=terms, k=k, n=n, coeffs=coeffs, ensure=ensure) |
| 218 | +`rformm` <- function(terms=30, k=7, n=20, ensure=TRUE, integer=TRUE){ |
| 219 | + rform(terms=terms, k=k, n=n, ensure=ensure) |
216 | 220 | } |
217 | 221 |
|
218 | | -`rformmm` <- function(terms=90, k=15, n=30, coeffs, ensure=TRUE){ |
219 | | - rform(terms=terms, k=k, n=n, coeffs=coeffs, ensure=ensure) |
| 222 | +`rformmm` <- function(terms=90, k=15, n=30, ensure=TRUE, integer=TRUE){ |
| 223 | + rform(terms=terms, k=k, n=n, ensure=ensure) |
220 | 224 | } |
221 | 225 |
|
222 | | -`rtensor` <- function(terms=9, k=3, n=7, coeffs){ |
223 | | - if(missing(coeffs)){coeffs <- seq_len(terms)} |
224 | | - M <- matrix(sample(seq_len(n),terms*k,replace=TRUE),terms,k) |
225 | | - ktensor(spray(M,seq_len(terms),addrepeats=TRUE)) |
| 226 | +`rtensor` <- function(terms=9, k=3, n=7, integer=TRUE){ |
| 227 | + M <- matrix(sample(seq_len(n), terms*k, replace=TRUE), terms, k) |
| 228 | + if(integer){ |
| 229 | + coeffs <- seq_len(terms) |
| 230 | + } else { |
| 231 | + coeffs <- runif(terms) |
| 232 | + } |
| 233 | + ktensor(spray(M, coeffs, addrepeats=TRUE)) |
226 | 234 | } |
227 | 235 |
|
228 | 236 | `as.1form` <- function(v){ |
|
0 commit comments