forked from lintool/Ivory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into clpwsim-lsh
- Loading branch information
Showing
15 changed files
with
496 additions
and
139 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ivory.ltr.operator; | ||
|
||
public class BooleanCount extends Operator { | ||
@Override public double getFinalScore() { | ||
int s = 0; | ||
for(double f: scores) { | ||
if(f > 0) { | ||
s++; | ||
} | ||
} | ||
return ((double) s); | ||
} | ||
|
||
@Override public Operator newInstance() { | ||
return new BooleanCount(); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ivory.ltr.operator; | ||
|
||
public class BooleanRatio extends Operator { | ||
@Override public double getFinalScore() { | ||
if(scores.size() == 0) { | ||
return 0; | ||
} | ||
|
||
int s = 0; | ||
for(double f: scores) { | ||
if(f > 0) { | ||
s++; | ||
} | ||
} | ||
return ((double) s) / scores.size(); | ||
} | ||
|
||
@Override public Operator newInstance() { | ||
return new BooleanRatio(); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ivory.ltr.operator; | ||
|
||
public class Max extends Operator { | ||
@Override public double getFinalScore() { | ||
double s = Double.NEGATIVE_INFINITY; | ||
for(double f: scores) { | ||
if(f > s) { | ||
s = f; | ||
} | ||
} | ||
return s; | ||
} | ||
|
||
@Override public Operator newInstance() { | ||
return new Max(); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ivory.ltr.operator; | ||
|
||
public class Mean extends Operator { | ||
@Override public double getFinalScore() { | ||
if(scores.size() == 0) { | ||
return 0; | ||
} | ||
|
||
double s = 0; | ||
for(double f: scores) { | ||
s += f; | ||
} | ||
|
||
return (s / scores.size()); | ||
} | ||
|
||
@Override public Operator newInstance() { | ||
return new Mean(); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ivory.ltr.operator; | ||
|
||
public class Min extends Operator { | ||
@Override public double getFinalScore() { | ||
double s = Double.POSITIVE_INFINITY; | ||
for(double f: scores) { | ||
if(f < s) { | ||
s = f; | ||
} | ||
} | ||
return s; | ||
} | ||
|
||
@Override public Operator newInstance() { | ||
return new Min(); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ivory.ltr.operator; | ||
|
||
import java.util.List; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
/** | ||
* Holds and computes the final value of a feature | ||
* | ||
* @author Nima Asadi | ||
*/ | ||
public abstract class Operator { | ||
protected List<Double> scores; | ||
|
||
protected Operator() { | ||
scores = Lists.newArrayList(); | ||
} | ||
|
||
/** | ||
* Adds a new score | ||
* | ||
* @param score Score | ||
*/ | ||
public void addScore(double score) { | ||
scores.add(score); | ||
} | ||
|
||
/** | ||
* Clears the scores | ||
*/ | ||
public void clear() { | ||
scores.clear(); | ||
} | ||
|
||
/** | ||
* Computes the final feature value | ||
* | ||
* @return Feature value | ||
*/ | ||
public abstract double getFinalScore(); | ||
|
||
/** | ||
* @return New instance | ||
*/ | ||
public abstract Operator newInstance(); | ||
} |
Oops, something went wrong.