lore_sa.neighgen.GeneticGenerator
- class lore_sa.neighgen.GeneticGenerator(bbox=None, dataset=None, encoder=None, ocr=0.1, alpha1=0.5, alpha2=0.5, metric=<function neuclidean>, ngen=100, mutpb=0.2, cxpb=0.5, tournsize=3, halloffame_ratio=0.1, random_seed=None)[source]
Random Generator creates neighbor instances by generating random values starting from an input instance and pruning the generation around a fitness function based on proximity to the instance to explain
- __init__(bbox=None, dataset=None, encoder=None, ocr=0.1, alpha1=0.5, alpha2=0.5, metric=<function neuclidean>, ngen=100, mutpb=0.2, cxpb=0.5, tournsize=3, halloffame_ratio=0.1, random_seed=None)[source]
- Parameters
bbox – the Black Box model to explain
dataset – the dataset with the descriptor of the original dataset
encoder – an encoder to transfrom the data from/to the black box model
ocr – acronym for One Class Ratio, it is the ratio of the number of instances of the minority class
alpha1 – the weight of the similarity of the features from the given instance. The sum of alpha1 and alpha2 must be 1
alpha2 – the weight of the similiarity of the target class from the given instance. The sum of alpha1 and alpha2 must be 1
metric – the distance metric to use to compute the distance between instances
ngen – the number of generations to run
mutpb – probability of mutation of a specific feature
cxpb –
tournsize –
halloffame_ratio –
random_seed – initial seed for the random number generator
Methods
__init__
([bbox, dataset, encoder, ocr, ...])- param bbox
the Black Box model to explain
add_halloffame
(population, halloffame)balance_neigh
(x, Z, num_samples)check_generated
([filter_function, check_fuction])It contains the logic to check the requirements for generated data
clone
(x)fit
(toolbox, population_size)fitness_equal
(x, x1)fitness_notequal
(x, x1)generate
(x, num_instances, descriptor)The generation is based on the strategy of generating a number of instances for the same class as the input instance and a number of instances for a different class.
generate_synthetic_instance
([from_z, mutpb])mutate
(toolbox, x)random_init
()record_init
(x)setup_toolbox
(x, evaluate, population_size)setup_toolbox_noteq
(x, x1, evaluate, ...)- abstract check_generated(filter_function=None, check_fuction=None)
It contains the logic to check the requirements for generated data
- generate(x, num_instances, descriptor)[source]
The generation is based on the strategy of generating a number of instances for the same class as the input instance and a number of instances for a different class. The generation of the instances for each subgroup is done through a genetic algorithm based on two fitness fuctions: one for the same class and one for the different class. :param x: the input instance :param num_instances: how many elements to generate :param descriptor: the descriptor of the dataset :return: