cimod
C++ library for a binary (and polynomial) quadratic model.
cimod::BinaryPolynomialModel< IndexType, FloatType > Class Template Reference

Class for BinaryPolynomialModel. More...

#include <binary_polynomial_model.hpp>

Public Member Functions

 BinaryPolynomialModel (const Polynomial< IndexType, FloatType > &poly_map, const Vartype vartype)
 BinaryPolynomialModel constructor. More...
 
 BinaryPolynomialModel (PolynomialKeyList< IndexType > &key_list, const PolynomialValueList< FloatType > &value_list, const Vartype vartype)
 BinaryPolynomialModel constructor. More...
 
 BinaryPolynomialModel (const PolynomialKeyList< IndexType > &key_list, const PolynomialValueList< FloatType > &value_list, const Vartype vartype)
 BinaryPolynomialModel constructor. More...
 
 BinaryPolynomialModel (const std::vector< IndexType > &variables, const PolynomialKeyList< std::size_t > &poly_key_distance_list, const PolynomialValueList< FloatType > &poly_value_list, const Vartype vartype)
 BinaryPolynomialModel constructor. More...
 
Polynomial< IndexType, FloatType > GetPolynomial () const
 Get the Polynomial object. More...
 
FloatType GetPolynomial (std::vector< IndexType > &key) const
 Get the specific value of the interaction according to the key representing the indices of the polynomial interactions. More...
 
FloatType GetPolynomial (const std::vector< IndexType > &key) const
 Get the specific value of the interaction according to the key representing the indices of the polynomial interactions. More...
 
const std::unordered_map< IndexType, int64_t > & GetVariablesToIntegers ()
 Get variables_to_integers object. More...
 
std::unordered_map< IndexType, int64_t > GetVariablesToIntegers () const
 Get variables_to_integers object. More...
 
int64_t GetVariablesToIntegers (const IndexType &index)
 Get the specific integer number corresponding to the input variable (index). More...
 
int64_t GetVariablesToIntegers (const IndexType &index) const
 Get the specific integer number corresponding to the input variable (index). More...
 
const PolynomialKeyList< IndexType > & GetKeyList () const
 Get the PolynomialKeyList object. More...
 
const PolynomialValueList< FloatType > & GetValueList () const
 Get the PolynomialValueList object. More...
 
const std::unordered_map< std::vector< IndexType >, std::size_t, vector_hash > & GetKeysInv () const
 Get The inverse key list, which indicates the index of the poly_key_list_ and poly_value_list_. More...
 
const std::unordered_set< IndexType > & GetVariables () const
 Return the variables as std::unordered_set. More...
 
const std::vector< IndexType > & GetSortedVariables ()
 Return the sorted variables as std::vector. More...
 
std::vector< IndexType > GetSortedVariables () const
 Return the sorted variables as std::vector. More...
 
std::size_t GetDegree () const
 Return the maximum degree of interaction. More...
 
FloatType GetOffset () const
 Return the offset. More...
 
Vartype GetVartype () const
 Return the vartype. More...
 
std::size_t GetNumInteractions () const
 Return the number of the interactions. More...
 
std::size_t GetNumVariables () const
 Return the number of variables. More...
 
BinaryPolynomialModel Empty (const Vartype vartype) const
 Create an empty BinaryPolynomialModel. More...
 
void Clear ()
 Clear the BinaryPolynomialModel. More...
 
void RemoveInteraction (std::vector< IndexType > &key)
 Remove the specified interaction from the BinaryPolynomialModel. More...
 
void RemoveInteraction (const std::vector< IndexType > &key)
 Remove the specified interaction from the BinaryPolynomialModel. More...
 
void RemoveInteractionsFrom (PolynomialKeyList< IndexType > &key_list)
 Remove the specified interactions from the BinaryPolynomialModel. More...
 
void RemoveInteractionsFrom (const PolynomialKeyList< IndexType > &key_list)
 Remove the specified interactions from the BinaryPolynomialModel. More...
 
void RemoveOffset ()
 Set the offset of the BinaryPolynomialModel to zero. More...
 
void RemoveVariable (const IndexType &index)
 Remove a variable from the BinaryPolynomialModel. More...
 
void RemoveVariablesFrom (const std::vector< IndexType > &key)
 Remove the specified variables from the BinaryPolynomialModel. More...
 
void AddInteraction (std::vector< IndexType > &key, const FloatType &value, const Vartype vartype=Vartype::NONE)
 Add an interaction to the BinaryPolynomialModel. More...
 
void AddInteraction (const std::vector< IndexType > &key, const FloatType &value, const Vartype vartype=Vartype::NONE)
 Add an interaction to the BinaryPolynomialModel. More...
 
