individualGetDenseVec: Convert an Individual's Sparse Gene Representation to a Dense...

View source: R/terga2.lib.R

individualGetDenseVecR Documentation

Convert an Individual's Sparse Gene Representation to a Dense Vector

Description

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.

Usage

individualGetDenseVec(individual, size)

Arguments

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.

Details

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.

Value

A numeric vector of length 'size', with non-zero values at positions specified by 'individual$indices_' and zeroes elsewhere.

Examples

## 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)


predomics/predomicspkg documentation built on Dec. 11, 2024, 11:06 a.m.