missing equals() for class Example

Legacy User
Legacy User New Altair Community Member
edited November 5 in Community Q&A
Hello,

During implementation of a new operator I would like to compute the epsilon environment of an example. I implemented the following code:

private List<Example> getEpsilonEnvironment(final Example example, final ExampleSet exampleSet) {
final List<Example> result = new LinkedList<Example>();

log.logNote("EPSILON-ENVIRONMENT FOR " + example);

for (final Example other: exampleSet) {
log.logNote("  TESTING " + other);
/*
* add all (other!) examples which are closer than epsilon
*/
if (!(example == other || example.equals(other)) && distance(example, other) < epsilon) {
result.add(other);
log.logNote("    ADDED!");
}
}

log.logNote("RESULT: " + result);
return result;
}
The problem is that the example itself is always added to the result list, although I check for == and equals():

[NOTE] EPSILON-ENVIRONMENT FOR 5.1 3.5 1.4 0.2 1.0
[NOTE]  TESTING 5.1 3.5 1.4 0.2 1.0
[NOTE]    ADDED!
[NOTE]  TESTING 5.6 3.0 4.1 1.3 2.0
[NOTE]    ADDED!
[NOTE]  TESTING 5.5 2.6 4.4 1.2 3.0
[NOTE]    ADDED!
[NOTE]  TESTING 5.4 3.7 1.5 0.2 4.0
[NOTE]    ADDED!
[NOTE]  TESTING 6.5 3.0 5.2 2.0 5.0
[NOTE]  TESTING 5.7 3.8 1.7 0.3 6.0
[NOTE]    ADDED!
[NOTE] RESULT: [5.1 3.5 1.4 0.2 1.0 , 5.6 3.0 4.1 1.3 2.0 , 5.5 2.6 4.4 1.2 3.0 , 5.4 3.7 1.5 0.2 4.0 , 5.7 3.8 1.7 0.3 6.0 ]
How can I assure not to add the example to the environment? Is there a way to check the identity of examples?

Thanks,
Robert

Answers

  • land
    land New Altair Community Member
    Hi Robert,
    Examples are only views onto the data. You should not store them anyway. If you need the data, you should copy them into an double[]

    Greetings,
      Sebastian