Basis#

Definitions for basis functions over a site function space.

The product of single site functions make up a cluster/orbit function used to obtain correlation vectors. The domain of a site function is a site space, which is defined by the allowed species at the site and their measures, i.e. the concentration of the species in the random structure.

class BasisIterator(species)[source]#

Bases: Iterator

Abstract basis iterator class.

A basis iterator iterates through all non-constant site basis functions, i.e. for basis \(\phi_0 = 1, \phi_1, ..., \phi_{n-1}\), the iterator will iterate through \(\phi_1, ..., \phi_{n-1}\)

flavor#

Name specifying the type of basis that is generated.

Type:

str

Initialize a BasisIterator.

Parameters:

species (tuple) – tuple of allowed species in site spaces

flavor = 'abstract'#
class ChebyshevIterator(species, low=-1, high=1)[source]#

Bases: NumpyPolyIterator

Chebyshev polynomial basis set iterator.

Initialize a NumpyPolyIterator.

Parameters:
  • species (tuple) – tuple of allowed species in site spaces

  • low (float) – optional lower limit of interval for encoding

  • high (float) – optional higher limit of interval for encoding

flavor = 'chebyshev'#
property polyval#

Return numpy Chebyshev polynomial eval.

class DiscreteBasis(site_space, basis_functions)[source]#

Bases: MSONable

Abstract class to represent a basis set over a discrete finite domain.

In our case the domain is a site space which can take on values of the allowed species.

Initialize a StandardBasis.

Currently also accepts an OrderedDict but if you find yourself creating one like so for use in production and not debugging, know that it will break MSONable methods in classes that use these, and at any point, compatibility with OrderedDicts could be removed.

Parameters:
  • site_space (OrderedDict or SiteSpace) – Dict representing site space (Specie, measure) or a SiteSpace object.

  • basis_functions (BasisIterator) – a BasisIterator for the nonconstant basis functions. Must take the values of species in the site space as input.

as_dict()[source]#

Get MSONable dict representation of a DiscreteBasis.

Return type:

dict

classmethod from_dict(d)[source]#

Create a DiscreteBasis from dict representation.

Parameters:

d (dict) – MSONable dict representation

Returns:

A subclass of DiscreteBasis

Return type:

DiscreteBasis

property function_array#

Get function array with site functions as rows.

property is_orthogonal#

Test if the basis is orthogonal.

property is_orthonormal#

Test if the basis is orthonormal.

property measure_array#

Get diagonal array with site species measures.

property measure_vector#

Get vector of site species measures.

property site_space#

Get dict of the site probability space.

The site space refers to the probability space represented by the allowed species and their respective probabilities (concentration) over which the site functions are defined.

property species#

Get list of allowed site species.

class IndicatorBasis(site_space)[source]#

Bases: DiscreteBasis, MSONable

Class that represents a full indicator basis for a site space.

This class represents the “trivial” indicator basis, which includes an indicator function for every species in the site space, and does NOT include a constant function. NOT to be confused with a cluster indicator basis used for a Cluster Expansion (that is represented in smol by a StandardBasis with an IndicatorIterator).

@lbluque takes full responsibility for the confusing terminology…

Initialize an indicator basis for given site space.

Parameters:

site_space (OrderedDict or SiteSpace) – dict representing site space (Specie, measure) or a SiteSpace object.

classmethod from_dict(d)[source]#

Create a SiteSpace from dict representation.

Parameters:

d (dict) – MSONable dict representation

Returns:

StandardBasis

class IndicatorIterator(species)[source]#

Bases: BasisIterator

Iterator for cluster indicator site basis functions.

The basis generated as defined is not orthogonal for any number of species.

Initialize a BasisIterator.

Parameters:

species (tuple) – tuple of allowed species in site spaces

flavor = 'indicator'#
class LegendreIterator(species, low=-1, high=1)[source]#

Bases: NumpyPolyIterator

Legendre polynomial basis set iterator.

Initialize a NumpyPolyIterator.

Parameters:
  • species (tuple) – tuple of allowed species in site spaces

  • low (float) – optional lower limit of interval for encoding

  • high (float) – optional higher limit of interval for encoding

flavor = 'legendre'#
property polyval#

Return numpy Legendre polynomial eval.

class NumpyPolyIterator(species, low=-1, high=1)[source]#

Bases: BasisIterator

Class to quickly implement polynomial basis sets included in numpy.

Initialize a NumpyPolyIterator.

Parameters:
  • species (tuple) – tuple of allowed species in site spaces

  • low (float) – optional lower limit of interval for encoding

  • high (float) – optional higher limit of interval for encoding

