neoml.Algorithms

NeoML library also provides some other algorithms.

Differential evolution

This method finds the global minimum (or maximum) of a non-differentiable, non-linear, multimodal function of many variables F(x1, x2, …, xn).

It uses mutation, crossover and selection to transform the current population (that is, the function parameters) into the next generation so that the function values on the new population “improve.” The process is repeated until the stop criteria are met.

Class description

class neoml.DifferentialEvolution.DifferentialEvolution(f, lower_bounds, upper_bounds, fluctuation=0.5, cross_probability=0.5, population=100, param_traits=None, result_traits=None, max_generation_count=None, max_non_growing_count=None)

Optimizing function value implementation based on differential evolution The purpose of the algorithm is to find the optimal system parameters (represented by a vector of real values X by default) for which the specified function value f(X) will be the closest to the reference value. The Evaluate function to calculate f(X) and compare it with the reference is provided by the user.

Parameters
  • f (object) – the function to be optimized.

  • lower_bounds (array of the same length as upper_bounds) – the minimum values for the parameters.

  • upper_bounds (array of the same length as lower_bounds) – the maximum values for the parameters.

  • fluctuation (float, default=0.5) – the fluctuation coefficient.

  • cross_probability (float, default=0.5) – the mutation probability.

  • population (int, >=5, default=100) – the number of elements in each generation.

  • param_traits (array of BaseTraits-implementing objects, default=None) – the parameter types.

  • result_traits (array of BaseTraits-implementing objects, default=None) – the result types.

  • max_generation_count (int, default=None) – the maximum number of generations after which the algorithm stops.

  • max_non_growing_count (int, default=None) – the maximum number of iterations for which the function minimum has been unchanged.

build_next_generation()

Builds the next generation.

Returns

if the stop condition was reached.

Return type

bool

property optimal_vector

Gets the “best vector.”

Returns

the best fector found

Return type

array-like of shape {vector_length,}

property population

Gets the resulting population.

Returns

the population on the current step.

Return type

array-like of shape {population, vector_length}

property population_function_values

Gets the function values on the resulting population.

Returns

the function values

Return type

array-like of shape {population,}

run()

Runs optimization until one of the stop conditions is fulfilled.

Parameter traits

Define your own parameter types:

class neoml.DifferentialEvolution.BaseTraits

Base class for working with traits in differential evolution.

abstract generate(min_value, max_value)

Generates a random trait value in the specified bounds.

Parameters
  • min_value (any type) – the lower bound for the interval.

  • max_value (any type) – the upper bound for the interval.

abstract less(first, second)

Checks if the first trait value is smaller than the second.

Parameters
  • first (any type) – the first value to be compared.

  • second (any type) – the second value to be compared.

abstract mutate(base, left, right, fluctuation, min_value, max_value)

Performs mutation for the differential evolution algorithm.

Parameters
  • base (any type) – a member of the original population.

  • left (any type) – another member of the original population.

  • right (any type) – another member of the original population.

  • fluctuation (any type) – the coefficient for mutation.

  • min_value (any type) – the lower bound for the mutated value.

  • max_value (any type) – the upper bound for the mutated value.

Predefined types for integer and double parameters:

class neoml.DifferentialEvolution.IntTraits

The implementation of an integer parameter.

generate(min_value, max_value)

Generates a random trait value in the specified bounds.

Parameters
  • min_value (int) – the lower bound for the interval.

  • max_value (int) – the upper bound for the interval.

less(first, second)

Checks if the first trait value is smaller than the second.

Parameters
  • first (int) – the first value to be compared.

  • second (int) – the second value to be compared.

mutate(base, left, right, fluctuation, min_value, max_value)

Performs mutation for the differential evolution algorithm.

Parameters
  • base (int) – a member of the original population.

  • left (int) – another member of the original population.

  • right (int) – another member of the original population.

  • fluctuation (double) – the coefficient for mutation.

  • min_value (int) – the lower bound for the mutated value.

  • max_value (int) – the upper bound for the mutated value.

class neoml.DifferentialEvolution.DoubleTraits

The implementation of a double parameter.

generate(min_value, max_value)

Generates a random trait value in the specified bounds.

Parameters
  • min_value (double) – the lower bound for the interval.

  • max_value (double) – the upper bound for the interval.

less(first, second)

Checks if the first trait value is smaller than the second.

Parameters
  • first (double) – the first value to be compared.

  • second (double) – the second value to be compared.

mutate(base, left, right, fluctuation, min_value, max_value)

Performs mutation for the differential evolution algorithm.

Parameters
  • base (double) – a member of the original population.

  • left (double) – another member of the original population.

  • right (double) – another member of the original population.

  • fluctuation (double) – the coefficient for mutation.

  • min_value (double) – the lower bound for the mutated value.

  • max_value (double) – the upper bound for the mutated value.

Principal components analysis

This algorithm reduces the dimensionality of a large multidimensional dataset while still retaining most of the information it contained. Principal components analysis (PCA) performs singular value decomposition of the data matrix, then selects the specified number of singular vectors that correspond to the largest singular values. In this way the maximum of data variance is preserved.

neoml.PCA

alias of neoml.PCA

neoml.PCA.svd(matrix, compute_u=True, compute_v=False, algorithm='full', components=None)

Byte-Pair Encoding

The implementation of a subword text tokenizing algorithm for modern Natural Language Processing models. It enables user to train BPE of a given size from scratch, encode and decode any text, import and export the subword dictionary.

neoml.BytePairEncoder

alias of neoml.BytePairEncoder