Objective Interface#

(hivenas.core.objective_interface)

The abstract definition of Objective Interfaces in HiveNAS.

class ObjectiveInterface[source]#

Bases: ABC

Encapsulates the method definitions required to satisfy the hooks used by the ArtificialBeeColony optimizer

abstract evaluate(candidate: str)[source]#

Evaluates a given string-encoded candidate and returns its fitness score

Parameters

candidate (str) – string-encoded candidate (an architecture in the case of NASInterface)

Returns

the candidate’s fitness score

Return type

float

Raises

NotImplementedError – requires implementation by child class

abstract fully_train_best_model(from_arch: bool = True)[source]#

Fully trains the best solution found thus far (exclusively used by NAS) (relies on paths set in Params)

Parameters

from_arch (bool, optional) – determines whether to train model from scratch using the string representations of the architecture (from_arch = True) or load the saved model file and continue training (from_arch = False). Note: optimizer settings are typically not saved, therefore training continuation from a model’s file can result in a worse overall accuracy (read more…).

Returns

a dictionary containing all relevant results to be saved, including: fitness, number of training epochs conducted (not including any previous trainings), hashed file name, number of trainable parameters

Return type

dict

Raises

NotImplementedError – requires implementation by child class

abstract get_neighbor(candidate: str)[source]#

Samples a neighbor for a given string-encoded candidate

Parameters

candidate (str) – the position on the solution surface to find a neighbor for

Returns

the neighboring string-encoded candidate

Return type

str

Raises

NotImplementedError – requires implementation by child class

abstract is_minimize()[source]#

Used by the optimization algorithm to determine whether this is a minimization or maximization problem

Returns

whether to minimize or maximize the fitness (True = minimize)

Return type

bool

Raises

NotImplementedError – requires implementation by child class

abstract momentum_eval(candidate: str, weights_filename: str, m_epochs: int)[source]#

Momentum Evaluation phase (MomentumAugmentation; used exclusively by NAS)

Parameters
  • candidate (str) – the selected string-encoded candidate to extend its training

  • weights_filename (str) – the SHA1-hashed unique string ID for the given candidate

  • m_epochs (int) – the additional momentum epochs the candidate should be trained for

Returns

final fitness value (accuracy) after training continuation

Return type

dict

Raises

NotImplementedError – requires implementation by child class

abstract sample()[source]#

Samples a random candidate from the optimization surface (used primarily by ScoutBee to initialize the FoodSource vector, \(\vec{x}_{m}\) )

Returns

a string-encoded candidate randomly sampled from the solution space

Return type

str

Raises

NotImplementedError – requires implementation by child class