void AddInteractionsFrom (const Polynomial< IndexType, FloatType > &poly_map, const Vartype vartype=Vartype::NONE)
 Add interactions to the BinaryPolynomialModel. More...
 
void AddInteractionsFrom (PolynomialKeyList< IndexType > &key_list, const PolynomialValueList< FloatType > &value_list, const Vartype vartype=Vartype::NONE)
 Add interactions to the BinaryPolynomialModel. More...
 
void AddInteractionsFrom (const PolynomialKeyList< IndexType > &key_list, const PolynomialValueList< FloatType > &value_list, const Vartype vartype=Vartype::NONE)
 Add interactions to the BinaryPolynomialModel. More...
 
void AddOffset (FloatType offset)
 Add specified value to the offset of the BinaryPolynomialModel. More...
 
FloatType Energy (const Sample< IndexType > &sample, bool omp_flag=true) const
 Determine the energy of the specified sample of the BinaryPolynomialModel. More...
 
FloatType Energy (const std::vector< int32_t > &sample_vec, bool omp_flag=true)
 Determine the energy of the specified sample_vec (as std::vector) of the BinaryPolynomialModel. More...
 
PolynomialValueList< FloatType > Energies (const std::vector< Sample< IndexType >> &samples) const
 Determine the energies of the given samples. More...
 
PolynomialValueList< FloatType > Energies (const std::vector< std::vector< int32_t >> &samples_vec)
 Determine the energies of the given samples_vec. More...
 
void Scale (const FloatType scalar, const PolynomialKeyList< IndexType > &ignored_interactions={}, const bool ignored_offset=false)
 Multiply by the specified scalar all the values of the interactions of the BinaryPolynomialModel. More...
 
void normalize (const std::pair< FloatType, FloatType > &range={ 1.0, 1.0 }, const PolynomialKeyList< IndexType > &ignored_interactions={}, const bool ignored_offset=false)
 Normalizes the values of the interactions of the BinaryPolynomialModel such that they fall in the provided range(s). More...
 
BinaryPolynomialModel ChangeVartype (const Vartype vartype, const bool inplace)
 Create a BinaryPolynomialModel with the specified vartype. More...
 
void ChangeVartype (const Vartype vartype)
 Change the vartype of the BinaryPolynomialModel. More...
 
bool HasVariable (const IndexType &index)
 Check if the specified index is in the BinaryPolynomialModel. More...
 
Polynomial< IndexType, FloatType > ToHubo () const
 Generate the polynomial interactions corresponding to the vartype being BINARY from the BinaryPolynomialModel. More...
 
Polynomial< IndexType, FloatType > ToHising () const
 Generate the polynomial interactions corresponding to the vartype being SPIN from the BinaryPolynomialModel. More...
 
nlohmann::json ToSerializable () const
 Convert the BinaryPolynomialModel to a serializable object. More...
 

Static Public Member Functions

template<typename IndexType_serial = IndexType, typename FloatType_serial = FloatType>
static BinaryPolynomialModel< IndexType_serial, FloatType_serial > FromSerializable (const nlohmann::json &input)
 Create a BinaryPolynomialModel instance from a serializable object. More...
 
static BinaryPolynomialModel FromHubo (const Polynomial< IndexType, FloatType > &poly_map)
 Create a BinaryPolynomialModel from a Hubo model. More...
 
static BinaryPolynomialModel FromHubo (const PolynomialKeyList< IndexType > &key_list, const PolynomialValueList< FloatType > &value_list)
 Create a BinaryPolynomialModel from a Hubo model. More...
 
static BinaryPolynomialModel FromHubo (PolynomialKeyList< IndexType > &key_list, const PolynomialValueList< FloatType > &value_list)
 Create a BinaryPolynomialModel from a Hubo model. More...
 
static BinaryPolynomialModel FromHising (const Polynomial< IndexType, FloatType > &poly_map)
 Create a BinaryPolynomialModel from a higher ordere Ising model. More...
 
static BinaryPolynomialModel FromHising (const PolynomialKeyList< IndexType > &key_list, const PolynomialValueList< FloatType > &value_list)
 Create a BinaryPolynomialModel from a higher ordere Ising model. More...
 
static BinaryPolynomialModel FromHising (PolynomialKeyList< IndexType > &key_list, const PolynomialValueList< FloatType > &value_list)
 Create a BinaryPolynomialModel from a higher ordere Ising model. More...
 

Protected Member Functions

void SetKeyAndValue (const std::vector< IndexType > &key, const FloatType &value)
 Set key and value. More...
 
std::size_t IntegerPower (std::size_t base, std::size_t exponent) const
 Caluculate the base to the power of exponent (std::pow(base, exponent) is too slow). More...
 
std::vector< IndexType > GenerateChangedKey (const std::vector< IndexType > &original_key, const std::size_t num_of_key) const
 Generate the num_of_key-th the key when the vartype is changed. More...
 
