Skip to content

Commit

Permalink
Information written to options file to see progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
BartJongejan committed Feb 23, 2015
1 parent 60d6863 commit e140338
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 82 deletions.
1 change: 0 additions & 1 deletion src/affixtrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2724,7 +2724,6 @@ static bool doTraining
{
bool moreToDo = false;
Nnodes = 0;

VertexPointerCount = 0;

aFile afile(fname, options);
Expand Down
41 changes: 27 additions & 14 deletions src/comp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4981,7 +4981,29 @@ void betterfound(int Nnodes,double weight,int swath,int iterations,int blobs,int
}
best = parms;
parms.better(options);
options->setSwath(swath);
options->setSwathIteration(iterations);
options->setNumberOfNodes(Nnodes);
options->setTrainingPairsLines(lines);
options->setWeight(weight);

options->printArgFile();
printf("%d.%d %d \tparms ",swath,iterations,Nnodes);
int i = 0;
for(;i < NPARMS;++i)
{
printf("%7.6f",parms.Matrix[i]);
if(((i+1) % parms.ROWPARMS) == 0)
{
if(i == NPARMS - 1)
printf("\n");
else
printf(";\n");
}
else
printf(";");
}

FILE * f = fopen(options->bestParms(),"a");
if(f)
{
Expand All @@ -5005,20 +5027,13 @@ void betterfound(int Nnodes,double weight,int swath,int iterations,int blobs,int
,DBL_DIG+2,fraction
,fraclines
);
// fprintf(f," { \t \t \t // # decisions\n ");
fprintf(f," {{\n ");
int i = 0;
for(;i < NPARMS;++i)
{
fprintf(f,"%.*e", DBL_DIG+2,parms.Matrix[i]);
if(((i+1) % parms.ROWPARMS) == 0)
{
/*
if(i == NPARMS - 1)
fprintf(f," //%d\n ",pcnt[i >> 2]);
else
fprintf(f,", //%d\n ",pcnt[i >> 2]);
*/
if(i == NPARMS - 1)
fprintf(f,"\n ");
else
Expand All @@ -5027,7 +5042,6 @@ void betterfound(int Nnodes,double weight,int swath,int iterations,int blobs,int
else
fprintf(f,",\t");
}
// fprintf(f,"} \t \t \t //(%d unresolved comparisons)\n\n",pcnt[NPARMS >> 2]);
fprintf(f,"}}\n\n");
fclose(f);
}
Expand Down Expand Up @@ -5150,15 +5164,16 @@ void testAngle()
getchar();
}

bool brown()
void brown()
{
static int it = 0;
if(it++ < 2)
{
normalise(parms.Matrix);
return false;
return;
}
double tangens = 0.1*pow(0.995,it);
double tangens = 1.0*pow(0.995,it);
//printf("tangens %f\n",tangens);
double vector[6];
double radius2 = 0.0;
do
Expand Down Expand Up @@ -5186,8 +5201,7 @@ bool brown()
times(vector,tangens);
plus(parms.Matrix,vector,parms.ROWPARMS);
normalise(parms.Matrix);
printvector("parms3",parms.Matrix,parms.ROWPARMS);
return false;
//printvector("parms3",parms.Matrix,parms.ROWPARMS);
}

bool init(optionStruct * options)
Expand Down Expand Up @@ -5635,7 +5649,6 @@ void setCompetitionFunction(optionStruct * options)
if(!strcmp(options->compfunc(),funcstructs[i].number) || !strcmp(options->compfunc(),funcstructs[i].name))
{
comp = funcstructs[i].comp;
bool compute_parms = false;
if(comp == comp_parms0_off)
{
for(unsigned int j = 0;j < sizeof(bests)/sizeof(bests[0]);++j)
Expand Down
2 changes: 1 addition & 1 deletion src/comp.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class optionStruct;
void setCompetitionFunction(optionStruct * options);
void copybest();
bool init(optionStruct * options);
bool brown();
void brown();
void printparms(int Nnodes,double weight,optionStruct * options);
void betterfound(int Nnodes,double weight,int swath,int iterations,int blobs,int lines,double fraction,int fraclines,bool improvement,optionStruct * options);
void worsefound();
Expand Down
2 changes: 1 addition & 1 deletion src/flexcombi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ class treenode
tp += 1;
if (Child.more)
tp += 2;
return tp;
return (typetype)tp;
}
treenode(char * rl, char * end, treenode * Sib, chain * ASib, treenode * Chld, chain * AChld)
:Rule(rl,end),Sibling(Sib,ASib),Child(Chld,AChld){}
Expand Down
137 changes: 73 additions & 64 deletions src/optionaff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "applyaffrules.h"
#include "optionaff.h"
#include "argopt.h"
#include <float.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -746,7 +747,6 @@ OptReturnTp optionStruct::readArgs(int argc, char * argv[])
FILE * f = fopen(wordList(), "r");
Blobs = 0; // If there are no non-empty lines, there are no blobs either.
Lines = 0;
int bl = 1;
int kar = 0;
int prevkar = 0;
unsigned int lineProfile = 0;
Expand Down Expand Up @@ -796,82 +796,91 @@ OptReturnTp optionStruct::readArgs(int argc, char * argv[])

void optionStruct::print(FILE * fp) const
{
fprintf(fp,"; verbose\n-v %s\n", Verbose ? "" : "-");
fprintf(fp," ; verbose\n-v %s\n", Verbose ? "" : "-");
if (b)
{
fprintf(fp, "; raw rules\n-b %s\n", b); if (b) fprintf(fp, "-b %s\n", b); else fprintf(fp, ";-b not specified\n");
fprintf(fp, "; (N/A) raw rules\n;-b not specified\n");
fprintf(fp, "; (N/A) word list\n-i %s\n", i ? i : "?");
fprintf(fp, "; (N/A) extra name suffix\n"); if (e) fprintf(fp, "-e %s\n", e); else fprintf(fp, ";-e not specified\n");
fprintf(fp, "; (N/A) suffix only (%s)\n-s %s\n", SuffixOnly ? "yes" : "no", SuffixOnly ? "" : "-");
fprintf(fp, "; (N/A) columns (1=word,2=lemma,3=tags,0=other)\n-n %s\n", n ? n : "?");
fprintf(fp, "; (N/A) max recursion depth when attempting to create candidate rule\n-Q %d\n", Q);
fprintf(fp, "; (N/A) flex rules\n-o %s\n", o ? o : "?");
fprintf(fp, "; (N/A) temp dir\n"); if (j) fprintf(fp, "-j %s\n", j); else fprintf(fp, ";-j not specified\n");
fprintf(fp, "; (N/A) percentage of training pairs to set aside for testing\n-q %d\n", q);
fprintf(fp, "; (N/A) penalties to decide which rule survives\n"); if (nD > 0){ fprintf(fp, "-D "); for (int i = 0; i < nD; ++i)fprintf(fp, "%f;", D[i]); fprintf(fp, "\n"); } else fprintf(fp, ";-D not specified\n");
fprintf(fp, "; (N/A) compute parms (%s)\n-p %s\n", ComputeParms ? "yes" : "no", ComputeParms ? "" : "-");
fprintf(fp, "; (N/A) expected cutoff\n-C %d\n", C);
fprintf(fp, "; (N/A) do weights (%s)\n-W %s\n", Doweights ? "yes" : "no", Doweights ? "" : "-");
fprintf(fp, "; (N/A) current parameters\n-P %s\n", P ? P : "?");
fprintf(fp, "; (N/A) best parameters\n-B %s\n", B ? B : "?");
fprintf(fp, "; (N/A) start training with minimal fraction of training pairs\n-L %f\n", Minfraction);
fprintf(fp, "; (N/A) end training with maximal fraction of training pairs\n-H %f\n", Maxfraction);
fprintf(fp, "; (N/A) number of differently sized fractions of trainingdata\n-K %d\n",K);
fprintf(fp, "; (N/A) number of iterations of training with same fraction of training data when fraction is minimal\n-N %f\n", N);
fprintf(fp, "; (N/A) number of iterations of training with same fraction of training data when fraction is maximal\n-M %f\n", M);
fprintf(fp, "; (N/A) competition function\n-f %s\n", f ? f : "?");
fprintf(fp, "; (N/A) redo training after homographs for next round are removed (%s)\n-R %s\n", Redo ? "yew" : "no", Redo ? "" : "-");
fprintf(fp, "; (N/A) cutoff\n-c %d\n", c);
fprintf(fp, " ; raw rules\n-b %s\n", b); if (b) fprintf(fp, "-b %s\n", b); else fprintf(fp, ";-b not specified\n");
fprintf(fp, " ; (N/A) raw rules\n;-b not specified\n");
fprintf(fp, " ; (N/A) word list\n-i %s\n", i ? i : "?");
fprintf(fp, " ; (N/A) extra name suffix\n"); if (e) fprintf(fp, "-e %s\n", e); else fprintf(fp, ";-e not specified\n");
fprintf(fp, " ; (N/A) suffix only (%s)\n-s %s\n", SuffixOnly ? "yes" : "no", SuffixOnly ? "" : "-");
fprintf(fp, " ; (N/A) columns (1=word,2=lemma,3=tags,0=other)\n-n %s\n", n ? n : "?");
fprintf(fp, " ; (N/A) max recursion depth when attempting to create candidate rule\n-Q %d\n", Q);
fprintf(fp, " ; (N/A) flex rules\n-o %s\n", o ? o : "?");
fprintf(fp, " ; (N/A) temp dir\n"); if (j) fprintf(fp, "-j %s\n", j); else fprintf(fp, ";-j not specified\n");
fprintf(fp, " ; (N/A) percentage of training pairs to set aside for testing\n-q %d\n", q);
fprintf(fp, " ; (N/A) penalties to decide which rule survives\n"); if (nD > 0){ fprintf(fp, "-D "); for (int i = 0; i < nD; ++i)fprintf(fp, "%f;", D[i]); fprintf(fp, "\n"); } else fprintf(fp, ";-D not specified\n");
fprintf(fp, " ; (N/A) compute parms (%s)\n-p %s\n", ComputeParms ? "yes" : "no", ComputeParms ? "" : "-");
fprintf(fp, " ; (N/A) expected cutoff\n-C %d\n", C);
fprintf(fp, " ; (N/A) do weights (%s)\n-W %s\n", Doweights ? "yes" : "no", Doweights ? "" : "-");
fprintf(fp, " ; (N/A) current parameters\n-P %s\n", P ? P : "?");
fprintf(fp, " ; (N/A) best parameters\n-B %s\n", B ? B : "?");
fprintf(fp, " ; (N/A) start training with minimal fraction of training pairs\n-L %f\n", Minfraction);
fprintf(fp, " ; (N/A) end training with maximal fraction of training pairs\n-H %f\n", Maxfraction);
fprintf(fp, " ; (N/A) number of differently sized fractions of trainingdata\n-K %d\n",K);
fprintf(fp, " ; (N/A) number of iterations of training with same fraction of training data when fraction is minimal\n-N %f\n", N);
fprintf(fp, " ; (N/A) number of iterations of training with same fraction of training data when fraction is maximal\n-M %f\n", M);
fprintf(fp, " ; (N/A) competition function\n-f %s\n", f ? f : "?");
fprintf(fp, " ; (N/A) redo training after homographs for next round are removed (%s)\n-R %s\n", Redo ? "yew" : "no", Redo ? "" : "-");
fprintf(fp, " ; (N/A) cutoff\n-c %d\n", c);
}
else
{
fprintf(fp, "; raw rules\n;-b not specified\n");
fprintf(fp, "; word list\n-i %s\n", i);
fprintf(fp, "; extra name suffix\n"); if (e) fprintf(fp, "-e %s\n", e); else fprintf(fp, ";-e not specified\n");
fprintf(fp, "; suffix only (%s)\n-s %s\n", SuffixOnly ? "yes" : "no", SuffixOnly ? "" : "-");
fprintf(fp, "; columns (1=word,2=lemma,3=tags,0=other)\n-n %s\n", n);
fprintf(fp, "; max recursion depth when attempting to create candidate rule\n-Q %d\n", Q);
fprintf(fp, "; flex rules\n-o %s\n", o);
fprintf(fp, "; temp dir\n"); if (j) fprintf(fp, "-j %s\n", j); else fprintf(fp, ";-j not specified\n");
fprintf(fp, "; percentage of training pairs to set aside for testing\n-q %d\n", q);
fprintf(fp, "; penalties to decide which rule survives\n"); if (nD > 0){ fprintf(fp, "-D "); for (int i = 0; i < nD; ++i)fprintf(fp, "%f;", D[i]); fprintf(fp, "\n"); } else fprintf(fp, ";-D not specified\n");
fprintf(fp, "; compute parms (%s)\n-p %s\n", ComputeParms ? "yes" : "no", ComputeParms ? "" : "-");
fprintf(fp, " ; raw rules\n;-b not specified\n");
fprintf(fp, " ; word list\n-i %s\n", i);
fprintf(fp, " ; extra name suffix\n"); if (e) fprintf(fp, "-e %s\n", e); else fprintf(fp, ";-e not specified\n");
fprintf(fp, " ; suffix only (%s)\n-s %s\n", SuffixOnly ? "yes" : "no", SuffixOnly ? "" : "-");
fprintf(fp, " ; columns (1=word,2=lemma,3=tags,0=other)\n-n %s\n", n);
fprintf(fp, " ; max recursion depth when attempting to create candidate rule\n-Q %d\n", Q);
fprintf(fp, " ; flex rules\n-o %s\n", o);
fprintf(fp, " ; temp dir\n"); if (j) fprintf(fp, "-j %s\n", j); else fprintf(fp, ";-j not specified\n");
fprintf(fp, " ; percentage of training pairs to set aside for testing\n-q %d\n", q);
fprintf(fp, " ; penalties to decide which rule survives\n"); if (nD > 0){ fprintf(fp, "-D "); for (int i = 0; i < nD; ++i)fprintf(fp, "%f;", D[i]); fprintf(fp, "\n"); } else fprintf(fp, ";-D not specified\n");
fprintf(fp, " ; compute parms (%s)\n-p %s\n", ComputeParms ? "yes" : "no", ComputeParms ? "" : "-");
if (ComputeParms)
{
assert(P);
assert(B);
fprintf(fp, "; expected cutoff\n-C %d\n", C);
fprintf(fp, "; do weights (%s)\n-W %s\n", Doweights ? "yes" : "no", Doweights ? "" : "-");
fprintf(fp, "; current parameters\n-P %s\n", P);
fprintf(fp, "; best parameters\n-B %s\n", B);
fprintf(fp, "; start training with minimal fraction of training pairs\n-L %f\n", Minfraction);
fprintf(fp, "; end training with maximal fraction of training pairs\n-H %f\n", Maxfraction);
fprintf(fp, "; number of differently sized fractions of trainingdata\n-K %d\n",K);
fprintf(fp, "; number of iterations of training with same fraction of training data when fraction is minimal\n-N %f\n", N);
fprintf(fp, "; number of iterations of training with same fraction of training data when fraction is maximal\n-M %f\n", M);
fprintf(fp, "; (N/A) competition function\n-f %s\n", f ? f : "?");
fprintf(fp, "; (N/A) redo training after homographs for next round are removed (%s)\n-R %s\n", Redo ? "yew" : "no", Redo ? "" : "-");
fprintf(fp, "; (N/A) cutoff\n-c %d\n", c);
fprintf(fp, " ; expected cutoff\n-C %d\n", C);
fprintf(fp, " ; do weights (%s)\n-W %s\n", Doweights ? "yes" : "no", Doweights ? "" : "-");
fprintf(fp, " ; current parameters\n-P %s\n", P);
fprintf(fp, " ; best parameters\n-B %s\n", B);
fprintf(fp, " ; start training with minimal fraction of training pairs\n-L %f\n", Minfraction);
fprintf(fp, " ; end training with maximal fraction of training pairs\n-H %f\n", Maxfraction);
fprintf(fp, " ; number of differently sized fractions of trainingdata\n-K %d\n",K);
fprintf(fp, " ; number of iterations of training with same fraction of training data when fraction is minimal\n-N %f\n", N);
fprintf(fp, " ; number of iterations of training with same fraction of training data when fraction is maximal\n-M %f\n", M);
fprintf(fp, " ; (N/A) competition function\n-f %s\n", f ? f : "?");
fprintf(fp, " ; (N/A) redo training after homographs for next round are removed (%s)\n-R %s\n", Redo ? "yew" : "no", Redo ? "" : "-");
fprintf(fp, " ; (N/A) cutoff\n-c %d\n", c);
}
else
{
assert(f);
fprintf(fp, "; (N/A) expected cutoff\n-C %d\n", C);
fprintf(fp, "; (N/A) do weights (%s)\n-W %s\n", Doweights ? "yes" : "no", Doweights ? "" : "-");
fprintf(fp, "; (N/A) current parameters\n-P %s\n", P ? P : "?");
fprintf(fp, "; (N/A) best parameters\n-B %s\n", B ? B : "?");
fprintf(fp, "; (N/A) start training with minimal fraction of training pairs\n-L %f\n", Minfraction);
fprintf(fp, "; (N/A) end training with maximal fraction of training pairs\n-H %f\n", Maxfraction);
fprintf(fp, "; (N/A) number of differently sized fractions of trainingdata\n-K %d\n",K);
fprintf(fp, "; (N/A) number of iterations of training with same fraction of training data when fraction is minimal\n-N %f\n", N);
fprintf(fp, "; (N/A) number of iterations of training with same fraction of training data when fraction is maximal\n-M %f\n", M);
fprintf(fp, "; competition function\n-f %s\n", f);
fprintf(fp, "; redo training after homographs for next round are removed (%s)\n-R %s\n", Redo ? "yew" : "no", Redo ? "" : "-");
fprintf(fp, "; cutoff\n-c %d\n", c);
fprintf(fp, " ; (N/A) expected cutoff\n-C %d\n", C);
fprintf(fp, " ; (N/A) do weights (%s)\n-W %s\n", Doweights ? "yes" : "no", Doweights ? "" : "-");
fprintf(fp, " ; (N/A) current parameters\n-P %s\n", P ? P : "?");
fprintf(fp, " ; (N/A) best parameters\n-B %s\n", B ? B : "?");
fprintf(fp, " ; (N/A) start training with minimal fraction of training pairs\n-L %f\n", Minfraction);
fprintf(fp, " ; (N/A) end training with maximal fraction of training pairs\n-H %f\n", Maxfraction);
fprintf(fp, " ; (N/A) number of differently sized fractions of trainingdata\n-K %d\n",K);
fprintf(fp, " ; (N/A) number of iterations of training with same fraction of training data when fraction is minimal\n-N %f\n", N);
fprintf(fp, " ; (N/A) number of iterations of training with same fraction of training data when fraction is maximal\n-M %f\n", M);
fprintf(fp, " ; competition function\n-f %s\n", f);
fprintf(fp, " ; redo training after homographs for next round are removed (%s)\n-R %s\n", Redo ? "yew" : "no", Redo ? "" : "-");
fprintf(fp, " ; cutoff\n-c %d\n", c);
}
fprintf(fp, "; Number of blobs found in word list: %d whereof used for training %d\n", Blobs, FracBlobs == 0 ? Blobs : FracBlobs);
fprintf(fp, "; Number of lines found in word list: %d whereof used for training %d\n", Lines, FracLines == 0 ? Lines : FracLines);
fprintf(fp, " ; Number of blobs found in word list: %d whereof used for training %d\n", Blobs, FracBlobs == 0 ? Blobs : FracBlobs);
fprintf(fp, " ; Number of lines found in word list: %d whereof used for training %d\n", Lines, FracLines == 0 ? Lines : FracLines);
fprintf(fp, " ; Current training size step: %d\n", Swath);
fprintf(fp, " ; Current iteration in current training size step: %d\n", SwathIteration);
fprintf(fp, " ; Current number of nodes: %d\n", NumberOfNodes);
fprintf(fp, " ; Current number of lines: %d\n", TrainingPairsLines);
fprintf(fp, " ; Nodes/line: %.*e\n", DBL_DIG+2,(double)NumberOfNodes/(double)TrainingPairsLines);
if(Doweights)
fprintf(fp, " ; Current weight: %.*e\n", DBL_DIG+2,Weight);
else
fprintf(fp, " ; Current weight: N/A\n");
}
}

Expand All @@ -894,7 +903,7 @@ void optionStruct::printArgFile() const
{
strcat(name, "C");
int L = strlen(name);
name[L] = C + '0';
name[L] = (char)(C + '0');
name[L + 1] = 0;
}
if (Doweights)
Expand Down
Loading

0 comments on commit e140338

Please sign in to comment.