Skip to content

Commit

Permalink
Started to implement p_succ experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
Folláth János committed Dec 1, 2014
1 parent d38db1b commit e3833b5
Show file tree
Hide file tree
Showing 26 changed files with 1,404 additions and 101 deletions.
1 change: 1 addition & 0 deletions ASCPU.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AMD Opteron(tm) Processor 3380
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SUBDIRS(src test app)

set(CMAKE_CXX_FLAGS "-O9 -Wall")
#set(CMAKE_CXX_FLAGS "-g -O0 -Wall")

# add a target to generate API documentation with Doxygen
find_package(Doxygen)
Expand Down
30 changes: 29 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,36 @@
+ átállitani integer programozásra az optimalizálást
+ induláskor mérjen le 10-et és az alapján irja ki a várható befejezési időt és a végén meg a teljes futái időt (elég egyet is)
+ grafikonokat készíteni a célfüggvény értékéről illetve a változások arányáról a megtett lépések függvényében
- tudjon a progi megszakítás után elmentett állapotból folytatni
+ tudjon a progi megszakítás után elmentett állapotból folytatni
+ megnézni, hogy a BKZ_QP1 mennyivel gyorsabb mint a BKZ_XD és kipróbálni, hogy lehet-e csak az első körben XD-t használni a többiben meg QP-t (már egy LLL is szépen lecsökkenti a számokat) - viszont ha ez működik, akkor már biztos benne van az NTL-ben (BKZ-t futtattam és LLL hibaüzenetet kaptam), ha meg nem akkor nem akarok ezzel kockáztatni 3 hónapnyi számitást)
+ hogyan lehet helyesen és statisztikailag relevánsan mérni az időket? (magas dimenzióban nincs sok lehetőség a BKZ-t lemérni úgyhogy halottnak tűnik az ötlet)
+ a timingben darmstadt challange-s latticekkel teszteljen ne pedig cjloss-al (a generátor viszonylag egyszerű NTL-es cuccokat használ), mégsem, magas dimenzióban sokkal jobb ha a konkrét lattice-t kezdi el darálni
+ boundtoolba betenni a darmstadt challange-es alapértelmezett korlátot
+ implementálni a konkrét lattice-s timing-ot
+ boundary kimenetet pontosságát maximumra venni
+ lépésközt állithatóra venni
+ valamelyikbe ellenőrzést implementálni: számolja teljesen végig a pruned enumerationt és dobjon egy grafikonfilet az összehasonlitásról
+ végiggondolni hogyan kell helyesen randomizálni a bázist, kell-e javitani rajta
+ az aritmetikát mindenhol ahol kell átirni RR-re (pl gh számitás gyanús, hogy kelleni fog) (100-as challange-el tesztelni)
+ kis progi ami kigenerálja
+ full
+ linear
+ a schneider
+ boundtoolba új funkció: bemeneti fájlban kapott boundary-ról kiirja a várható időtartamot és a sikeresélyt
+ letesztelni, hogy LLL-XD followed by BKZ-FP blocksize 40 mennyivel gyorsabb mint a BKZ-XD simán... (kezdve valamilyen alacsonyabb blokkmérettel pl 30)
+ összevonni a timing-ot és a preprocesst
- egy 110 dimenziós boundary-t számolni és összevetni phong-éval (vagy a Schneider félével, mert ebben e dimenzióban mindkettő ugyanaz)
- átirni a psuccexpet randomra
- megnézni, hogy az psuccexp-ben jó lambdát adok-e meg neki vagy egyel nagyobbat

- a verify-ba olyan opciót, hogy csak a predictiont csinálja meg, ne kelljen várni az enumeration-re
- a végén kiirni az eredmény hermite faktorát (végiggondolni, hogy az utsó sorban valóban a hermite faktorok vannak-e
- állitható gh approx faktort irni a boundary keresőhöz
- a boundary generatort kiegésziteni a schnorr- hörnerrel


Majd egyszer:
- a verify programot integrálni az eprune-ba
******** Itt lesz kész az extreme pruning *****
- Megnézni az early termination-ös cikkeket, hogy milyen blokkméretet lenne érdemes használni egy 128 dimenziós bázis előfeldolgozásához
- Megirni a pruningos BKZ-t, enumerationt külön függvénybe tenni
Expand Down
8 changes: 8 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ SET(TARGET1 timing)
SET(TARGET2 boundtool)
SET(TARGET3 genlattice)
SET(TARGET4 eprune)
SET(TARGET5 verify)
SET(TARGET6 genbound)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})