BinaryPolynomialModel ToSpin () const
 Generate BinaryPolynomialModel with the vartype being SPIN. More...
 
BinaryPolynomialModel ToBinary () const
 Generate BinaryPolynomialModel with the vartype being BINARY. More...
 
void UpdateVariablesToIntegers ()
 Update sorted_variables_ and variables_to_integers_. More...
 
std::unordered_map< IndexType, int64_t > GenerateVariablesToIntegers () const
 Generate variables_to_integers. More...
 
std::vector< IndexType > GenerateSortedVariables () const
 Generate sorted variables. More...
 

Protected Attributes

std::unordered_set< IndexType > variables_
 Variable list as std::unordered_set. More...
 
std::unordered_map< IndexType, std::size_t > each_variable_num_
 The list of the number of the variables appeared in the polynomial interactions as std::unordered_map. More...
 
std::unordered_map< IndexType, int64_t > variables_to_integers_
 The correspondence from variables to the integer numbers. More...
 
std::vector< IndexType > sorted_variables_
 Sorted variables is represents the correspondence from integer numbers.to the variables. More...
 
bool relabel_flag_for_variables_to_integers_ = true
 If true variable_to_index must be relabeled. More...
 
PolynomialKeyList< IndexType > poly_key_list_
 The list of the indices of the polynomial interactions (namely, the list of keys of the polynomial interactions as std::unordered_map) as std::vector<std::vector>>. More...
 
PolynomialValueList< FloatType > poly_value_list_
 The list of the values of the polynomial interactions (namely, the list of values of the polynomial interactions as std::unordered_map) as std::vector. More...
 
std::unordered_map< std::vector< IndexType >, std::size_t, vector_hashpoly_key_inv_
 The inverse key list, which indicates the index of the poly_key_list_ and poly_value_list_. More...
 
Vartype vartype_ = Vartype::NONE
 The model's type. SPIN or BINARY. More...
 

Detailed Description

template<typename IndexType, typename FloatType>
class cimod::BinaryPolynomialModel< IndexType, FloatType >

Class for BinaryPolynomialModel.

Template Parameters
IndexType
FloatType

Constructor & Destructor Documentation

◆ BinaryPolynomialModel() [1/4]

◆ BinaryPolynomialModel() [2/4]

template<typename IndexType , typename FloatType >
cimod::BinaryPolynomialModel< IndexType, FloatType >::BinaryPolynomialModel ( PolynomialKeyList< IndexType > &  key_list,
const PolynomialValueList< FloatType > &  value_list,
const Vartype  vartype 
)
inline

◆ BinaryPolynomialModel() [3/4]

template<typename IndexType , typename FloatType >
cimod::BinaryPolynomialModel< IndexType, FloatType >::BinaryPolynomialModel ( const PolynomialKeyList< IndexType > &  key_list,
const PolynomialValueList< FloatType > &  value_list,
const Vartype  vartype 
)
inline

◆ BinaryPolynomialModel() [4/4]

template<typename IndexType , typename FloatType >
cimod::BinaryPolynomialModel< IndexType, FloatType >::BinaryPolynomialModel ( const std::vector< IndexType > &  variables,
const PolynomialKeyList< std::size_t > &  poly_key_distance_list,
const PolynomialValueList< FloatType > &  poly_value_list,
const Vartype  vartype 
)
inline

Member Function Documentation

◆ AddInteraction() [1/2]

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteraction ( const std::vector< IndexType > &  key,
const FloatType &  value,
const Vartype  vartype = Vartype::NONE 
)
inline

Add an interaction to the BinaryPolynomialModel.

Parameters
key
value
vartype

References cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteraction(), and cimod.model.legacy.binary_quadratic_model::vartype.

Here is the call graph for this function:

◆ AddInteraction() [2/2]

◆ AddInteractionsFrom() [1/3]

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteractionsFrom ( const Polynomial< IndexType, FloatType > &  poly_map,
const Vartype  vartype = Vartype::NONE 
)
inline

Add interactions to the BinaryPolynomialModel.

Parameters
poly_map
vartype

References cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteraction(), and cimod.model.legacy.binary_quadratic_model::vartype.

Referenced by cimod::BinaryPolynomialModel< IndexType, FloatType >::BinaryPolynomialModel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddInteractionsFrom() [2/3]

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteractionsFrom ( const PolynomialKeyList< IndexType > &  key_list,
const PolynomialValueList< FloatType > &  value_list,
const Vartype  vartype = Vartype::NONE 
)
inline

Add interactions to the BinaryPolynomialModel.

Parameters
key_list
value_list
vartype

References cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteraction(), and cimod.model.legacy.binary_quadratic_model::vartype.

Here is the call graph for this function:

