26#define PRUNER_MAX_N 2047
86 int prune_end = 1,
double prune_pre_nodes = 1e6,
double prune_min_prob = -1,
87 double gh_factor = 1.0);
120 int prune_start = 0,
int prune_end = 1,
double prune_pre_nodes = 1e6,
121 double prune_min_prob = -1,
double gh_factor = 1.0);
190 const double enumeration_radius,
const double preproc_cost,
const vector<double> &gso_r,
191 const double target = .9,
217 double enumeration_radius,
const double preproc_cost,
218 const vector<vector<double>> &gso_rs,
const double target = .9,
285 set_tabulated_consts();
287 min_pruning_coefficients.resize(d);
290 fill(min_pruning_coefficients.begin(), min_pruning_coefficients.end(), 0.);
307 Pruner(
const FT enumeration_radius,
const FT preproc_cost,
const vector<double> &gso_r,
310 : enumeration_radius(enumeration_radius), preproc_cost(preproc_cost), target(target),
311 metric(metric), flags(flags)
321 min_pruning_coefficients.resize(d);
324 fill(min_pruning_coefficients.begin(), min_pruning_coefficients.end(), 0.);
325 set_tabulated_consts();
333 throw std::invalid_argument(
334 "Error: flags PRUNER_HALF and PRUNER_SINGLE are mutually exclusive.");
343 if (this->target >= 1.0 || this->target <= 0.0)
345 throw std::invalid_argument(
"Invalid value for target with metric "
346 "PRUNER_METRIC_PROBABILITY_OF_SHORTEST (need 0 < target < 1).");
354 if (this->target <= 0.0)
356 throw std::invalid_argument(
"Invalid value for target with metric "
357 "PRUNER_METRIC_EXPECTED_SOLUTIONS (need 0 < target).");
362 throw std::invalid_argument(
"Pruner was set to an unknown metric");
365 load_basis_shape(gso_r);
385 Pruner(
const FT enumeration_radius,
const FT preproc_cost,
const vector<vector<double>> &gso_rs,
388 : enumeration_radius(enumeration_radius), preproc_cost(preproc_cost), target(target),
389 metric(metric), flags(flags)
392 n = gso_rs[0].size();
398 min_pruning_coefficients.resize(d);
401 fill(min_pruning_coefficients.begin(), min_pruning_coefficients.end(), 0.);
402 set_tabulated_consts();
410 throw std::invalid_argument(
411 "Error: flags PRUNER_HALF and PRUNER_SINGLE are mutually exclusive.");
420 if (this->target >= 1.0 || this->target <= 0.0)
422 throw std::invalid_argument(
"Invalid value for target with metric "
423 "PRUNER_METRIC_PROBABILITY_OF_SHORTEST (0 < target < 1).");
431 if (this->target <= 0.0)
433 throw std::invalid_argument(
434 "Invalid value for target with metric PRUNER_METRIC_EXPECTED_SOLUTIONS (0 < target).");
439 throw std::invalid_argument(
"Pruner was set to an unknown metric");
441 load_basis_shapes(gso_rs);
552 double single_enum_cost(
const vector<double> &pr, vector<double> *detailed_cost =
nullptr)
556 load_coefficients(b, pr);
571 load_coefficients(b, pr);
581 load_coefficients(b, pr);
593 FT enumeration_radius;
597 bool shape_loaded =
false;
603 vector<FT> min_pruning_coefficients;
604 bool opt_single =
false;
606 double descent_starting_clock;
607 static bool tabulated_values_imported;
611 FT epsilon = std::pow(2., -7);
612 FT min_step = std::pow(2., -6);
615 FT step_factor = std::pow(2, .5);
616 FT shell_ratio = .995;
617 FT symmetry_factor = .5;
620 using vec = vector<FT>;
621 using evec = vector<FT>;
622 using poly = vector<FT>;
627 FT normalization_factor;
628 FT normalized_radius;
638 void set_tabulated_consts();
644 void load_basis_shape(
const vector<double> &gso_r,
bool reset_normalization =
true);
653 void load_basis_shapes(
const vector<vector<double>> &gso_rs);
663 void load_coefficients( evec &b,
const vector<double> &pr);
668 void print_coefficients(
const vector<double> &pr);
673 void print_coefficients(
const evec &pr);
683 void save_coefficients( vector<double> &pr,
const evec &b);
695 inline bool enforce( vec &b,
const int j = 0);
704 inline FT eval_poly(
const int ld,
const poly &p,
const FT x);
712 inline void integrate_poly(
const int ld, poly &p);
722 inline FT relative_volume(
const int rd,
const evec &b);
737 FT
single_enum_cost(
const vec &b, vector<double> *detailed_cost =
nullptr);
738 FT single_enum_cost_evec(
const evec &b, vector<double> *detailed_cost =
nullptr);
739 FT single_enum_cost_lower(
const vec &b, vector<double> *detailed_cost =
nullptr);
740 FT single_enum_cost_upper(
const vec &b, vector<double> *detailed_cost =
nullptr);
755 FT svp_probability_evec(
const evec &b);
756 FT svp_probability_lower(
const vec &b);
757 FT svp_probability_upper(
const vec &b);
766 FT expected_solutions(
const vec &b);
767 FT expected_solutions_evec(
const evec &b);
768 FT expected_solutions_lower(
const vec &b);
769 FT expected_solutions_upper(
const vec &b);
815 FT target_function(
const evec &b);
823 void target_function_gradient(
const vec &b, vec &res);
847 void optimize_coefficients_preparation( vector<double> &pr);
869 void optimize_coefficients_evec_core( vector<double> &pr);
890 void optimize_coefficients_full_core( vector<double> &pr);
898 void greedy(evec &b);
904 int gradient_descent_step( vec &b);
911 int gradient_descent( vec &b);
918 int nelder_mead_step( evec &b);
930 void optimize_coefficients_local_adjust_decr_single( vector<double> &pr);
941 void optimize_coefficients_local_adjust_incr_prob( vector<double> &pr);
951 void optimize_coefficients_local_adjust_smooth( vector<double> &pr);
969 void optimize_coefficients_incr_prob( vector<double> &pr);
983 void optimize_coefficients_decr_prob( vector<double> &pr);
1001 void optimize_coefficients_local_adjust_prob( vector<double> &pr);
1015 int c = (dn == d) ? 1 : 2;
1016 bool status =
false;
1019 if ((b[dn - 1] < .999) & (j != dn - 1))
1025 for (
int i = 0; i < dn; ++i)
1027 status |= (b[i] > 1.0001);
1028 b[i] = b[i] > 1 ? 1. : b[i];
1031 if (i / c < d && b[i] <= min_pruning_coefficients[i / c])
1032 b[i] = min_pruning_coefficients[i / c];
1035 for (
int i = j; i < dn - 1; ++i)
1037 if (b[i + 1] < b[i])
1039 status |= (b[i + 1] + .000001 < b[i]);
1044 for (
int i = std::min(j - 1, dn - 2); i >= 0; --i)
1046 if (b[i + 1] < b[i])
1048 status |= (b[i + 1] + .000001 < b[i]);
Definition: test_pruner.cpp:50
Pruner class, to compute and optimize cost and success probability of pruned enumeration.
Definition: pruner.h:273
FT gaussian_heuristic()
gaussian heuristic for the shortest vector length of the loaded basis.
Definition: pruner_util.cpp:93
void optimize_coefficients_cost_vary_prob(vector< double > &pr)
Main interface for optimizing the pruning coefficients with respect to the overall enumeration time.
Definition: pruner_optimize.cpp:8
void optimize_coefficients_cost_fixed_prob(vector< double > &pr)
Main interface to optimize the pruning coefficients with respect to the single enumeration.
Definition: pruner_optimize.cpp:102
Pruner(const FT enumeration_radius, const FT preproc_cost, const vector< double > &gso_r, const FT target=0.9, const PrunerMetric metric=PRUNER_METRIC_PROBABILITY_OF_SHORTEST, int flags=PRUNER_GRADIENT)
Constructor for Pruner.
Definition: pruner.h:307
Pruner(const FT enumeration_radius, const FT preproc_cost, const vector< vector< double > > &gso_rs, const FT target=0.9, const PrunerMetric metric=PRUNER_METRIC_PROBABILITY_OF_SHORTEST, int flags=PRUNER_GRADIENT)
Constructor for Pruner with multiple basis (averaging the cost function over all of them)
Definition: pruner.h:385
double repeated_enum_cost(const vector< double > &pr)
cost of repeating enumeration and preprocessing
Definition: pruner.h:568
void optimize_coefficients_evec(vector< double > &pr)
Run the optimization process using 'even' coefficients.
Definition: pruner_optimize_tc.cpp:65
void optimize_coefficients_full(vector< double > &pr)
Run the optimization process using all the coefficients.
Definition: pruner_optimize_tc.cpp:122
double measure_metric(const vector< double > &pr)
Return either SVP probability or expected number of solution depending on metric.
Definition: pruner.h:578
void optimize_coefficients(vector< double > &pr)
Main interface for optimizing pruning coefficients.
Definition: pruner_optimize.cpp:150
Pruner(const int n)
(limited) Constructor for Pruner. Only for svp_probability.
Definition: pruner.h:282
double single_enum_cost(const vector< double > &pr, vector< double > *detailed_cost=nullptr)
Compute the cost of a single enumeration.
Definition: pruner.h:552
PrunerMetric metric
Definition: pruner.h:41
static PruningParams LinearPruningParams(int block_size, int level)
Definition: bkz_param.cpp:11
PruningParams()
Definition: pruner.h:47
std::vector< double > detailed_cost
Definition: pruner.h:42
std::vector< double > coefficients
Definition: pruner.h:36
double gh_factor
Definition: pruner.h:35
double expectation
Definition: pruner.h:37
#define FPLLL_END_NAMESPACE
Definition: defs.h:117
FloatType
Definition: defs.h:210
@ FT_DEFAULT
Definition: defs.h:211
PrunerMetric
Definition: defs.h:292
@ PRUNER_METRIC_PROBABILITY_OF_SHORTEST
Definition: defs.h:293
@ PRUNER_METRIC_EXPECTED_SOLUTIONS
Definition: defs.h:294
#define FPLLL_BEGIN_NAMESPACE
Definition: defs.h:114
@ PRUNER_SINGLE
Definition: defs.h:312
@ PRUNER_VERBOSE
Definition: defs.h:306
@ PRUNER_GRADIENT
Definition: defs.h:303
@ PRUNER_CVP
Definition: defs.h:299
@ PRUNER_HALF
Definition: defs.h:309
fplll_float float_type
Definition: enumeration.h:61
void prune(PruningParams &pruning, const double enumeration_radius, const double preproc_cost, const vector< double > &gso_r, const double target=.9, const PrunerMetric metric=PRUNER_METRIC_PROBABILITY_OF_SHORTEST, const int flags=PRUNER_GRADIENT)
Search for optimal pruning parameters.
Definition: pruner.cpp:204
FT svp_probability(const PruningParams &pruning)
Probability that a pruned enumeration indeed returns the shortest vector.
Definition: pruner.cpp:178
#define PRUNER_MAX_N
Definition: pruner.h:26
int run_pruner_f(ZZ_mat< mpz_t > &B, int sel_ft, int precision=0, int prune_start=0, int prune_end=1, double prune_pre_nodes=1e6, double prune_min_prob=-1, double gh_factor=1.0)
Run pruner on B.
int run_pruner(ZZ_mat< mpz_t > &B, FloatType float_type=FT_DEFAULT, int precision=0, int prune_start=0, int prune_end=1, double prune_pre_nodes=1e6, double prune_min_prob=-1, double gh_factor=1.0)
Run pruner on B.
Definition: pruner.cpp:116