Skip to content

Commit 33e8a78

Browse files
committed
docs
1 parent c6b507a commit 33e8a78

File tree

3 files changed

+49
-132
lines changed

3 files changed

+49
-132
lines changed

R/b_conv.R

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#' Random convolutional features
22
#'
3-
#' Generates random convolutional features from a list of images for use in
4-
#' regression modeling. Convolutional kernels are generated randomly (either
3+
#' Generates random convolutional features from a list of images.
4+
#' Convolutional kernels are generated randomly (either
55
#' from a Gaussian distribution or as patches extracted from the training
66
#' images), applied to each image via efficient matrix multiplication, and then
7-
#' pooled to produce a fixed-size feature vector per image. This approach allows
8-
#' kernel methods and other flexible models to be applied to image data.
7+
#' pooled to produce a fixed-size feature vector per image.
98
#'
9+
#' @inheritParams b_rff
1010
#' @param x A list of images, where each image is a matrix (for grayscale) or a
1111
#' 3D array with dimensions (height, width, channels) for color images. Images
1212
#' may have different dimensions, but must be large enough to accommodate the
@@ -17,35 +17,37 @@
1717
#' @param stride The stride for the convolution operation, i.e., how many
1818
#' pixels to skip between kernel applications. Default is 1.
1919
#' @param kernel_gen Method for generating convolutional kernels. Either `"rnorm"`
20-
#' to generate kernels with entries drawn iid from a standard Normal
20+
#' to generate kernels with entries drawn i.i.d. from a standard Normal
2121
#' distribution, or `"patch"` to extract random patches from the input images.
2222
#' @param activation A function to pool the convolution outputs for each kernel.
2323
#' Defaults to [max()]. The function should accept a numeric vector and return
2424
#' a scalar or vector of pooled values. Common choices include [max()],
25-
#' [mean()], or custom functions.
26-
#' @param stdize How to standardize the image pixel values before convolution,
27-
#' if at all. The default `"scale"` applies `scale()` to the pixels so they
28-
#' have mean zero and unit variance across all images. `"box"` scales pixels
29-
#' to lie in \[0, 1\], `"symbox"` scales to lie in \[-0.5, 0.5\], and `"none"`
30-
#' applies no standardization.
25+
#' [mean()], functions like the proportion of positive values (PPV), which
26+
#' can be implemented with `function(x) mean(x > 0)`. Multivariate pooling
27+
#' functions are also supported.
3128
#' @param kernels Optional matrix of pre-specified convolutional kernels, where
3229
#' each column is a kernel in column-major format. If provided, overrides `p`,
3330
#' `size`, and `kernel_gen`.
34-
#' @param shift Optional shift value(s) for standardization. If provided,
35-
#' overrides the shift calculated according to `stdize`.
36-
#' @param scale Optional scale value(s) for standardization. If provided,
37-
#' overrides the scale calculated according to `stdize`.
3831
#'
3932
#' @returns A matrix of random convolutional features with one row per image in
4033
#' `x` and one column per kernel (or more columns if `activation` is
4134
#' multivariate).
4235
#'
4336
#' @examples
44-
#' # Create synthetic grayscale images
45-
#' images = lapply(1:20, function(i) matrix(runif(28*28), 28, 28))
37+
#' x = outer(1:28, 1:28, function(x, y) {
38+
#' d = sqrt(4*(x - 14)^2 + (y - 14)^2)
39+
#' dnorm(d, mean = 10, sd = 0.8)
40+
#' })
41+
#' pal = gray.colors(256, 1, 0)
42+
#' image(x, col = pal)
4643
#'
47-
#' # Generate random convolutional features
48-
#' m = b_conv(images, p = 10, size = 3)
44+
#' # one random kernel (no activation)
45+
#' m = b_conv(list(x), p=1, activation=\(x) x)
46+
#' image(matrix(m, nrow = 26), col = pal)
47+
#'
48+
#' # many kernels (realistic use case)
49+
#' m = b_conv(list(x), p = 100, size = 3)
50+
#' str(m)
4951
#' @export
5052
b_conv <- function(
5153
x,

REVIEW.md

Lines changed: 0 additions & 88 deletions
This file was deleted.

man/b_conv.Rd

Lines changed: 28 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)