◆ AddInteractionsFrom() [3/3]

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteractionsFrom ( PolynomialKeyList< IndexType > &  key_list,
const PolynomialValueList< FloatType > &  value_list,
const Vartype  vartype = Vartype::NONE 
)
inline

Add interactions to the BinaryPolynomialModel.

Parameters
key_list
value_list
vartype

References cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteraction(), and cimod.model.legacy.binary_quadratic_model::vartype.

Here is the call graph for this function:

◆ AddOffset()

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::AddOffset ( FloatType  offset)
inline

Add specified value to the offset of the BinaryPolynomialModel.

Parameters
offset

References cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteraction().

Here is the call graph for this function:

◆ ChangeVartype() [1/2]

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::ChangeVartype ( const Vartype  vartype)
inline

◆ ChangeVartype() [2/2]

template<typename IndexType , typename FloatType >
BinaryPolynomialModel cimod::BinaryPolynomialModel< IndexType, FloatType >::ChangeVartype ( const Vartype  vartype,
const bool  inplace 
)
inline

Create a BinaryPolynomialModel with the specified vartype.

Parameters
vartype
inplace
Returns
A new instance of the BinaryPolynomialModel.

References cimod::BINARY, cimod::SPIN, cimod::BinaryPolynomialModel< IndexType, FloatType >::ToBinary(), cimod::BinaryPolynomialModel< IndexType, FloatType >::ToSpin(), and cimod.model.legacy.binary_quadratic_model::vartype.

Here is the call graph for this function:

◆ Clear()

◆ Empty()

template<typename IndexType , typename FloatType >
BinaryPolynomialModel cimod::BinaryPolynomialModel< IndexType, FloatType >::Empty ( const Vartype  vartype) const
inline

Create an empty BinaryPolynomialModel.

Parameters
vartype
Returns
The empty BinaryPolynomialModel.

References cimod::BinaryPolynomialModel< IndexType, FloatType >::BinaryPolynomialModel(), and cimod.model.legacy.binary_quadratic_model::vartype.

Here is the call graph for this function:

◆ Energies() [1/2]

template<typename IndexType , typename FloatType >
PolynomialValueList<FloatType> cimod::BinaryPolynomialModel< IndexType, FloatType >::Energies ( const std::vector< Sample< IndexType >> &  samples) const
inline

Determine the energies of the given samples.

Parameters
samples
Returns
Energies with respect to the samples as std::vector

References cimod::BinaryPolynomialModel< IndexType, FloatType >::Energy().

Here is the call graph for this function:

◆ Energies() [2/2]

template<typename IndexType , typename FloatType >
PolynomialValueList<FloatType> cimod::BinaryPolynomialModel< IndexType, FloatType >::Energies ( const std::vector< std::vector< int32_t >> &  samples_vec)
inline

Determine the energies of the given samples_vec.

Parameters
samples_vec
Returns
Energies with respect to the samples as std::vector

References cimod::BinaryPolynomialModel< IndexType, FloatType >::Energy().

Here is the call graph for this function:

◆ Energy() [1/2]

template<typename IndexType , typename FloatType >
FloatType cimod::BinaryPolynomialModel< IndexType, FloatType >::Energy ( const Sample< IndexType > &  sample,
bool  omp_flag = true 
) const
inline

Determine the energy of the specified sample of the BinaryPolynomialModel.

When omp_flag is true, the OpenMP is used to calculate the energy in parallel.

Parameters
sample
omp_flag
Returns
An energy with respect to the sample.

References cimod::BinaryPolynomialModel< IndexType, FloatType >::GetNumInteractions(), cimod::BinaryPolynomialModel< IndexType, FloatType >::GetNumVariables(), cimod::BinaryPolynomialModel< IndexType, FloatType >::poly_key_list_, and cimod::BinaryPolynomialModel< IndexType, FloatType >::poly_value_list_.

Referenced by cimod::BinaryPolynomialModel< IndexType, FloatType >::Energies().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Energy() [2/2]

template<typename IndexType , typename FloatType >
FloatType cimod::BinaryPolynomialModel< IndexType, FloatType >::Energy ( const std::vector< int32_t > &  sample_vec,
bool  omp_flag = true 
)
inline

◆ FromHising() [1/3]

template<typename IndexType , typename FloatType >
static BinaryPolynomialModel cimod::BinaryPolynomialModel< IndexType, FloatType >::FromHising ( const Polynomial< IndexType, FloatType > &  poly_map)
inlinestatic

Create a BinaryPolynomialModel from a higher ordere Ising model.

Parameters
poly_map
Returns
BinaryPolynomialModel instance with the vartype being SPIN.

References cimod::SPIN.

◆ FromHising() [2/3]

