Example #1
0
    virtual void operator()( EOT & x )
    {
        if( x.invalid() ) { return; }

        double sum = 0;
        int sign = 1;
        for( unsigned int i=0, s=x.size(); i<s; ++i ) {
            sum += x[i] * x[i];
            sign *= x[i]<0 ? -1 : 1;
        }

        x.fitness( std::make_pair( sum, sign>0 ? true : false ) );
    }
Example #2
0
    void operator()(EOT& _eo)
    {
        if (_eo.invalid())
        {
            double a1 = _eo[ 0 ];
            double a2 = _eo[ 1 ];
            double a3 = _eo[ 3 ];
            double a4 = _eo[ 4 ];
            double a5 = _eo[ 5 ];

            double chi2 = 0.0;
            size_t N = min3( m_x1.size() , m_x2.size() , m_y.size() );
            for( size_t i=0 ; i<N ; ++i )
            {
                double x1 = m_x1[i] , x2 = m_x2[i];
                double val = a1 * ( x1*x1 + x2*x2 ) + a2 * cos( a3 * x1 + a4 ) + a5;
                chi2 += ( val - m_y[i] ) * ( val - m_y[i] );
            }
            _eo.fitness( chi2 );
        }
    }