base
— Basic Operations and Objects¶
Basic infrastructure for DFO methods.
-
class
dfoalgos.base.
Observable
¶ Part of the Observer/Observable design pattern.
-
attach
(observer)¶ Add observer to the list of observers.
Parameters: observer (callable) – The object to be informed about changes.
-
detach
(observer)¶ Remove observer from the list of observers.
Parameters: observer (callable) – The object to be informed about changes.
-
notify_observers
()¶ Inform the observers about a potential state change.
-
-
dfoalgos.base.
center_of_mass
(points)¶ Calculate the center of mass of the given points.
-
dfoalgos.base.
create_nash_simplex
(position, size_param=0.1)¶ Create a simplex according to the rule of John C. Nash.
This construction method is described in [Nash1990], pp. 168-178. It is also the default in the Nelder-Mead implementation of the statistical programming language R, which can be called through the function
optim()
of the R standard library.Parameters: - position (iterable) – The position being used as location vector for the simplex. In this construction, position is the vertex in the simplex closest to the origin.
- size_param (float, optional) – For each coordinate, a fraction of the maximal absolute value in position is added to it. This value is the fraction.
Returns: simplex – A list containing
len(position) + 1
points.Return type: list of list
References
[Nash1990] John C. Nash (1990). Compact Numerical Methods for Computers: Linear Algebra and Function Minimisation, second edition, Taylor & Francis.
-
dfoalgos.base.
create_pfeffer_simplex
(position, size_param=0.05)¶ Create a simplex according to the rule of Lawrence E. Pfeffer.
This construction method is the default in Matlab’s
fminsearch()
and SciPy’sscipy.optimize.fmin()
. According to [Fan2002], p. 73, this approach was proposed by Lawrence E. Pfeffer at Stanford.Parameters: - position (iterable) – The position being used as location vector for the simplex. In this construction, position is the vertex in the simplex closest to the origin.
- size_param (float, optional) – For each coordinate, a fraction of itself is added to it. This value is the fraction.
Returns: simplex – A list containing
len(position) + 1
points.Return type: list of list
References
[Fan2002] Ellen Fan (2002). Global optimization of Lennard-Jones atomic clusters. Master’s thesis, McMaster University. http://www.cas.mcmaster.ca/~oplab/thesis/faneMS.pdf
-
dfoalgos.base.
create_standard_basis
(dimension, scale_factor=1.0)¶ Create an orthogonal, maximal, positive basis.
-
dfoalgos.base.
create_tilted_regular_simplex
(position, size_param=None)¶ Create a simplex by the method of Ravi Varadhan.
This construction method was originally proposed by [Spendley1962]. The scaling heuristic is taken from the function
nmk()
in the R package dfoptim (see https://cran.r-project.org/package=dfoptim). The resulting simplex is regular and position becomes the “lower left” corner of the simplex.Parameters: - position (iterable) – The position being used as location vector for the simplex. In this construction, position is the vertex in the simplex closest to the origin.
- size_param (float, optional) – The side length of all edges of the simplex.
Returns: simplex – A list containing
len(position) + 1
points.Return type: list of list
-
dfoalgos.base.
create_upright_regular_simplex
(position, size_param=1.0)¶ Create a regular simplex.
This simplex is a regular pyramid standing on its base. The base is a (n - 1)-dimensional regular simplex. The last dimension is only sampled at two values. The apex is above the centroid of the base.
Parameters: - position (iterable) – The position being used as location vector for the simplex. In this construction, position is the vertex in the simplex closest to the origin.
- size_param (float, optional) – The side length of all edges of the simplex.
Returns: simplex – A list containing
len(position) + 1
points.Return type: list of list
-
dfoalgos.base.
displace
(point1, point2, factor)¶ Displace point1 by
factor * (point1 - point2)
.Parameters: - point1 (iterable) – The position vector.
- point2 (iterable) – The second vector necessary to calculate the displacement vector.
- factor (float) – The scale factor.
Returns: new_point – The displaced point.
Return type:
-
dfoalgos.base.
lexicographic_sort_key
(individual)¶ Sort key for lexicographic sorting with special treatment of None.
None is replaced with infinity (the worst possible value).
-
dfoalgos.base.
order
(values, sort_key=None)¶ Return the ordering of the elements of values.
The list
[values[j] for j in order(values)]
is a sorted version of values.Adapted from https://code.activestate.com/recipes/491268-ordering-and-ranking-for-lists/
Parameters: - values (list) – The list to process
- sort_key (callable, optional) – A callable to determine the ordering. Default sort key is
(value is None, value)
.
Returns: order – The indices the values would have in a sorted list.
Return type:
-
dfoalgos.base.
rank
(values, sort_key=None, ties='average')¶ Return the ranking of the elements of values.
The best obtainable rank is 1. Calls the function
order()
.Adapted from https://code.activestate.com/recipes/491268-ordering-and-ranking-for-lists/
Parameters: Returns: ranks – The ranks of the values in the same order.
Return type:
-
dfoalgos.base.
reflect
(points, fixed_point)¶ Reflect points across a fixed point.
-
dfoalgos.base.
scale
(points, fixed_point, factor)¶ Scale a point cloud by a given factor.
Parameters: - points (iterable of iterable) – The points to scale.
- fixed_point (iterable) – The fixed point of the transformation.
- factor (float) – The scale factor.
Returns: scaled_points – List containing scaled points.
Return type: list of list
-
dfoalgos.base.
translate
(points, vector)¶ Translate points by given vector.