| Chunk |
|---|
| Conflicting content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures; <<<<<<< HEAD ======= import javax.annotation.CheckReturnValue; import javax.annotation.concurrent.Immutable; import uk.ac.susx.mlcl.byblo.weighings.FeatureMarginalsCarrier; import uk.ac.susx.mlcl.byblo.weighings.MarginalDistribution; >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 import uk.ac.susx.mlcl.byblo.weighings.Weighting; import uk.ac.susx.mlcl.lib.Checks; import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures; import javax.annotation.CheckReturnValue; import javax.annotation.concurrent.Immutable; import uk.ac.susx.mlcl.byblo.weighings.FeatureMarginalsCarrier; import uk.ac.susx.mlcl.byblo.weighings.MarginalDistribution; import uk.ac.susx.mlcl.byblo.weighings.Weighting; import uk.ac.susx.mlcl.lib.Checks; import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; |
| File |
|---|
| AutoWeightingMeasure.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
* The weighting scheme to use is determined by calling
* {@link Measure#getExpectedWeighting() }.
*
<<<<<<< HEAD
*
=======
*
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
@Immutable |
| Solution content |
|---|
* The weighting scheme to use is determined by calling
* {@link Measure#getExpectedWeighting() }.
*
*
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
@Immutable |
| File |
|---|
| AutoWeightingMeasure.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
this.weighting = weighting;
}
<<<<<<< HEAD
public AutoWeightingMeasure(Measure delegate, Weighting weighting) {
super(delegate);
Checks.checkNotNull("weighting", weighting);
this.weighting = weighting;
}
=======
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
return getDelegate().similarity(weighting.apply(A), weighting.apply(B));
}
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
public Weighting getWeighting() {
return weighting; |
| Solution content |
|---|
public AutoWeightingMeasure(Measure delegate, Weighting weighting) {
super(delegate);
Checks.checkNotNull("weighting", weighting);
this.weighting = weighting;
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
return getDelegate().similarity(weighting.apply(A), weighting.apply(B));
}
public Weighting getWeighting() {
return weighting; |
| File |
|---|
| AutoWeightingMeasure.java |
| Developer's decision |
|---|
| Concatenation |
| Kind of conflict |
|---|
| Annotation |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
/** * |
| Solution content |
|---|
/** * |
| File |
|---|
| ForwardingMeasure.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
@CheckReturnValue public abstract class ForwardingMeasure |
| Solution content |
|---|
@CheckReturnValue public abstract class ForwardingMeasure |
| File |
|---|
| ForwardingMeasure.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Comment |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
return NullWeighting.class;
}
<<<<<<< HEAD
@Override
public boolean isCommutative() {
return delegate.isCommutative();
}
public boolean equals(ForwardingMeasure> other) {
if (this.delegate != other.delegate
&& (this.delegate == null
|| !this.delegate.equals(other.delegate)))
return false;
return true;
}
=======
@Override
public boolean isCommutative() {
return deligate.isCommutative();
}
public boolean equals(ForwardingMeasure> other) {
if (this.deligate != other.deligate
&& (this.deligate == null || !this.deligate
.equals(other.deligate)))
return false;
return true;
}
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
@Override
public boolean equals(Object obj) { |
| Solution content |
|---|
@Override
public boolean isCommutative() {
return delegate.isCommutative();
}
public boolean equals(ForwardingMeasure> other) {
if (this.delegate != other.delegate
&& (this.delegate == null
|| !this.delegate.equals(other.delegate)))
return false;
return true;
}
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
return equals((ForwardingMeasure) obj);
}
@Override
public int hashCode() {
return 79 * 5 + (delegate != null ? delegate.hashCode() : 0);
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "{delegate=" + delegate + '}';
}
} |
| File |
|---|
| ForwardingMeasure.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Annotation |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
return equals((ForwardingMeasure) obj);
}
<<<<<<< HEAD
@Override
public int hashCode() {
return 79 * 5 + (delegate != null ? delegate.hashCode() : 0);
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "{delegate=" + delegate + '}';
}
=======
@Override
public int hashCode() {
return 79 * 5 + (deligate != null ? deligate.hashCode() : 0);
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "{deligate=" + deligate + '}';
}
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
} |
| Solution content |
|---|
@Override
public int hashCode() {
return 79 * 5 + (delegate != null ? delegate.hashCode() : 0);
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "{delegate=" + delegate + '}';
}
} |
| File |
|---|
| ForwardingMeasure.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Annotation |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
/**
* Measure is a common super-interface to various similarity measure types.
*
<<<<<<< HEAD
*
=======
*
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public interface Measure { |
| Solution content |
|---|
/**
* Measure is a common super-interface to various similarity measure types.
*
*
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public interface Measure { |
| File |
|---|
| Measure.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
/**
@CheckReturnValue
*/
public interface Measure {
<<<<<<< HEAD
/**
* Compute the similarity score between the vector operands.
*
*
* @param A first feature vector
* @param B second feature vector
* @return similarity of the feature vectors
*/
@CheckReturnValue
double similarity(SparseDoubleVector A, SparseDoubleVector B);
/**
* Gets the to similarity score that will be produced by this measure when
* two vectors are identical. In the case of proximity scores this value
* should usually be 0. For distance metrics it is usually +infinity,
*
*
* @return value indicating vectors are identical
*/
@CheckReturnValue
double getHomogeneityBound();
/**
* Gets the similarity score that will be produced by this measure when two
* vectors could not be more dissimilar. In the case of proximity scores
* this value should usually be 1 or +infinity. For distance metrics it is
* usually 0,
*
*
* @return value indicating vectors are maximally dissimilar
*/
double getHeterogeneityBound();
/**
* Gets the {@link Weighting} scheme that should have been previously
* applied to feature vectors before this {@link Measure} implementation is
* used.
*
* Some measures can operate on pretty much any kind of vector (for example
* geometric distance measures). Others require the vectors to take a
* particular form. Set theoretic measures {@link Dice} and {@link Jaccard}
* require feature weights to be positive, though not binary as one might
* expect since multi-set generalizations are implemented. Lin and Weeds
* measure expect PMI weighting.
*
*
* @return weighting scheme that should have been previously applied to
* vectors
*/
@CheckReturnValue
Class extends Weighting> getExpectedWeighting();
/**
* Whether or not the operands can be reversed without changing the
* resultant similarity score.
*
* Traditionally, similarity measures define a symmetric space but this does
* not have to be the case. Symmetric space must be defined by a commutative
* similarity measure (where sim(x,y) = sim(y,x)). However, non-symmetric
* spaces are possible. In these cases the measure should be marked as
* non-commutative.
*
* In the case of distance measures, a commutative kernel will define a
* true metric, while a non-commutative kernel will not. For
* example {@link KLDivergence} is a distance measure while the
* {@link LpSpace} variants are true metrics.
*
*
* @return true if the measure defines a symmetric space, false otherwise
*/
@CheckReturnValue
boolean isCommutative();
=======
/**
* Compute the similarity score between the vector operands.
*
*
* @param A
* first feature vector
* @param B
* second feature vector
* @return similarity of the feature vectors
*/
@CheckReturnValue
double similarity(SparseDoubleVector A, SparseDoubleVector B);
/**
* Gets the to similarity score that will be produced by this measure when
* two vectors are identical. In the case of proximity scores this value
* should usually be 0. For distance metrics it is usually +infinity,
*
*
* @return value indicating vectors are identical
*/
@CheckReturnValue
double getHomogeneityBound();
/**
* Gets the similarity score that will be produced by this measure when two
* vectors could not be more dissimilar. In the case of proximity scores
* this value should usually be 1 or +infinity. For distance metrics it is
* usually 0,
*
*
* @return value indicating vectors are maximally dissimilar
*/
@CheckReturnValue
double getHeterogeneityBound();
/**
* Gets the {@link Weighting} scheme that should have been previously
* applied to feature vectors before this {@link Measure} implementation is
* used.
*
* Some measures can operate on pretty much any kind of vector (for example
* geometric distance measures). Others require the vectors to take a
* particular form. Set theoretic measures {@link Dice} and {@link Jaccard}
* require feature weights to be positive, though not binary as one might
* expect since multi-set generalizations are implemented. Lin and Weeds
* measure expect PMI weighting.
*
*
* @return weighting scheme that should have been previously applied to
* vectors
*/
@CheckReturnValue
Class extends Weighting> getExpectedWeighting();
* Whether or not the operands can be reversed without changing the
* resultant similarity score.
*
* Traditionally, similarity measures define a symmetric space but this does
* not have to be the case. Symmetric space must be defined by a commutative
* similarity measure (where sim(x,y) = sim(y,x)). However, non-symmetric
* spaces are possible. In these cases the measure should be marked as
* non-commutative.
*
* In the case of distance measures, a commutative kernel will define a
* true metric, while a non-commutative kernel will not. For
* example {@link KLDivergence} is a distance measure while the
* {@link LpSpace} variants are true metrics.
*
*
* @return true if the measure defines a symmetric space, false otherwise
*/
@CheckReturnValue
boolean isCommutative();
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
} |
| Solution content |
|---|
*/
public interface Measure {
/**
* Compute the similarity score between the vector operands.
*
*
* @param A first feature vector
* @param B second feature vector
* @return similarity of the feature vectors
*/
@CheckReturnValue
double similarity(SparseDoubleVector A, SparseDoubleVector B);
/**
* Gets the to similarity score that will be produced by this measure when
* two vectors are identical. In the case of proximity scores this value
* should usually be 0. For distance metrics it is usually +infinity,
*
*
* @return value indicating vectors are identical
*/
@CheckReturnValue
double getHomogeneityBound();
/**
* Gets the similarity score that will be produced by this measure when two
* vectors could not be more dissimilar. In the case of proximity scores
* this value should usually be 1 or +infinity. For distance metrics it is
* usually 0,
*
*
* @return value indicating vectors are maximally dissimilar
*/
@CheckReturnValue
double getHeterogeneityBound();
/**
* Gets the {@link Weighting} scheme that should have been previously
* applied to feature vectors before this {@link Measure} implementation is
* used.
*
* Some measures can operate on pretty much any kind of vector (for example
* geometric distance measures). Others require the vectors to take a
* particular form. Set theoretic measures {@link Dice} and {@link Jaccard}
* require feature weights to be positive, though not binary as one might
* expect since multi-set generalizations are implemented. Lin and Weeds
* measure expect PMI weighting.
*
*
* @return weighting scheme that should have been previously applied to
* vectors
*/
@CheckReturnValue
Class extends Weighting> getExpectedWeighting();
/**
* Whether or not the operands can be reversed without changing the
* resultant similarity score.
*
* Traditionally, similarity measures define a symmetric space but this does
* not have to be the case. Symmetric space must be defined by a commutative
* similarity measure (where sim(x,y) = sim(y,x)). However, non-symmetric
* spaces are possible. In these cases the measure should be marked as
* non-commutative.
*
* In the case of distance measures, a commutative kernel will define a
* true metric, while a non-commutative kernel will not. For
* example {@link KLDivergence} is a distance measure while the
* {@link LpSpace} variants are true metrics.
*
*
* @return true if the measure defines a symmetric space, false otherwise
*/
@CheckReturnValue
boolean isCommutative();
} |
| File |
|---|
| Measure.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Method interface |
| Chunk |
|---|
| Conflicting content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; <<<<<<< HEAD ======= import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 import uk.ac.susx.mlcl.byblo.measures.Measure; import uk.ac.susx.mlcl.byblo.weighings.FeatureMarginalsCarrier; import uk.ac.susx.mlcl.byblo.weighings.MarginalDistribution; |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import uk.ac.susx.mlcl.byblo.measures.Measure; import uk.ac.susx.mlcl.byblo.weighings.FeatureMarginalsCarrier; import uk.ac.susx.mlcl.byblo.weighings.MarginalDistribution; |
| File |
|---|
| Confusion.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
* not necessarily the most similar entry to itself.
*
*
<<<<<<< HEAD
*
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
* @see JE Weeds (2003) "Measures and Applications of Lexical Distributional
* Similarity", which references (Sugawara, Nishimura, Toshioka, Okachi, &
* Kaneko, 1985; Essen & Steinbiss, 1992; Grishman & Sterling, 1993; Dagan et
* al., 1999; Lapata et al., 2001)
* @see Essen, Ute and Volker Steinbiss. 1992. Co-occurrence smoothing for
* stochastic language modeling. In Proceedings of ICASSP, volume 1, pages
* 161{164.
* @see Sugawara, K., M. Nishimura, K. Toshioka, M. Okochi, and T. Kaneko. 1985.
* Isolated word recognition using hidden Markov models. In Proceedings of
* ICASSP, pages 1--4, Tampa, Florida. IEEE.
=======
*
*
* @see JE Weeds (2003) "Measures and Applications of Lexical Distributional
* Similarity", which references (Sugawara, Nishimura, Toshioka, Okachi, &
* Kaneko, 1985; Essen & Steinbiss, 1992; Grishman & Sterling, 1993; Dagan
* et al., 1999; Lapata et al., 2001)
*
* @see Essen, Ute and Volker Steinbiss. 1992. Co-occurrence smoothing for
* stochastic language modeling. In Proceedings of ICASSP, volume 1, pages
* 161{164.
*
* @see Sugawara, K., M. Nishimura, K. Toshioka, M. Okochi, and T. Kaneko. 1985.
* Isolated word recognition using hidden Markov models. In Proceedings of
* ICASSP, pages 1--4, Tampa, Florida. IEEE.
*
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
* @see Grishman, Ralph and John Sterling. 1993. Smoothing of automatically
* generated selectional constraints. In Human Language Technology, pages
* 254{259, San Francisco, California. Advanced Research Projects Agency, |
| Solution content |
|---|
* not necessarily the most similar entry to itself.
*
*
*
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
* @see JE Weeds (2003) "Measures and Applications of Lexical Distributional
* Similarity", which references (Sugawara, Nishimura, Toshioka, Okachi, &
* Kaneko, 1985; Essen & Steinbiss, 1992; Grishman & Sterling, 1993; Dagan et
* al., 1999; Lapata et al., 2001)
* @see Essen, Ute and Volker Steinbiss. 1992. Co-occurrence smoothing for
* stochastic language modeling. In Proceedings of ICASSP, volume 1, pages
* 161{164.
* @see Sugawara, K., M. Nishimura, K. Toshioka, M. Okochi, and T. Kaneko. 1985.
* Isolated word recognition using hidden Markov models. In Proceedings of
* ICASSP, pages 1--4, Tampa, Florida. IEEE.
* @see Grishman, Ralph and John Sterling. 1993. Smoothing of automatically
* generated selectional constraints. In Human Language Technology, pages
* 254{259, San Francisco, California. Advanced Research Projects Agency, |
| File |
|---|
| Confusion.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
* generated selectional constraints. In Human Language Technology, pages
* 254{259, San Francisco, California. Advanced Research Projects Agency,
* Software and Intelligent Systems Technology Oce, Morgan Kaufmann.
<<<<<<< HEAD
=======
*
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
*/
@CheckReturnValue
public class Confusion implements Measure, FeatureMarginalsCarrier { |
| Solution content |
|---|
* generated selectional constraints. In Human Language Technology, pages
* 254{259, San Francisco, California. Advanced Research Projects Agency,
* Software and Intelligent Systems Technology Oce, Morgan Kaufmann.
*/
@CheckReturnValue
public class Confusion implements Measure, FeatureMarginalsCarrier { |
| File |
|---|
| Confusion.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
* Proximity measure calculating proximity as the degree orthogonality between * vectors; the cosine of the angle between them. * <<<<<<< HEAD * ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| Solution content |
|---|
* Proximity measure calculating proximity as the degree orthogonality between * vectors; the cosine of the angle between them. * * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| File |
|---|
| Cosine.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; <<<<<<< HEAD ======= import java.io.Serializable; import javax.annotation.CheckReturnValue; import javax.annotation.concurrent.Immutable; >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 import uk.ac.susx.mlcl.byblo.measures.Measure; import uk.ac.susx.mlcl.byblo.measures.Measures; import uk.ac.susx.mlcl.byblo.weighings.Weighting; |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import uk.ac.susx.mlcl.byblo.measures.Measure; import uk.ac.susx.mlcl.byblo.measures.Measures; import uk.ac.susx.mlcl.byblo.weighings.Weighting; |
| File |
|---|
| DotProduct.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
* Proximity measure calculating proximity as the dot product of the vectors.
* For unit vectors this is equivalent to {@link Cosine }.
*
<<<<<<< HEAD
*
=======
*
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
@Immutable |
| Solution content |
|---|
* Proximity measure calculating proximity as the dot product of the vectors.
* For unit vectors this is equivalent to {@link Cosine }.
*
*
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
@Immutable |
| File |
|---|
| DotProduct.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
import java.io.Serializable; /** <<<<<<< HEAD ======= * * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| Solution content |
|---|
import java.io.Serializable; /** * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| File |
|---|
| Hindle.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; <<<<<<< HEAD ======= import java.io.Serializable; import javax.annotation.CheckReturnValue; import javax.annotation.concurrent.Immutable; >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 import uk.ac.susx.mlcl.byblo.measures.DecomposableMeasure; import uk.ac.susx.mlcl.byblo.measures.Measures; import uk.ac.susx.mlcl.byblo.weighings.Weighting; |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import uk.ac.susx.mlcl.byblo.measures.DecomposableMeasure; import uk.ac.susx.mlcl.byblo.measures.Measures; import uk.ac.susx.mlcl.byblo.weighings.Weighting; |
| File |
|---|
| Jaccard.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
* than zero and one) this measures takes a multi-set view of set operations: * intersection is the maximum and union is the minimum. * <<<<<<< HEAD * ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| Solution content |
|---|
* than zero and one) this measures takes a multi-set view of set operations: * intersection is the maximum and union is the minimum. * * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| File |
|---|
| Jaccard.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
/** * Distance measure that computes similarity as the Jensen-Shannon divergence. * <<<<<<< HEAD * ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| Solution content |
|---|
/** * Distance measure that computes similarity as the Jensen-Shannon divergence. * * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| File |
|---|
| JensenShannonDivergence.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
}
=======
return divergence;
if (Math.abs(divergence - getHomogeneityBound()) < EPSILON)
divergence = getHomogeneityBound();
<<<<<<< HEAD
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double divergence = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
divergence += A.values[i] / A.sum;
i++;
} else if (A.keys[i] > B.keys[j]) {
divergence += B.values[j] / B.sum;
j++;
} else {
final double pA = A.values[i] / A.sum;
final double pB = B.values[j] / B.sum;
final double lpAvg = log2(pA + pB) - 1.;
divergence += pA * (log2(pA) - lpAvg);
divergence += pB * (log2(pB) - lpAvg);
i++;
j++;
}
}
while (i < A.size) {
divergence += A.values[i] / A.sum;
i++;
}
while (j < B.size) {
divergence += B.values[j] / B.sum;
j++;
}
return divergence / 2.;
}
@Override
public boolean isCommutative() {
return true;
}
@Override
public double getHomogeneityBound() {
return 0;
}
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
@Override
public double getHeterogeneityBound() { |
| Solution content |
|---|
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double divergence = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
divergence += A.values[i] / A.sum;
i++;
} else if (A.keys[i] > B.keys[j]) {
divergence += B.values[j] / B.sum;
j++;
} else {
final double pA = A.values[i] / A.sum;
final double pB = B.values[j] / B.sum;
final double lpAvg = log2(pA + pB) - 1.;
divergence += pA * (log2(pA) - lpAvg);
divergence += pB * (log2(pB) - lpAvg);
i++;
j++;
}
}
while (i < A.size) {
divergence += A.values[i] / A.sum;
i++;
}
while (j < B.size) {
divergence += B.values[j] / B.sum;
j++;
}
divergence = divergence / 2.;
// The algorithm introduces a small amount of floating point error, which can lead to result slightly outside
// the expected bounds. To correct for this we clamp results to the bound when they are within some small value.
if(Math.abs(divergence - getHeterogeneityBound()) < EPSILON)
divergence = getHeterogeneityBound();
if(Math.abs(divergence - getHomogeneityBound()) < EPSILON)
divergence = getHomogeneityBound();
return divergence;
}
@Override
public boolean isCommutative() {
return true;
}
@Override
public double getHomogeneityBound() {
return 0;
}
@Override
public double getHeterogeneityBound() {
return 1;
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositiveWeighting.class;
}
public boolean equals(Object obj) {
return obj != null && obj.getClass() == this.getClass();
}
public int hashCode() {
return this.getClass().hashCode();
}
@Override
public String toString() {
return "JS-Divergence";
}
} |
| File |
|---|
| JensenShannonDivergence.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Annotation |
| Method declaration |
| Return statement |
| Variable |
| Chunk |
|---|
| Conflicting content |
|---|
return PositiveWeighting.class;
}
<<<<<<< HEAD
@Override
public double getHeterogeneityBound() {
return 1;
}
=======
@Override
public String toString() {
return "JS-Divergence";
}
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
@Override
public int hashCode() { |
| Solution content |
|---|
@Override
public double getHeterogeneityBound() {
return 1;
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositiveWeighting.class;
}
public boolean equals(Object obj) {
return obj != null && obj.getClass() == this.getClass();
}
public int hashCode() {
return this.getClass().hashCode();
}
@Override
public String toString() {
return "JS-Divergence";
}
} |
| File |
|---|
| JensenShannonDivergence.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Annotation |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
* * * <<<<<<< HEAD * ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> * @see "A New Measure of Rank Correlation." Maurice Kendall (1938). Biometrika * 30 (1–2): 81–89." |
| Solution content |
|---|
* * * * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> * @see "A New Measure of Rank Correlation." Maurice Kendall (1938). Biometrika * 30 (1–2): 81–89." |
| File |
|---|
| KendallsTau.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
}
* 30 (1–2): 81–89."
*/
@CheckReturnValue
<<<<<<< HEAD
public final class KendallsTau
implements Measure, Serializable {
private static final long serialVersionUID = 1L;
private static final Log LOG = LogFactory.getLog(KendallsTau.class);
/**
* Default expected minimum dimensionality of vectors ({@value}) if not
* explicitly set.
*/
@Nonnegative
public static final int DEFAULT_MIN_CARDINALITY = 1;
/**
* Expected dimensionality of vectors.
*/
@Nonnegative
private int minCardinality;
/**
* Construct a new instance of {@link KendallsTau } similarity measure.
*
* The minCardinality field is initialized to
* {@link KendallsTau#DEFAULT_MIN_CARDINALITY}, which is {@value
* #DEFAULT_MIN_CARDINALITY}
*/
public KendallsTau() {
this(DEFAULT_MIN_CARDINALITY);
}
/**
* Construct new instance of {@link KendallsTau } similarity measure,
* initializing the expected dimensionality of vectors to
* minCardinality.
*
*
* @param minCardinality expected dimensionality of vectors
* @throws IllegalArgumentException when |
| Solution content |
|---|
* 30 (1–2): 81–89."
*/
@CheckReturnValue
public final class KendallsTau
implements Measure, Serializable {
private static final long serialVersionUID = 1L;
private static final Log LOG = LogFactory.getLog(KendallsTau.class);
/**
* Default expected minimum dimensionality of vectors ({@value}) if not
* explicitly set.
*/
@Nonnegative
public static final int DEFAULT_MIN_CARDINALITY = 1;
/**
* Expected dimensionality of vectors.
*/
@Nonnegative
private int minCardinality;
/**
* Construct a new instance of {@link KendallsTau } similarity measure.
*
* The minCardinality field is initialized to
* {@link KendallsTau#DEFAULT_MIN_CARDINALITY}, which is {@value
* #DEFAULT_MIN_CARDINALITY}
*/
public KendallsTau() {
this(DEFAULT_MIN_CARDINALITY);
}
/**
* Construct new instance of {@link KendallsTau } similarity measure,
* initializing the expected dimensionality of vectors to
* minCardinality.
*
*
* @param minCardinality expected dimensionality of vectors
* @throws IllegalArgumentException when |
| File |
|---|
| KendallsTau.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Method declaration |
| Method invocation |
| Chunk |
|---|
| Conflicting content |
|---|
*/ @CheckReturnValue * Distance measure that computes similarity as the Kullback–Leibler divergence, * with Laplace smoothing. * <<<<<<< HEAD * ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> |
| Solution content |
|---|
* Distance measure that computes similarity as the Kullback–Leibler divergence, * with Laplace smoothing. * * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @CheckReturnValue |
| File |
|---|
| KullbackLeiblerDivergence.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
@CheckReturnValue
} else if (A.keys[i] > B.keys[j]) {
public final class KullbackLeiblerDivergence implements Measure, Serializable {
<<<<<<< HEAD
private static final long serialVersionUID = 1L;
/**
* Default expected minimum dimensionality of vectors ({@value}) if not
* explicitly set.
*/
@Nonnegative
public static final int DEFAULT_MIN_CARDINALITY = 1;
/**
* Expected dimensionality of vectors.
*/
@Nonnegative
private int minCardinality;
/**
* Construct a new instance of {@link KullbackLeiblerDivergence } similarity
* measure.
*
* The minCardinality field is initialized to
* {@link KullbackLeiblerDivergence#DEFAULT_MIN_CARDINALITY}, which is
* {@value #DEFAULT_MIN_CARDINALITY}
*/
public KullbackLeiblerDivergence() {
this(DEFAULT_MIN_CARDINALITY);
}
/**
* Construct new instance of {@link KullbackLeiblerDivergence } similarity
* measure, initializing the expected dimensionality of vectors to
* minCardinality.
*
*
* @param minCardinality expected dimensionality of vectors
* @throws IllegalArgumentException when |
| Solution content |
|---|
@CheckReturnValue
public final class KullbackLeiblerDivergence implements Measure, Serializable {
private static final long serialVersionUID = 1L;
/**
* Default expected minimum dimensionality of vectors ({@value}) if not
* explicitly set.
*/
@Nonnegative
public static final int DEFAULT_MIN_CARDINALITY = 1;
/**
* Expected dimensionality of vectors.
*/
@Nonnegative
private int minCardinality;
/**
* Construct a new instance of {@link KullbackLeiblerDivergence } similarity
* measure.
*
* The minCardinality field is initialized to
* {@link KullbackLeiblerDivergence#DEFAULT_MIN_CARDINALITY}, which is
* {@value #DEFAULT_MIN_CARDINALITY}
*/
public KullbackLeiblerDivergence() {
this(DEFAULT_MIN_CARDINALITY);
}
/**
* Construct new instance of {@link KullbackLeiblerDivergence } similarity
* measure, initializing the expected dimensionality of vectors to
* minCardinality.
*
*
* @param minCardinality expected dimensionality of vectors
* @throws IllegalArgumentException when |
| File |
|---|
| KullbackLeiblerDivergence.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Comment |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
* For lambda = 0 and lambda = 1 the divergence is always 0, which is * meaningless. Hence, lambda must be in the range 0 < lambda < 1. * <<<<<<< HEAD * ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @CheckReturnValue |
| Solution content |
|---|
* For lambda = 0 and lambda = 1 the divergence is always 0, which is * meaningless. Hence, lambda must be in the range 0 < lambda < 1. * * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @CheckReturnValue |
| File |
|---|
| LambdaDivergence.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
return 1.0;
}
@CheckReturnValue
public final class LambdaDivergence implements Measure, Serializable {
<<<<<<< HEAD
private static final long serialVersionUID = 1L;
@Nonnegative
public static final double DEFAULT_LAMBDA = 0.5;
@Nonnegative
private double lambda;
public LambdaDivergence() {
setLambda(DEFAULT_LAMBDA);
}
public LambdaDivergence(@Nonnegative double lambda) {
setLambda(lambda);
}
@Nonnegative
public final double getLambda() {
return lambda;
}
public final void setLambda(@Nonnegative double lambda) {
Checks.checkRangeExcl("lambda", lambda, 0.0, 1.0);
this.lambda = lambda;
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double divergence = 0.0;
int i = 0;
int j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
final double q = A.values[i] / A.sum;
divergence += lambda * q * (log2(q) - log2(lambda * q));
++i;
} else if (A.keys[i] > B.keys[j]) {
final double r = B.values[j] / B.sum;
divergence += (1.0 - lambda) * r
* (log2(r) - log2((1.0 - lambda) * r));
++j;
} else {
final double q = A.values[i] / A.sum;
final double r = B.values[j] / B.sum;
final double logAvg = log2(lambda * q + (1.0 - lambda) * r);
divergence += lambda * q * (log2(q) - logAvg)
+ (1.0 - lambda) * r * (log2(r) - logAvg);
++i;
++j;
}
}
while (i < A.size) {
final double q = A.values[i] / A.sum;
divergence += lambda * q * (log2(q) - log2(lambda * q));
i++;
}
while (j < B.size) {
final double r = B.values[j] / B.sum;
divergence += (1.0 - lambda) * r * (log2(r) - log2(
(1.0 - lambda) * r));
j++;
}
return divergence;
}
@Override
public boolean isCommutative() {
return Measures.epsilonEquals(lambda, 0.5);
}
@Override
public double getHomogeneityBound() {
return 0;
}
@Override
public double getHeterogeneityBound() {
@Override
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositiveWeighting.class;
}
@Override
public String toString() {
return "Lambda-Divergence{lambda=" + lambda + '}';
}
=======
private static final long serialVersionUID = 1L;
private static final double EPSILON = 1E-10;
@Nonnegative
public static final double DEFAULT_LAMBDA = 0.5;
@Nonnegative
private double lambda;
public LambdaDivergence() {
setLambda(DEFAULT_LAMBDA);
}
public LambdaDivergence(@Nonnegative double lambda) {
setLambda(lambda);
}
@Nonnegative
public final double getLambda() {
return lambda;
}
public final void setLambda(@Nonnegative double lambda) {
Checks.checkRangeExcl("lambda", lambda, 0.0, 1.0);
this.lambda = lambda;
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double divergence = 0.0;
int i = 0;
int j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
final double q = A.values[i] / A.sum;
divergence += lambda * q * (log2(q) - log2(lambda * q));
++i;
} else if (A.keys[i] > B.keys[j]) {
final double r = B.values[j] / B.sum;
divergence += (1.0 - lambda) * r
* (log2(r) - log2((1.0 - lambda) * r));
++j;
} else {
final double q = A.values[i] / A.sum;
final double r = B.values[j] / B.sum;
final double logAvg = log2(lambda * q + (1.0 - lambda) * r);
divergence += lambda * q * (log2(q) - logAvg) + (1.0 - lambda)
* r * (log2(r) - logAvg);
++i;
++j;
}
}
while (i < A.size) {
final double q = A.values[i] / A.sum;
divergence += lambda * q * (log2(q) - log2(lambda * q));
i++;
}
while (j < B.size) {
final double r = B.values[j] / B.sum;
divergence += (1.0 - lambda) * r
* (log2(r) - log2((1.0 - lambda) * r));
j++;
}
// The algorithm can introduce slight floating point errors so set the
// divergence to the bound if it's very close
if (Math.abs(divergence - getHeterogeneityBound()) < EPSILON)
divergence = getHeterogeneityBound();
if (Math.abs(divergence - getHomogeneityBound()) < EPSILON)
divergence = getHomogeneityBound();
return divergence;
}
public boolean isCommutative() {
return Measures.epsilonEquals(lambda, 0.5);
}
@Override
public double getHomogeneityBound() {
return 0;
}
@Override
public double getHeterogeneityBound() {
return 1.0;
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositiveWeighting.class;
}
@Override
public String toString() {
return "Lambda-Divergence{lambda=" + lambda + '}';
}
@Override
public int hashCode() {
final int prime = 29;
int result = 1;
long temp;
temp = Double.doubleToLongBits(lambda);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
LambdaDivergence other = (LambdaDivergence) obj;
if (Double.doubleToLongBits(lambda) != Double
.doubleToLongBits(other.lambda)) {
return false;
}
return true;
}
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
} |
| Solution content |
|---|
@CheckReturnValue
public final class LambdaDivergence implements Measure, Serializable {
private static final long serialVersionUID = 1L;
private static final double EPSILON = 1E-15;
@Nonnegative
public static final double DEFAULT_LAMBDA = 0.5;
@Nonnegative
private double lambda;
public LambdaDivergence() {
setLambda(DEFAULT_LAMBDA);
}
public LambdaDivergence(@Nonnegative double lambda) {
setLambda(lambda);
}
@Nonnegative
public final double getLambda() {
return lambda;
}
public final void setLambda(@Nonnegative double lambda) {
Checks.checkRangeExcl("lambda", lambda, 0.0, 1.0);
this.lambda = lambda;
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double divergence = 0.0;
int i = 0;
int j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
final double q = A.values[i] / A.sum;
divergence += lambda * q * (log2(q) - log2(lambda * q));
++i;
} else if (A.keys[i] > B.keys[j]) {
final double r = B.values[j] / B.sum;
divergence += (1.0 - lambda) * r
* (log2(r) - log2((1.0 - lambda) * r));
++j;
} else {
final double q = A.values[i] / A.sum;
final double r = B.values[j] / B.sum;
final double logAvg = log2(lambda * q + (1.0 - lambda) * r);
divergence += lambda * q * (log2(q) - logAvg)
+ (1.0 - lambda) * r * (log2(r) - logAvg);
++i;
++j;
}
}
while (i < A.size) {
final double q = A.values[i] / A.sum;
divergence += lambda * q * (log2(q) - log2(lambda * q));
i++;
}
while (j < B.size) {
final double r = B.values[j] / B.sum;
divergence += (1.0 - lambda) * r * (log2(r) - log2(
(1.0 - lambda) * r));
j++;
}
// The algorithm introduces a small amount of floating point error, which can lead to result slightly outside
// the expected bounds. To correct for this we clamp results to the bound when they are within some small value.
if(Math.abs(divergence - getHeterogeneityBound()) < EPSILON)
divergence = getHeterogeneityBound();
if(Math.abs(divergence - getHomogeneityBound()) < EPSILON)
divergence = getHomogeneityBound();
return divergence;
}
@Override
public boolean isCommutative() {
return Measures.epsilonEquals(lambda, 0.5);
}
@Override
public double getHomogeneityBound() {
return 0;
}
@Override
public double getHeterogeneityBound() {
return 1.0;
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositiveWeighting.class;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LambdaDivergence that = (LambdaDivergence) o;
if (Double.compare(that.lambda, lambda) != 0) return false;
return true;
}
@Override
public int hashCode() {
long temp = lambda != +0.0d ? Double.doubleToLongBits(lambda) : 0L;
return (int) (temp ^ (temp >>> 32));
}
@Override
public String toString() {
return "Lambda-Divergence{lambda=" + lambda + '}';
}
} |
| File |
|---|
| LambdaDivergence.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; <<<<<<< HEAD ======= import static uk.ac.susx.mlcl.byblo.weighings.Weightings.log2; import java.io.Serializable; import java.text.MessageFormat; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnegative; >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 import uk.ac.susx.mlcl.byblo.measures.Measure; import uk.ac.susx.mlcl.byblo.weighings.Weighting; import uk.ac.susx.mlcl.byblo.weighings.impl.PositiveWeighting; |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import uk.ac.susx.mlcl.byblo.measures.Measure; import uk.ac.susx.mlcl.byblo.weighings.Weighting; import uk.ac.susx.mlcl.byblo.weighings.impl.PositiveWeighting; |
| File |
|---|
| LeeSkewDivergence.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
* Statistical Language Analysis" Artificial Intelligence and Statistics 2001, * pp. 65--72, 2001 * <<<<<<< HEAD * ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @CheckReturnValue |
| Solution content |
|---|
* Statistical Language Analysis" Artificial Intelligence and Statistics 2001, * pp. 65--72, 2001 * * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @CheckReturnValue |
| File |
|---|
| LeeSkewDivergence.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
int i = 0;
int j = 0;
@CheckReturnValue
public final class LeeSkewDivergence implements Measure, Serializable {
<<<<<<< HEAD
private static final long serialVersionUID = 1L;
@Nonnegative
public static final double DEFAULT_ALPHA = 0.99;
@Nonnegative
private double alpha;
public LeeSkewDivergence() {
setAlpha(DEFAULT_ALPHA);
}
public LeeSkewDivergence(double alpha) {
setAlpha(alpha);
}
@Nonnegative
public final double getAlpha() {
return alpha;
}
public final void setAlpha(@Nonnegative double alpha) {
if(Double.isInfinite(alpha) || Double.isNaN(alpha))
throw new IllegalArgumentException("alpha");
Checks.checkRangeExcl("alpha", alpha, 0.0, 1.0);
this.alpha = alpha;
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double divergence = 0.0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
++i;
} else if (A.keys[i] > B.keys[j]) {
final double r = B.values[j] / B.sum;
final double logAvg = log2((1 - alpha) * r);
divergence += r * (log2(r) - logAvg);
++j;
} else {
final double q = A.values[i] / A.sum;
final double r = B.values[j] / B.sum;
final double logAvg = log2(alpha * q + (1 - alpha) * r);
divergence += r * (log2(r) - logAvg);
++i;
++j;
}
}
while (j < B.size) {
final double r = B.values[j] / B.sum;
final double logAvg = log2((1 - alpha) * r);
divergence += r * (log2(r) - logAvg);
j++;
}
return divergence;
}
@Override
public boolean isCommutative() {
return false;
}
@Override
public double getHomogeneityBound() {
return 0;
}
@Override
public double getHeterogeneityBound() {
return Double.POSITIVE_INFINITY;
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositiveWeighting.class;
}
@Override
public String toString() {
return MessageFormat.format("LeeSkewDivergence[alpha={0}]", alpha);
}
=======
private static final long serialVersionUID = 1L;
@Nonnegative
public static final double DEFAULT_ALPHA = 0.99;
@Nonnegative
private double alpha;
public LeeSkewDivergence() {
setAlpha(DEFAULT_ALPHA);
}
public LeeSkewDivergence(double alpha) {
setAlpha(alpha);
}
@Nonnegative
public final double getAlpha() {
return alpha;
}
public final void setAlpha(@Nonnegative double alpha) {
Checks.checkNotNaN("alpha", alpha);
Checks.checkFinite("alpha", alpha);
Checks.checkRangeExcl("alpha", alpha, 0.0, 1.0);
this.alpha = alpha;
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double divergence = 0.0;
int i = 0;
int j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
++i;
} else if (A.keys[i] > B.keys[j]) {
final double r = B.values[j] / B.sum;
final double logAvg = log2((1 - alpha) * r);
divergence += r * (log2(r) - logAvg);
++j;
} else {
final double q = A.values[i] / A.sum;
final double r = B.values[j] / B.sum;
final double logAvg = log2(alpha * q + (1 - alpha) * r);
divergence += r * (log2(r) - logAvg);
++i;
++j;
}
}
while (j < B.size) {
final double r = B.values[j] / B.sum;
final double logAvg = log2((1 - alpha) * r);
divergence += r * (log2(r) - logAvg);
j++;
}
return divergence;
}
@Override
public boolean isCommutative() {
return false;
}
@Override
public double getHomogeneityBound() {
return 0;
}
@Override
public double getHeterogeneityBound() {
return Double.POSITIVE_INFINITY;
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositiveWeighting.class;
}
@Override
public String toString() {
return MessageFormat.format("LeeSkewDivergence[alpha={0}]", alpha);
}
@Override
public int hashCode() {
return 31;
}
@Override
public boolean equals(Object obj) {
return obj == this || (obj != null && getClass() == obj.getClass());
}
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
} |
| Solution content |
|---|
@CheckReturnValue
public final class LeeSkewDivergence implements Measure, Serializable {
private static final long serialVersionUID = 1L;
@Nonnegative
public static final double DEFAULT_ALPHA = 0.99;
@Nonnegative
private double alpha;
public LeeSkewDivergence() {
setAlpha(DEFAULT_ALPHA);
}
public LeeSkewDivergence(double alpha) {
setAlpha(alpha);
}
@Nonnegative
public final double getAlpha() {
return alpha;
}
public final void setAlpha(@Nonnegative double alpha) {
if(Double.isInfinite(alpha) || Double.isNaN(alpha))
throw new IllegalArgumentException("alpha");
Checks.checkRangeExcl("alpha", alpha, 0.0, 1.0);
this.alpha = alpha;
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double divergence = 0.0;
int i = 0;
int j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
++i;
} else if (A.keys[i] > B.keys[j]) {
final double r = B.values[j] / B.sum;
final double logAvg = log2((1 - alpha) * r);
divergence += r * (log2(r) - logAvg);
++j;
} else {
final double q = A.values[i] / A.sum;
final double r = B.values[j] / B.sum;
final double logAvg = log2(alpha * q + (1 - alpha) * r);
divergence += r * (log2(r) - logAvg);
++i;
++j;
}
}
while (j < B.size) {
final double r = B.values[j] / B.sum;
final double logAvg = log2((1 - alpha) * r);
divergence += r * (log2(r) - logAvg);
j++;
}
return divergence;
}
@Override
public boolean isCommutative() {
return false;
}
@Override
public double getHomogeneityBound() {
return 0;
}
@Override
public double getHeterogeneityBound() {
return Double.POSITIVE_INFINITY;
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositiveWeighting.class;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LeeSkewDivergence that = (LeeSkewDivergence) o;
if (Double.compare(that.alpha, alpha) != 0) return false;
return true;
}
@Override
public int hashCode() {
long temp = alpha != +0.0d ? Double.doubleToLongBits(alpha) : 0L;
return (int) (temp ^ (temp >>> 32));
}
@Override
public String toString() {
return MessageFormat.format("LeeSkewDivergence[alpha={0}]", alpha);
}
} |
| File |
|---|
| LeeSkewDivergence.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
import java.io.Serializable; /** <<<<<<< HEAD ======= * * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| Solution content |
|---|
import java.io.Serializable; /** * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| File |
|---|
| Lin.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
import static java.lang.Math.*; /** <<<<<<< HEAD ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * |
| Solution content |
|---|
import static java.lang.Math.*; /** * |
| File |
|---|
| LpSpaceDistance.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
* vectors. * * <<<<<<< HEAD * ======= * * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @CheckReturnValue |
| Solution content |
|---|
* vectors. * * * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @CheckReturnValue |
| File |
|---|
| LpSpaceDistance.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
@CheckReturnValue
public final class LpSpaceDistance implements Measure {
<<<<<<< HEAD
public static final double DEFAULT_POWER = 2;
private static final long serialVersionUID = 1L;
private double power = Double.NaN;
private Measure delegate = null;
public LpSpaceDistance() {
setPower(DEFAULT_POWER);
}
public LpSpaceDistance(double power) {
setPower(power);
}
public final double getPower() {
return power;
}
public final void setPower(final double newPower) {
if (Double.isNaN(newPower))
throw new IllegalArgumentException("newPower is NaN");
if (power != newPower) {
power = newPower;
if (Measures.epsilonEquals(power, 0, 0)) {
delegate = new HammingDistance();
} else if (Measures.epsilonEquals(power, 1, 0)) {
delegate = new ManhattanDistance();
} else if (Measures.epsilonEquals(power, 2, 0)) {
delegate = new EuclideanDistance();
} else if (Measures.
epsilonEquals(power, Double.POSITIVE_INFINITY, 0)) {
delegate = new MaxSpaceDistance();
} else if (Measures.
epsilonEquals(power, Double.NEGATIVE_INFINITY, 0)) {
delegate = new MinSpaceDistance();
} else {
if (delegate == null || delegate.getClass() != MinkowskiDistance.class)
delegate = new MinkowskiDistance();
}
}
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
return delegate.similarity(A, B);
}
@Override
public double getHomogeneityBound() {
return delegate.getHomogeneityBound();
}
@Override
public double getHeterogeneityBound() {
return delegate.getHeterogeneityBound();
}
@Override
@CheckReturnValue
public Class extends Weighting> getExpectedWeighting() {
return NullWeighting.class;
}
@Override
public String toString() {
return "Lp{" + "p=" + power + '}';
}
@Override
public boolean isCommutative() {
return true;
}
/**
* Abstract super class to the various Lp Space metric implementations.
*/
@Immutable
@CheckReturnValue
private static abstract class LpSpaceDelegate implements Measure {
@Override
public Class extends Weighting> getExpectedWeighting() {
return NullWeighting.class;
}
@Override
public final boolean isCommutative() {
return true;
}
@Override
public final double getHomogeneityBound() {
return 0.0;
}
@Override
public final double getHeterogeneityBound() {
return Double.POSITIVE_INFINITY;
}
}
/**
* Fallback implementation for arbitrary p-spaces. Not though that it will
* not produce the correct results of p = -inf, 0, or +inf.
*/
@CheckReturnValue
private final class MinkowskiDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += pow(A.values[i], power);
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += pow(B.values[j], power);
j++;
} else {
distance += pow(abs(A.values[i] - B.values[j]), power);
i++;
j++;
}
}
while (i < A.size) {
distance += pow(A.values[i], power);
i++;
}
while (j < B.size) {
distance += pow(B.values[j], power);
j++;
}
return Math.pow(distance, 1.0 / power);
}
}
/**
* Implementation of the power-2 space; i.e standard Euclidean space that we
* are all used to.
*/
@Immutable
@CheckReturnValue
private static final class EuclideanDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += A.values[i] * A.values[i];
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += B.values[j] * B.values[j];
j++;
} else {
distance += (A.values[i] - B.values[j])
* (A.values[i] - B.values[j]);
i++;
j++;
}
}
while (i < A.size) {
distance += A.values[i] * A.values[i];
i++;
}
while (j < B.size) {
distance += B.values[j] * B.values[j];
j++;
}
return Math.sqrt(distance);
}
}
/**
* Implementation of the power-1 space; known as Manhattan or taxicab
* distance.
*/
@Immutable
@CheckReturnValue
private static final class ManhattanDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += abs(A.values[i]);
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += abs(B.values[j]);
j++;
} else {
distance += abs(A.values[i] - B.values[j]);
i++;
j++;
}
}
while (i < A.size) {
distance += abs(A.values[i]);
i++;
}
while (j < B.size) {
distance += abs(B.values[j]);
j++;
}
return distance;
}
}
/**
* Implementation of power-zero L space.
*/
@Immutable
@CheckReturnValue
private static final class HammingDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += signum(abs(A.values[i]));
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += signum(abs(B.values[j]));
j++;
} else {
distance += signum(abs(A.values[i] - B.values[j]));
i++;
j++;
}
}
while (i < A.size) {
distance += signum(abs(A.values[i]));
i++;
}
while (j < B.size) {
distance += signum(abs(B.values[j]));
j++;
}
return distance;
}
}
/**
* Implementation of power +infinity L-space metric.
*/
@Immutable
private static final class MaxSpaceDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance = max(distance, abs(A.values[i]));
i++;
} else if (A.keys[i] > B.keys[j]) {
distance = max(distance, abs(B.values[j]));
j++;
} else {
distance = max(distance, abs(A.values[i] - B.values[j]));
i++;
j++;
}
}
while (i < A.size) {
distance = max(distance, abs(A.values[i]));
i++;
}
while (j < B.size) {
distance = max(distance, abs(B.values[j]));
j++;
}
return distance;
}
}
/**
* Implementation of power -infinity L-space metric.
*/
@Immutable
@CheckReturnValue
private static final class MinSpaceDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance = min(distance, abs(A.values[i]));
i++;
} else if (A.keys[i] > B.keys[j]) {
distance = min(distance, abs(B.values[j]));
j++;
} else {
distance = min(distance, abs(A.values[i] - B.values[j]));
i++;
j++;
}
}
while (i < A.size) {
distance = min(distance, abs(A.values[i]));
i++;
}
while (j < B.size) {
distance = min(distance, abs(B.values[j]));
j++;
}
return distance;
}
}
=======
public static final double DEFAULT_POWER = 2;
private static final long serialVersionUID = 1L;
private double power = Double.NaN;
private Measure deligate = null;
@Override
public LpSpaceDistance() {
setPower(DEFAULT_POWER);
}
public LpSpaceDistance(double power) {
setPower(power);
}
public final double getPower() {
return power;
}
public final void setPower(final double newPower) {
if (Double.isNaN(newPower))
throw new IllegalArgumentException("newPower is NaN");
if (!Measures.epsilonEquals(power, newPower, 0)) {
power = newPower;
if (Measures.epsilonEquals(power, 0, 0)) {
deligate = new HammingDistance();
} else if (Measures.epsilonEquals(power, 1, 0)) {
deligate = new ManhattanDistance();
} else if (Measures.epsilonEquals(power, 2, 0)) {
deligate = new EuclideanDistance();
} else if (Measures.epsilonEquals(power, Double.POSITIVE_INFINITY,
0)) {
deligate = new MaxSpaceDistance();
} else if (Measures.epsilonEquals(power, Double.NEGATIVE_INFINITY,
0)) {
deligate = new MinSpaceDistance();
} else {
if (deligate == null
|| deligate.getClass() != MinkowskiDistance.class)
deligate = new MinkowskiDistance();
}
}
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
return deligate.similarity(A, B);
}
@Override
public double getHomogeneityBound() {
return deligate.getHomogeneityBound();
}
@Override
public double getHeterogeneityBound() {
return deligate.getHeterogeneityBound();
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return NullWeighting.class;
}
@Override
public String toString() {
return "Lp{" + "p=" + power + '}';
}
@Override
public boolean isCommutative() {
return true;
}
/**
* Abstract super class to the various Lp Space metric implementations.
*/
@Immutable
@CheckReturnValue
private static abstract class LpSpaceDeligate implements Measure {
@Override
public Class extends Weighting> getExpectedWeighting() {
return NullWeighting.class;
}
@Override
public final boolean isCommutative() {
return true;
}
@Override
public final double getHomogeneityBound() {
return 0.0;
}
@Override
public final double getHeterogeneityBound() {
return Double.POSITIVE_INFINITY;
}
}
/**
* Fallback implementation for arbitrary p-spaces. Not though that it will
* not produce the correct results of p = -inf, 0, or +inf.
*/
@CheckReturnValue
private final class MinkowskiDistance extends LpSpaceDeligate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += pow(A.values[i], power);
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += pow(B.values[j], power);
j++;
} else {
distance += pow(abs(A.values[i] - B.values[j]), power);
i++;
j++;
}
}
while (i < A.size) {
distance += pow(A.values[i], power);
i++;
}
while (j < B.size) {
distance += pow(B.values[j], power);
j++;
}
return Math.pow(distance, 1.0 / power);
}
}
/**
while (j < B.size) {
* Implementation of the power-2 space; i.e standard Euclidean space that we
* are all used to.
*/
@Immutable
@CheckReturnValue
private static final class EuclideanDistance extends LpSpaceDeligate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += A.values[i] * A.values[i];
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += B.values[j] * B.values[j];
j++;
} else {
distance += (A.values[i] - B.values[j])
* (A.values[i] - B.values[j]);
i++;
j++;
}
}
while (i < A.size) {
distance += A.values[i] * A.values[i];
i++;
}
while (j < B.size) {
distance += B.values[j] * B.values[j];
j++;
}
return Math.sqrt(distance);
}
}
/**
* Implementation of the power-1 space; known as Manhattan or taxicab
* distance.
*/
@Immutable
@CheckReturnValue
private static final class ManhattanDistance extends LpSpaceDeligate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += abs(A.values[i]);
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += abs(B.values[j]);
j++;
} else {
distance += abs(A.values[i] - B.values[j]);
i++;
j++;
}
}
while (i < A.size) {
distance += abs(A.values[i]);
i++;
}
while (j < B.size) {
distance += abs(B.values[j]);
j++;
}
return distance;
}
}
/**
* Implementation of power-zero L space.
*/
@Immutable
@CheckReturnValue
private static final class HammingDistance extends LpSpaceDeligate {
private static final long serialVersionUID = 1L;
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += signum(abs(A.values[i]));
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += signum(abs(B.values[j]));
j++;
} else {
distance += signum(abs(A.values[i] - B.values[j]));
i++;
j++;
}
}
while (i < A.size) {
distance += signum(abs(A.values[i]));
i++;
}
distance += signum(abs(B.values[j]));
j++;
}
return distance;
}
}
/**
* Implementation of power +infinity L-space metric.
*/
@Immutable
@CheckReturnValue
private static final class MaxSpaceDistance extends LpSpaceDeligate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance = max(distance, abs(A.values[i]));
i++;
} else if (A.keys[i] > B.keys[j]) {
distance = max(distance, abs(B.values[j]));
j++;
} else {
distance = max(distance, abs(A.values[i] - B.values[j]));
i++;
j++;
}
}
while (i < A.size) {
distance = max(distance, abs(A.values[i]));
i++;
}
while (j < B.size) {
distance = max(distance, abs(B.values[j]));
j++;
}
return distance;
}
}
/**
* Implementation of power -infinity L-space metric.
*/
@Immutable
@CheckReturnValue
private static final class MinSpaceDistance extends LpSpaceDeligate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance = min(distance, abs(A.values[i]));
i++;
} else if (A.keys[i] > B.keys[j]) {
distance = min(distance, abs(B.values[j]));
j++;
} else {
distance = min(distance, abs(A.values[i] - B.values[j]));
i++;
j++;
}
}
while (i < A.size) {
distance = min(distance, abs(A.values[i]));
i++;
}
while (j < B.size) {
distance = min(distance, abs(B.values[j]));
j++;
}
return distance;
}
}
@Override
public int hashCode() {
return 39;
}
@Override
public boolean equals(Object obj) {
return obj == this || (obj != null && getClass() == obj.getClass());
}
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
} |
| Solution content |
|---|
@CheckReturnValue
public final class LpSpaceDistance implements Measure {
public static final double DEFAULT_POWER = 2;
private static final long serialVersionUID = 1L;
private double power = Double.NaN;
private Measure delegate = null;
public LpSpaceDistance() {
setPower(DEFAULT_POWER);
}
public LpSpaceDistance(double power) {
setPower(power);
}
public final double getPower() {
return power;
}
public final void setPower(final double newPower) {
if (Double.isNaN(newPower))
throw new IllegalArgumentException("newPower is NaN");
if (power != newPower) {
power = newPower;
if (Measures.epsilonEquals(power, 0, 0)) {
delegate = new HammingDistance();
} else if (Measures.epsilonEquals(power, 1, 0)) {
delegate = new ManhattanDistance();
} else if (Measures.epsilonEquals(power, 2, 0)) {
delegate = new EuclideanDistance();
} else if (Measures.
epsilonEquals(power, Double.POSITIVE_INFINITY, 0)) {
delegate = new MaxSpaceDistance();
} else if (Measures.
epsilonEquals(power, Double.NEGATIVE_INFINITY, 0)) {
delegate = new MinSpaceDistance();
} else {
if (delegate == null || delegate.getClass() != MinkowskiDistance.class)
delegate = new MinkowskiDistance();
}
}
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
return delegate.similarity(A, B);
}
@Override
public double getHomogeneityBound() {
return delegate.getHomogeneityBound();
}
@Override
public double getHeterogeneityBound() {
return delegate.getHeterogeneityBound();
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return NullWeighting.class;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LpSpaceDistance that = (LpSpaceDistance) o;
if (Double.compare(that.power, power) != 0) return false;
if (delegate != null ? !delegate.equals(that.delegate) : that.delegate != null) return false;
return true;
}
@Override
public int hashCode() {
int result;
long temp;
temp = power != +0.0d ? Double.doubleToLongBits(power) : 0L;
result = (int) (temp ^ (temp >>> 32));
result = 31 * result + (delegate != null ? delegate.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Lp{" + "p=" + power + '}';
}
@Override
public boolean isCommutative() {
return true;
}
/**
* Abstract super class to the various Lp Space metric implementations.
*/
@Immutable
@CheckReturnValue
private static abstract class LpSpaceDelegate implements Measure {
@Override
public Class extends Weighting> getExpectedWeighting() {
return NullWeighting.class;
}
@Override
public final boolean isCommutative() {
return true;
}
@Override
public final double getHomogeneityBound() {
return 0.0;
}
@Override
public final double getHeterogeneityBound() {
return Double.POSITIVE_INFINITY;
}
}
/**
* Fallback implementation for arbitrary p-spaces. Not though that it will
* not produce the correct results of p = -inf, 0, or +inf.
*/
@CheckReturnValue
private final class MinkowskiDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += pow(A.values[i], power);
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += pow(B.values[j], power);
j++;
} else {
distance += pow(abs(A.values[i] - B.values[j]), power);
i++;
j++;
}
}
while (i < A.size) {
distance += pow(A.values[i], power);
i++;
}
while (j < B.size) {
distance += pow(B.values[j], power);
j++;
}
return Math.pow(distance, 1.0 / power);
}
}
/**
* Implementation of the power-2 space; i.e standard Euclidean space that we
* are all used to.
*/
@Immutable
@CheckReturnValue
private static final class EuclideanDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += A.values[i] * A.values[i];
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += B.values[j] * B.values[j];
j++;
} else {
distance += (A.values[i] - B.values[j])
* (A.values[i] - B.values[j]);
i++;
j++;
}
}
while (i < A.size) {
distance += A.values[i] * A.values[i];
i++;
}
while (j < B.size) {
distance += B.values[j] * B.values[j];
j++;
}
return Math.sqrt(distance);
}
}
/**
* Implementation of the power-1 space; known as Manhattan or taxicab
* distance.
*/
@Immutable
@CheckReturnValue
private static final class ManhattanDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += abs(A.values[i]);
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += abs(B.values[j]);
j++;
} else {
distance += abs(A.values[i] - B.values[j]);
i++;
j++;
}
}
while (i < A.size) {
distance += abs(A.values[i]);
i++;
}
while (j < B.size) {
distance += abs(B.values[j]);
j++;
}
return distance;
}
}
/**
* Implementation of power-zero L space.
*/
@Immutable
@CheckReturnValue
private static final class HammingDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance += signum(abs(A.values[i]));
i++;
} else if (A.keys[i] > B.keys[j]) {
distance += signum(abs(B.values[j]));
j++;
} else {
distance += signum(abs(A.values[i] - B.values[j]));
i++;
j++;
}
}
while (i < A.size) {
distance += signum(abs(A.values[i]));
i++;
}
while (j < B.size) {
distance += signum(abs(B.values[j]));
j++;
}
return distance;
}
}
/**
* Implementation of power +infinity L-space metric.
*/
@Immutable
@CheckReturnValue
private static final class MaxSpaceDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance = max(distance, abs(A.values[i]));
i++;
} else if (A.keys[i] > B.keys[j]) {
distance = max(distance, abs(B.values[j]));
j++;
} else {
distance = max(distance, abs(A.values[i] - B.values[j]));
i++;
j++;
}
}
while (i < A.size) {
distance = max(distance, abs(A.values[i]));
i++;
}
while (j < B.size) {
distance = max(distance, abs(B.values[j]));
j++;
}
return distance;
}
}
/**
* Implementation of power -infinity L-space metric.
*/
@Immutable
@CheckReturnValue
private static final class MinSpaceDistance extends LpSpaceDelegate {
private static final long serialVersionUID = 1L;
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
double distance = 0;
int i = 0, j = 0;
while (i < A.size && j < B.size) {
if (A.keys[i] < B.keys[j]) {
distance = min(distance, abs(A.values[i]));
i++;
} else if (A.keys[i] > B.keys[j]) {
distance = min(distance, abs(B.values[j]));
j++;
} else {
distance = min(distance, abs(A.values[i] - B.values[j]));
i++;
j++;
}
}
while (i < A.size) {
distance = min(distance, abs(A.values[i]));
i++;
}
while (j < B.size) {
distance = min(distance, abs(B.values[j]));
j++;
}
return distance;
}
}
} |
| File |
|---|
| LpSpaceDistance.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class declaration |
| Comment |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
import java.io.Serializable; /** <<<<<<< HEAD ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| Solution content |
|---|
import java.io.Serializable; /** * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| File |
|---|
| Overlap.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
import javax.annotation.CheckReturnValue; import javax.annotation.concurrent.Immutable; <<<<<<< HEAD ======= import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 /** * This measure attempts to encapsulate, for each pair of feature vectors A and |
| Solution content |
|---|
import javax.annotation.CheckReturnValue; import javax.annotation.concurrent.Immutable; /** * This measure attempts to encapsulate, for each pair of feature vectors A and |
| File |
|---|
| Precision.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
* Note that recall(x,y) = precision(y,x) so the precision can be calculated by * wrapping an instance of RecallMi in the ReversedProximity decorator. * <<<<<<< HEAD * ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| Solution content |
|---|
* Note that recall(x,y) = precision(y,x) so the precision can be calculated by * wrapping an instance of RecallMi in the ReversedProximity decorator. * * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| File |
|---|
| Precision.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; <<<<<<< HEAD ======= import java.io.Serializable; import javax.annotation.CheckReturnValue; import javax.annotation.concurrent.Immutable; >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 import uk.ac.susx.mlcl.byblo.measures.DecomposableMeasure; import uk.ac.susx.mlcl.byblo.weighings.Weighting; import uk.ac.susx.mlcl.byblo.weighings.impl.PositiveWeighting; |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import uk.ac.susx.mlcl.byblo.measures.DecomposableMeasure; import uk.ac.susx.mlcl.byblo.weighings.Weighting; import uk.ac.susx.mlcl.byblo.weighings.impl.PositiveWeighting; |
| File |
|---|
| Recall.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
* Note that recall(x,y) = precision(y,x) so the precision can be calculated by * wrapping an instance of RecallMi in the ReversedProximity decorator. * <<<<<<< HEAD * ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| Solution content |
|---|
* Note that recall(x,y) = precision(y,x) so the precision can be calculated by * wrapping an instance of RecallMi in the ReversedProximity decorator. * * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ @Immutable |
| File |
|---|
| Recall.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
import java.io.Serializable; /** <<<<<<< HEAD ======= * >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 * Parameters * * β γ Special Case |
| Solution content |
|---|
import java.io.Serializable; /** * Parameters * * β γ Special Case |
| File |
|---|
| Weeds.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
* arithmetic mean of precision and recall 1 0 precision 0 0 recall 0.5 0 * unweighted arithmetic mean * <<<<<<< HEAD *
|
| Solution content |
|---|
* arithmetic mean of precision and recall 1 0 precision 0 0 recall 0.5 0 * unweighted arithmetic mean * *
|
| File |
|---|
| Weeds.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
private static final Precision PRECISION = new Precision();
<<<<<<< HEAD
@Nonnegative
public static final double DEFAULT_BETA = 0.5;
@Nonnegative
public static final double DEFAULT_GAMMA = 0.5;
@Nonnegative
private double beta;
@Nonnegative
private double gamma;
public Weeds() {
this(DEFAULT_BETA, DEFAULT_GAMMA);
}
public Weeds(@Nonnegative final double beta, @Nonnegative final double gamma) {
setBeta(beta);
setGamma(gamma);
}
public final void setBeta(@Nonnegative final double beta) {
if (beta < 0.0 || beta > 1.0)
throw new IllegalArgumentException(
"beta parameter expected in range 0 to 1, but found " + beta);
this.beta = beta;
}
public final void setGamma(@Nonnegative final double gamma) {
if (gamma < 0 || gamma > 1)
throw new IllegalArgumentException(
"beta parameter expected in range 0 to 1, but found " + gamma);
this.gamma = gamma;
}
@Nonnegative
public final double getBeta() {
return beta;
}
@Nonnegative
public final double getGamma() {
return gamma;
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
assert beta >= 0 && beta <= 1;
assert gamma >= 0 && gamma <= 1;
final double recall = RECALL.similarity(A, B);
final double precision = PRECISION.similarity(A, B);
// arithmetic mean
final double am = (beta * precision) + ((1 - beta) * recall);
// harmonic mean (aka F1 score)
final double hm = (precision + recall) != 0
? (2 * precision * recall) / (precision + recall)
: 0;
final double sim = gamma * hm + (1.0 - gamma) * am;
assert sim >= 0.0 && sim <= 1.0;
return sim;
}
@Override
public boolean isCommutative() {
// If gamma = 1.0 then only then harmonic component is used, hense the
// measure is symetric. Otherwise some portion of the arithimentic
// component is used which is symetric only when beta = 0.5.
return Measures.epsilonEquals(gamma, 1.0)
|| Measures.epsilonEquals(beta, 0.5);
}
@Override
public double getHomogeneityBound() {
return 1.0;
}
@Override
public double getHeterogeneityBound() {
return 0.0;
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositivePMI.class;
}
@Override
public String toString() {
return "Weeds{" + "beta=" + beta + ", gamma=" + gamma + '}';
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Weeds other = (Weeds) obj;
if (Double.doubleToLongBits(this.beta) != Double.doubleToLongBits(
other.beta))
return false;
if (Double.doubleToLongBits(this.gamma) != Double.doubleToLongBits(
other.gamma))
return false;
return true;
}
@Override
public int hashCode() {
int hash = 5;
final long betaBits = Double.doubleToLongBits(this.beta);
final long gammaBits = Double.doubleToLongBits(this.gamma);
hash = 37 * hash + (int) (betaBits ^ (betaBits >>> 32));
hash = 37 * hash + (int) (gammaBits ^ (gammaBits >>> 32));
return hash;
}
=======
@Nonnegative
public static final double DEFAULT_BETA = 0.5;
@Nonnegative
public static final double DEFAULT_GAMMA = 0.5;
@Nonnegative
private double beta;
@Nonnegative
private double gamma;
public Weeds() {
this(DEFAULT_BETA, DEFAULT_GAMMA);
}
public Weeds(@Nonnegative final double beta, @Nonnegative final double gamma) {
setBeta(beta);
setGamma(gamma);
}
public final void setBeta(@Nonnegative final double beta) {
if (beta < 0.0 || beta > 1.0)
throw new IllegalArgumentException(
"beta parameter expected in range 0 to 1, but found "
+ beta);
this.beta = beta;
}
public final void setGamma(@Nonnegative final double gamma) {
if (gamma < 0 || gamma > 1)
throw new IllegalArgumentException(
"beta parameter expected in range 0 to 1, but found "
+ gamma);
this.gamma = gamma;
}
@Nonnegative
public final double getBeta() {
return beta;
}
@Nonnegative
public final double getGamma() {
return gamma;
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
assert beta >= 0 && beta <= 1;
assert gamma >= 0 && gamma <= 1;
final double recall = RECALL.similarity(A, B);
final double precision = PRECISION.similarity(A, B);
// arithmetic mean
final double am = (beta * precision) + ((1 - beta) * recall);
// harmonic mean (aka F1 score)
final double hm = (precision + recall) != 0 ? (2 * precision * recall)
/ (precision + recall) : 0;
final double sim = gamma * hm + (1.0 - gamma) * am;
assert sim >= 0.0 && sim <= 1.0;
return sim;
}
@Override
public boolean isCommutative() {
// If gamma = 1.0 then only then harmonic component is used, hense the
// measure is symetric. Otherwise some portion of the arithimentic
// component is used which is symetric only when beta = 0.5.
return Measures.epsilonEquals(gamma, 1.0)
|| Measures.epsilonEquals(beta, 0.5);
}
@Override
public double getHomogeneityBound() {
return 1.0;
}
@Override
public double getHeterogeneityBound() {
return 0.0;
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositivePMI.class;
}
@Override
public String toString() {
return "Weeds{" + "beta=" + beta + ", gamma=" + gamma + '}';
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Weeds other = (Weeds) obj;
if (Double.doubleToLongBits(this.beta) != Double
.doubleToLongBits(other.beta))
return false;
if (Double.doubleToLongBits(this.gamma) != Double
.doubleToLongBits(other.gamma))
return false;
return true;
}
@Override
public int hashCode() {
int hash = 49;
final long betaBits = Double.doubleToLongBits(this.beta);
final long gammaBits = Double.doubleToLongBits(this.gamma);
hash = 37 * hash + (int) (betaBits ^ (betaBits >>> 32));
hash = 37 * hash + (int) (gammaBits ^ (gammaBits >>> 32));
return hash;
}
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
} |
| Solution content |
|---|
private static final Precision PRECISION = new Precision();
@Nonnegative
public static final double DEFAULT_BETA = 0.5;
@Nonnegative
public static final double DEFAULT_GAMMA = 0.5;
@Nonnegative
private double beta;
@Nonnegative
private double gamma;
public Weeds() {
this(DEFAULT_BETA, DEFAULT_GAMMA);
}
public Weeds(@Nonnegative final double beta, @Nonnegative final double gamma) {
setBeta(beta);
setGamma(gamma);
}
public final void setBeta(@Nonnegative final double beta) {
if (beta < 0.0 || beta > 1.0)
throw new IllegalArgumentException(
"beta parameter expected in range 0 to 1, but found " + beta);
this.beta = beta;
}
public final void setGamma(@Nonnegative final double gamma) {
if (gamma < 0 || gamma > 1)
throw new IllegalArgumentException(
"beta parameter expected in range 0 to 1, but found " + gamma);
this.gamma = gamma;
}
@Nonnegative
public final double getBeta() {
return beta;
}
@Nonnegative
public final double getGamma() {
return gamma;
}
@Override
public double similarity(SparseDoubleVector A, SparseDoubleVector B) {
assert beta >= 0 && beta <= 1;
assert gamma >= 0 && gamma <= 1;
final double recall = RECALL.similarity(A, B);
final double precision = PRECISION.similarity(A, B);
// arithmetic mean
final double am = (beta * precision) + ((1 - beta) * recall);
// harmonic mean (aka F1 score)
final double hm = (precision + recall) != 0
? (2 * precision * recall) / (precision + recall)
: 0;
final double sim = gamma * hm + (1.0 - gamma) * am;
assert sim >= 0.0 && sim <= 1.0;
return sim;
}
@Override
public boolean isCommutative() {
// If gamma = 1.0 then only then harmonic component is used, hense the
// measure is symetric. Otherwise some portion of the arithimentic
// component is used which is symetric only when beta = 0.5.
return Measures.epsilonEquals(gamma, 1.0)
|| Measures.epsilonEquals(beta, 0.5);
}
@Override
public double getHomogeneityBound() {
return 1.0;
}
@Override
public double getHeterogeneityBound() {
return 0.0;
}
@Override
public Class extends Weighting> getExpectedWeighting() {
return PositivePMI.class;
}
@Override
public String toString() {
return "Weeds{" + "beta=" + beta + ", gamma=" + gamma + '}';
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Weeds other = (Weeds) obj;
if (Double.doubleToLongBits(this.beta) != Double.doubleToLongBits(
other.beta))
return false;
if (Double.doubleToLongBits(this.gamma) != Double.doubleToLongBits(
other.gamma))
return false;
return true;
}
@Override
public int hashCode() {
int hash = 5;
final long betaBits = Double.doubleToLongBits(this.beta);
final long gammaBits = Double.doubleToLongBits(this.gamma);
hash = 37 * hash + (int) (betaBits ^ (betaBits >>> 32));
hash = 37 * hash + (int) (gammaBits ^ (gammaBits >>> 32));
return hash;
}
} |
| File |
|---|
| Weeds.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
@Override
public String toString() {
<<<<<<< HEAD
return MessageFormat.format("Bound{{1},{2}}",
getLowerBound(), getUpperBound());
=======
return MessageFormat.format("Bound[{1},{2}]",
getLowerBound(), getUpperBound());
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
}
private boolean equals(Bound that) { |
| Solution content |
|---|
@Override
public String toString() {
return MessageFormat.format("Bound[{1},{2}]",
getLowerBound(), getUpperBound());
}
private boolean equals(Bound that) { |
| File |
|---|
| Bound.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Method invocation |
| Return statement |
| Chunk |
|---|
| Conflicting content |
|---|
import static org.junit.Assert.*;
/**
<<<<<<< HEAD
=======
*
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class TestConstants { |
| Solution content |
|---|
import static org.junit.Assert.*;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class TestConstants { |
| File |
|---|
| TestConstants.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
*/
public class TestConstants {
<<<<<<< HEAD
public static List |
| Solution content |
|---|
*/
public class TestConstants {
public static List |
| File |
|---|
| TestConstants.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Attribute |
| Method declaration |
| Method invocation |
| Chunk |
|---|
| Conflicting content |
|---|
public static final File TEST_FRUIT_DIR = TEST_DATA_DIR;
<<<<<<< HEAD
public static final File TEST_FRUIT_ENTRIES_FILTERED =
new File(TEST_FRUIT_ENTRIES.getParentFile(), TEST_FRUIT_ENTRIES.
getName() + ".filtered");
public static final File TEST_FRUIT_FEATURES_FILTERED =
new File(TEST_FRUIT_FEATURES.getParentFile(), TEST_FRUIT_FEATURES.
getName() + ".filtered");
public static final File TEST_FRUIT_EVENTS_FILTERED =
new File(TEST_FRUIT_EVENTS.getParentFile(),
TEST_FRUIT_EVENTS.getName() + ".filtered");
public static final File TEST_FRUIT_SIMS =
new File(TEST_FRUIT_DIR, FRUIT_NAME + ".sims");
public static final File TEST_FRUIT_SIMS_100NN =
new File(TEST_FRUIT_DIR, TEST_FRUIT_SIMS.getName() + ".100nn");
public static final File TEST_FRUIT_INDEXED_ENTRIES =
new File(TEST_FRUIT_DIR, FRUIT_NAME + ".indexed.entries");
public static final File TEST_FRUIT_SKIP_INDEXED_ENTRIES =
new File(TEST_FRUIT_DIR, FRUIT_NAME + ".skipindexed.entries");
public static final File TEST_FRUIT_INDEXED_FEATURES =
new File(TEST_FRUIT_DIR, FRUIT_NAME + ".indexed.features");
public static final File TEST_FRUIT_SKIP_INDEXED_FEATURES =
new File(TEST_FRUIT_DIR, FRUIT_NAME + ".skipindexed.features");
public static final File TEST_FRUIT_INDEXED_EVENTS =
new File(TEST_FRUIT_DIR, FRUIT_NAME + ".indexed.events");
public static final File TEST_FRUIT_SKIP_INDEXED_EVENTS =
new File(TEST_FRUIT_DIR, FRUIT_NAME + ".skipindexed.events");
public static final File TEST_FRUIT_INDEXED_SIMS =
new File(TEST_FRUIT_DIR, FRUIT_NAME + ".indexed.sims");
public static final File TEST_FRUIT_INDEXED_SIMS_100NN =
new File(TEST_FRUIT_DIR, FRUIT_NAME + ".indexed.sims.100nn");
public static final File TEST_OUTPUT_DIR = new File("target/test-out");
public static final File TEST_TMP_DIR = new File(TEST_OUTPUT_DIR, "temp");
public static final Charset DEFAULT_CHARSET = Files.DEFAULT_CHARSET;
static {
if (!TEST_OUTPUT_DIR.exists() && !TEST_OUTPUT_DIR.mkdir())
throw new AssertionError();
if (!TEST_TMP_DIR.exists() && !TEST_TMP_DIR.mkdir())
throw new AssertionError();
}
static final Random RAND = new Random();
public static File makeTempFile(int size) throws IOException {
final File file = File.createTempFile(
TestConstants.class.getName(), ".tmp");
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
byte[] data = new byte[1024];
RAND.nextBytes(data);
int i = 0;
while (i < size) {
out.write(data, 0, Math.min(data.length, size - i));
i += data.length;
}
} finally {
if (out != null) {
Flushables.flushQuietly(out);
Closeables.closeQuietly(out);
}
}
return file;
}
public static void assertValidInputFiles(File... files) throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
assertTrue(format("Input file does not exist: \"{0}\" ", file),
file.exists());
assertTrue(
format("Input file is not a regular file: \"{0}\" ", file),
file.isFile());
assertTrue(format("Input file is empty: ", file) + file,
file.length() > 0);
}
}
public static void assertValidPlaintextInputFiles(File... files) throws IOException {
assertValidInputFiles(files);
for (File file : files) {
// The last character should be a newline.
RandomAccessFile raf = new RandomAccessFile(file, "r");
raf.seek(file.length() - 1);
int ch = raf.read();
assertEquals(format(
"Expecting newline chracter at end of inout file: \"{0}\"",
file), ch, '\n');
raf.close();
}
}
public static void assertValidJDBMInputFiles(File... files) throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
// File trans = new File(file.getParentFile(), file.getName() + ".t");
assertValidInputFiles(data, index);
}
}
public static void assertValidIndexInputFiles(File... files) throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
// File trans = new File(file.getParentFile(), file.getName() + ".t");
assertValidInputFiles(data, index);
}
}
public static void assertValidOutputFiles(File... files) throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
if (file.exists()) {
assertTrue(format("Input file is not a regular: \"{0}\"", file),
file.isFile());
assertTrue(format("Input file is not writable: \"{0}\"", file),
file.canWrite());
} else {
assertTrue(format("Cannot be created: \"{0}\"", file),
file.getParentFile().canWrite());
}
}
}
public static void assertValidJDBMOutputFiles(File... files) throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
File trans = new File(file.getParentFile(), file.getName() + ".t");
assertValidOutputFiles(data, index, trans);
}
}
public static void assertSizeGT(File bigger, File smaller) throws IOException {
assertValidPlaintextInputFiles(bigger, smaller);
assertTrue(
format("\"{0}\" is not smaller than \"{1}\"", smaller, bigger),
bigger.length() > smaller.length());
}
public static void deleteIfExist(File... files) throws IOException {
for (File file : files) {
if (file.exists()) {
boolean deleted = file.delete();
if (!deleted)
throw new IOException("Failed to delete file " + file);
}
}
}
public static void deleteJDBMIfExist(File... files) throws IOException {
for (File file : files) {
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
File trans = new File(file.getParentFile(), file.getName() + ".t");
deleteIfExist(data, index, trans);
}
}
public static File suffix(File file, String suffix) {
return new File(file.getParentFile(), file.getName() + suffix);
}
public static class InfoProgressListener implements ProgressListener {
private long tick = System.currentTimeMillis();
@Override
public void progressChanged(final ProgressEvent progressEvent) {
System.out.println(MiscUtil.memoryInfoString());
long newTick = System.currentTimeMillis();
double timeDiff = (newTick - tick) / 1000.0d;
tick = newTick;
System.out
.println(MessageFormat.format("Tick: {0} seconds", timeDiff));
//
// MemoryUsage mu = new MemoryUsage();
// mu.add(progressEvent.getSource());
// mu.add(this);
// System.out.println(progressEvent.getSource());
// System.out.println(mu.getInfoString());
}
}
/**
* Routine that creates a large amount of data, that should be the absolute
* worst case for counting stage of the pipeline. That is data where entries
* and features only ever appear once, and consequently events also are
* unique. This causes the counting maps to be at the upper bound of their
* potential size.
*
* @throws IOException
*/
public static void generateUniqueInstanceData(
final File outFile, final int nEntries,
final int nFeaturesPerEntry) throws IOException {
assert nEntries < Integer.MAX_VALUE / nFeaturesPerEntry
: "number of events must be less than max_integer";
final int nEvents = nEntries * nFeaturesPerEntry;
System.out.printf("Generating worst-case data for ExternalCount " +
"(nEntries=%d, nFeaturesPerEntry=%d, nEvents=%d)...%n",
nEntries, nFeaturesPerEntry, nEvents);
TokenPairSink sink = null;
try {
final DoubleEnumeratingDelegate ded = new DoubleEnumeratingDelegate(
Enumerating.DEFAULT_TYPE, true, true, null, null);
sink = BybloIO.openInstancesSink(outFile, DEFAULT_CHARSET, ded);
for (int entryId = 0; entryId < nEntries; entryId++) {
final int startId = entryId * nFeaturesPerEntry;
final int endId = (entryId + 1) * nFeaturesPerEntry;
for (int featureId = startId; featureId < endId; featureId++) {
sink.write(new TokenPair(entryId, featureId));
if (featureId % 5000000 == 0 || featureId == nEvents - 1) {
System.out.printf("> generated %d of %d events (%.2f%% complete)%n",
featureId, nEvents, (100.0d * featureId) / nEvents);
}
}
}
} finally {
if (sink != null)
sink.close();
}
System.out.println("Generation completed.");
}
=======
public static final String FRUIT_NAME = "bnc-gramrels-fruit";
public static final File TEST_FRUIT_INPUT = new File(TEST_FRUIT_DIR,
FRUIT_NAME);
public static final File TEST_FRUIT_INPUT_INDEXED = new File(
TEST_FRUIT_DIR, FRUIT_NAME + ".indexed");
public static final File TEST_FRUIT_ENTRY_INDEX = new File(TEST_FRUIT_DIR,
FRUIT_NAME + ".entry-index");
public static final File TEST_FRUIT_FEATURE_INDEX = new File(
TEST_FRUIT_DIR, FRUIT_NAME + ".feature-index");
public static final File TEST_FRUIT_ENTRIES = new File(TEST_FRUIT_DIR,
FRUIT_NAME + ".entries");
public static final File TEST_FRUIT_FEATURES = new File(TEST_FRUIT_DIR,
FRUIT_NAME + ".features");
public static final File TEST_FRUIT_EVENTS = new File(TEST_FRUIT_DIR,
FRUIT_NAME + ".events");
public static final File TEST_FRUIT_ENTRIES_FILTERED = new File(
TEST_FRUIT_ENTRIES.getParentFile(), TEST_FRUIT_ENTRIES.getName()
+ ".filtered");
public static final File TEST_FRUIT_FEATURES_FILTERED = new File(
TEST_FRUIT_FEATURES.getParentFile(), TEST_FRUIT_FEATURES.getName()
+ ".filtered");
public static final File TEST_FRUIT_EVENTS_FILTERED = new File(
TEST_FRUIT_EVENTS.getParentFile(), TEST_FRUIT_EVENTS.getName()
+ ".filtered");
public static final File TEST_FRUIT_SIMS = new File(TEST_FRUIT_DIR,
FRUIT_NAME + ".sims");
public static final File TEST_FRUIT_SIMS_100NN = new File(TEST_FRUIT_DIR,
TEST_FRUIT_SIMS.getName() + ".100nn");
public static final File TEST_FRUIT_INDEXED_ENTRIES = new File(
TEST_FRUIT_DIR, FRUIT_NAME + ".indexed.entries");
public static final File TEST_FRUIT_SKIPINDEXED_ENTRIES = new File(
TEST_FRUIT_DIR, FRUIT_NAME + ".skipindexed.entries");
public static final File TEST_FRUIT_INDEXED_FEATURES = new File(
TEST_FRUIT_DIR, FRUIT_NAME + ".indexed.features");
public static final File TEST_FRUIT_SKIPINDEXED_FEATURES = new File(
TEST_FRUIT_DIR, FRUIT_NAME + ".skipindexed.features");
public static final File TEST_FRUIT_INDEXED_EVENTS = new File(
TEST_FRUIT_DIR, FRUIT_NAME + ".indexed.events");
public static final File TEST_FRUIT_SKIPINDEXED_EVENTS = new File(
TEST_FRUIT_DIR, FRUIT_NAME + ".skipindexed.events");
public static final File TEST_FRUIT_INDEXED_SIMS = new File(TEST_FRUIT_DIR,
FRUIT_NAME + ".indexed.sims");
public static final File TEST_FRUIT_INDEXED_SIMS_100NN = new File(
TEST_FRUIT_DIR, FRUIT_NAME + ".indexed.sims.100nn");
public static final File TEST_OUTPUT_DIR = new File("target/test-out");
public static final File TEST_TMP_DIR = new File(TEST_OUTPUT_DIR, "temp");
public static final Charset DEFAULT_CHARSET = Files.DEFAULT_CHARSET;
;
static {
if (!TEST_OUTPUT_DIR.exists() && !TEST_OUTPUT_DIR.mkdir())
throw new AssertionError();
if (!TEST_TMP_DIR.exists() && !TEST_TMP_DIR.mkdir())
throw new AssertionError();
}
static final Random RAND = new Random();
public static File makeTempFile(int size) throws IOException {
final File file = File.createTempFile(TestConstants.class.getName(),
".tmp");
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
byte[] data = new byte[1024];
RAND.nextBytes(data);
int i = 0;
while (i < size) {
out.write(data, 0, Math.min(data.length, size - i));
i += data.length;
}
} finally {
if (out != null) {
Flushables.flushQuietly(out);
Closeables.closeQuietly(out);
}
}
return file;
}
public static void assertValidInputFiles(File... files) throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
assertTrue(format("Input file is null: \"{0}\"", file),
file != null);
assertTrue(format("Input file does not exist: \"{0}\" ", file),
file.exists());
assertTrue(
format("Input file is not a regular file: \"{0}\" ", file),
file.isFile());
assertTrue(format("Input file is empty: ", file) + file,
file.length() > 0);
}
}
public static void assertValidPlaintextInputFiles(File... files)
throws IOException {
assertValidInputFiles(files);
for (File file : files) {
// The last character should be a newline.
RandomAccessFile raf = new RandomAccessFile(file, "r");
raf.seek(file.length() - 1);
int ch = raf.read();
assertEquals(
format("Expecting newline chracter at end of inout file: \"{0}\"",
file), ch, '\n');
raf.close();
}
}
public static void assertValidJDBMInputFiles(File... files)
throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
assertTrue(format("Input file is null: \"{0}\"", file),
file != null);
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
// File trans = new File(file.getParentFile(), file.getName() +
// ".t");
assertValidInputFiles(data, index);
}
}
public static void assertValidIndexInputFiles(File... files)
throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
assertTrue(format("Input file is null: \"{0}\"", file),
file != null);
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
// File trans = new File(file.getParentFile(), file.getName() +
// ".t");
assertValidInputFiles(data, index);
}
}
public static void assertValidOutputFiles(File... files) throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
if (file.exists()) {
assertTrue(
format("Input file is not a regular: \"{0}\"", file),
file.isFile());
assertTrue(
format("Input file is not writeable: \"{0}\"", file),
file.canWrite());
} else {
assertTrue(format("Cannot be created: \"{0}\"", file), file
.getParentFile().canWrite());
}
}
}
public static void assertValidJDBMOutputFiles(File... files)
throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
File trans = new File(file.getParentFile(), file.getName() + ".t");
assertValidOutputFiles(data, index, trans);
}
}
public static void assertSizeGT(File bigger, File smaller)
throws IOException {
assertValidPlaintextInputFiles(bigger, smaller);
assertTrue(
format("\"{0}\" is not smaller than \"{1}\"", smaller, bigger),
bigger.length() > smaller.length());
}
public static void deleteIfExist(File... files) throws IOException {
for (File file : files) {
if (file.exists()) {
boolean deleted = file.delete();
if (!deleted)
throw new IOException("Failed to delete file " + file);
}
}
}
public static void deleteJDBMIfExist(File... files) throws IOException {
for (File file : files) {
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
File trans = new File(file.getParentFile(), file.getName() + ".t");
deleteIfExist(data, index, trans);
}
}
public static File suffix(File file, String suffix) {
return new File(file.getParentFile(), file.getName() + suffix);
}
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
} |
| Solution content |
|---|
public static final File TEST_OUTPUT_DIR = new File("target/test-out");
public static final File TEST_TMP_DIR = new File(TEST_OUTPUT_DIR, "temp");
public static final Charset DEFAULT_CHARSET = Files.DEFAULT_CHARSET;
;
static {
if (!TEST_OUTPUT_DIR.exists() && !TEST_OUTPUT_DIR.mkdir())
throw new AssertionError();
if (!TEST_TMP_DIR.exists() && !TEST_TMP_DIR.mkdir())
throw new AssertionError();
}
static final Random RAND = new Random();
public static File makeTempFile(int size) throws IOException {
final File file = File.createTempFile(TestConstants.class.getName(),
".tmp");
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
byte[] data = new byte[1024];
RAND.nextBytes(data);
int i = 0;
while (i < size) {
out.write(data, 0, Math.min(data.length, size - i));
i += data.length;
}
} finally {
if (out != null) {
Flushables.flushQuietly(out);
Closeables.closeQuietly(out);
}
}
return file;
}
public static void assertValidInputFiles(File... files) throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
assertTrue(format("Input file is null: \"{0}\"", file),
file != null);
assertTrue(format("Input file does not exist: \"{0}\" ", file),
file.exists());
assertTrue(
format("Input file is not a regular file: \"{0}\" ", file),
file.isFile());
assertTrue(format("Input file is empty: ", file) + file,
file.length() > 0);
}
}
public static void assertValidPlaintextInputFiles(File... files)
throws IOException {
assertValidInputFiles(files);
for (File file : files) {
// The last character should be a newline.
RandomAccessFile raf = new RandomAccessFile(file, "r");
raf.seek(file.length() - 1);
int ch = raf.read();
assertEquals(
format("Expecting newline chracter at end of inout file: \"{0}\"",
file), ch, '\n');
raf.close();
}
}
public static void assertValidJDBMInputFiles(File... files)
throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
assertTrue(format("Input file is null: \"{0}\"", file),
file != null);
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
// File trans = new File(file.getParentFile(), file.getName() +
// ".t");
assertValidInputFiles(data, index);
}
}
public static void assertValidIndexInputFiles(File... files)
throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
assertTrue(format("Input file is null: \"{0}\"", file),
file != null);
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
// File trans = new File(file.getParentFile(), file.getName() +
// ".t");
assertValidInputFiles(data, index);
}
}
public static void assertValidOutputFiles(File... files) throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
if (file.exists()) {
assertTrue(
format("Input file is not a regular: \"{0}\"", file),
file.isFile());
assertTrue(
format("Input file is not writeable: \"{0}\"", file),
file.canWrite());
} else {
assertTrue(format("Cannot be created: \"{0}\"", file), file
.getParentFile().canWrite());
}
}
}
public static void assertValidJDBMOutputFiles(File... files)
throws IOException {
for (File file : files) {
assertNotNull("File is null.", file);
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
File trans = new File(file.getParentFile(), file.getName() + ".t");
assertValidOutputFiles(data, index, trans);
}
}
public static void assertSizeGT(File bigger, File smaller)
throws IOException {
assertValidPlaintextInputFiles(bigger, smaller);
assertTrue(
format("\"{0}\" is not smaller than \"{1}\"", smaller, bigger),
bigger.length() > smaller.length());
}
public static void deleteIfExist(File... files) throws IOException {
for (File file : files) {
if (file.exists()) {
boolean deleted = file.delete();
if (!deleted)
throw new IOException("Failed to delete file " + file);
}
}
}
public static void deleteJDBMIfExist(File... files) throws IOException {
for (File file : files) {
File data = new File(file.getParentFile(), file.getName() + ".d.0");
File index = new File(file.getParentFile(), file.getName() + ".i.0");
File trans = new File(file.getParentFile(), file.getName() + ".t");
deleteIfExist(data, index, trans);
}
}
public static File suffix(File file, String suffix) {
return new File(file.getParentFile(), file.getName() + suffix);
}
public static class InfoProgressListener implements ProgressListener {
private long tick = System.currentTimeMillis();
@Override
public void progressChanged(final ProgressEvent progressEvent) {
System.out.println(MiscUtil.memoryInfoString());
long newTick = System.currentTimeMillis();
double timeDiff = (newTick - tick) / 1000.0d;
tick = newTick;
System.out
.println(MessageFormat.format("Tick: {0} seconds", timeDiff));
//
// MemoryUsage mu = new MemoryUsage();
// mu.add(progressEvent.getSource());
// mu.add(this);
// System.out.println(progressEvent.getSource());
// System.out.println(mu.getInfoString());
}
}
/**
* Routine that creates a large amount of data, that should be the absolute
* worst case for counting stage of the pipeline. That is data where entries
* and features only ever appear once, and consequently events also are
* unique. This causes the counting maps to be at the upper bound of their
* potential size.
*
* @throws IOException
*/
public static void generateUniqueInstanceData(
final File outFile, final int nEntries,
final int nFeaturesPerEntry) throws IOException {
assert nEntries < Integer.MAX_VALUE / nFeaturesPerEntry
: "number of events must be less than max_integer";
final int nEvents = nEntries * nFeaturesPerEntry;
System.out.printf("Generating worst-case data for ExternalCount " +
"(nEntries=%d, nFeaturesPerEntry=%d, nEvents=%d)...%n",
nEntries, nFeaturesPerEntry, nEvents);
TokenPairSink sink = null;
try {
final DoubleEnumeratingDelegate ded = new DoubleEnumeratingDelegate(
Enumerating.DEFAULT_TYPE, true, true, null, null);
sink = BybloIO.openInstancesSink(outFile, DEFAULT_CHARSET, ded);
for (int entryId = 0; entryId < nEntries; entryId++) {
final int startId = entryId * nFeaturesPerEntry;
final int endId = (entryId + 1) * nFeaturesPerEntry;
for (int featureId = startId; featureId < endId; featureId++) {
sink.write(new TokenPair(entryId, featureId));
if (featureId % 5000000 == 0 || featureId == nEvents - 1) {
System.out.printf("> generated %d of %d events (%.2f%% complete)%n",
featureId, nEvents, (100.0d * featureId) / nEvents);
}
}
}
} finally {
if (sink != null)
sink.close();
}
System.out.println("Generation completed.");
}
} |
| File |
|---|
| TestConstants.java |
| Developer's decision |
|---|
| Combination |
| Kind of conflict |
|---|
| Attribute |
| Class declaration |
| Comment |
| Method declaration |
| Method invocation |
| Static initializer |
| Chunk |
|---|
| Conflicting content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; <<<<<<< HEAD import org.junit.BeforeClass; import org.junit.Test; import uk.ac.susx.mlcl.byblo.Tools; ======= import static uk.ac.susx.mlcl.TestConstants.DEFAULT_CHARSET; import static uk.ac.susx.mlcl.TestConstants.TEST_FRUIT_FEATURES; import java.io.IOException; import java.util.Arrays; import java.util.List; import javax.naming.OperationNotSupportedException; import junit.framework.Assert; import org.junit.Ignore; import org.junit.Test; import uk.ac.susx.mlcl.TestConstants; >>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56 import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating; import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate; import uk.ac.susx.mlcl.byblo.enumerators.EnumeratingDelegates; |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import org.junit.Ignore; import org.junit.Test; import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating; import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate; import uk.ac.susx.mlcl.byblo.enumerators.EnumeratingDelegates; |
| File |
|---|
| ConfusionTest.java |
| Developer's decision |
|---|
| Combination |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
}
@Test
import uk.ac.susx.mlcl.byblo.weighings.MarginalDistribution;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
<<<<<<< HEAD
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class ConfusionTest {
static Confusion INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
static List |
| Solution content |
|---|
import uk.ac.susx.mlcl.byblo.weighings.MarginalDistribution; import java.io.IOException; import static uk.ac.susx.mlcl.TestConstants.DEFAULT_CHARSET; import static uk.ac.susx.mlcl.TestConstants.TEST_FRUIT_FEATURES; /** * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class ConfusionTest extends AbstractMeasureTest |
| File |
|---|
| ConfusionTest.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| If statement |
| Import |
| Method declaration |
| Method invocation |
| Method signature |
| Variable |
| Chunk |
|---|
| Conflicting content |
|---|
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class CosineTest {
static Cosine INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new Cosine();
RANDOM = new Random(1234);
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME + ".Cosine");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "Cosine",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, RANDOM.nextDouble());
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
=======
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
/**
*
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class CosineTest extends AbstractMeasureTest |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import static org.junit.Assert.assertEquals; import org.junit.Test; import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class CosineTest extends AbstractMeasureTest |
| File |
|---|
| CosineTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
@Test
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class DiceTest {
static Dice INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new Dice();
RANDOM = new Random(1234);
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME + ".Dice");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "Dice",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, RANDOM.nextDouble());
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
public void testHeteroginiety() throws Exception {
System.out.println("testHeteroginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size / 2; i++) {
A.set(i * 2, i);
B.set(i * 2 + 1, i);
}
double expect = INSTANCE.getHeterogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
int limit = 5;
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class DiceTest extends AbstractMeasureTest |
| File |
|---|
| DiceTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
return "dice";
}
<<<<<<< HEAD
public double test(SparseDoubleVector A, SparseDoubleVector B) {
final double val = INSTANCE.similarity(A, B);
assertFalse("Similarity is NaN", Double.isNaN(val));
assertFalse("Similarity is " + val, Double.isInfinite(val));
assertTrue("Similarity < -1", val >= INSTANCE.getHeterogeneityBound());
assertTrue("Similarity > +1", val <= INSTANCE.getHomogeneityBound());
return val;
}
=======
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
} |
| Solution content |
|---|
return "dice"; } } |
| File |
|---|
| DiceTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
}
A.set(1, 1);
Tools.main(new String[]{
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
B.set(0, 1);
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class DotProductTest {
static DotProduct INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new DotProduct();
RANDOM = new Random(1234);
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME + ".DotProduct");
deleteIfExist(output);
try {
enableExistTrapping();
"allpairs",
"--charset", "UTF-8",
"--measure", "dp",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, RANDOM.nextDouble());
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
B.set(1, 1);
double expect = 2;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
@Test
public void testHeteroginiety() throws Exception {
System.out.println("testHeteroginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size / 2; i++) {
A.set(i * 2, i);
B.set(i * 2 + 1, i);
}
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
int limit = 5;
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import static org.junit.Assert.assertEquals; import junit.framework.Assert; import org.junit.Ignore; import org.junit.Test; import uk.ac.susx.mlcl.byblo.measures.Measure; import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class DotProductTest extends AbstractMeasureTest |
| File |
|---|
| DotProductTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class HindleTest {
static Hindle INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new Hindle();
RANDOM = new Random(1234);
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME + ".Hindle");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "hindle",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int limit = 5;
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, RANDOM.nextDouble());
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = 2;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHeteroginiety() throws Exception {
System.out.println("testHeteroginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size / 2; i++) {
A.set(i * 2, i);
B.set(i * 2 + 1, i);
}
double expect = INSTANCE.getHeterogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import junit.framework.Assert; import org.junit.Ignore; import org.junit.Test; import uk.ac.susx.mlcl.byblo.measures.Measure; import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class HindleTest extends AbstractMeasureTest |
| File |
|---|
| HindleTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.*;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class JaccardTest {
static Jaccard INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new Jaccard();
RANDOM = new Random(1234);
}
@Test
public void testJaccardCLI() throws Exception {
System.out.println("testJaccardCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME + ".Jaccard");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "Jaccard",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
/**
* http://people.revoledu.com/kardi/tutorial/Similarity/Jaccard.html
*/
@Test
public void testJaccardExample1() {
System.out.println("testJaccardExample1");
double[] objectA = new double[]{1, 1, 1, 1};
double[] objectB = new double[]{0, 1, 0, 0};
int p = 1; // number of variables that positive for both objects
int q = 3; // number of variables that positive for the th objects and negative for the th object
int r = 0; // number of variables that negative for the th objects and positive for the th object
int s = 0; // number of variables that negative for both objects
// int t = p + q + r + s; // total number of variables
// double jaccardDistance = (double) (q + r) / (double) (p + q + r);
double jaccardCoef = (double) p / (double) (p + q + r);
SparseDoubleVector vecA = SparseDoubleVector.from(objectA);
SparseDoubleVector vecB = SparseDoubleVector.from(objectB);
double result = INSTANCE.combine(INSTANCE.shared(vecA, vecB),
INSTANCE.left(vecA),
INSTANCE.left(vecB));
assertEquals(jaccardCoef, result, 0.0001);
}
/**
* http://people.revoledu.com/kardi/tutorial/Similarity/Jaccard.html
*/
@Test
public void testJaccardExample2() {
System.out.println("testJaccardExample2");
Set |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import org.junit.Test; import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class JaccardTest extends AbstractMeasureTest |
| File |
|---|
| JaccardTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
// @Test
assertEquals(expect, actual, EPSILON);
}
//
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class JensenShannonDivergenceTest {
static JensenShannonDivergence INSTANCE;
static final double EPSILON = 1E-15;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new JensenShannonDivergence();
RANDOM = new Random(1234);
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME
+ ".JensenShannonDivergence");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "js",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
// public void testOneEmptyVector() throws Exception {
// System.out.println("testOneEmptyVector");
// int size = 100;
// SparseDoubleVector A = new SparseDoubleVector(size, 0);
// SparseDoubleVector B = new SparseDoubleVector(size, size);
// for (int i = 0; i < size; i++)
// B.set(i, RANDOM.nextDouble());
//
// double expect = 0;
// double actual = test(A, B);
//
// assertEquals(expect, actual, EPSILON);
// }
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
//
// @Test
// public void testCardinalityOneVectors() throws Exception {
// System.out.println("testCardinalityOneVectors");
// SparseDoubleVector A = new SparseDoubleVector(1, 1);
// SparseDoubleVector B = new SparseDoubleVector(1, 1);
// A.set(0, 1);
// B.set(0, 1);
// double expect = 1;
// double actual = test(A, B);
//
// assertEquals(expect, actual, EPSILON);
// }
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
if (INSTANCE.isCommutative()) {
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
//
// @Test
// public void testHeteroginiety() throws Exception {
// System.out.println("testHeteroginiety");
// int size = 100;
// SparseDoubleVector A = new SparseDoubleVector(size, size);
// SparseDoubleVector B = new SparseDoubleVector(size, size);
// for (int i = 0; i < size / 2; i++) {
// A.set(i * 2, i);
// B.set(i * 2 + 1, i);
// }
//
// double expect = INSTANCE.getHeterogeneityBound();
// double actual = test(A, B);
//
// assertEquals(expect, actual, EPSILON);
// }
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
int limit = 5;
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import java.util.Random; import junit.framework.Assert; import org.junit.Test; import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class JensenShannonDivergenceTest extends AbstractMeasureTest |
| File |
|---|
| JensenShannonDivergenceTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.*;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
=======
import java.util.Random;
import javax.annotation.CheckReturnValue;
import junit.framework.Assert;
import org.junit.Ignore;
import org.junit.Test;
import uk.ac.susx.mlcl.byblo.measures.Measure;
import uk.ac.susx.mlcl.byblo.weighings.Weighting;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
/**
* Unit tests for {@link KendallsTau } proximity measure. |
| Solution content |
|---|
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
import java.util.Random;
import javax.annotation.CheckReturnValue;
import junit.framework.Assert;
import org.junit.Ignore;
import org.junit.Test;
import uk.ac.susx.mlcl.byblo.measures.Measure;
import uk.ac.susx.mlcl.byblo.weighings.Weighting;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
/**
* Unit tests for {@link KendallsTau } proximity measure. |
| File |
|---|
| KendallsTauTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
/**
* Unit tests for {@link KendallsTau } proximity measure.
*
<<<<<<< HEAD
*
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class KendallsTauTest {
public KendallsTauTest() {
}
static KendallsTau INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new KendallsTau();
RANDOM = new Random(1234);
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME + ".KendallsTau");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "tau",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = INSTANCE.getIndependenceBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, RANDOM.nextDouble());
double expect = INSTANCE.getIndependenceBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, RANDOM.nextDouble());
B.set(0, RANDOM.nextDouble());
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, RANDOM.nextDouble());
B.set(0, RANDOM.nextDouble());
double expect = INSTANCE.getIndependenceBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, RANDOM.nextDouble());
A.set(1, 1 + RANDOM.nextDouble());
B.set(0, RANDOM.nextDouble());
B.set(1, 1 + RANDOM.nextDouble());
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHeteroginiety() throws Exception {
System.out.println("testHeteroginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, i);
B.set(i, size - i);
}
=======
*
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class KendallsTauTest extends AbstractMeasureTest |
| Solution content |
|---|
/**
* Unit tests for {@link KendallsTau } proximity measure.
*
*
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class KendallsTauTest extends AbstractMeasureTest |
| File |
|---|
| KendallsTauTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| For statement |
| Method declaration |
| Method invocation |
| Method signature |
| Variable |
| Chunk |
|---|
| Conflicting content |
|---|
return cordance / denom;
}
<<<<<<< HEAD
static double tauB_naive1(SparseDoubleVector A, SparseDoubleVector B) {
assert A.cardinality == B.cardinality :
"Cardinalities not equal " + A.cardinality + " != "
+ B.cardinality;
=======
@Override
@CheckReturnValue
public double getHomogeneityBound() {
throw new UnsupportedOperationException();
}
//
// @Override
// public double getIndependenceBound() {
// throw new UnsupportedOperationException();
// }
>>>>>>> 5f0ba9177b34449ea27dabdc17fd0793620c7d56
@Override
@CheckReturnValue |
| Solution content |
|---|
return cordance / denom;
}
@Override
@CheckReturnValue
public double getHomogeneityBound() {
throw new UnsupportedOperationException();
}
//
// @Override
// public double getIndependenceBound() {
// throw new UnsupportedOperationException();
// }
@Override
@CheckReturnValue |
| File |
|---|
| KendallsTauTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Assert statement |
| Comment |
| Method declaration |
| Method signature |
| Chunk |
|---|
| Conflicting content |
|---|
throw new UnsupportedOperationException();
}
<<<<<<< HEAD
static List |
| Solution content |
|---|
throw new UnsupportedOperationException();
}
}
//
// //
// // static double tauA_naive1(SparseDoubleVector A, SparseDoubleVector B)
// {
// // assert A.cardinality == B.cardinality :
// // "Cardinalities not equal " + A.cardinality + " != " + B.cardinality;
// //
// // final int n = A.cardinality;
// // double result = 0;
// // for (int i = 1; i < n; i++) {
// // for (int j = 0; j < i; j++) {
// // result += Math.signum(A.get(i) - A.get(j))
// // * Math.signum(B.get(i) - B.get(j));
// // }
// // }
// // double denom = 0.5 * n * (n - 1);
// //
// // return result / denom;
// // }
// //
// // @Test
// // @Ignore
// // public void testThing() throws Exception {
// // System.out.println("test");
// //
// // DoubleEnumerating indexDelegate = new DoubleEnumeratingDelegate();
// // FastWeightedTokenPairVectorSource eventSrc =
// // BybloIO.openEventsVectorSource(
// // TEST_FRUIT_EVENTS, DEFAULT_CHARSET, indexDelegate);
// //
// // List |
| File |
|---|
| KendallsTauTest.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Comment |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
});
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class KullbackLeiblerDivergenceTest {
static KullbackLeiblerDivergence INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new KullbackLeiblerDivergence();
RANDOM = new Random(1234);
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR,
FRUIT_NAME + ".KullbackLeiblerDivergence");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "kl",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
int limit = 5;
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import junit.framework.Assert; import org.junit.Ignore; import org.junit.Test; import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class KullbackLeiblerDivergenceTest extends AbstractMeasureTest |
| File |
|---|
| KullbackLeiblerDivergenceTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
}
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class LambdaDivergenceTest {
static LambdaDivergence INSTANCE;
static final double EPSILON = 0.000000000001;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new LambdaDivergence();
RANDOM = new Random(1234);
}
@Test
public void testCLI_001() throws Exception {
testCLI(0.01);
}
@Test
public void testCLI_010() throws Exception {
testCLI(0.10);
}
@Test
public void testCLI_050() throws Exception {
testCLI(0.50);
}
@Test
public void testCLI_090() throws Exception {
testCLI(0.90);
}
@Test
public void testCLI_099() throws Exception {
testCLI(0.99);
}
public void testCLI(final double lambda) throws Exception {
System.out.printf("testCLI(lambda=%.2f)%n", lambda);
File output = new File(TEST_OUTPUT_DIR,
FRUIT_NAME
+ String.format(".LambdaDivergence-lambda%03d",
(int) (lambda * 100)));
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "lambda",
"--lambda-lambda", Double.toString(lambda),
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, 1);
}
double expect = 0.5;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHeteroginiety() throws Exception {
System.out.println("testHeteroginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size / 2; i++) {
A.set(i * 2, i);
B.set(i * 2 + 1, i);
}
double expect = INSTANCE.getHeterogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
int limit = 5;
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import java.util.Random; import junit.framework.Assert; import org.junit.Test; import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class LambdaDivergenceTest extends AbstractMeasureTest |
| File |
|---|
| LambdaDivergenceTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class LeeSkewDivergenceTest {
static LeeSkewDivergence INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new LeeSkewDivergence();
RANDOM = new Random(1234);
}
@Test
public void testCLI_001() throws Exception {
testCLI(0.01);
}
@Test
public void testCLI_010() throws Exception {
testCLI(0.10);
}
@Test
public void testCLI_050() throws Exception {
testCLI(0.50);
}
@Test
public void testCLI_090() throws Exception {
testCLI(0.90);
}
@Test
public void testCLI_099() throws Exception {
testCLI(0.99);
}
public void testCLI(double alpha) throws Exception {
System.out.printf("testCLI(alpha=%.2f)%n", alpha);
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME
+ String.format(".Lee-%03d", (int) (alpha * 100)));
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "lee",
"--lee-alpha", Double.toString(alpha),
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
int limit = 5;
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import junit.framework.Assert; import org.junit.Ignore; import org.junit.Test; import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class LeeSkewDivergenceTest extends AbstractMeasureTest |
| File |
|---|
| LeeSkewDivergenceTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| If statement |
| Import |
| Method declaration |
| Method invocation |
| Method signature |
| Variable |
| Chunk |
|---|
| Conflicting content |
|---|
@BeforeClass
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class LinTest {
static Lin INSTANCE;
static final double EPSILON = 0.0000000001;
static Random RANDOM;
public static void setUpClass() throws Exception {
INSTANCE = new Lin();
RANDOM = new Random(1234);
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME + ".Lin");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "lin",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, RANDOM.nextDouble());
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHeteroginiety() throws Exception {
System.out.println("testHeteroginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size / 2; i++) {
A.set(i * 2, i);
B.set(i * 2 + 1, i);
}
double expect = INSTANCE.getHeterogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
int limit = 5;
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class LinTest extends AbstractMeasureTest |
| File |
|---|
| LinTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| If statement |
| Import |
| Method declaration |
| Method invocation |
| Method signature |
| Variable |
| Chunk |
|---|
| Conflicting content |
|---|
}
@Test
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class LpSpaceDistanceTest {
static LpSpaceDistance INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new LpSpaceDistance();
RANDOM = new Random(1234);
}
@Test
public void testCLI_neginf() throws Exception {
testCLI(Double.NEGATIVE_INFINITY);
}
@Test
public void testCLI_posinf() throws Exception {
testCLI(Double.POSITIVE_INFINITY);
}
@Test
public void testCLI_neg1() throws Exception {
testCLI(-1);
}
@Test
public void testCLI_0() throws Exception {
testCLI(0);
}
public void testCLI_1() throws Exception {
testCLI(1);
}
@Test
public void testCLI_2() throws Exception {
testCLI(2);
}
@Test
public void testCLI_3() throws Exception {
testCLI(3);
}
@Test
public void testCLI_e() throws Exception {
testCLI(Math.E);
}
public void testCLI(double power) throws Exception {
System.out.printf("testCLI(power=%f)%n", power);
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME
+ String.format(".L-%4.2f-Space", power));
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "lp",
"--mink-p", Double.toString(power),
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, 1);
double expect = Math.sqrt(size);
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
int limit = 5;
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import org.junit.Ignore; import org.junit.Test; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class LpSpaceDistanceTest extends AbstractMeasureTest |
| File |
|---|
| LpSpaceDistanceTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
int limit = 5;
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class OverlapTest {
static Overlap INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new Overlap();
RANDOM = new Random(1234);
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME + ".Overlap");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "Overlap",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, RANDOM.nextDouble());
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHeteroginiety() throws Exception {
System.out.println("testHeteroginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size / 2; i++) {
A.set(i * 2, i);
B.set(i * 2 + 1, i);
}
double expect = INSTANCE.getHeterogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class OverlapTest extends AbstractMeasureTest |
| File |
|---|
| OverlapTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
return "overlap";
}
<<<<<<< HEAD
public double test(SparseDoubleVector A, SparseDoubleVector B) {
final double val = INSTANCE.similarity(A, B);
assertFalse("Similarity is NaN", Double.isNaN(val));
assertFalse("Similarity is " + val, Double.isInfinite(val));
assertTrue("Similarity < -1", val >= INSTANCE.getHeterogeneityBound());
assertTrue("Similarity > +1", val <= INSTANCE.getHomogeneityBound());
return val;
}
static List |
| Solution content |
|---|
return "overlap"; } } |
| File |
|---|
| OverlapTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class PrecisionTest {
static Precision INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new Precision();
RANDOM = new Random(1234);
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME + ".Precision");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "precision",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, RANDOM.nextDouble());
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHeteroginiety() throws Exception {
System.out.println("testHeteroginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size / 2; i++) {
A.set(i * 2, i);
B.set(i * 2 + 1, i);
}
double expect = INSTANCE.getHeterogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
int limit = 5;
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class PrecisionTest extends AbstractMeasureTest |
| File |
|---|
| PrecisionTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| For statement |
| Import |
| Method declaration |
| Method invocation |
| Method signature |
| Variable |
| Chunk |
|---|
| Conflicting content |
|---|
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class RecallTest {
static Recall INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new Recall();
RANDOM = new Random(1234);
}
@Test
public void testCLI() throws Exception {
System.out.println("testCLI");
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME + ".Recall");
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "recall",
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, RANDOM.nextDouble());
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHeteroginiety() throws Exception {
System.out.println("testHeteroginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size / 2; i++) {
A.set(i * 2, i);
B.set(i * 2 + 1, i);
}
double expect = INSTANCE.getHeterogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
int limit = 5;
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class RecallTest extends AbstractMeasureTest |
| File |
|---|
| RecallTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
return "recall";
}
<<<<<<< HEAD
public double test(SparseDoubleVector A, SparseDoubleVector B) {
final double val = INSTANCE.similarity(A, B);
assertFalse("Similarity is NaN", Double.isNaN(val));
assertFalse("Similarity is " + val, Double.isInfinite(val));
assertTrue("Similarity < -1", val >= INSTANCE.getHeterogeneityBound());
assertTrue("Similarity > +1", val <= INSTANCE.getHomogeneityBound());
return val;
}
static List |
| Solution content |
|---|
return "recall"; } } |
| File |
|---|
| RecallTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
double expect = 0;
*/
package uk.ac.susx.mlcl.byblo.measures.impl;
<<<<<<< HEAD
import org.junit.BeforeClass;
import org.junit.Test;
import uk.ac.susx.mlcl.TestConstants;
import uk.ac.susx.mlcl.byblo.Tools;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumerating;
import uk.ac.susx.mlcl.byblo.enumerators.DoubleEnumeratingDelegate;
import uk.ac.susx.mlcl.byblo.io.BybloIO;
import uk.ac.susx.mlcl.byblo.io.FastWeightedTokenPairVectorSource;
import uk.ac.susx.mlcl.lib.collect.Indexed;
import uk.ac.susx.mlcl.lib.collect.SparseDoubleVector;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static uk.ac.susx.mlcl.TestConstants.*;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.disableExitTrapping;
int limit = 5;
import static uk.ac.susx.mlcl.lib.test.ExitTrapper.enableExistTrapping;
/**
* @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk>
*/
public class WeedsTest {
static Weeds INSTANCE;
static final double EPSILON = 0;
static Random RANDOM;
@BeforeClass
public static void setUpClass() throws Exception {
INSTANCE = new Weeds();
RANDOM = new Random(1234);
}
@Test
public void testCLI_000_100() throws Exception {
testCLI(0, 1);
}
@Test
public void testCLI_050_050() throws Exception {
testCLI(0.5, 0.5);
}
@Test
public void testCLI_100_000() throws Exception {
testCLI(1, 0);
}
@Test
public void testCLI_075_000() throws Exception {
testCLI(0.75, 0);
}
@Test
public void testCLI_050_000() throws Exception {
testCLI(0.5, 0);
}
@Test
public void testCLI_025_000() throws Exception {
testCLI(0.25, 0);
}
@Test
public void testCLI_000_000() throws Exception {
testCLI(0, 0);
}
public void testCLI(double beta, double gamma) throws Exception {
System.out.println(String.format("testCLI(beta=%.2f, gamma=%.2f)",
beta, gamma));
File output = new File(TEST_OUTPUT_DIR, FRUIT_NAME
+ String.format(".Weeds-beta%03d-gamma%03d",
(int) (100 * beta), (int) (100 * gamma)));
deleteIfExist(output);
try {
enableExistTrapping();
Tools.main(new String[]{
"allpairs",
"--charset", "UTF-8",
"--measure", "Weeds",
"--crmi-beta", Double.toHexString(beta),
"--crmi-gamma", Double.toHexString(gamma),
"--input", TEST_FRUIT_EVENTS.toString(),
"--input-features", TEST_FRUIT_FEATURES.toString(),
"--input-entries", TEST_FRUIT_ENTRIES.toString(),
"--output", output.toString()
});
} finally {
disableExitTrapping();
}
assertTrue("Output file " + output + " does not exist.", output.exists());
assertTrue("Output file " + output + " is empty.", output.length() > 0);
}
@Test
public void testBothEmptyVectors() throws Exception {
System.out.println("testBothEmptyVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, 0);
double expect = 0;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testOneEmptyVector() throws Exception {
System.out.println("testOneEmptyVector");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 0);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++)
B.set(i, RANDOM.nextDouble());
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeOneVectors() throws Exception {
System.out.println("testSizeOneVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 1);
SparseDoubleVector B = new SparseDoubleVector(size, 1);
A.set(0, 1);
B.set(0, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCardinalityOneVectors() throws Exception {
System.out.println("testCardinalityOneVectors");
SparseDoubleVector A = new SparseDoubleVector(1, 1);
SparseDoubleVector B = new SparseDoubleVector(1, 1);
A.set(0, 1);
B.set(0, 1);
double expect = 1;
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testSizeTwoVectors() throws Exception {
System.out.println("testSizeTwoVectors");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, 2);
SparseDoubleVector B = new SparseDoubleVector(size, 2);
A.set(0, 1);
A.set(1, 1);
B.set(0, 1);
B.set(1, 1);
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testCommutative() throws Exception {
System.out.println("testCommutative");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
A.set(i, RANDOM.nextDouble());
B.set(i, RANDOM.nextDouble());
}
double expect = test(A, B);
double actual = test(B, A);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHomoginiety() throws Exception {
System.out.println("testHomoginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size; i++) {
double value = RANDOM.nextDouble();
A.set(i, value);
B.set(i, value);
}
double expect = INSTANCE.getHomogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testHeteroginiety() throws Exception {
System.out.println("testHeteroginiety");
int size = 100;
SparseDoubleVector A = new SparseDoubleVector(size, size);
SparseDoubleVector B = new SparseDoubleVector(size, size);
for (int i = 0; i < size / 2; i++) {
A.set(i * 2, i);
B.set(i * 2 + 1, i);
}
double expect = INSTANCE.getHeterogeneityBound();
double actual = test(A, B);
assertEquals(expect, actual, EPSILON);
}
@Test
public void testFruitData() throws Exception {
System.out.println("testFruitData");
List |
| Solution content |
|---|
*/ package uk.ac.susx.mlcl.byblo.measures.impl; import org.junit.Test; /** * * @author Hamish I A Morgan <hamish.morgan@sussex.ac.uk> */ public class WeedsTest extends AbstractMeasureTest |
| File |
|---|
| WeedsTest.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Class signature |
| Comment |
| Import |
| Method declaration |