style: run clang-format and configure pre-commit hooks

This commit is contained in:
AI-anonymous
2026-05-20 00:18:23 +02:00
parent 041eab7155
commit 3b15770437
28 changed files with 2226 additions and 2061 deletions

View File

@@ -2,14 +2,15 @@
/**
* @file fitness.hpp
* @brief Fitness evaluation — loss signal processing and multi-objective evaluation.
* @brief Fitness evaluation — loss signal processing and multi-objective
* evaluation.
*
* Port of: packages/fces/core/fitness_engine.py + fitness.py
*/
#include <cmath>
#include <vector>
#include <string>
#include <vector>
namespace fces {
@@ -19,18 +20,18 @@ namespace fces {
*/
class RunningStats {
public:
void update(float value);
float z_score(float value) const;
float get_mean() const { return mean_; }
float get_std() const;
int get_count() const { return count_; }
void update(float value);
float z_score(float value) const;
float get_mean() const { return mean_; }
float get_std() const;
int get_count() const { return count_; }
void reset();
void reset();
private:
int count_ = 0;
float mean_ = 0.0f;
float m2_ = 0.0f;
int count_ = 0;
float mean_ = 0.0f;
float m2_ = 0.0f;
};
/**
@@ -38,26 +39,27 @@ private:
*/
class FitnessEngine {
public:
explicit FitnessEngine(float grokking_coefficient = 0.1f);
explicit FitnessEngine(float grokking_coefficient = 0.1f);
/**
* Calculate loss velocity signal.
*
* @param current_loss Current step loss
* @param ema_loss Exponential moving average loss
* @param mode "relative" or "absolute"
* @return Velocity signal (negative = improving)
*/
float calculate_loss_signal(float current_loss, float ema_loss, const std::string& mode = "relative") const;
/**
* Calculate loss velocity signal.
*
* @param current_loss Current step loss
* @param ema_loss Exponential moving average loss
* @param mode "relative" or "absolute"
* @return Velocity signal (negative = improving)
*/
float calculate_loss_signal(float current_loss, float ema_loss,
const std::string &mode = "relative") const;
/**
* Compute Kibble-Zurek Mechanism damping factor.
* Prevents topological defects during phase transitions.
*/
float compute_kzm_damping(float spectral_alpha) const;
/**
* Compute Kibble-Zurek Mechanism damping factor.
* Prevents topological defects during phase transitions.
*/
float compute_kzm_damping(float spectral_alpha) const;
private:
float grokking_coefficient_;
float grokking_coefficient_;
};
/**
@@ -65,75 +67,76 @@ private:
*/
class FuzzySet {
public:
FuzzySet(std::string name, float a, float b, float c, float d) noexcept
: name_(std::move(name)), a_(a), b_(b), c_(c), d_(d) {}
FuzzySet(std::string name, float a, float b, float c, float d) noexcept
: name_(std::move(name)), a_(a), b_(b), c_(c), d_(d) {}
float membership(float x) const noexcept {
if (!std::isfinite(x)) {
return 0.0f;
}
if (x <= a_ || x >= d_) {
return 0.0f;
}
if (x >= b_ && x <= c_) {
return 1.0f;
}
if (x > a_ && x < b_) {
float range = b_ - a_;
return (x - a_) / (range > 0.0f ? range : 1e-9f);
}
if (x > c_ && x < d_) {
float range = d_ - c_;
return (d_ - x) / (range > 0.0f ? range : 1e-9f);
}
return 0.0f;
float membership(float x) const noexcept {
if (!std::isfinite(x)) {
return 0.0f;
}
if (x <= a_ || x >= d_) {
return 0.0f;
}
if (x >= b_ && x <= c_) {
return 1.0f;
}
if (x > a_ && x < b_) {
float range = b_ - a_;
return (x - a_) / (range > 0.0f ? range : 1e-9f);
}
if (x > c_ && x < d_) {
float range = d_ - c_;
return (d_ - x) / (range > 0.0f ? range : 1e-9f);
}
return 0.0f;
}
const std::string& name() const noexcept { return name_; }
const std::string &name() const noexcept { return name_; }
private:
std::string name_;
float a_;
float b_;
float c_;
float d_;
std::string name_;
float a_;
float b_;
float c_;
float d_;
};
/**
* Fitness metrics for multi-objective evaluation.
*/
struct FitnessMetrics {
float training_advantage = 0.0f;
float validation_advantage = 0.0f;
float grad_cv = 0.0f;
float sparsity_delta = 0.0f;
float consistency_gap = 0.0f;
float stable_rank = 0.0f;
float training_advantage = 0.0f;
float validation_advantage = 0.0f;
float grad_cv = 0.0f;
float sparsity_delta = 0.0f;
float consistency_gap = 0.0f;
float stable_rank = 0.0f;
};
/**
* FuzzyFitnessEvaluator — multi-objective fitness evaluation with fuzzy weighting.
* FuzzyFitnessEvaluator — multi-objective fitness evaluation with fuzzy
* weighting.
*/
class FuzzyFitnessEvaluator {
public:
FuzzyFitnessEvaluator() noexcept;
FuzzyFitnessEvaluator() noexcept;
float evaluate(const FitnessMetrics& metrics) const noexcept;
float evaluate(const FitnessMetrics &metrics) const noexcept;
private:
FuzzySet stability_set_;
FuzzySet train_set_;
FuzzySet val_set_;
FuzzySet sparsity_set_;
FuzzySet consistency_set_;
FuzzySet rank_set_;
FuzzySet stability_set_;
FuzzySet train_set_;
FuzzySet val_set_;
FuzzySet sparsity_set_;
FuzzySet consistency_set_;
FuzzySet rank_set_;
float w_stability_ = 0.2f;
float w_train_ = 0.2f;
float w_val_ = 0.3f;
float w_sparsity_ = 0.1f;
float w_consistency_ = 0.2f;
float w_rank_ = 0.1f;
float w_stability_ = 0.2f;
float w_train_ = 0.2f;
float w_val_ = 0.3f;
float w_sparsity_ = 0.1f;
float w_consistency_ = 0.2f;
float w_rank_ = 0.1f;
};
} // namespace fces
} // namespace fces