Skip to content

Commit

Permalink
Adds v0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
cornerfarmer committed May 21, 2017
1 parent 896b5a2 commit 06bb269
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ namespace LightBulb
* \brief Describes the results of a AbstractCombiningStrategy.
* \details Maps: First individual - Second individual - round number => True, if first individual has won.
*/
typedef std::map<AbstractIndividual*, std::map<AbstractIndividual*, std::map<int, bool>>> CombiningStrategyResults;
struct CombiningStrategyResults : std::map<AbstractIndividual*, std::map<AbstractIndividual*, std::map<int, bool>>>
{
virtual ~CombiningStrategyResults() { };
};
/**
* \brief Describes a strategy for combining individual from one or two coevolution environments.
* \details The strategy compares each two individuals and stores the results in a CombiningStrategyResults object.
Expand All @@ -32,11 +35,11 @@ namespace LightBulb
* \brief Stores the current combining results.
*/
std::unique_ptr<CombiningStrategyResults> results;
protected:
/**
* \brief Counts how often the first player has won.
*/
* \brief Counts how often the first player has won.
*/
int firstPlayerWins;
protected:
/**
* \brief Contains a second environment, if one is used.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace LightBulb
* \brief True, if the highscore should be recalculated.
*/
bool recalculateHighscore;
static bool pairCompare(const std::pair<double, AbstractIndividual*>& firstElem, const std::pair<double, AbstractIndividual*>& secondElem);
protected:
/**
* \brief A pointer to the learning state used by the corresponding learning rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ namespace LightBulb
template <class Archive>
friend void serialize(Archive& archive, AbstractHallOfFameAlgorithm& hallOfFameAlgorithm);
private:
protected:
/**
* \brief Stores the current CombiningStrategyResults.
*/
* \brief Stores the current CombiningStrategyResults.
*/
CombiningStrategyResults* currentResults;
protected:
/**
* \brief The current environment to use for simulations.
*/
Expand All @@ -43,7 +43,7 @@ namespace LightBulb
* \param memberID The id of the member to use.
* \param round The round number.
*/
void simulateAgainstMember(AbstractIndividual& individual, int memberID, int round);
virtual void simulateAgainstMember(AbstractIndividual& individual, int memberID, int round);
/**
* \brief Evaluates the given individuals.
* \param individuals A vector of individuals.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace LightBulb
void doCalculationAfterLearningProcess() override;
void setHelperToUsedObjects() override;
AbstractLearningResult* getLearningResult() override;
void initializeStartLearningAlgoritm() override;
public:
/**
* \brief Creates the coevolution learning rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace LightBulb
{
template <class Archive>
friend void serialize(Archive& archive, SharedSamplingCombiningStrategy& sharedSamplingCombiningStrategy);
private:
protected:
/**
* \brief Determines the number of competitions per individual.
*/
Expand All @@ -37,8 +37,15 @@ namespace LightBulb
* \brief Contains the combining strategy of the parasite population.
*/
const AbstractCombiningStrategy* otherCombiningStrategy;
/**
* \brief Combines every individual from the given pool with every individual from the given sample.
* \param simulationEnvironment The environment which should be used for comparing individuals.
* \param firstIndividuals The pool of individuals.
* \param sample The sample.
*/
virtual void executeSample(AbstractCoevolutionEnvironment& simulationEnvironment, std::vector<AbstractIndividual*>& firstIndividuals, std::vector<AbstractIndividual*>& sample);
// Inherited:
void combine(AbstractCoevolutionEnvironment& simulationEnvironment, std::vector<AbstractIndividual*>& firstIndividuals, std::vector<AbstractIndividual*>& secondIndividuals) override;
void combine(AbstractCoevolutionEnvironment& simulationEnvironment, std::vector<AbstractIndividual*>& firstIndividuals, std::vector<AbstractIndividual*>& secondIndividuals) override;
public:
/**
* \brief Creates the shared sampling combining strategy.
Expand Down
3 changes: 3 additions & 0 deletions include/LightBulbApp/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace LightBulb
{
class AbstractTrainingPlan;
class AbstractNetworkExporter;

/**
* \brief The LightBulbApp.
Expand All @@ -26,6 +27,7 @@ namespace LightBulb
* \brief Contains all available training plans.
*/
std::vector<AbstractTrainingPlan*> trainingPlans;
std::vector<AbstractNetworkExporter*> exporters;
std::unique_ptr<NeuralNetworkRepository> neuralNetworkRepository;
std::unique_ptr<TrainingPlanRepository> trainingPlanRepository;
std::unique_ptr<TrainingController> trainingController;
Expand All @@ -35,6 +37,7 @@ namespace LightBulb
* \param trainingPlan The new trianing plan.
*/
void addTrainingPlan(AbstractTrainingPlan* trainingPlan);
void addExporter(AbstractNetworkExporter* exporter);
// Inherited:
bool OnInit() override;
void OnUnhandledException() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace LightBulb
recalculateHighscore = true;
}

bool AbstractEvolutionEnvironment::pairCompare(const std::pair<double, AbstractIndividual*>& firstElem, const std::pair<double, AbstractIndividual*>& secondElem) {
return firstElem.first > secondElem.first;
}

Highscore& AbstractEvolutionEnvironment::getHighscoreList()
{
if (recalculateHighscore)
Expand All @@ -26,6 +30,8 @@ namespace LightBulb

}
// Sort the list
//std::random_shuffle(currentHighscore.begin(), currentHighscore.end());
//std::stable_sort(currentHighscore.begin(), currentHighscore.end(), pairCompare);
sort(currentHighscore.begin(), currentHighscore.end(), std::greater<std::pair<double, AbstractIndividual*>>());
recalculateHighscore = false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/LightBulb/Learning/Evolution/EvolutionLearningRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ namespace LightBulb

}

void EvolutionLearningRule::initializeStartLearningAlgoritm()
{
EvolutionLearningRule::setHelperToUsedObjects();
}

void EvolutionLearningRule::setHelperToUsedObjects()
{
getOptions().environment->setLogger(*options->logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ namespace LightBulb
}
}

executeSample(simulationEnvironment, firstIndividuals, sample);
}

void SharedSamplingCombiningStrategy::executeSample(AbstractCoevolutionEnvironment& simulationEnvironment, std::vector<AbstractIndividual*>& firstIndividuals, std::vector<AbstractIndividual*>& sample)
{
for (auto firstPlayer = firstIndividuals.begin(); firstPlayer != firstIndividuals.end(); firstPlayer++)
{
for (auto secondPlayer = sample.begin(); secondPlayer != sample.end(); secondPlayer++)
Expand Down
7 changes: 7 additions & 0 deletions src/LightBulbApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace LightBulb

trainingController->addNetworkExporter(new BrainJSExporter());
trainingController->addNetworkExporter(new SynapticExporter());
for (auto exporter = exporters.begin(); exporter != exporters.end(); exporter++)
trainingController->addNetworkExporter(*exporter);

trainingController->show();
return true;
Expand All @@ -55,4 +57,9 @@ namespace LightBulb
{
trainingPlans.push_back(trainingPlan);
}

void App::addExporter(AbstractNetworkExporter* exporter)
{
exporters.push_back(exporter);
}
}

0 comments on commit 06bb269

Please sign in to comment.