-
Notifications
You must be signed in to change notification settings - Fork 17
Feature pruning #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature pruning #106
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10bdba4
This includes the code to invoke feature pruning as well as the imple…
156fd5f
Fixed documentation, did some cleanup.
b0993ec
Hopefully fix an issue with the mvn plugin.
e7a2aea
Sparse net optimizer had a bit when used with SparseAveragedPerceptro…
51ae957
Fixed up the docs a bit, and changes fixed an issue in the optimizer.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,12 +9,15 @@ | |
|
|
||
| import java.io.Serializable; | ||
| import java.net.URL; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import edu.illinois.cs.cogcomp.core.datastructures.vectors.*; | ||
| import edu.illinois.cs.cogcomp.lbjava.classify.DiscreteConjunctiveFeature; | ||
| import edu.illinois.cs.cogcomp.lbjava.classify.Feature; | ||
| import edu.illinois.cs.cogcomp.lbjava.classify.RealConjunctiveFeature; | ||
| import edu.illinois.cs.cogcomp.lbjava.util.ByteString; | ||
| import edu.illinois.cs.cogcomp.lbjava.util.ClassUtils; | ||
| import edu.illinois.cs.cogcomp.lbjava.util.FVector; | ||
|
|
@@ -305,7 +308,7 @@ public boolean contains(Feature f) { | |
| * | ||
| * @param f The feature to look up. | ||
| * @return The integer key that the feature maps to. | ||
| **/ | ||
| **/ | ||
| public int lookup(Feature f) { | ||
| return lookup(f, false, -1); | ||
| } | ||
|
|
@@ -661,6 +664,36 @@ public void discardPrunedFeatures() { | |
| pruneCutoff = -1; | ||
| } | ||
|
|
||
| /** | ||
| * Discard features at the provided indices. This operation is performed | ||
| * last to first so we can do it in place. This method will sort the input | ||
| * array. | ||
| * @param dumpthese the indexes of the features to dump. | ||
| */ | ||
| public void discardPrunedFeatures(int [] dumpthese) { | ||
| Arrays.sort(dumpthese); | ||
| lexiconInv.remove(dumpthese); | ||
|
|
||
| // this compresses the FVector | ||
| lexiconInv = new FVector(lexiconInv); | ||
| if (lexicon != null) { | ||
|
|
||
| // reconstitute the lexicon. | ||
| lexicon.clear(); | ||
| for (int i = 0; i < lexiconInv.size();i++) { | ||
| lexicon.put(lexiconInv.get(i), new Integer(i)); | ||
| } | ||
|
|
||
| // sanity check, make sure the indices in the lexicon map matches the index in the feature vector | ||
| for (int i = 0; i < lexiconInv.size();i++) { | ||
| if (i != ((Integer)lexicon.get(lexiconInv.get(i))).intValue()) { | ||
| throw new RuntimeException("After optimization pruning, the index in the lexicon did " | ||
| + "not match the inverted index."); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * <!-- clone() --> Returns a deep clone of this lexicon implemented as a <code>HashMap</code>. | ||
|
|
@@ -742,10 +775,9 @@ public int compare(int i1, int i2) { | |
| ByteString previousBSIdentifier = null; | ||
| out.writeInt(indexes.length); | ||
| out.writeInt(pruneCutoff); | ||
|
|
||
| for (int i = 0; i < indexes.length; ++i) { | ||
| Feature f = inverse.get(indexes[i]); | ||
| previousClassName = | ||
| previousClassName = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drop the extra space? |
||
| f.lexWrite(out, this, previousClassName, previousPackage, previousClassifier, | ||
| previousSIdentifier, previousBSIdentifier); | ||
| previousPackage = f.getPackage(); | ||
|
|
@@ -757,7 +789,6 @@ else if (f.hasByteStringIdentifier()) | |
|
|
||
| out.writeInt(indexes[i]); | ||
| } | ||
|
|
||
| if (featureCounts == null) | ||
| out.writeInt(0); | ||
| else | ||
|
|
@@ -801,14 +832,12 @@ public void read(ExceptionlessInputStream in, boolean readCounts) { | |
| pruneCutoff = in.readInt(); | ||
| lexicon = null; | ||
| lexiconInv = new FVector(N); | ||
|
|
||
| for (int i = 0; i < N; ++i) { | ||
| Feature f = | ||
| Feature.lexReadFeature(in, this, previousClass, previousPackage, | ||
| previousClassifier, previousSIdentifier, previousBSIdentifier); | ||
| int index = in.readInt(); | ||
| lexiconInv.set(index, f); | ||
|
|
||
| previousClass = f.getClass(); | ||
| previousPackage = f.getPackage(); | ||
| previousClassifier = f.getGeneratingClassifier(); | ||
|
|
@@ -817,7 +846,7 @@ public void read(ExceptionlessInputStream in, boolean readCounts) { | |
| else if (f.hasByteStringIdentifier()) | ||
| previousBSIdentifier = f.getByteStringIdentifier(); | ||
| } | ||
|
|
||
| if (readCounts) { | ||
| featureCounts = new IVector(); | ||
| featureCounts.read(in); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cowchipkid can you clarify the change here? Confused about what's happening here ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the Accuracy reporting outside the block to ensure doneTraining() gets called before accuracy reporting. doneTraining will apply the feature optimization, we want the score after that. If accuracy is reported before doneTraining, we will get the score of the un-optimized models, which would be for not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. Makes sense.