Hi Márcio,

If you send me the code for your Individual and Measures objects with me, I'm happy to take a look at it and see if I can identify the problem.

Thanks,
Siggy

On Tue, Jan 30, 2018 at 11:55 AM, Márcio Basgalupp <[log in to unmask]> wrote:
Hi, Siggy.

I initialized a new Measures object in the setup() method, as you
suggested, but it didn't work, unfortunately.

Best,
Márcio
--------
Prof. Márcio Porto Basgalupp
Instituto de Ciência e Tecnologia (ICT)
Universidade Federal de São Paulo (UNIFESP)


On Mon, Jan 29, 2018 at 7:13 PM, Márcio Basgalupp <[log in to unmask]> wrote:
> Thank you very much, Siggy. You were very clear in your explanation, and it
> will work for sure if i move to setup(). I indeed iniialized in the
> constructor, that’s the reason.
>
> Best,
> Marcio
>
> On Mon, Jan 29, 2018 at 17:49 Eric 'Siggy' Scott <[log in to unmask]> wrote:
>>
>> Hi Márcio,
>>
>> Try moving the your assignment of the 'performances' variable inside your
>> MyIndividual.setup() method.
>>
>> It's hard to know without seeing your code, but I suspect that every
>> individual in your population is actually storing a reference to the same
>> instance of 'Measures'.  This line is only called when the MyIndividual
>> constructor is called:
>>
>>> private Measures performances = new Measures();
>>
>>
>> But when ECJ creates the initial population, it only uses the default
>> constructor of your Individual once, to initialize a "prototype" instance of
>> the Individual.  The population itself is created by cloning this prototype
>> individual and then calling setup() on the clones.
>>
>> So, to initialize a new Measures object for each clone, you either need to
>> do it in the setup() method, or override MyIndividual.clone() to perform a
>> deep copy.  Using setup() is cleaner, though, since it follows ECJ's
>> convention, and you don't actually care about copying the data.
>>
>> Thanks,
>> Siggy
>>
>> On Mon, Jan 29, 2018 at 9:11 AM, Márcio Basgalupp <[log in to unmask]>
>> wrote:
>>>
>>> Hi all.
>>>
>>> When running NSGA-II, I'm having a problem when extending the
>>> Individual class. I create a new class called Measures, when I have
>>> some attributes of performance such as accuracy, fmeasure, etc. My
>>> Individual class (called myIndividual.java) has an object fro this
>>> Measures class (the attribute calls performances). It is a private
>>> attribute, and to get this I need to use individual.getPerformances().
>>>
>>> public myIndividual () {
>>>
>>> private Measures performances = new Measures();
>>>
>>> ...
>>>
>>> }
>>>
>>>
>>> At the end of the evolution, I get the paretoFront and it is very
>>> weird because if I get, for example,
>>> individual.getPerformance.getAccuracy(), the value is completely
>>> wrong. Just to make sure, I added an attribute called accuracy
>>> directly in myIndividual class, as below.
>>>
>>> public myIndividual () {
>>>
>>> private double accuracy;
>>> private Measures performances = new Measures();
>>> ...
>>>    void testMethod() {
>>>       accuracy = 0.8;
>>>       performance.setAccuracy(0.8);
>>>    }
>>> ...
>>> }
>>>
>>> I assign the same value to both (as in testMethod()), but when I print
>>> it in my Main class (when I have the paretoFront), these values are
>>> different. The value accuracy attribute is correct, but the one in
>>> performances.getAccuracy() is completely wrong.
>>>
>>> Should I make some additional thing to fix it? I tried to make
>>> Measures implements Serializable and Clonable, but it didn't work. It
>>> is possible to add into myIndividual.java all attributes on
>>> Measures.java, but I would not like to do it because it must have a
>>> way to fix it correctly.
>>>
>>> Best,
>>> Márcio
>>>
>>>
>>> --------
>>> Prof. Márcio Porto Basgalupp
>>> Instituto de Ciência e Tecnologia (ICT)
>>> Universidade Federal de São Paulo (UNIFESP)
>>
>>
>>
>>
>> --
>>
>> Ph.D student in Computer Science, George Mason University
>> Web Director, Journal of Mason Graduate Research
>> http://mason.gmu.edu/~escott8/
>
> --
> --------
> Prof. Márcio Porto Basgalupp
> Instituto de Ciência e Tecnologia (ICT)
> Universidade Federal de São Paulo (UNIFESP)



--

Ph.D student in Computer Science, George Mason University
Web Director, Journal of Mason Graduate Research