template<typename IndexType , typename FloatType >
static BinaryPolynomialModel cimod::BinaryPolynomialModel< IndexType, FloatType >::FromHising ( const PolynomialKeyList< IndexType > &  key_list,
const PolynomialValueList< FloatType > &  value_list 
)
inlinestatic

Create a BinaryPolynomialModel from a higher ordere Ising model.

Parameters
key_list
value_list
Returns
BinaryPolynomialModel instance with the vartype being SPIN.

References cimod::SPIN.

◆ FromHising() [3/3]

template<typename IndexType , typename FloatType >
static BinaryPolynomialModel cimod::BinaryPolynomialModel< IndexType, FloatType >::FromHising ( PolynomialKeyList< IndexType > &  key_list,
const PolynomialValueList< FloatType > &  value_list 
)
inlinestatic

Create a BinaryPolynomialModel from a higher ordere Ising model.

Parameters
key_list
value_list
Returns
BinaryPolynomialModel instance with the vartype being SPIN.

References cimod::SPIN.

◆ FromHubo() [1/3]

template<typename IndexType , typename FloatType >
static BinaryPolynomialModel cimod::BinaryPolynomialModel< IndexType, FloatType >::FromHubo ( const Polynomial< IndexType, FloatType > &  poly_map)
inlinestatic

Create a BinaryPolynomialModel from a Hubo model.

Parameters
poly_map
Returns
BinaryPolynomialModel instance with the vartype being BINARY.

References cimod::BINARY.

◆ FromHubo() [2/3]

template<typename IndexType , typename FloatType >
static BinaryPolynomialModel cimod::BinaryPolynomialModel< IndexType, FloatType >::FromHubo ( const PolynomialKeyList< IndexType > &  key_list,
const PolynomialValueList< FloatType > &  value_list 
)
inlinestatic

Create a BinaryPolynomialModel from a Hubo model.

Parameters
key_list
value_list
Returns
BinaryPolynomialModel instance with the vartype being BINARY.

References cimod::BINARY.

◆ FromHubo() [3/3]

template<typename IndexType , typename FloatType >
static BinaryPolynomialModel cimod::BinaryPolynomialModel< IndexType, FloatType >::FromHubo ( PolynomialKeyList< IndexType > &  key_list,
const PolynomialValueList< FloatType > &  value_list 
)
inlinestatic

Create a BinaryPolynomialModel from a Hubo model.

Parameters
key_list
value_list
Returns
BinaryPolynomialModel instance with the vartype being BINARY.

References cimod::BINARY.

◆ FromSerializable()

template<typename IndexType , typename FloatType >
template<typename IndexType_serial = IndexType, typename FloatType_serial = FloatType>
static BinaryPolynomialModel<IndexType_serial, FloatType_serial> cimod::BinaryPolynomialModel< IndexType, FloatType >::FromSerializable ( const nlohmann::json &  input)
inlinestatic

Create a BinaryPolynomialModel instance from a serializable object.

Template Parameters
IndexType_serial
FloatType_serial
Parameters
input
Returns
BinaryPolynomialModel instance

References cimod::BINARY, cimod::SPIN, and cimod.model.legacy.binary_quadratic_model::vartype.

◆ GenerateChangedKey()

template<typename IndexType , typename FloatType >
std::vector<IndexType> cimod::BinaryPolynomialModel< IndexType, FloatType >::GenerateChangedKey ( const std::vector< IndexType > &  original_key,
const std::size_t  num_of_key 
) const
inlineprotected

Generate the num_of_key-th the key when the vartype is changed.

Parameters
original_key
num_of_key
Returns
The changed key

Referenced by cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteraction(), cimod::BinaryPolynomialModel< IndexType, FloatType >::ToHising(), and cimod::BinaryPolynomialModel< IndexType, FloatType >::ToHubo().

Here is the caller graph for this function:

◆ GenerateSortedVariables()

template<typename IndexType , typename FloatType >
std::vector<IndexType> cimod::BinaryPolynomialModel< IndexType, FloatType >::GenerateSortedVariables ( ) const
inlineprotected

◆ GenerateVariablesToIntegers()

template<typename IndexType , typename FloatType >
std::unordered_map<IndexType, int64_t> cimod::BinaryPolynomialModel< IndexType, FloatType >::GenerateVariablesToIntegers ( ) const
inlineprotected

Generate variables_to_integers.

Returns
variables_to_integers

References cimod::BinaryPolynomialModel< IndexType, FloatType >::GenerateSortedVariables().

Referenced by cimod::BinaryPolynomialModel< IndexType, FloatType >::GetVariablesToIntegers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDegree()

template<typename IndexType , typename FloatType >
std::size_t cimod::BinaryPolynomialModel< IndexType, FloatType >::GetDegree ( ) const
inline

Return the maximum degree of interaction.

Returns
degree

References cimod::BinaryPolynomialModel< IndexType, FloatType >::poly_key_list_.