Expand All @@ -16,3 +18,9 @@ TARGET_LINK_LIBRARIES(${TARGET3} cleanbkz ntl)

ADD_EXECUTABLE(${TARGET4} eprune.cpp)
TARGET_LINK_LIBRARIES(${TARGET4} cleanbkz ntl)

ADD_EXECUTABLE(${TARGET5} verify.cpp)
TARGET_LINK_LIBRARIES(${TARGET5} cleanbkz ntl)

ADD_EXECUTABLE(${TARGET6} genbound.cpp)
TARGET_LINK_LIBRARIES(${TARGET6} cleanbkz ntl)
144 changes: 96 additions & 48 deletions app/boundtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
using namespace std;

// Defined in boundary.cpp
extern double ball_vol(int k, double r);
extern RR ball_vol_RR(int k, RR r);
extern void init_factorials(int up_to);
extern RR RR_PI;

// Defined in tools.cpp
char* get_cmd_option(char** begin, char** end, const string& option);
Expand All @@ -40,11 +42,14 @@ bool cmd_option_exists(char** begin, char** end, const string& option);
int main(int argc, char** argv) {
double t_node= 0;
double t_reduc= 0;
double delta= 1e-1;
unsigned long iterations= 1000;
mat_ZZ basis;
int dim;
double* boundary;
ZZ v;
v= 0;
ZZ delta;
delta= 1;

stringstream ss;
char* act_arg;
Expand All @@ -56,28 +61,33 @@ int main(int argc, char** argv) {
<< "\t-n n\t\tThe (avarage) time the enumeration algorithm takes to process a single node. (required)" << endl
<< "\t-r n\t\tThe (avarege) running time of the preprocessing reduction algorithm. (required)" << endl
<< "\t-c n\t\tNumber of random changes to make during the numerical optimization. (default: 1000)" << endl
<< "\t-d n\t\tThe size of the single random changes to meke during the optimization. (default: 0.1)" << endl
<< "\t-l n\t\tOptimize for shortest vector with length square root of n. (the Gaussian heuristic is default)" << endl;
<< "\t-d n\t\tThe size of the single random changes to meke during the optimization. (default: 1)" << endl
<< "\t-l n\t\tOptimize for shortest vector with length square root of n. (the Gaussian heuristic is default)" << endl
<< "\t-o n\t\tThe name of the file containing the information about previous computation that has to be continued. Just the -c switch can be used in this case." << endl;
return 0;
}

if (!cmd_option_exists(argv, argv+argc, "-f")) {
cout << "Input basis is missing. Run again with -h for help." << endl;
if (!cmd_option_exists(argv, argv+argc, "-f") && !cmd_option_exists(argv, argv+argc, "-o")) {
cout << "Input basis information is missing. Run again with -h for help." << endl;
return 0;
}

if (!cmd_option_exists(argv, argv+argc, "-n")) {
if (!cmd_option_exists(argv, argv+argc, "-n") && !cmd_option_exists(argv, argv+argc, "-o")) {
cout << "Parameter t_node is missing. Run again with -h for help." << endl;
return 0;
}

if (!cmd_option_exists(argv, argv+argc, "-r")) {
if (!cmd_option_exists(argv, argv+argc, "-r") && !cmd_option_exists(argv, argv+argc, "-o")) {
cout << "Parameter t_reduc is missing. Run again with -h for help." << endl;
return 0;
}

act_arg= get_cmd_option(argv, argv + argc, "-n");
if (act_arg) {
if(cmd_option_exists(argv, argv+argc, "-o")){
cerr << "ERROR: invalid switch. In the presence of the -o switch the only other switch allowed is the -c" << endl;
return 1;
}
ss << act_arg;
ss >> t_node;
ss.clear();
Expand All @@ -89,6 +99,10 @@ int main(int argc, char** argv) {

act_arg= get_cmd_option(argv, argv + argc, "-r");
if (act_arg) {
if(cmd_option_exists(argv, argv+argc, "-o")){
cerr << "ERROR: invalid switch. In the presence of the -o switch the only other switch allowed is the -c" << endl;
return 1;
}
ss << act_arg;
ss >> t_reduc;
ss.clear();
Expand All @@ -100,10 +114,14 @@ int main(int argc, char** argv) {

act_arg= get_cmd_option(argv, argv + argc, "-d");
if (act_arg) {
if(cmd_option_exists(argv, argv+argc, "-o")){
cerr << "ERROR: invalid switch. In the presence of the -o switch the only other switch allowed is the -c" << endl;
return 1;
}
ss << act_arg;
ss >> delta;
ss.clear();
if(delta <= 0) {
if(delta < 1) {
cerr << "ERROR: invalid delta. The optimization step should be greater than zero. Aborting." << endl;
return 1;
}
Expand All @@ -122,6 +140,10 @@ int main(int argc, char** argv) {

act_arg= get_cmd_option(argv, argv + argc, "-l");
if (act_arg) {
if(cmd_option_exists(argv, argv+argc, "-o")){
cerr << "ERROR: invalid switch. In the presence of the -o switch the only other switch allowed is the -c" << endl;
return 1;
}
ss << act_arg;
ss >> v;
ss.clear();
Expand All @@ -131,9 +153,23 @@ int main(int argc, char** argv) {
}
}

act_arg= get_cmd_option(argv, argv + argc, "-o");
if (act_arg) {
ifstream infile(act_arg);
if (infile.is_open()) {
continue_boundary_gen(infile, iterations, &boundary, dim);
} else {
cerr << "ERROR: can't open input file: '" << act_arg << "'. Aborting." << endl;
return 1;
}
}

act_arg= get_cmd_option(argv, argv + argc, "-f");
if (act_arg) {
if(cmd_option_exists(argv, argv+argc, "-o")){
cerr << "ERROR: invalid switch. In the presence of the -o switch the only other switch allowed is the -c" << endl;
return 1;
}
ifstream basis_file(act_arg);
if (basis_file.is_open())
basis_file >> basis;
Expand All @@ -143,63 +179,75 @@ int main(int argc, char** argv) {
}
}

mat_RR mu1;
vec_RR c1;
ComputeGS(basis,mu1,c1);

//lengths of the GS basis vectors
RR* c= new RR[mu1.NumRows()];
for(int i= 0; i < mu1.NumRows(); i++) {
c[i]= SqrRoot(c1[i]);
c[i].SetPrecision(RR_PRECISION);
}

int dim= mu1.NumRows();
double* boundary= new double[dim];

cout << "# Generated with cleanbkz " << CBKZ_VERSION << endl
<< "# Copyright (C) 2014 Janos Follath" << endl
<< "# This is free software with ABSOLUTELY NO WARRANTY." << endl << "#" << endl;

//length of the shortest vector in the cjloss lattice
if(v>0) {
//v= sqrt(v);
cout << "# Using supplied lambda square: " << v << endl;
}
else {
double tmp,gh= 1;
double* gsghs= new double[dim];
if(!cmd_option_exists(argv, argv+argc, "-o")){
mat_RR mu1;
vec_RR c1;
ComputeGS(basis,mu1,c1);

//lengths of the GS basis vectors
RR* c= new RR[mu1.NumRows()];
for(int i= 0; i < mu1.NumRows(); i++) {
conv(tmp, c[i]);
gh*= tmp;
gsghs[i]= pow(gh/ball_vol(i+1, 1),1.0/(i+1));
c[i].SetPrecision(RR_PRECISION);
c[i]= SqrRoot(c1[i]);
}

dim= mu1.NumRows();
boundary= new double[dim];

//length of the shortest vector in the cjloss lattice
if(v>0) {
//v= sqrt(v);
cout << "# Using supplied lambda square: " << v << endl;
}
else {
RR_PI.SetPrecision(RR_PRECISION);
RR_PI= ComputePi_RR();
init_factorials(2*dim+1);
RR one,gh,exp;
one.SetPrecision(RR_PRECISION);
gh.SetPrecision(RR_PRECISION);
exp.SetPrecision(RR_PRECISION);
gh= one= 1;
for(int i= 0; i < mu1.NumRows(); i++) {
gh*= sqrt(c1[i]);
}
exp= 1.0/dim;
pow(gh, gh/ball_vol_RR(dim, one), exp);
gh*= 1.05;
conv(v, gh*gh);
cout << "# No lambda square supplied, using Gaussian heuristic: " << gh << endl;
}
delete gsghs;
gh= pow(gh/ball_vol(dim, 1),1.0/dim);
v= gh*gh;
cout << "# No lambda square supplied, using Gaussian heuristic: " << v << endl;
}


double p_succ;
double t_enum;
//NOTE: gs vector lengths and wanted vector length given

generate_boundary(c, t_node, t_reduc, dim, boundary, v, delta, iterations, p_succ, t_enum, false);

double p_succ;
double t_enum;
//NOTE: gs vector lengths and wanted vector length given
generate_boundary(c, t_node, t_reduc, dim, boundary, v, delta, iterations, p_succ, t_enum, false);
cout << "# basis: '" << act_arg << "' " << endl
<< "# estimated enumeration time: " << t_enum << endl
<< "# success probability: " << p_succ << endl;
}

cout << "# basis: '" << act_arg << "' " << endl
<< "# estimated enumeration time: " << t_enum << endl
<< "# success probability: " << p_succ << endl
<< "# boudary function: " << endl;
cout << "# boudary function: " << endl;


vec_RR out;
out.SetLength(dim);
for(int i= 0; i < dim; i++)
out[i]= boundary[i];
cout << "# " << out << endl << endl;

for(int i= 0; i < dim; i++)
cout << i << " " << boundary[i] << endl;
for(int i= 0; i < dim; i++) {
out[i].SetOutputPrecision(RR_PRECISION);
cout << i << " " << out[i] << endl;
}
cout << endl;

return 0;
Expand Down
15 changes: 9 additions & 6 deletions app/eprune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ extern void enumerate_epr(double** mu, double *b, double* Rvec, int n, vec_RR& r

extern void profile_enumerate_epr(double** mu, double *b, double* Rvec, int n, vec_RR& result);

// The maximum of the coefficients of the random unimodular matrix
#define UNIMOD_SIZE 100
mat_ZZ unimod(int dim){
mat_ZZ L, U;
L.SetDims(dim, dim);
Expand All @@ -43,8 +45,8 @@ mat_ZZ unimod(int dim){

for(int i= 0; i < dim; i++)
for(int j= i+1; j < dim; j++) {
U[i][j]= RandomBnd(2);
L[j][i]= RandomBnd(2);
U[i][j]= RandomBnd(UNIMOD_SIZE);
L[j][i]= RandomBnd(UNIMOD_SIZE);
}

return L*U;
Expand All @@ -60,7 +62,7 @@ int main(int argc, char** argv) {
if (argc==1 || cmd_option_exists(argv, argv+argc, "-h")) {
cout << "This program performs lattice enumeration with extreme pruning:" << endl
<< "\t-h \t\tPrint this help." << endl
<< "\t-v \t\tPerforms a single enumeration round and compares the nodes to the prediction." << endl
//<< "\t-v \t\tPerforms a single enumeration round and compares the nodes to the prediction." << endl
<< "\t-l filename\tReads the lattice from the file filename. (This option is mandatory)" << endl
<< "\t-b filename\tReads the boundary function from the file filename. (This option is mandatory)" << endl;
return 0;
Expand Down Expand Up @@ -119,7 +121,7 @@ int main(int argc, char** argv) {
double* boundary= new double[basis.NumRows()];
for(int i= 0; i < basis.NumRows(); i++){
conv(boundary[i], bnd[i]);
boundary[i]*= boundary[i];
//boundary[i]*= boundary[i];
}

vec_RR solution;
Expand Down Expand Up @@ -147,7 +149,8 @@ int main(int argc, char** argv) {

begin= clock();
basis= basis*unimod(basis.NumRows());
BKZ_QP1(basis, 0.99, beta);
LLL_XD(basis, 0.99);
BKZ_FP(basis, 0.99, beta);

ComputeGS(basis,mu1,c1);

Expand Down Expand Up @@ -192,7 +195,7 @@ int main(int argc, char** argv) {
for(int i= 0; i< basis.NumRows(); i++)
sqrdLength+= sol[i]*sol[i];

cout << "Squared length of the shortest vector: " << sqrdLength << endl << endl;
cout << "Length of the shortest vector: " << sqrt(sqrdLength) << endl << endl;

cout << "Time spent with enumeration: " << t_all/CLOCKS_PER_SEC << endl;
cout << "Time spent with reduction: " << t_reduc/CLOCKS_PER_SEC << endl;
Expand Down
Loading

0 comments on commit e3833b5

Please sign in to comment.