tmp update

This commit is contained in:
张壹 2024-10-17 13:41:46 +08:00
parent ba43d30e06
commit ec60030b91
3 changed files with 21 additions and 9 deletions

View File

@ -46,10 +46,11 @@ int main(int argc, char const *argv[])
lgd_para p = e.default_lgd_para();
p.beta = 1.2;
p.seed = 125;
e.set_lgd_para(p);
array<double> dist;
e.get_levy_distribution(dist, 125);
e.get_levy_distribution(dist);
double m = dist.mean();
double s = dist.std();

View File

@ -30,7 +30,7 @@
/**
* Default parameter for the Lévy-Gradient Descent (L-GD) method.
*/
static const gctl::lgd_para lgd_defparam = {1000, 0, 1e-5, 1.0, 1.5, 0.01, 1e-8, -1.0};
static const gctl::lgd_para lgd_defparam = {1000, 0, 0, 1e-5, 1.0, 1.5, 0.01, 1e-8, -1.0};
gctl::lgd_solver::lgd_solver()
{
@ -154,7 +154,7 @@ void gctl::lgd_solver::save_lgd_trace(std::string trace_file)
return;
}
gctl::lgd_return_code gctl::lgd_solver::get_levy_distribution(array<double> &dist, unsigned int seed)
gctl::lgd_return_code gctl::lgd_solver::get_levy_distribution(array<double> &dist)
{
if (lgd_param_.flight_times <= 0) return LGD_INVALID_MAX_ITERATIONS;
if (lgd_param_.beta <= 1.0 || lgd_param_.beta >= 2.0) return LGD_INVALID_BETA;
@ -164,8 +164,11 @@ gctl::lgd_return_code gctl::lgd_solver::get_levy_distribution(array<double> &dis
double stddev_u = pow((gamma1*sin(0.5*GCTL_Pi*lgd_param_.beta))/
(gamma2*lgd_param_.beta*pow(2, 0.5*(lgd_param_.beta-1.0))), 1.0/lgd_param_.beta);
if (seed == 0) seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine generator(seed);
unsigned int sd;
if (lgd_param_.seed == 0) sd = std::chrono::system_clock::now().time_since_epoch().count();
else sd = lgd_param_.seed;
std::default_random_engine generator(sd);
std::normal_distribution<double> dist_u(0, stddev_u);
std::normal_distribution<double> dist_v(0, lgd_param_.stddev_v);
std::uniform_real_distribution<double> dist_s(1.0, 2.0);
@ -386,8 +389,11 @@ gctl::lgd_return_code gctl::lgd_solver::lgd(array<double> &best_m, array<double>
double gamma2 = tgamma(0.5*(lgd_param_.beta + 1.0));
double stddev_u = pow((gamma1*sin(0.5*GCTL_Pi*lgd_param_.beta)) / (gamma2*lgd_param_.beta*pow(2, 0.5*(lgd_param_.beta-1.0))), 1.0/lgd_param_.beta);
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine generator(seed);
unsigned int sd;
if (lgd_param_.seed == 0) sd = std::chrono::system_clock::now().time_since_epoch().count();
else sd = lgd_param_.seed;
std::default_random_engine generator(sd);
std::normal_distribution<double> dist_u(0, stddev_u);
std::normal_distribution<double> dist_v(0, lgd_param_.stddev_v);
std::uniform_real_distribution<double> dist_s(1.0, 2.0);

View File

@ -88,6 +88,12 @@ namespace gctl
*/
int batch;
/**
* Random seed for generating the Lévy distribution. Input zero for setting the seed according
* to the current time value. The default is 0.
*/
int seed;
/**
* Epsilon for the mean convergence test. This parameter determines the accuracy
* with which the mean solution is to be found. The default is 1e-5.
@ -176,11 +182,10 @@ namespace gctl
* @brief levy分布采样一组数据set_lgd_para函数设置
*
* @param dist levy分布
* @param seed
*
* @return
*/
lgd_return_code get_levy_distribution(array<double> &dist, unsigned int seed = 0);
lgd_return_code get_levy_distribution(array<double> &dist);
lgd_para default_lgd_para();
void set_lgd_para(const lgd_para &param);