individualGetDenseVec | R Documentation |
This function converts an individual's sparse gene representation (where only specific indices have non-zero values) into a dense vector of a specified size. It creates a vector with values from the individual's coefficients at the specified indices and zeros elsewhere.
individualGetDenseVec(individual, size)
individual |
A list representing an individual, with attributes: - 'indices_': A vector of indices where the individual has non-zero gene values. - 'coeffs_': A vector of coefficients corresponding to the genes at 'indices_'. |
size |
An integer specifying the size of the dense vector to be returned. |
The function initializes a dense vector ('res') of length 'size' with all elements set to zero. It then populates this vector with the values from 'individual$coeffs_' at the positions specified in 'individual$indices_'. The result is a dense vector representation of the individual's gene information.
A numeric vector of length 'size', with non-zero values at positions specified by 'individual$indices_' and zeroes elsewhere.
## Not run:
individual <- list(indices_ = c(2, 4, 6), coeffs_ = c(1.5, -0.5, 2.0))
size <- 10
dense_vector <- individualGetDenseVec(individual, size)
print(dense_vector) # Should show a vector of length 10 with specified values at indices 2, 4, and 6
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.