Pure_Optical_CUDA / fungi.hpp
Agnuxo's picture
Upload 36 files
db3c893 verified
#pragma once
#include <vector>
#include <cstdint>
/**
* Fungal (mycelium) population in SoA layout for coalesced GPU access.
* Each fungus contributes a local basis φ_h(x,y) to build amplitude/phase masks.
*/
struct FungiSoA {
int F = 0; // number of fungi
int H = 0, W = 0; // mask geometry
// Genome / state
std::vector<float> x, y; // position in [0, W-1] & [0, H-1]
std::vector<float> sigma; // radius
std::vector<float> alpha; // anisotropy (ellipse)
std::vector<float> theta; // orientation
std::vector<float> a_base; // amplitude base coeff
std::vector<float> p_base; // phase base coeff
// Energy & life-cycle
std::vector<float> energy;
std::vector<float> mass;
std::vector<int> age;
void resize(int F_, int H_, int W_);
void init_random(unsigned seed, float sigma_min=1.5f, float sigma_max=5.5f);
void adjust_population(int newF, unsigned seed);
};
/** Build masks A(x,y), P(x,y) from fungi population (GPU). */
void fungi_build_masks_GPU(const FungiSoA& pop,
float* d_A, float* d_P, // [H*W]
int tiles_y=7, int tiles_x=7);
/** Evolution step (GPU): compute per-fungus reward and update energy, size, reproduction. */
void fungi_evolve_GPU(FungiSoA& pop,
const float* d_grad_map, // e.g., gradient magnitude per pixel [H*W]
int evo_pairs,
float food=0.05f, float decay=0.98f, float death_th=-0.5f,
float cost=1e-3f, unsigned seed=1337);
/** Host helpers: download masks (optional debug). */
void download_mask(float* h, const float* d, int HW);
/** DIAGNOSTIC TOOLS: Visual debugging for fungi evolution */
void fungi_export_debug_images(const FungiSoA& pop,
const float* d_A, const float* d_P,
const float* d_grad_map,
const char* prefix = "debug");
void fungi_create_test_pattern(float* h_pattern, int H, int W, int pattern_type = 0);
void fungi_analyze_mask_statistics(const float* d_A, const float* d_P, int HW);