flavor = 'numpy-poly'#
abstract property polyval#

Return a numpy polyval function.

class PolynomialIterator(species, low=-1, high=1)[source]#

Bases: NumpyPolyIterator

A standard polynomial basis set iterator.

Initialize a NumpyPolyIterator.

Parameters:
  • species (tuple) – tuple of allowed species in site spaces

  • low (float) – optional lower limit of interval for encoding

  • high (float) – optional higher limit of interval for encoding

flavor = 'polynomial'#
property polyval#

Return numpy polynomial eval.

class SinusoidIterator(species)[source]#

Bases: BasisIterator

Iterator for sinusoid (trig basis) as proposed by A. van de Walle.

  1. van de Walle, Calphad. 33, 266–278 (2009).

This basis is properly orthogonal for any number of allowed species out of the box, but it is not orthonormal for allowed species > 2.

Initialize a SinusoidIterator.

Parameters:

species (tuple) – tuple of allowed species in site spaces

flavor = 'sinusoid'#
class StandardBasis(site_space, basis_functions)[source]#

Bases: DiscreteBasis

Class that represents the basis for a site function space.

Note that all StandardBasis in theory have the first basis function \(\phi_0 = 1\), but this should not be defined since it is handled implicitly when computing bit_combos using total no. species - 1 in the Orbit class. As such a StandardBasis as implemented here represents a Standard and/or Fourier site basis (the standard basis using indicator functions is not a Fourier basis but can be used as a”cluster site basis”).

The particular basis set is set by giving an iterable of basis functions. See BasisIterator classes for details.

Initialize a StandardBasis.

Currently also accepts an OrderedDict but if you find yourself creating one like so for use in production and not debugging, know that it will break MSONable methods in classes that use these, and at any point, compatibility with OrderedDicts could be removed.

Parameters:
  • site_space (OrderedDict or SiteSpace) – Dict representing site space (Specie, measure) or a SiteSpace object.

  • basis_functions (BasisIterator) – a BasisIterator for the nonconstant basis functions. Must take the values of species in the site space as input.

as_dict()[source]#

Get MSONable dict representation.

Return type:

dict

classmethod from_dict(d)[source]#

Create a StandardBasis from dict representation.

Parameters:

d (dict) – MSONable dict representation

Returns:

StandardBasis

property function_array#

Get array with the non-constant site functions as rows.

property orthonormalization_array#

Get R array from QR factorization.

orthonormalize()[source]#

Orthonormalizes basis function set based on initial basis set.

Functions are orthonormal w.r.t the measure given. (Basis functions are also orthogonal to phi_0 = 1).

Modified GS-QR factorization of function array. (Here we are using row vectors as opposed to the correct way of doing QR using columns.) Due to how the func_arr is saved (rows are vectors/functions) this allows us to not sprinkle so many transposes.

rotate(angle, index1=0, index2=1)[source]#

Rotate basis functions about subspace spanned by two vectors.

This operation will rotate the two selected basis vectors about a subspace spanned by them. This implies a rotation orthogonal to all other basis vectors. This will keep any underlying orthogonality.

Warning

this is only implemented for uniform site space measures, not for non-uniform measures.

Warning

I haven’t really thought through what happens if basis vectors are not orthogonal to the constant (i.e. indicator basis); use at your own peril with non-orthogonal basis sets.

Warning

When rotating a binary space basis this will only multiply by -1, regardless of the indices or angle provided. Think about what it means to rotate in this case…

Parameters:
  • angle (float) – angle to rotate in radians

  • index1 (int) – index of first basis vector in function_array

  • index2 (int) – index of second basis vector in function_array

property rotation_array#

Get the rotation array.

available_site_basis_sets()[source]#

Return a list of available site basis sets.

basis_factory(basis_name, site_space)[source]#

Create a site basis for the given basis name.

Parameters:
  • basis_name (str) – name of the basis.

  • site_space (Sequence or OrderedDict) – SiteSpace over which the basis set is defined.

Returns:

StandardBasis

cos_f(s, a, m)[source]#

Return basis function for odd indices.

encode_domain(encoding)[source]#

Decorate a function with an encoding for its domain.

Parameters:

encoding (dict) – dictionary for encoding.

indicator(s, sp)[source]#

Singleton indicator function for elementary events.

sin_f(s, a, m)[source]#

Return basis function for even indices.

sinusoid_factory(n, m)[source]#

Sine or cosine based on AVdW sinusoid site basis.