mutator_v1: Mutate an Individual's Genes in the Population

View source: R/terga2.lib.R

mutator_v1R Documentation

Mutate an Individual's Genes in the Population

Description

This function mutates a specified individual's genes by altering a subset of them according to a defined mutation rate and gene reservoir.

Usage

mutator_v1(X, y, clf, pop, individual_to_be_mutated, all_genes, featEval)

Arguments

X

A matrix or data frame of feature values, where each row represents a feature and each column represents a sample.

y

A response vector or target variable for supervised learning. The length of y should match the number of columns in X.

clf

A classifier object containing parameters for mutation, including 'mutate_rate' and 'size_world'.

pop

The current population list, used as context for the mutation but not directly modified by this function.

individual_to_be_mutated

A list representing the individual to be mutated, with attributes 'eval.sparsity' (sparsity level) and 'indices_' (genes).

all_genes

A vector of all possible gene indices, representing the complete set of genes that could be selected during mutation.

featEval

A vector or list of feature evaluation metrics, used to guide the mutation.

Details

The function calculates the number of genes to mutate ('perc') based on the individual’s sparsity level and the mutation rate defined in 'clf'. If the number of genes to mutate exceeds the available gene reservoir, the mutation rate is adjusted accordingly. Genes for mutation are chosen from ‘all_genes' and replaced in the individual’s genome.

The mutation process includes: - Calculating mutation degree based on mutation rate and sparsity. - Selecting genes for mutation and replacing them with new genes from the reservoir.

Value

A mutated individual list, representing the modified genome of the input individual.

Examples

## Not run: 
X <- matrix(rnorm(100), nrow = 10) # Random features
y <- sample(c(0, 1), 10, replace = TRUE) # Random binary response
clf <- list(params = list(mutate_rate = 20, size_world = 100))
individual_to_be_mutated <- list(eval.sparsity = 5, indices_ = sample(1:100, 5))
all_genes <- 1:100
featEval <- runif(10)
mutated_individual <- mutator_v1(X, y, clf, pop = NULL, individual_to_be_mutated, all_genes, featEval)

## End(Not run)


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