checkpoint: port evolutionary and population dynamics
This commit is contained in:
@@ -22,9 +22,9 @@
|
||||
namespace fces {
|
||||
|
||||
// Controller input dimension (layer stats features)
|
||||
constexpr int GENOME_INPUT_DIM = 9;
|
||||
constexpr int GENOME_INPUT_DIM = 14;
|
||||
// Controller hidden dimension
|
||||
constexpr int GENOME_HIDDEN_DIM = 16;
|
||||
constexpr int GENOME_HIDDEN_DIM = 8;
|
||||
// Controller output dimension: [multiplier, sign_gate, wd_mult]
|
||||
constexpr int GENOME_OUTPUT_DIM = 3;
|
||||
// Total genome size: input->hidden weights + hidden biases + hidden->output weights + output biases
|
||||
|
||||
@@ -59,19 +59,55 @@ private:
|
||||
float grokking_coefficient_;
|
||||
};
|
||||
|
||||
/**
|
||||
* FuzzySet represents a fuzzy set with a trapezoidal membership function.
|
||||
*/
|
||||
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) {}
|
||||
|
||||
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_; }
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
float a_;
|
||||
float b_;
|
||||
float c_;
|
||||
float d_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fitness metrics for multi-objective evaluation.
|
||||
*/
|
||||
struct FitnessMetrics {
|
||||
float loss_improvement = 0.0f;
|
||||
float sparsity_score = 0.0f;
|
||||
float stability_score = 0.0f;
|
||||
float novelty_score = 0.0f;
|
||||
|
||||
/// Weighted combination
|
||||
float total(float alpha = 0.7f, float beta = 0.3f) const {
|
||||
return alpha * loss_improvement + beta * sparsity_score;
|
||||
}
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -79,12 +115,24 @@ struct FitnessMetrics {
|
||||
*/
|
||||
class FuzzyFitnessEvaluator {
|
||||
public:
|
||||
FitnessMetrics evaluate(
|
||||
float loss_before,
|
||||
float loss_after,
|
||||
float sparsity = 0.0f,
|
||||
float val_loss = -1.0f
|
||||
) const;
|
||||
FuzzyFitnessEvaluator() 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_;
|
||||
|
||||
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
|
||||
|
||||
@@ -74,10 +74,18 @@ private:
|
||||
float rollback_ema_ = 0.0f;
|
||||
int stagnation_counter_ = 0;
|
||||
float last_loss_velocity_ = 0.0f;
|
||||
float last_sparsity_ = 0.0f;
|
||||
|
||||
// RAM backup
|
||||
std::vector<torch::Tensor> ram_backup_;
|
||||
|
||||
// Layer stats and group mappings
|
||||
std::vector<std::vector<float>> layer_stats_;
|
||||
std::vector<int> param_group_mapping_;
|
||||
std::unique_ptr<SpectralSensor> spectral_sensor_;
|
||||
SpectralController spectral_controller_;
|
||||
float last_spectral_rank_ = 0.0f;
|
||||
|
||||
// Internal methods
|
||||
void gather_stats();
|
||||
void apply_parameter_updates(const torch::Tensor& actions);
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace fces {
|
||||
*/
|
||||
class SpectralSensor {
|
||||
public:
|
||||
SpectralSensor() = default;
|
||||
explicit SpectralSensor(torch::nn::Module& model);
|
||||
|
||||
/// Track a layer's weight tensor
|
||||
|
||||
Reference in New Issue
Block a user