◆ GetKeyList()

template<typename IndexType , typename FloatType >
const PolynomialKeyList<IndexType>& cimod::BinaryPolynomialModel< IndexType, FloatType >::GetKeyList ( ) const
inline

Get the PolynomialKeyList object.

Returns
PolynomialKeyList object as std::vector<std::vector>>.

References cimod::BinaryPolynomialModel< IndexType, FloatType >::poly_key_list_.

◆ GetKeysInv()

template<typename IndexType , typename FloatType >
const std::unordered_map<std::vector<IndexType>, std::size_t, vector_hash>& cimod::BinaryPolynomialModel< IndexType, FloatType >::GetKeysInv ( ) const
inline

Get The inverse key list, which indicates the index of the poly_key_list_ and poly_value_list_.

Returns
The inverse key list.

References cimod::BinaryPolynomialModel< IndexType, FloatType >::poly_key_inv_.

◆ GetNumInteractions()

template<typename IndexType , typename FloatType >
std::size_t cimod::BinaryPolynomialModel< IndexType, FloatType >::GetNumInteractions ( ) const
inline

◆ GetNumVariables()

template<typename IndexType , typename FloatType >
std::size_t cimod::BinaryPolynomialModel< IndexType, FloatType >::GetNumVariables ( ) const
inline

Return the number of variables.

Returns
The number of the variables.

References cimod::BinaryPolynomialModel< IndexType, FloatType >::variables_.

Referenced by cimod::BinaryPolynomialModel< IndexType, FloatType >::Energy().

Here is the caller graph for this function:

◆ GetOffset()

template<typename IndexType , typename FloatType >
FloatType cimod::BinaryPolynomialModel< IndexType, FloatType >::GetOffset ( ) const
inline

Return the offset.

Returns
The offset

References cimod::BinaryPolynomialModel< IndexType, FloatType >::GetPolynomial().

Here is the call graph for this function:

◆ GetPolynomial() [1/3]

template<typename IndexType , typename FloatType >
Polynomial<IndexType, FloatType> cimod::BinaryPolynomialModel< IndexType, FloatType >::GetPolynomial ( ) const
inline

◆ GetPolynomial() [2/3]

template<typename IndexType , typename FloatType >
FloatType cimod::BinaryPolynomialModel< IndexType, FloatType >::GetPolynomial ( const std::vector< IndexType > &  key) const
inline

Get the specific value of the interaction according to the key representing the indices of the polynomial interactions.

If the interaction corresponding to the key dose not exist, return 0

Parameters
key
Returns
Corresponding value of the interaction

References cimod::BinaryPolynomialModel< IndexType, FloatType >::GetPolynomial().

Here is the call graph for this function:

◆ GetPolynomial() [3/3]

template<typename IndexType , typename FloatType >
FloatType cimod::BinaryPolynomialModel< IndexType, FloatType >::GetPolynomial ( std::vector< IndexType > &  key) const
inline

Get the specific value of the interaction according to the key representing the indices of the polynomial interactions.

If the interaction corresponding to the key dose not exist, return 0

Parameters
key
Returns
Corresponding value of the interaction

References cimod::FormatPolynomialKey(), cimod::BinaryPolynomialModel< IndexType, FloatType >::poly_key_inv_, cimod::BinaryPolynomialModel< IndexType, FloatType >::poly_value_list_, and cimod::BinaryPolynomialModel< IndexType, FloatType >::vartype_.

Here is the call graph for this function:

◆ GetSortedVariables() [1/2]

template<typename IndexType , typename FloatType >
const std::vector<IndexType>& cimod::BinaryPolynomialModel< IndexType, FloatType >::GetSortedVariables ( )
inline

Return the sorted variables as std::vector.

This function may need O(N) calculation time (N is the number of the variables).

Returns
sorted variables as std::vector.

References cimod::BinaryPolynomialModel< IndexType, FloatType >::relabel_flag_for_variables_to_integers_, cimod::BinaryPolynomialModel< IndexType, FloatType >::sorted_variables_, and cimod::BinaryPolynomialModel< IndexType, FloatType >::UpdateVariablesToIntegers().

Referenced by cimod::BinaryPolynomialModel< IndexType, FloatType >::GetVariablesToIntegers(), and cimod::BinaryPolynomialModel< IndexType, FloatType >::ToSerializable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSortedVariables() [2/2]

template<typename IndexType , typename FloatType >
std::vector<IndexType> cimod::BinaryPolynomialModel< IndexType, FloatType >::GetSortedVariables ( ) const
inline

Return the sorted variables as std::vector.

This function may need O(N) calculation time (N is the number of the variables).

Returns
sorted variables as std::vector.

