Beispiel #1
0
TwoDoubles f10(double* x) {
    /* ellipsoid with monotone transformation, condition 1e6*/
    int i, j, rseed; /*Loop over dim*/
    static unsigned int funcId = 10;
    static double condition = 1e6;
    double Fadd, Fval, Ftrue = 0.;
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = funcId + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        computeXopt(rseed, DIM);
        computeRotation(rotation, rseed + 1000000, DIM);
        isInitDone = 1;
    }
    Fadd = Fopt;
    /* BOUNDARY HANDLING*/

    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++)
    {
        tmx[i] = 0.;
        for (j = 0; j < DIM; j++) {
            tmx[i] += rotation[i][j] * (x[j] - Xopt[j]);
        }
    }

    monotoneTFosc(tmx);
    /* COMPUTATION core*/
    for (i = 0; i < DIM; i++)
    {
        Ftrue += pow(condition, ((double)i)/((double)(DIM-1))) * tmx[i] * tmx[i];
    }
    Ftrue += Fadd;
    Fval = Ftrue; /* without noise*/

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
    void CovarianceVisual::setMessage(const geometry_msgs::PoseWithCovariance& msg)
    {
        // Construct pose position and orientation.
        const geometry_msgs::Point& p = msg.pose.position;
        const geometry_msgs::Quaternion& q = msg.pose.orientation;

        Ogre::Vector3 position(p.x, p.y, p.z);
        Ogre::Quaternion orientation(q.w, q.x, q.y, q.z);

        // Set position and orientation for axes scene node.
        if(!position.isNaN())
            axes_->setPosition(position);
        else
            ROS_WARN_STREAM_THROTTLE(1, "position contains NaN: " << position);

        if(!orientation.isNaN())
            axes_->setOrientation (orientation);
        else
            ROS_WARN_STREAM_THROTTLE(1, "orientation contains NaN: " << orientation);

        // check for NaN in covariance
        for (unsigned i = 0; i < 3; ++i)
        {
            if(isnan(msg.covariance[i]))
            {
                ROS_WARN_THROTTLE(1, "covariance contains NaN");
                return;
            }
        }

        // Compute eigen values and vectors for both shapes.
        std::pair<Eigen::Matrix3d, Eigen::Vector3d> positionEigenVectorsAndValues(computeEigenValuesAndVectors(msg, 0));
        std::pair<Eigen::Matrix3d, Eigen::Vector3d> orientationEigenVectorsAndValues(computeEigenValuesAndVectors(msg, 3));

        Ogre::Quaternion positionQuaternion(computeRotation(msg, positionEigenVectorsAndValues));
        Ogre::Quaternion orientationQuaternion(computeRotation(msg, orientationEigenVectorsAndValues));

        positionNode_->setOrientation(positionQuaternion);
        orientationNode_->setOrientation(orientationQuaternion);

        // Compute scaling.
        //Ogre::Vector3 axesScaling(1, 1, 1);

        //axesScaling *= scaleFactor_;

        Ogre::Vector3 positionScaling
                      (std::sqrt (positionEigenVectorsAndValues.second[0]),
                       std::sqrt (positionEigenVectorsAndValues.second[1]),
                       std::sqrt (positionEigenVectorsAndValues.second[2]));

        positionScaling *= scaleFactor_;

        Ogre::Vector3 orientationScaling
                      (std::sqrt (orientationEigenVectorsAndValues.second[0]),
                       std::sqrt (orientationEigenVectorsAndValues.second[1]),
                       std::sqrt (orientationEigenVectorsAndValues.second[2]));

        orientationScaling *= scaleFactor_;

        // Set the scaling.
        /*if(!axesScaling.isNaN())
            axes_->setScale(axesScaling);
        else
            ROS_WARN_STREAM("axesScaling contains NaN: " << axesScaling);*/

        if(!positionScaling.isNaN())
            positionNode_->setScale(positionScaling);
        else
            ROS_WARN_STREAM("positionScaling contains NaN: " << positionScaling);

        if(!orientationScaling.isNaN())
            orientationNode_->setScale(orientationScaling);
        else
            ROS_WARN_STREAM("orientationScaling contains NaN: " << orientationScaling);

        // Debugging.
        ROS_INFO_STREAM_THROTTLE
        (1.,
        "Position:\n"
        << position << "\n"
        << "Positional part 3x3 eigen values:\n"
        << positionEigenVectorsAndValues.second << "\n"
        << "Positional part 3x3 eigen vectors:\n"
        << positionEigenVectorsAndValues.first << "\n"
        << "Sphere orientation:\n"
        << positionQuaternion << "\n"
        << positionQuaternion.getRoll () << " "
        << positionQuaternion.getPitch () << " "
        << positionQuaternion.getYaw () << "\n"
        << "Sphere scaling:\n"
        << positionScaling << "\n"
        << "Rotational part 3x3 eigen values:\n"
        << orientationEigenVectorsAndValues.second << "\n"
        << "Rotational part 3x3 eigen vectors:\n"
        << orientationEigenVectorsAndValues.first << "\n"
        << "Cone orientation:\n"
        << orientationQuaternion << "\n"
        << orientationQuaternion.getRoll () << " "
        << orientationQuaternion.getPitch () << " "
        << orientationQuaternion.getYaw () << "\n"
        << "Cone scaling:\n"
        << orientationScaling
        );
    }
