diff --git a/examples/structureLearning/Makefile b/examples/structureLearning/Makefile index ff4f6fa2..0441dfdd 100644 --- a/examples/structureLearning/Makefile +++ b/examples/structureLearning/Makefile @@ -1,6 +1,6 @@ include ../Makefile.in -DIR=v12 +DIR=$(shell pwd) JM=java -cp .:$(PROPPR)/bin/:$(PROPPR)/lib/*:$(PROPPR)/conf/ edu.cmu.ml.praprolog PSTEM=h22 P=$(PSTEM).crules @@ -54,7 +54,7 @@ clean-expt: %.grounded %.params: %-train.trainData %-train.cfacts echo now creating .grounded and .params for $* - $(JM).Experiment --programFiles $P:x.cfacts:$*-train.cfacts --prover $(PR) --epochs $(EPOCHS) --strict \ + $(JM).Experiment --programFiles $P:x.cfacts:$*.cfacts --prover $(PR) --epochs $(EPOCHS) --strict \ --train $*-train.trainData --test $*-train.trainData --srw $(SRW1) \ --output $*.grounded --params $*.params --threads 3 perl bin/view-params.pl $*.params @@ -62,7 +62,7 @@ clean-expt: #test the learned second-order theory parameters - step 1, the raw answers; step 2, the map %.testAnswers: %.params %-test.testData - $(JM).QueryAnswerer --programFiles $P:x.cfacts:$*-test.cfacts --threads 3 --prover $(PR) --queries $*-test.testData --params $*.params --output $*.testAnswers --unnormalized + $(JM).QueryAnswerer --programFiles $P:x.cfacts:$*.cfacts --threads 3 --prover $(PR) --queries $*-test.testData --params $*.params --output $*.testAnswers --unnormalized --force %.testMap: %-test.testData %.testAnswers python bin/orderAnswers.py $*.testAnswers $*-test.testData | sort -gr > $*.labeledTestAnswers @@ -73,7 +73,7 @@ clean-expt: # baseline for full-data only %.baseline-testAnswers: programFiles.arg %-test.testData %-test.cfacts - java edu.cmu.ml.praprolog.QueryAnswerer --programFiles baseline.crules:x.cfacts:$*-test.cfacts --threads 3 --prover dpr:0.0001 \ + java edu.cmu.ml.praprolog.QueryAnswerer --programFiles baseline.crules:x.cfacts:$*.cfacts --threads 3 --prover dpr:0.0001 \ --queries $*-test.testData --output $*.baseline-testAnswers --unnormalized %.baseline-testMap: %-test.testData %.baseline-testAnswers @@ -102,7 +102,7 @@ clean-expt: #again step 1, the raw answers; step 2, the map %.ugr-testAnswers: %-test.testData %.crules - $(JM).QueryAnswerer --programFiles $*.crules:$*-test.cfacts --threads 3 --prover $(PR) --queries $*-test.testData --output $*.ugr-testAnswers --unnormalized + $(JM).QueryAnswerer --programFiles $*.crules:$*.cfacts --threads 3 --prover $(PR) --queries $*-test.testData --output $*.ugr-testAnswers --unnormalized %.ugr-testMap: %.ugr-testAnswers %-test.testData python bin/orderAnswers.py $*.ugr-testAnswers $*-test.testData | sort -gr > $*.ugr-labeledTestAnswers @@ -112,7 +112,7 @@ clean-expt: #step 4 - retrain the gradient theory %.gr-grounded %.gr-params: %-train.trainData %.crules %-train.cfacts - $(JM).Experiment --programFiles uml.cfacts:$*.crules --prover $(PR) --epochs $(EPOCHS) \ + $(JM).Experiment --programFiles $*.crules:$*.cfacts --prover $(PR) --epochs $(EPOCHS) \ --train $*-train.trainData --srw $(SRW2) --test $*-train.trainData \ --output $*.gr-grounded --params $*.gr-params --threads 3 cat $*.gr-params @@ -121,8 +121,8 @@ clean-expt: #again step 1, the raw answers; step 2, the map %.gr-testAnswers: %.gr-params %-test.testData %.crules - $(JM).QueryAnswerer --programFiles $*.crules:uml.cfacts --threads 3 --prover $(PR) --queries $*-test.testData --output $*.gr-testAnswers \ - --params $*.gr-params --unnormalized + $(JM).QueryAnswerer --programFiles $*.crules:$*.cfacts --threads 3 --prover $(PR) --queries $*-test.testData --output $*.gr-testAnswers \ + --params $*.gr-params --unnormalized --force %.gr-testMap: %.gr-testAnswers %-test.testData python bin/orderAnswers.py $*.gr-testAnswers $*-test.testData | sort -gr > $*.gr-labeledTestAnswers @@ -142,7 +142,7 @@ clean-expt: %.fig-params %-fig.crules: %-train.trainData %.fig-crules %-train.cfacts cp $*.fig-crules $*-fig.crules - $(JM).Experiment --programFiles $*-fig.crules:uml.cfacts --prover $(PR) --epochs $(EPOCHS) \ + $(JM).Experiment --programFiles $*-fig.crules:$*.cfacts --prover $(PR) --epochs $(EPOCHS) \ --train $*-train.trainData --srw $(SRW2) --test $*-train.trainData \ --output $*.gr-grounded --params $*.fig-params --threads $(TH) cat $*.fig-params @@ -150,7 +150,7 @@ clean-expt: # testing the fig rules %.fig-testAnswers: %.fig-params %-test.testData %-fig.crules - $(JM).QueryAnswerer --programFiles $*-fig.crules:uml.cfacts --strict off --threads $(TH) --prover $(PR) --tester mt:$(TH) --queries $*-test.testData --params $*.fig-params --output $*.fig-testAnswers --unnormalized --weightingScheme tanh + $(JM).QueryAnswerer --programFiles $*-fig.crules:$*.cfacts --strict off --threads $(TH) --prover $(PR) --tester mt:$(TH) --queries $*-test.testData --params $*.fig-params --output $*.fig-testAnswers --unnormalized --weightingScheme tanh --force %.fig-testMap: %-test.testData %.fig-testAnswers python bin/orderAnswers.py $*.fig-testAnswers $*-test.testData | sort -gr > $*.fig-labeledTestAnswers @@ -158,7 +158,7 @@ clean-expt: tail $*.fig-testMap %.ufig-testAnswers: %-test.testData %-fig.crules - $(JM).QueryAnswerer --programFiles $*-fig.crules:x.cfacts:$*-test.cfacts --threads 3 --prover $(PR) --queries $*-test.testData --output $*.ufig-testAnswers --unnormalized + $(JM).QueryAnswerer --programFiles $*-fig.crules:x.cfacts:$*.cfacts --threads 3 --prover $(PR) --queries $*-test.testData --output $*.ufig-testAnswers --unnormalized %.ufig-testMap: %-test.testData %.ufig-testAnswers python bin/orderAnswers.py $*.ufig-testAnswers $*-test.testData | sort -gr > $*.ufig-labeledTestAnswers diff --git a/examples/structureLearning/tmp-train.tmp-fig.solutions.txt b/examples/structureLearning/tmp-train.tmp-fig.solutions.txt deleted file mode 100644 index 0e654dc5..00000000 --- a/examples/structureLearning/tmp-train.tmp-fig.solutions.txt +++ /dev/null @@ -1,144 +0,0 @@ -# proved 1 interp(i_uncle,christine,-1) 449541 msec -# proved 2 interp(i_son,charlotte,-1) 364399 msec -# proved 3 interp(i_niece,charles,-1) 399759 msec -# proved 4 interp(i_nephew,margaret,-1) 407523 msec -# proved 5 interp(i_father,jennifer,-1) 410213 msec -# proved 6 interp(i_husband,penelope,-1) 407399 msec -# proved 7 interp(i_mother,charles,-1) 415572 msec -# proved 8 interp(i_husband,christopher,-1) 412162 msec -# proved 9 interp(i_mother,christine,-1) 415038 msec -# proved 10 interp(i_husband,charlotte,-1) 409266 msec -# proved 11 interp(i_brother,christine,-1) 411386 msec -# proved 12 interp(i_uncle,margaret,-1) 426753 msec -# proved 13 interp(i_niece,charlotte,-1) 401070 msec -# proved 14 interp(i_aunt,colin,-1) 387816 msec -# proved 15 interp(i_niece,penelope,-1) 400533 msec -# proved 16 interp(i_wife,victoria,-1) 404286 msec -# proved 17 interp(i_nephew,charlotte,-1) 408000 msec -# proved 18 interp(i_daughter,christine,-1) 404100 msec -# proved 19 interp(i_son,colin,-1) 363829 msec -# proved 20 interp(i_brother,margaret,-1) 408739 msec -# proved 21 interp(i_wife,penelope,-1) 400723 msec -# proved 22 interp(i_son,james,-1) 366191 msec -# proved 23 interp(i_sister,andrew,-1) 416048 msec -# proved 24 interp(i_husband,colin,-1) 407167 msec -# proved 25 interp(i_sister,colin,-1) 414904 msec -# proved 26 interp(i_uncle,arthur,-1) 427541 msec -# proved 27 interp(i_niece,jennifer,-1) 400948 msec -# proved 28 interp(i_father,victoria,-1) 410463 msec -# proved 29 interp(i_uncle,andrew,-1) 430119 msec -# proved 30 interp(i_daughter,victoria,-1) 405622 msec -# proved 31 interp(i_brother,charles,-1) 414262 msec -# proved 32 interp(i_father,christine,-1) 411314 msec -# proved 33 interp(i_niece,andrew,-1) 401746 msec -# proved 34 interp(i_nephew,jennifer,-1) 410224 msec -# proved 35 interp(i_aunt,christine,-1) 386630 msec -# proved 36 interp(i_husband,andrew,-1) 405867 msec -# proved 37 interp(i_nephew,james,-1) 407611 msec -# proved 38 interp(i_aunt,arthur,-1) 384514 msec -# proved 39 interp(i_mother,margaret,-1) 411497 msec -# proved 40 interp(i_son,jennifer,-1) 366042 msec -# proved 41 interp(i_son,victoria,-1) 367031 msec -# proved 42 interp(i_sister,margaret,-1) 417227 msec -# proved 43 interp(i_mother,charlotte,-1) 411703 msec -# proved 44 interp(i_brother,charlotte,-1) 411998 msec -# proved 45 interp(i_daughter,margaret,-1) 403187 msec -# proved 46 interp(i_aunt,jennifer,-1) 386978 msec -# proved 47 interp(i_aunt,margaret,-1) 387269 msec -# proved 48 interp(i_father,james,-1) 409538 msec -# proved 49 interp(i_sister,charlotte,-1) 416084 msec -# proved 50 interp(i_nephew,christine,-1) 408891 msec -# proved 51 interp(i_wife,christopher,-1) 404637 msec -# proved 52 interp(i_father,margaret,-1) 408327 msec -# proved 53 interp(i_niece,margaret,-1) 398822 msec -# proved 54 interp(i_sister,james,-1) 414749 msec -# proved 55 interp(i_nephew,arthur,-1) 407148 msec -# proved 56 interp(i_son,andrew,-1) 364741 msec -# proved 57 interp(i_mother,penelope,-1) 413527 msec -# proved 58 interp(i_brother,penelope,-1) 410602 msec -# proved 59 interp(i_wife,jennifer,-1) 403347 msec -# proved 60 interp(i_uncle,colin,-1) 428342 msec -# proved 61 interp(i_brother,victoria,-1) 411850 msec -# proved 62 interp(i_father,andrew,-1) 410505 msec -# proved 63 interp(i_husband,arthur,-1) 408355 msec -# proved 64 interp(i_aunt,andrew,-1) 386365 msec -# proved 65 interp(i_daughter,charles,-1) 403110 msec -# proved 66 interp(i_father,colin,-1) 405395 msec -# proved 67 interp(i_mother,victoria,-1) 410230 msec -# proved 68 interp(i_uncle,james,-1) 427774 msec -# proved 69 interp(i_uncle,charlotte,-1) 429447 msec -# proved 70 interp(i_son,penelope,-1) 367880 msec -# proved 71 interp(i_husband,jennifer,-1) 408956 msec -# proved 72 interp(i_sister,christopher,-1) 417096 msec -# proved 73 interp(i_husband,james,-1) 407258 msec -# proved 74 interp(i_daughter,colin,-1) 406354 msec -# proved 75 interp(i_wife,christine,-1) 404361 msec -# proved 76 interp(i_son,charles,-1) 366275 msec -# proved 77 interp(i_husband,victoria,-1) 408713 msec -# proved 78 interp(i_daughter,jennifer,-1) 404922 msec -# proved 79 interp(i_son,christine,-1) 367752 msec -# proved 80 interp(i_aunt,penelope,-1) 386538 msec -# proved 81 interp(i_father,arthur,-1) 410297 msec -# proved 82 interp(i_sister,jennifer,-1) 415851 msec -# proved 83 interp(i_brother,james,-1) 412934 msec -# proved 84 interp(i_uncle,christopher,-1) 430061 msec -# proved 85 interp(i_sister,penelope,-1) 415651 msec -# proved 86 interp(i_husband,margaret,-1) 408045 msec -# proved 87 interp(i_nephew,victoria,-1) 410240 msec -# proved 88 interp(i_niece,james,-1) 400350 msec -# proved 89 interp(i_daughter,penelope,-1) 405487 msec -# proved 90 interp(i_niece,christopher,-1) 402855 msec -# proved 91 interp(i_niece,christine,-1) 399901 msec -# proved 92 interp(i_wife,andrew,-1) 405506 msec -# proved 93 interp(i_niece,colin,-1) 401565 msec -# proved 94 interp(i_daughter,charlotte,-1) 403597 msec -# proved 95 interp(i_nephew,penelope,-1) 407476 msec -# proved 96 interp(i_brother,jennifer,-1) 413534 msec -# proved 97 interp(i_husband,christine,-1) 405406 msec -# proved 98 interp(i_brother,christopher,-1) 412110 msec -# proved 99 interp(i_daughter,andrew,-1) 403640 msec -# proved 100 interp(i_uncle,penelope,-1) 428944 msec -# proved 101 interp(i_aunt,christopher,-1) 386173 msec -# proved 102 interp(i_mother,colin,-1) 411327 msec -# proved 103 interp(i_wife,charles,-1) 402286 msec -# proved 104 interp(i_wife,margaret,-1) 403692 msec -# proved 105 interp(i_daughter,arthur,-1) 405172 msec -# proved 106 interp(i_mother,arthur,-1) 413890 msec -# proved 107 interp(i_nephew,andrew,-1) 410274 msec -# proved 108 interp(i_aunt,victoria,-1) 386124 msec -# proved 109 interp(i_sister,victoria,-1) 416042 msec -# proved 110 interp(i_sister,christine,-1) 420066 msec -# proved 111 interp(i_uncle,charles,-1) 431404 msec -# proved 112 interp(i_uncle,jennifer,-1) 430267 msec -# proved 113 interp(i_brother,arthur,-1) 410439 msec -# proved 114 interp(i_niece,arthur,-1) 400908 msec -# proved 115 interp(i_mother,andrew,-1) 415824 msec -# proved 116 interp(i_son,margaret,-1) 367828 msec -# proved 117 interp(i_nephew,colin,-1) 408278 msec -# proved 118 interp(i_brother,andrew,-1) 412471 msec -# proved 119 interp(i_son,christopher,-1) 366579 msec -# proved 120 interp(i_daughter,james,-1) 404023 msec -# proved 121 interp(i_wife,colin,-1) 405543 msec -# proved 122 interp(i_sister,arthur,-1) 416736 msec -# proved 123 interp(i_mother,jennifer,-1) 414855 msec -# proved 124 interp(i_wife,james,-1) 402369 msec -# proved 125 interp(i_father,penelope,-1) 408376 msec -# proved 126 interp(i_aunt,charlotte,-1) 386848 msec -# proved 127 interp(i_wife,arthur,-1) 403102 msec -# proved 128 interp(i_mother,christopher,-1) 414565 msec -# proved 129 interp(i_uncle,victoria,-1) 429607 msec -# proved 130 interp(i_son,arthur,-1) 365777 msec -# proved 131 interp(i_nephew,christopher,-1) 407165 msec -# proved 132 interp(i_father,charlotte,-1) 407069 msec -# proved 133 interp(i_husband,charles,-1) 405914 msec -# proved 134 interp(i_daughter,christopher,-1) 402358 msec -# proved 135 interp(i_aunt,james,-1) 384105 msec -# proved 136 interp(i_wife,charlotte,-1) 402346 msec -# proved 137 interp(i_nephew,charles,-1) 406932 msec -# proved 138 interp(i_father,christopher,-1) 407288 msec -# proved 139 interp(i_mother,james,-1) 412048 msec -# proved 140 interp(i_aunt,charles,-1) 384162 msec -# proved 141 interp(i_father,charles,-1) 407523 msec -# proved 142 interp(i_niece,victoria,-1) 398732 msec -# proved 143 interp(i_brother,colin,-1) 410352 msec -# proved 144 interp(i_sister,charles,-1) 414700 msec diff --git a/src/edu/cmu/ml/praprolog/learn/L2PosNegLossTrainedSRW.java b/src/edu/cmu/ml/praprolog/learn/L2PosNegLossTrainedSRW.java index 28df5669..788dbdc1 100644 --- a/src/edu/cmu/ml/praprolog/learn/L2PosNegLossTrainedSRW.java +++ b/src/edu/cmu/ml/praprolog/learn/L2PosNegLossTrainedSRW.java @@ -63,7 +63,7 @@ public Map gradient(ParamVector paramVec, PosNegRWExample exa if(px > pmax) pmax = px; for (String f : trainableFeatures) { if (Dictionary.safeContains(d,x,f)) { - if (log.isDebugEnabled()) log.debug(String.format(" - delta %s is - %f * %f", f,dx.get(f),1.0/px)); + if (log.isDebugEnabled()) log.debug(String.format(" + delta %s is - %f / %f", f,dx.get(f),px)); Dictionary.increment(derivFparamVec, f, -dx.get(f)/px); } } @@ -79,8 +79,10 @@ public Map gradient(ParamVector paramVec, PosNegRWExample exa Map dx = Dictionary.safeGet(d, x, Collections.EMPTY_MAP);//d.get(x); double px = Dictionary.safeGet(p,x,c.weightingScheme.defaultWeight());//p.get(x); for (String f : trainableFeatures) { - if (Dictionary.safeContains(d,x,f)) + if (Dictionary.safeContains(d,x,f)) { + if (log.isDebugEnabled()) log.debug(String.format(" - delta %s is %f * %f / (1-%f)", f,beta,dx.get(f),px)); Dictionary.increment(derivFparamVec, f, beta*dx.get(f)/clip(1-px)); + } } this.cumloss.add(LOSS.LOG, -Math.log(clip(1.0-px))); } diff --git a/src/edu/cmu/ml/praprolog/trove/learn/L2PosNegLossTrainedSRW.java b/src/edu/cmu/ml/praprolog/trove/learn/L2PosNegLossTrainedSRW.java index 163bb21b..3869a6e8 100644 --- a/src/edu/cmu/ml/praprolog/trove/learn/L2PosNegLossTrainedSRW.java +++ b/src/edu/cmu/ml/praprolog/trove/learn/L2PosNegLossTrainedSRW.java @@ -62,13 +62,15 @@ public TObjectDoubleHashMap gradient(ParamVector paramVec, PosNegRWExamp //compute gradient double pmax = 0; + if (log.isDebugEnabled()) log.debug("example "+example.toString()); for (int x : example.getPosList()) { TObjectDoubleHashMap dx = d.get(x); double px = p.get(x); if(px > pmax) pmax = px; for (String f : trainableFeatures) { - if (Dictionary.safeContains(d,x,f) && dx.get(f) != 0.0) { + if (Dictionary.safeContains(d,x,f) && dx.get(f) != 0.0) { + if (log.isDebugEnabled()) log.debug(String.format(" + delta %s is - %f / %f", f,dx.get(f),px)); Dictionary.increment(derivFparamVec, f, -dx.get(f)/px); } } @@ -84,8 +86,10 @@ public TObjectDoubleHashMap gradient(ParamVector paramVec, PosNegRWExamp TObjectDoubleHashMap dx = d.get(x); double px = p.get(x); for (String f : trainableFeatures) { - if (Dictionary.safeContains(d,x,f) && dx.get(f) != 0.0) + if (Dictionary.safeContains(d,x,f) && dx.get(f) != 0.0) { + if (log.isDebugEnabled()) log.debug(String.format(" - delta %s is %f * %f / (1-%f)", f,beta,dx.get(f),px)); Dictionary.increment(derivFparamVec, f, beta*dx.get(f)/(1-px)); + } } this.cumloss.add(LOSS.LOG, -Math.log(checkProb(1.0-px))); } diff --git a/src/edu/cmu/ml/praprolog/util/ParamsFile.java b/src/edu/cmu/ml/praprolog/util/ParamsFile.java index 400370d6..5c32ea5d 100644 --- a/src/edu/cmu/ml/praprolog/util/ParamsFile.java +++ b/src/edu/cmu/ml/praprolog/util/ParamsFile.java @@ -129,10 +129,19 @@ public void check(Configuration c) { if (this.getProperty("programFiles") != null) { if (c.programFiles == null) { failCheck("programFiles",this.getProperty("programFiles"),"null",c.force); + return; } else { int i=0; - for (String p : this.getProperty("programFiles").split(":")) { - if (!p.equals(c.programFiles[i])) failCheck("programFiles:"+i,p,c.programFiles[i], c.force); + String[] params = this.getProperty("programFiles").split(":"); + if (params.length != c.programFiles.length) { + failCheck("programFiles:length",String.valueOf(params.length),String.valueOf(c.programFiles.length),c.force); + return; + } + for (String p : params) { + if (!p.equals(c.programFiles[i])) { + failCheck("programFiles:"+i,p,c.programFiles[i], c.force); + return; + } i++; } }