References cimod::BinaryPolynomialModel< IndexType, FloatType >::GenerateSortedVariables(), cimod::BinaryPolynomialModel< IndexType, FloatType >::relabel_flag_for_variables_to_integers_, and cimod::BinaryPolynomialModel< IndexType, FloatType >::sorted_variables_.

Here is the call graph for this function:

◆ GetValueList()

template<typename IndexType , typename FloatType >
const PolynomialValueList<FloatType>& cimod::BinaryPolynomialModel< IndexType, FloatType >::GetValueList ( ) const
inline

Get the PolynomialValueList object.

Returns
PolynomialValueList object as std::vector.

References cimod::BinaryPolynomialModel< IndexType, FloatType >::poly_value_list_.

◆ GetVariables()

template<typename IndexType , typename FloatType >
const std::unordered_set<IndexType>& cimod::BinaryPolynomialModel< IndexType, FloatType >::GetVariables ( ) const
inline

Return the variables as std::unordered_set.

Returns
variables

References cimod::BinaryPolynomialModel< IndexType, FloatType >::variables_.

◆ GetVariablesToIntegers() [1/4]

template<typename IndexType , typename FloatType >
const std::unordered_map<IndexType, int64_t>& cimod::BinaryPolynomialModel< IndexType, FloatType >::GetVariablesToIntegers ( )
inline

Get variables_to_integers object.

This function may need O(N) calculation time (N is the number of the variables).

Returns
variables_to_integers object, which represents the correspondence from variables to integer numbers

References cimod::BinaryPolynomialModel< IndexType, FloatType >::relabel_flag_for_variables_to_integers_, cimod::BinaryPolynomialModel< IndexType, FloatType >::UpdateVariablesToIntegers(), and cimod::BinaryPolynomialModel< IndexType, FloatType >::variables_to_integers_.

Here is the call graph for this function:

◆ GetVariablesToIntegers() [2/4]

template<typename IndexType , typename FloatType >
std::unordered_map<IndexType, int64_t> cimod::BinaryPolynomialModel< IndexType, FloatType >::GetVariablesToIntegers ( ) const
inline

Get variables_to_integers object.

This function may need O(N) calculation time (N is the number of the variables).

Returns
variables_to_integers, which represents the correspondence from variables to integer numbers

References cimod::BinaryPolynomialModel< IndexType, FloatType >::GenerateVariablesToIntegers(), cimod::BinaryPolynomialModel< IndexType, FloatType >::relabel_flag_for_variables_to_integers_, and cimod::BinaryPolynomialModel< IndexType, FloatType >::variables_to_integers_.

Here is the call graph for this function:

◆ GetVariablesToIntegers() [3/4]

template<typename IndexType , typename FloatType >
int64_t cimod::BinaryPolynomialModel< IndexType, FloatType >::GetVariablesToIntegers ( const IndexType &  index)
inline

Get the specific integer number corresponding to the input variable (index).

This function may need O(N) calculation time (N is the number of the variables).

Parameters
index
Returns
Non-negative integer number if the input variable is in the BinaryPolynomialModel, else -1

References cimod::BinaryPolynomialModel< IndexType, FloatType >::relabel_flag_for_variables_to_integers_, cimod::BinaryPolynomialModel< IndexType, FloatType >::UpdateVariablesToIntegers(), and cimod::BinaryPolynomialModel< IndexType, FloatType >::variables_to_integers_.

Here is the call graph for this function:

◆ GetVariablesToIntegers() [4/4]

template<typename IndexType , typename FloatType >
int64_t cimod::BinaryPolynomialModel< IndexType, FloatType >::GetVariablesToIntegers ( const IndexType &  index) const
inline

Get the specific integer number corresponding to the input variable (index).

This function may need O(N) calculation time (N is the number of the variables).

Parameters
index
Returns
Non-negative integer number if the input variable is in the BinaryPolynomialModel, else -1

References cimod::BinaryPolynomialModel< IndexType, FloatType >::GetSortedVariables(), and cimod::BinaryPolynomialModel< IndexType, FloatType >::variables_.

Here is the call graph for this function:

◆ GetVartype()

template<typename IndexType , typename FloatType >
Vartype cimod::BinaryPolynomialModel< IndexType, FloatType >::GetVartype ( ) const
inline

Return the vartype.

Returns
The vartype

References cimod::BinaryPolynomialModel< IndexType, FloatType >::vartype_.

◆ HasVariable()

template<typename IndexType , typename FloatType >
bool cimod::BinaryPolynomialModel< IndexType, FloatType >::HasVariable ( const IndexType &  index)
inline

Check if the specified index is in the BinaryPolynomialModel.

Parameters
index
Returns
true or false

References cimod::BinaryPolynomialModel< IndexType, FloatType >::variables_.

◆ IntegerPower()

