Skip to content

Commit

Permalink
structureLearning runs on kinship dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
krivard committed Jun 15, 2015
1 parent 9091072 commit 5fa898c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 161 deletions.
22 changes: 11 additions & 11 deletions examples/structureLearning/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -54,15 +54,15 @@ 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

#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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -142,23 +142,23 @@ 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

# 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
python bin/avgprec.py < $*.fig-labeledTestAnswers > $*.fig-testMap
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
Expand Down
144 changes: 0 additions & 144 deletions examples/structureLearning/tmp-train.tmp-fig.solutions.txt

This file was deleted.

6 changes: 4 additions & 2 deletions src/edu/cmu/ml/praprolog/learn/L2PosNegLossTrainedSRW.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Map<String, Double> gradient(ParamVector paramVec, PosNegRWExample<T> 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);
}
}
Expand All @@ -79,8 +79,10 @@ public Map<String, Double> gradient(ParamVector paramVec, PosNegRWExample<T> exa
Map<String,Double> 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)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ public TObjectDoubleHashMap<String> gradient(ParamVector paramVec, PosNegRWExamp

//compute gradient
double pmax = 0;
if (log.isDebugEnabled()) log.debug("example "+example.toString());

for (int x : example.getPosList()) {
TObjectDoubleHashMap<String> 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);
}
}
Expand All @@ -84,8 +86,10 @@ public TObjectDoubleHashMap<String> gradient(ParamVector paramVec, PosNegRWExamp
TObjectDoubleHashMap<String> 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)));
}
Expand Down
13 changes: 11 additions & 2 deletions src/edu/cmu/ml/praprolog/util/ParamsFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
Expand Down

0 comments on commit 5fa898c

Please sign in to comment.