Beispiel #3
0
void TumblerWindow::keyPressEvent ( QKeyEvent * event)
{
  TumblerStruct *xtum = mTum;
  float tstep = xtum->tstep;
  int key = event->key();
  int shift = event->modifiers() & Qt::ShiftModifier;
  int ctrl = event->modifiers() & Qt::ControlModifier;
  int keypad = event->modifiers() & Qt::KeypadModifier;
  int dodraw = 1;
  int handled = 1;
  int newdata = 1;
  float xrot, yrot, zrot;
  
  if (inputTestMetaKey(event))
    return;

  if (utilCloseKey(event)) {
    close();
    return;
  }    

  inputConvertNumLock(key, keypad);

  if (key == hotSliderKey()) {
    mCtrlPressed = true;
    grabKeyboard();
    return;
  }

  switch(key){
  case Qt::Key_B:
    xtum->bbox = 1 - xtum->bbox;
    newdata = 0;
    break;
               
  case Qt::Key_S:
    if (shift || ctrl){
      
      // Snapshots
      draw(xtum);
      b3dKeySnapshot("tumbler", shift, ctrl, NULL);
      dodraw = 0;
    } else {

      // Toggle stereo
      xtum->stereo = 1 - xtum->stereo;
      setSlice(xtum);
      newdata = 0;
    }
    break;

  case Qt::Key_Comma:
    xtum->tstep /= sqrt(2.);
    if (xtum->tstep < 1.)
      xtum->tstep = 1.;
    break;

  case Qt::Key_Period:
    xtum->tstep *= sqrt(2.);
    if (xtum->tstep > 16.)
      xtum->tstep = 16.;
    break;

  case Qt::Key_Plus:
  case Qt::Key_Equal:
    if (xtum->zoom < XTUM_MAX_ZOOM) {
      xtum->zoom++;
      diaSetSpinBox(mZoomBox, xtum->zoom);
      setSlice(xtum);
      newdata = 0;
    } else
      dodraw = 0;
    break;
  case Qt::Key_Minus:
    if (xtum->zoom > 1) {
      xtum->zoom--;
      diaSetSpinBox(mZoomBox, xtum->zoom);
      setSlice(xtum);
      newdata = 0;
    } else
      dodraw = 0;
    break;
    
  case Qt::Key_PageDown:
  case Qt::Key_PageUp:
  case Qt::Key_Up:
  case Qt::Key_Down:
  case Qt::Key_Right:
  case Qt::Key_Left:
    if (keypad) {

      // Someone with a better eye than mine may see that the directions
      // of X and Y need to be reversed
      xrot = (key == Qt::Key_Up ? tstep : 0.) - 
        (key == Qt::Key_Down ? tstep : 0.); 
      yrot = (key == Qt::Key_Right ? tstep : 0.) - 
        (key == Qt::Key_Left ? tstep : 0.);
      zrot = (key == Qt::Key_PageUp ? tstep : 0.) - 
        (key == Qt::Key_PageDown ? tstep : 0.);
      computeRotation(xrot, yrot, zrot);
    } else
      handled = 0;
    break;
    
  case Qt::Key_F5:
    if (xtum->minval >= 3) {
      xtum->minval -= 3;
      mSliders->setValue(0, xtum->minval);
    } else
      dodraw = 0;
    break;
  case Qt::Key_F6:
    if (xtum->minval < xtum->maxval - 3) {
      xtum->minval += 3;
      mSliders->setValue(0, xtum->minval);
    } else
      dodraw = 0;
    break;
  case Qt::Key_F7:
    if (xtum->maxval > xtum->minval + 3) {
      xtum->maxval -= 3;
      mSliders->setValue(1, xtum->maxval);
    } else
      dodraw = 0;
    break;
  case Qt::Key_F8:
    if (xtum->maxval <= 255 -  3) {
      xtum->maxval += 3;
      mSliders->setValue(1, xtum->maxval);
    } else
      dodraw = 0;
    break;

  default:
    handled = 0;
    break;
  }

  // If key not handled, call the default processor
  if (!handled) {
    inputQDefaultKeys(event, xtum->vi);
    return;
  }
  
  // Do the draws as needed
  if (dodraw && newdata)
    newData(xtum);
  if (dodraw)
    draw(xtum);
}
TwoDoubles f115(double* x) {
    /* step-ellipsoid with Cauchy noise, condition 100*/
    int i, j, rseed; /*Loop over dim*/
    static int funcId = 115;
    static int rrseed = 7;
    static double condition = 100.;
    static double alpha = 10.;
    double x1, Fadd, Fval, tmp, Fpen = 0., Ftrue = 0.;
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = rrseed + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        computeXopt(rseed, DIM);
        computeRotation(rotation, rseed + 1000000, DIM);
        computeRotation(rot2, rseed, DIM);
        isInitDone = 1;
    }
    Fadd = Fopt;

    /* BOUNDARY HANDLING*/
    for (i = 0; i < DIM; i++) 
    {
        tmp = fabs(x[i]) - 5.;
        if (tmp > 0.)
        {
            Fpen += tmp * tmp;
        }
    }
    Fadd += 100. * Fpen;

    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++) {
        tmpvect[i] = 0.;
        tmp = sqrt(pow(condition/10., ((double)i)/((double)(DIM-1))));
        for (j = 0; j < DIM; j++) {
            tmpvect[i] += tmp * rot2[i][j] * (x[j] - Xopt[j]);
        }
    }
    x1 = tmpvect[0];
    for (i = 0; i < DIM; i++) {
        if (fabs(tmpvect[i]) > 0.5)
        {
            tmpvect[i] = round(tmpvect[i]);
        }
        else
        {
            tmpvect[i] = round(alpha * tmpvect[i])/alpha;
        }
    }

    for (i = 0; i < DIM; i++) {
        tmx[i] = 0.;
        for (j = 0; j < DIM; j++) {
            tmx[i] += rotation[i][j] * tmpvect[j];
        }
    }

    /* COMPUTATION core*/
    for (i = 0; i < DIM; i++)
    {
        Ftrue += pow(condition, ((double)i)/((double)(DIM-1))) * tmx[i] * tmx[i];
    }
    Ftrue = 0.1 * fmax(1e-4 * fabs(x1), Ftrue);
    Fval = FCauchy(Ftrue, 1., 0.2);

    Ftrue += Fadd;
    Fval += Fadd;

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
TwoDoubles f130(double* x) {
    /* Gallagher with 101 Gaussian peaks with Cauchy noise, condition up to 1000, one global rotation*/
    int i, j, k, rseed; /*Loop over dim*/
    static int funcId = 130;
    static int rrseed = 21;
    static double fitvalues[2] = {1.1, 9.1};
    static double maxcondition = 1000.;
    static double arrCondition[NHIGHPEAKS21];
    static double peakvalues[NHIGHPEAKS21];
    static double a = 0.1;
    double tmp2, f = 0., Fadd, Fval, tmp, Fpen = 0., Ftrue = 0.;
    double fac = -0.5 / (double)DIM;
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = rrseed + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        computeRotation(rotation, rseed, DIM);
        peaks = peaks21;
        unif(peaks, NHIGHPEAKS21 - 1, rseed);
        rperm = rperm21;
        for (i = 0; i < NHIGHPEAKS21 - 1; i++)
            rperm[i] = i;
        qsort(rperm, NHIGHPEAKS21 - 1, sizeof(int), compare_doubles);

        /* Random permutation*/

        arrCondition[0] = sqrt(maxcondition);
        peakvalues[0] = 10;
        for (i = 1; i < NHIGHPEAKS21; i++)
        {
            arrCondition[i] = pow(maxcondition, (double)(rperm[i-1])/((double)(NHIGHPEAKS21-2)));
            peakvalues[i] = (double)(i-1)/(double)(NHIGHPEAKS21-2) * (fitvalues[1] - fitvalues[0]) + fitvalues[0];
        }
        arrScales = arrScales21;
        for (i = 0; i < NHIGHPEAKS21; i++)
        {
            unif(peaks, DIM, rseed + 1000 * i);
            for (j = 0; j < DIM; j++)
                rperm[j] = j;
            qsort(rperm, DIM, sizeof(int), compare_doubles);
            for (j = 0; j < DIM; j++)
            {
                arrScales[i][j] = pow(arrCondition[i], ((double)rperm[j])/((double)(DIM-1)) - 0.5);
            }
        }

        unif(peaks, DIM * NHIGHPEAKS21, rseed);
        Xlocal = Xlocal21;
        for (i = 0; i < DIM; i++)
        {
            Xopt[i] = 0.8 * (10. * peaks[i] -5.);
            for (j = 0; j < NHIGHPEAKS21; j++)
            {
                Xlocal[i][j] = 0.;
                for (k = 0; k < DIM; k++)
                {
                    Xlocal[i][j] += rotation[i][k] * (10. * peaks[j * DIM + k] -5.);
                }
                if (j == 0)
                    Xlocal[i][j] *= 0.8;
            }
        }
        isInitDone = 1;
    }
    Fadd = Fopt;

    /* BOUNDARY HANDLING*/
    for (i = 0; i < DIM; i++) 
    {
        tmp = fabs(x[i]) - 5.;
        if (tmp > 0.)
        {
            Fpen += tmp * tmp;
        }
    }
    Fadd += 100. * Fpen;

    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++)
    {
        tmx[i] = 0.;
        for (j = 0; j < DIM; j++)
        {
            tmx[i] += rotation[i][j] * x[j];
        }
    }

    /* COMPUTATION core*/
    for (i = 0; i < NHIGHPEAKS21; i++)
    {
        tmp2 = 0.;
        for (j = 0; j < DIM; j++)
        {
            tmp2 += arrScales[i][j] * (tmx[j] - Xlocal[j][i]) * (tmx[j] - Xlocal[j][i]);
        }
        tmp2 = peakvalues[i] * exp(fac * tmp2);
        f = fmax(f, tmp2);
    }

    f = 10 - f;
    /*monotoneTFosc*/
    if (f > 0)
    {
        Ftrue = log(f)/a;
        Ftrue = pow(exp(Ftrue + 0.49*(sin(Ftrue) + sin(0.79*Ftrue))), a);
    }
    else if (f < 0)
    {
        Ftrue = log(-f)/a;
        Ftrue = -pow(exp(Ftrue + 0.49*(sin(0.55 * Ftrue) + sin(0.31*Ftrue))), a);
    }
    else
        Ftrue = f;

    Ftrue *= Ftrue;

    Fval = FCauchy(Ftrue, 1., 0.2);

    Ftrue += Fadd;
    Fval += Fadd;
    /* free(Xopt); //Not used!*/

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
TwoDoubles f127(double* x) {
    /* F8F2 sum of Griewank-Rosenbrock 2-D blocks with seldom Cauchy noise*/
    int i, j, rseed; /*Loop over dim*/
    static int funcId = 127;
    static int rrseed = 19;
    static double scales;
    double F2, Fadd, Fval, tmp, Fpen = 0., Ftrue = 0.;
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = rrseed + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        /* computeXopt(rseed, DIM);*/
        scales = fmax(1., sqrt((double)DIM) / 8.);
        computeRotation(rotation, rseed, DIM);
/*        for (i = 0; i < DIM; i++)
        {
            Xopt[i] = 0.;
            for (j = 0; j < DIM; j++)
            {
                Xopt[i] += rotation[j][i] * 0.5/scales;
                //computed only if Xopt is returned which is not the case at this point.
            }
        }*/
        isInitDone = 1;
    }
    Fadd = Fopt;

    /* BOUNDARY HANDLING*/
    for (i = 0; i < DIM; i++) 
    {
        tmp = fabs(x[i]) - 5.;
        if (tmp > 0.)
        {
            Fpen += tmp * tmp;
        }
    }
    Fadd += 100. * Fpen;

    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++) {
        tmx[i] = 0.5;
        for (j = 0; j < DIM; j++) {
            tmx[i] += scales * rotation[i][j] * x[j];
        }
    }

    /* COMPUTATION core*/
    tmp = 0.;
    for (i = 0; i < DIM - 1; i++)
    {
        F2 = 100. * (tmx[i] * tmx[i] - tmx[i+1]) * (tmx[i] * tmx[i] - tmx[i+1]) + (1 - tmx[i]) * (1 - tmx[i]);
        tmp += F2 / 4000. - cos(F2);
    }
    Ftrue = 1. + 1. * tmp / (double)(DIM - 1);

    Fval = FCauchy(Ftrue, 1., 0.2);

    Ftrue += Fadd;
    Fval += Fadd;

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
TwoDoubles f124(double* x) {
    /* Schaffers F7 with seldom Cauchy noise, with asymmetric non-linear transformation, condition 10*/
    int i, j, rseed; /*Loop over dim*/
    static int funcId = 124;
    static int rrseed = 17;
    static double condition = 10.;
    static double beta = 0.5;
    double Fadd, Fval, tmp, Fpen = 0., Ftrue = 0.;
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = rrseed + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        computeXopt(rseed, DIM);
        computeRotation(rotation, rseed + 1000000, DIM);
        computeRotation(rot2, rseed, DIM);
        isInitDone = 1;
    }
    Fadd = Fopt;

    /* BOUNDARY HANDLING*/
    for (i = 0; i < DIM; i++) 
    {
        tmp = fabs(x[i]) - 5.;
        if (tmp > 0.)
        {
            Fpen += tmp * tmp;
        }
    }
    Fadd += 100. * Fpen;

    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++)
    {
        tmpvect[i] = 0.;
        for (j = 0; j < DIM; j++)
        {
            tmpvect[i] += rotation[i][j] * (x[j] - Xopt[j]);
        }
        if (tmpvect[i] > 0)
            tmpvect[i] = pow(tmpvect[i], 1 + beta * ((double)i)/((double)(DIM-1)) * sqrt(tmpvect[i]));
    }

    for (i = 0; i < DIM; i++)
    {
        tmx[i] = 0.;
        tmp = pow(sqrt(condition), ((double)i)/((double)(DIM-1)));
        for (j = 0; j < DIM; j++)
        {
            tmx[i] += tmp * rot2[i][j] * tmpvect[j];
        }
    }

    /* COMPUTATION core*/
    for (i = 0; i < DIM - 1; i++)
    {
        tmp = tmx[i] * tmx[i] + tmx[i+1] * tmx[i+1];
        Ftrue += pow(tmp, 0.25) * (pow(sin(50. * pow(tmp, 0.1)), 2.) + 1.);
    }
    Ftrue = pow(Ftrue/(double)(DIM - 1), 2.);

    Fval = FCauchy(Ftrue, 1., 0.2);

    Ftrue += Fadd;
    Fval += Fadd;

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
Beispiel #8
0
TwoDoubles f16(double* x) {
    /* Weierstrass, condition 100*/
    int i, j, k, rseed; /*Loop over dim*/
    static unsigned int funcId = 16;
    static double condition = 100.;
    static double aK[12];
    static double bK[12];
    static double F0;
    double tmp, Fadd, Fval, Fpen = 0., Ftrue = 0.;
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = funcId + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        computeXopt(rseed, DIM);
        computeRotation(rotation, rseed + 1000000, DIM);
        computeRotation(rot2, rseed, DIM);
        for (i = 0; i < DIM; i++)
        {
            for (j = 0; j < DIM; j++)
            {
                linearTF[i][j] = 0.;
                for (k = 0; k < DIM; k++) {
                    linearTF[i][j] += rotation[i][k] * pow(1./sqrt(condition), ((double)k)/((double)(DIM-1))) * rot2[k][j];
                }
            }
        }

        F0 = 0.;
        for (i = 0; i < 12; i ++) /* number of summands, 20 in CEC2005, 10/12 saves 30% of time*/
        {
            aK[i] = pow(0.5, (double)i);
            bK[i] = pow(3., (double)i);
            F0 += aK[i] * cos(2 * M_PI * bK[i] * 0.5);
        }
        isInitDone = 1;
    }
    Fadd = Fopt;

    /* BOUNDARY HANDLING*/
    for (i = 0; i < DIM; i++)
    {
        tmp = fabs(x[i]) - 5.;
        if (tmp > 0.)
        {
            Fpen += tmp * tmp;
        }
    }
    Fadd += 10./(double)DIM * Fpen;

    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++)
    {
        tmpvect[i] = 0.;
        for (j = 0; j < DIM; j++)
        {
            tmpvect[i] += rotation[i][j] * (x[j] - Xopt[j]);
        }
    }

    monotoneTFosc(tmpvect);
    for (i = 0; i < DIM; i++)
    {
        tmx[i] = 0.;
        for (j = 0; j < DIM; j++)
        {
            tmx[i] += linearTF[i][j] * tmpvect[j];
        }
    }
    /* COMPUTATION core*/
    for (i = 0; i < DIM; i++)
    {
        tmp = 0.;
        for (j = 0; j < 12; j++)
        {
            tmp += cos(2 * M_PI * (tmx[i] + 0.5) * bK[j]) * aK[j];
        }
        Ftrue += tmp;
    }
    Ftrue = 10. * pow(Ftrue/(double)DIM - F0, 3.);
    Ftrue += Fadd;
    Fval = Ftrue; /* without noise*/

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
Beispiel #9
0
TwoDoubles f15(double* x) {
    /* Rastrigin with asymmetric non-linear distortion, "condition" 10*/
    int i, j, k, rseed; /*Loop over dim*/
    static unsigned int funcId = 15;
    static double condition = 10.;
    static double beta = 0.2;
    double tmp = 0., tmp2 = 0., Fadd, Fval, Ftrue;
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = funcId + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        computeXopt(rseed, DIM);
        computeRotation(rotation, rseed + 1000000, DIM);
        computeRotation(rot2, rseed, DIM);
        for (i = 0; i < DIM; i++)
        {
            for (j = 0; j < DIM; j++)
            {
                linearTF[i][j] = 0.;
                for (k = 0; k < DIM; k++) {
                    linearTF[i][j] += rotation[i][k] * pow(sqrt(condition), ((double)k)/((double)(DIM-1))) * rot2[k][j];
                }
            }
        }
        isInitDone = 1;
    }
    Fadd = Fopt;
    /* BOUNDARY HANDLING*/

    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++)
    {
        tmpvect[i] = 0.;
        for (j = 0; j < DIM; j++)
        {
            tmpvect[i] += rotation[i][j] * (x[j] - Xopt[j]);
        }
    }

    monotoneTFosc(tmpvect);
    for (i = 0; i < DIM; i++)
    {
        if (tmpvect[i] > 0)
            tmpvect[i] = pow(tmpvect[i], 1 + beta * ((double)i)/((double)(DIM-1)) * sqrt(tmpvect[i]));
    }
    for (i = 0; i < DIM; i++)
    {
        tmx[i] = 0.;
        for (j = 0; j < DIM; j++)
        {
            tmx[i] += linearTF[i][j] * tmpvect[j];
        }
    }
    /* COMPUTATION core*/
    for (i = 0; i < DIM; i++)
    {
        tmp += cos(2. * M_PI * tmx[i]);
        tmp2 += tmx[i] * tmx[i];
    }
    Ftrue = 10. * ((double)DIM - tmp) + tmp2;
    Ftrue += Fadd;
    Fval = Ftrue; /* without noise*/

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
Beispiel #10
0
TwoDoubles f9(double* x) {
    /* Rosenbrock, rotated*/
    int i, j, rseed; /*Loop over dim*/
    static unsigned int funcId = 9;
    double scales, tmp, Fadd, Fval, Ftrue = 0.;
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = funcId + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        /* computeXopt(rseed, DIM);*/
        computeRotation(rotation, rseed, DIM);
        scales = fmax(1., sqrt(DIM) / 8.);
        for (i = 0; i < DIM; i ++)
        {
            for (j = 0; j < DIM; j++)
                linearTF[i][j] = scales * rotation[i][j];
        }
/*         for (i = 0; i < DIM; i++)
           {
               Xopt[i] = 0.;
               for (j = 0; j < DIM; j++)
               {
                   Xopt[i] += linearTF[j][i] * 0.5/scales/scales;
                   //computed only if Xopt is returned which is not the case at this point.
               }
            }*/
        isInitDone = 1;
    }
    Fadd = Fopt;

    /* BOUNDARY HANDLING*/

    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++) {
        tmx[i] = 0.5;
        for (j = 0; j < DIM; j++) {
            tmx[i] += linearTF[i][j] * x[j];
        }
    }

    /* COMPUTATION core*/
    for (i = 0; i < DIM - 1; i++)
    {
        tmp = (tmx[i] * tmx[i] - tmx[i+1]);
        Ftrue += tmp * tmp;
    }
    Ftrue *= 1e2;
    for (i = 0; i < DIM - 1; i ++)
    {
       tmp = (tmx[i] - 1.);
        Ftrue += tmp * tmp;
    }

    Ftrue += Fadd;
    Fval = Ftrue; /* without noise*/

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
Beispiel #11
0
TwoDoubles f6(double* x) {
    /* attractive sector function*/
    int i, j, k, rseed; /*Loop over dim*/
    static unsigned int funcId = 6;
    static double alpha = 100.;
    double Fadd, Fval, Ftrue = 0.;
    TwoDoubles res;

    if (!isInitDone)
    {
        static double condition = 10.;
        rseed = funcId + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        computeXopt(rseed, DIM);
        computeRotation(rotation, rseed + 1000000, DIM);
        computeRotation(rot2, rseed, DIM);
        /* decouple scaling from function definition*/
        for (i = 0; i < DIM; i ++)
        {
            for (j = 0; j < DIM; j++)
            {
                linearTF[i][j] = 0.;
                for (k = 0; k < DIM; k++) {
                    linearTF[i][j] += rotation[i][k] * pow(sqrt(condition), ((double)k)/((double)(DIM-1))) * rot2[k][j];
                }
            }
        }
        isInitDone = 1;
    }
    Fadd = Fopt;

    /* BOUNDARY HANDLING*/
    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++) {

        tmx[i] = 0.;
        for (j = 0; j < DIM; j++) {
            tmx[i] += linearTF[i][j] * (x[j] - Xopt[j]);
        }
    }

    /* COMPUTATION core*/
    for (i = 0; i < DIM; i++)
    {
        if (tmx[i] * Xopt[i] > 0)
            tmx[i] *= alpha;
        Ftrue += tmx[i] * tmx[i];
    }

    /*MonotoneTFosc...*/
    if (Ftrue > 0)
    {
        Ftrue = pow(exp(log(Ftrue)/0.1 + 0.49*(sin(log(Ftrue)/0.1) + sin(0.79*log(Ftrue)/0.1))), 0.1);
    }
    else if (Ftrue < 0)
    {
        Ftrue = -pow(exp(log(-Ftrue)/0.1 + 0.49*(sin(0.55 * log(-Ftrue)/0.1) + sin(0.31*log(-Ftrue)/0.1))), 0.1);
    }
    Ftrue = pow(Ftrue, 0.9);
    Ftrue += Fadd;
    Fval = Ftrue; /* without noise*/

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
Beispiel #12
0
TwoDoubles f24(double* x) {
    /* Lunacek bi-Rastrigin, condition 100*/
    /* in PPSN 2008, Rastrigin part rotated and scaled*/
    int i, j, k, rseed; /*Loop over dim*/
    static unsigned int funcId = 24;
    static double condition = 100.;
    static double mu1 = 2.5;
    double Fadd, Fpen = 0., tmp, Ftrue = 0., tmp2 = 0., tmp3 = 0., tmp4 = 0., Fval;
    double s = 1. - 0.5 / (sqrt((double)(DIM + 20)) - 4.1);
    static double d = 1.;
    double mu2 = -sqrt((mu1 * mu1 - d) / s);
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = funcId + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        computeRotation(rotation, rseed + 1000000, DIM);
        computeRotation(rot2, rseed, DIM);
        gauss(tmpvect, DIM, rseed);
        for (i = 0; i < DIM; i++)
        {
            Xopt[i] = 0.5 * mu1;
            if (tmpvect[i] < 0.)
                Xopt[i] *= -1.;
        }

        for (i = 0; i < DIM; i++)
        {
            for (j = 0; j < DIM; j++)
            {
                linearTF[i][j] = 0.;
                for (k = 0; k < DIM; k++) {
                    linearTF[i][j] += rotation[i][k] * pow(sqrt(condition), ((double)k)/((double)(DIM-1))) * rot2[k][j];
                }
            }
        }
        isInitDone = 1;
    }
    Fadd = Fopt;

    /* BOUNDARY HANDLING*/
    for (i = 0; i < DIM; i++)
    {
        tmp = fabs(x[i]) - 5.;
        if (tmp > 0.)
        {
            Fpen += tmp * tmp;
        }
    }
    Fadd += 1e4 * Fpen;

    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++)
    {
        tmx[i] = 2. * x[i];
        if (Xopt[i] < 0.)
            tmx[i] *= -1.;
    }

    /* COMPUTATION core*/
    tmp = 0.;
    for (i = 0; i < DIM; i++)
    {
        tmp2 += (tmx[i] - mu1) * (tmx[i] - mu1);
        tmp3 += (tmx[i] - mu2) * (tmx[i] - mu2);
        tmp4 = 0.;
        for (j = 0; j < DIM; j++)
        {
            tmp4 += linearTF[i][j] * (tmx[j] - mu1);
        }
        tmp += cos(2 * M_PI * tmp4);
    }
    Ftrue = fmin(tmp2, d * (double)DIM + s * tmp3) + 10. * ((double)DIM - tmp);
    Ftrue += Fadd;
    Fval = Ftrue; /* without noise*/

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
Beispiel #13
0
TwoDoubles f23(double* x) {
    /* Katsuura function*/
    int i, j, k, rseed; /*Loop over dim*/
    static unsigned int funcId = 23;
    static double condition = 100.;
    double Fadd = 0., Fpen = 0., tmp, Ftrue = 0., arr, prod = 1., tmp2, Fval;
    double *ptmx, *plinTF, *ptmp;
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = funcId + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        computeXopt(rseed, DIM);
        computeRotation(rotation, rseed + 1000000, DIM);
        computeRotation(rot2, rseed, DIM);

        for (i = 0; i < DIM; i++)
        {
            for (j = 0; j < DIM; j++)
            {
                linearTF[i][j] = 0.;
                for (k = 0; k < DIM; k++)
                {
                    linearTF[i][j] += rotation[i][k] * pow(sqrt(condition), ((double)k)/(double)(DIM - 1)) * rot2[k][j];
                }
            }
        }
        isInitDone = 1;
    }
    Fadd = Fopt;

    /* BOUNDARY HANDLING*/
    for (i = 0; i < DIM; i++)
    {
        tmp = fabs(x[i]) - 5.;
        if (tmp > 0.)
        {
            Fpen += tmp * tmp;
        }
    }
    Fadd += Fpen;

    /* TRANSFORMATION IN SEARCH SPACE*/
    /* write rotated difference vector into tmx*/
    for (j = 0; j < DIM; j++)  /* store difference vector*/
        tmpvect[j] = x[j] - Xopt[j];
    for (i = 0; i < DIM; i++) {
        tmx[i] = 0.;
        ptmx = &tmx[i];
        plinTF = linearTF[i];
        ptmp = tmpvect;
        for (j = 0; j < DIM; j++) {
            *ptmx += *plinTF++ * *ptmp++;
        }
    }