template<typename IndexType , typename FloatType >
std::size_t cimod::BinaryPolynomialModel< IndexType, FloatType >::IntegerPower ( std::size_t  base,
std::size_t  exponent 
) const
inlineprotected

Caluculate the base to the power of exponent (std::pow(base, exponent) is too slow).

Parameters
base
exponent
Returns
The base to the power of exponent

Referenced by cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteraction(), cimod::BinaryPolynomialModel< IndexType, FloatType >::ToHising(), and cimod::BinaryPolynomialModel< IndexType, FloatType >::ToHubo().

Here is the caller graph for this function:

◆ normalize()

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::normalize ( const std::pair< FloatType, FloatType > &  range = { 1.0, 1.0 },
const PolynomialKeyList< IndexType > &  ignored_interactions = {},
const bool  ignored_offset = false 
)
inline

Normalizes the values of the interactions of the BinaryPolynomialModel such that they fall in the provided range(s).

Parameters
range
ignored_interactions
ignored_offset

◆ RemoveInteraction() [1/2]

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveInteraction ( const std::vector< IndexType > &  key)
inline

Remove the specified interaction from the BinaryPolynomialModel.

Parameters
key

References cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveInteraction().

Here is the call graph for this function:

◆ RemoveInteraction() [2/2]

◆ RemoveInteractionsFrom() [1/2]

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveInteractionsFrom ( const PolynomialKeyList< IndexType > &  key_list)
inline

Remove the specified interactions from the BinaryPolynomialModel.

Parameters
key_list

References cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveInteraction().

Here is the call graph for this function:

◆ RemoveInteractionsFrom() [2/2]

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveInteractionsFrom ( PolynomialKeyList< IndexType > &  key_list)
inline

Remove the specified interactions from the BinaryPolynomialModel.

Parameters
key_list

References cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveInteraction().

Here is the call graph for this function:

◆ RemoveOffset()

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveOffset ( )
inline

Set the offset of the BinaryPolynomialModel to zero.

References cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveInteraction().

Here is the call graph for this function:

◆ RemoveVariable()

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveVariable ( const IndexType &  index)
inline

Remove a variable from the BinaryPolynomialModel.

Parameters
index

References cimod::BinaryPolynomialModel< IndexType, FloatType >::poly_key_list_, and cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveInteraction().

Referenced by cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveVariablesFrom().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveVariablesFrom()

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveVariablesFrom ( const std::vector< IndexType > &  key)
inline

Remove the specified variables from the BinaryPolynomialModel.

Parameters
key

References cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveVariable().

Here is the call graph for this function:

◆ Scale()

template<typename IndexType , typename FloatType >
void cimod::BinaryPolynomialModel< IndexType, FloatType >::Scale ( const FloatType  scalar,
const PolynomialKeyList< IndexType > &  ignored_interactions = {},
const bool  ignored_offset = false 
)
inline

Multiply by the specified scalar all the values of the interactions of the BinaryPolynomialModel.

Parameters
scalar
ignored_interactions
ignored_offset

◆ SetKeyAndValue()

◆ ToBinary()

template<typename IndexType , typename FloatType >
BinaryPolynomialModel cimod::BinaryPolynomialModel< IndexType, FloatType >::ToBinary ( ) const
inlineprotected

◆ ToHising()

◆ ToHubo()

◆ ToSerializable()

template<typename IndexType , typename FloatType >
nlohmann::json cimod::BinaryPolynomialModel< IndexType, FloatType >::ToSerializable ( ) const
inline

◆ ToSpin()

template<typename IndexType , typename FloatType >
BinaryPolynomialModel cimod::BinaryPolynomialModel< IndexType, FloatType >::ToSpin ( ) const
inlineprotected

◆ UpdateVariablesToIntegers()

Member Data Documentation

◆ each_variable_num_

template<typename IndexType , typename FloatType >
std::unordered_map<IndexType, std::size_t> cimod::BinaryPolynomialModel< IndexType, FloatType >::each_variable_num_
protected

◆ poly_key_inv_

◆ poly_key_list_

◆ poly_value_list_

◆ relabel_flag_for_variables_to_integers_

◆ sorted_variables_

template<typename IndexType , typename FloatType >
std::vector<IndexType> cimod::BinaryPolynomialModel< IndexType, FloatType >::sorted_variables_
protected

Sorted variables is represents the correspondence from integer numbers.to the variables.

Referenced by cimod::BinaryPolynomialModel< IndexType, FloatType >::GetSortedVariables(), and cimod::BinaryPolynomialModel< IndexType, FloatType >::UpdateVariablesToIntegers().

◆ variables_

◆ variables_to_integers_

template<typename IndexType , typename FloatType >
std::unordered_map<IndexType, int64_t> cimod::BinaryPolynomialModel< IndexType, FloatType >::variables_to_integers_
protected

◆ vartype_


The documentation for this class was generated from the following file: