jeffheaton / encog-java-core

http://www.heatonresearch.com/encog
Other
743 stars 268 forks source link

Java 7 compliance: XORNEAT with Target low values throws IllegalArgumentException: Comparison method violates its general contract! #132

Closed serdarsemen closed 11 years ago

serdarsemen commented 11 years ago
public int compareTo(NEATLink other) {
    return other.toNeuron - this.fromNeuron;
}

must be changed accourding to the new contract for mergesort. An alternative may be as follows but still has same holes :)

    public int compareTo(NEATLink other) {
    if (other == null)
        return 0;
    if (other.toNeuron == this.fromNeuron) 
        return 0;
    else 
    if  (other.toNeuron > this.fromNeuron)
        return 1;
    else 
        if  (other.toNeuron < this.fromNeuron) 
        return -1;
    return 0;
}

http://stackoverflow.com/questions/6626437/why-does-my-compare-method-throw-exception-comparison-method-violates-its-gen

Iteration #444 Error:12.324298% Target Error: 1.000000% Exception in thread "pool-446-thread-2" java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.ComparableTimSort.mergeLo(Unknown Source) at java.util.ComparableTimSort.mergeAt(Unknown Source) at java.util.ComparableTimSort.mergeCollapse(Unknown Source) at java.util.ComparableTimSort.sort(Unknown Source) at java.util.ComparableTimSort.sort(Unknown Source) at java.util.Arrays.sort(Unknown Source) at java.util.Collections.sort(Unknown Source) at org.encog.neural.neat.NEATCODEC.decode(NEATCODEC.java:58) at org.encog.neural.neat.training.NEATTraining.calculateScore(NEATTraining.java:465) at org.encog.neural.neat.training.NEATTrainWorker.run(NEATTrainWorker.java:92) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Iteration #445 Error:12.320838% Target Error: 1.000000%

jeffheaton commented 11 years ago

Thanks! I believe this is resolved now.