/*     for (i = 0; i < DIM; i++) {
           tmx[i] = 0.;
           for (j = 0; j < DIM; j++) {
               tmx[i] += linearTF[i][j] * (x[j] - Xopt[j]);
           }
       }*/

    /* COMPUTATION core*/
    for (i = 0; i < DIM; i++)
    {
        tmp = 0.;
        for (j = 1; j < 33; j++)
        {
            tmp2 = pow(2., (double)j);
            arr = tmx[i] * tmp2;
            tmp += fabs(arr - round(arr)) / tmp2;
        }
        tmp = 1. + tmp * (double)(i + 1);
        prod *= tmp;
    }
    Ftrue = 10./(double)DIM/(double)DIM * (-1. + pow(prod, 10./pow((double)DIM, 1.2)));
    Ftrue += Fadd;
    Fval = Ftrue; /* without noise*/

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}
Beispiel #14
0
TwoDoubles f19(double* x) {
    /* F8F2 sum of Griewank-Rosenbrock 2-D blocks*/
    int i, j, rseed; /*Loop over dim*/
    static unsigned int funcId = 19;
    double scales, F2, tmp = 0., tmp2, Fadd, Fval, Ftrue = 0.;
    TwoDoubles res;

    if (!isInitDone)
    {
        rseed = funcId + 10000 * trialid;
        /*INITIALIZATION*/
        Fopt = computeFopt(funcId, trialid);
        /* computeXopt(rseed, DIM); Xopt is not used.*/
        scales = fmax(1., sqrt(DIM) / 8.);
        computeRotation(rotation, rseed, DIM);
        for (i = 0; i < DIM; i ++)
        {
            for (j = 0; j < DIM; j++)
            {
                linearTF[i][j] = scales * rotation[i][j];
            }
        }
        for (i = 0; i < DIM; i++)
        {
            Xopt[i] = 0.;
            for (j = 0; j < DIM; j++)
            {
                Xopt[i] += linearTF[j][i] * 0.5/scales/scales;
            }
        }
        isInitDone = 1;
    }
    Fadd = Fopt;
    /* BOUNDARY HANDLING*/

    /* TRANSFORMATION IN SEARCH SPACE*/
    for (i = 0; i < DIM; i++) {
        tmx[i] = 0.5;
        for (j = 0; j < DIM; j++) {
            tmx[i] += linearTF[i][j] * x[j];
        }
    }

    /* COMPUTATION core*/
    for (i = 0; i < DIM - 1; i++)
    {
        tmp2 = tmx[i] * tmx[i] -tmx[i+1];
        F2 = 100. * tmp2 * tmp2;
        tmp2 = 1 - tmx[i];
        F2 += tmp2 * tmp2;
        tmp += F2 / 4000. - cos(F2);
    }
    Ftrue = 10. + 10. * tmp / (double)(DIM - 1);

    Ftrue += Fadd;
    Fval = Ftrue; /* without noise*/

    res.Fval = Fval;
    res.Ftrue = Ftrue;
    return res;
}