/*!
 *  \brief Initialize the derandomized ES initialization operator.
 *  \param ioSystem System of the evolution.
 */
void GA::InitQRESVecOp::init(System& ioSystem)
{
	Beagle_StackTraceBeginM();
	GA::InitESVecOp::init(ioSystem);
	QuasiRandom::Handle lQRComponent =
	    castHandleT<QuasiRandom>(ioSystem.getComponent("QuasiRandom"));
	if(lQRComponent->getDimensionality() == 0) {
		lQRComponent->reset(mESVectorSize->getWrappedValue()+1, ioSystem.getRandomizer());
	}
	Beagle_StackTraceEndM("void GA::InitQRESVecOp::init(System&)");
}
Exemplo n.º 2
0
/*!
 *  \brief Initialize the derandomized Gaussian float vector initialization operator.
 *  \param ioSystem System of the evolution.
 */
void FltVec::InitGaussianQROp::init(System& ioSystem)
{
    Beagle_StackTraceBeginM();
    FltVec::InitGaussianOp::init(ioSystem);
    QuasiRandom::Handle lQRComponent =
        castHandleT<QuasiRandom>(ioSystem.getComponent("QuasiRandom"));
    if(lQRComponent->getDimensionality() == 0) {
        lQRComponent->reset(mFloatVectorSize->getWrappedValue(), ioSystem.getRandomizer());
    }
    Beagle_StackTraceEndM();
}
/*!
 *  \brief Initialize ES individual with initial strategy parameter.
 *  \param outIndividual Individual to initialize.
 *  \param ioContext Evolution context.
 *
 *  Size of ES individual is given by integer vector "es.init.vectorsize". Initial strategy
 *  parameter value of ES pair is given by parameter "es.init.strategy". Initial value of ES pair
 *  is given using random numbers following a Gaussian distribution of zero mean and standard
 *  deviation equal to initial strategy parameter value.
 */
void GA::InitQRESVecOp::initIndividual(Beagle::Individual& outIndividual, Context& ioContext)
{
	Beagle_StackTraceBeginM();
#ifndef BEAGLE_NDEBUG
	if(mESVectorSize->getWrappedValue() == 0) {
		std::string lMessage = "GA::InitQRESVecOp::initIndividual: ";
		lMessage += "ES vector size parameter is zero; ";
		lMessage += "could not initialize the individuals!";
		throw Beagle_RunTimeExceptionM(lMessage);
	}
#endif // BEAGLE_NDEBUG

	const Factory& lFactory = ioContext.getSystem().getFactory();
	GA::ESVector::Alloc::Handle lESVectorAlloc =
		castHandleT<GA::ESVector::Alloc>(lFactory.getConceptAllocator("Genotype"));
	GA::ESVector::Handle lESVector = castHandleT<GA::ESVector>(lESVectorAlloc->allocate());
	lESVector->resize(mESVectorSize->getWrappedValue());
	outIndividual.clear();
	outIndividual.push_back(lESVector);
	Vector lQRValues(mESVectorSize->getWrappedValue()+1);
	QuasiRandom::Handle lQRComponent =
	    castHandleT<QuasiRandom>(ioContext.getSystem().getComponent("QuasiRandom"));
	lQRComponent->getUniformVector(lQRValues);
	Beagle_AssertM((mESVectorSize->getWrappedValue()+1) == lQRValues.size());
	const double lInitStrategy = mInitStrategyValue->getWrappedValue();
	for(unsigned int j=0; j<lESVector->size(); ++j) {
		const double lMaxVal = j<mMaxValue->size() ? (*mMaxValue)[j] : mMaxValue->back();
		const double lMinVal = j<mMinValue->size() ? (*mMinValue)[j] : mMinValue->back();
		(*lESVector)[j].mValue = (lQRValues[j] * lInitStrategy);
		if((*lESVector)[j].mValue > lMaxVal) (*lESVector)[j].mValue = lMaxVal;
		if((*lESVector)[j].mValue < lMinVal) (*lESVector)[j].mValue = lMinVal;
		(*lESVector)[j].mStrategy = lInitStrategy;
	}
	Beagle_LogDebugM(
	    ioContext.getSystem().getLogger(),
	    "initialization", "Beagle::GA::InitQRESVecOp",
	    "ES vector is initialized as"
	);
	Beagle_LogObjectDebugM(
	    ioContext.getSystem().getLogger(),
	    "initialization", "Beagle::GA::InitQRESVecOp",
	    *lESVector
	);
	Beagle_StackTraceEndM("void GA::InitQRESVecOp::initIndividual(Beagle::Individual& outIndividual, Context& ioContext)");
}
Exemplo n.º 4
0
/*!
 *  \brief Initialize real-valued individual with derandomized Gaussian values.
 *  \param outIndividual Individual to initialize.
 *  \param ioContext Evolution context.
 */
void FltVec::InitGaussianQROp::initIndividual(Beagle::Individual& outIndividual, Context& ioContext)
{
    Beagle_StackTraceBeginM();
#ifndef BEAGLE_NDEBUG
    if(mFloatVectorSize->getWrappedValue() == 0) {
        string lMessage = "FltVec::InitGaussianQROp::initIndividual: ";
        lMessage += "float vector size parameter is zero; ";
        lMessage += "could not initialize the individuals!";
        throw Beagle_RunTimeExceptionM(lMessage);
    }
#endif // BEAGLE_NDEBUG
    const Factory& lFactory = ioContext.getSystem().getFactory();
    FltVec::FloatVector::Alloc::Handle lVectorAlloc =
        castHandleT<FltVec::FloatVector::Alloc>(lFactory.getConceptAllocator("Genotype"));
    FltVec::FloatVector::Handle lVector =
        castHandleT<FltVec::FloatVector>(lVectorAlloc->allocate());
    lVector->resize(mFloatVectorSize->getWrappedValue());
    outIndividual.clear();
    outIndividual.push_back(lVector);
    QuasiRandom::Handle lQRComponent =
        castHandleT<QuasiRandom>(ioContext.getSystem().getComponent("QuasiRandom"));
    Vector lQRValues(lVector->size());
    lQRComponent->getGaussianVector(lQRValues);
    Beagle_AssertM(mFloatVectorSize->getWrappedValue() == lQRValues.size());
    for(unsigned int j=0; j<lVector->size(); ++j) {
        const double lMaxVal = j<mMaxInitValue->size() ? (*mMaxInitValue)[j] : mMaxInitValue->back();
        const double lMinVal = j<mMinInitValue->size() ? (*mMinInitValue)[j] : mMinInitValue->back();
        const double lIncVal = j<mIncValue->size() ? (*mIncValue)[j] : mIncValue->back();
        const double lMean   = j<mMean->size() ? (*mMean)[j] : mMean->back();
        const double lStdev  = j<mStdev->size() ? (*mStdev)[j] : mStdev->back();
        (*lVector)[j] = (lQRValues[j] * lStdev) + lMean;
        if((*lVector)[j] > lMaxVal) (*lVector)[j] = lMaxVal;
        if((*lVector)[j] < lMinVal) (*lVector)[j] = lMinVal;
        if(std::fabs(lIncVal)>1e-12) {
            (*lVector)[j] = lIncVal * round((*lVector)[j] / lIncVal);
            if((*lVector)[j] > lMaxVal) (*lVector)[j] -= lIncVal;
            if((*lVector)[j] < lMinVal) (*lVector)[j] += lIncVal;
        }
    }
    Beagle_LogDebugM(
        ioContext.getSystem().getLogger(),
        *lVector
    );
    Beagle_StackTraceEndM();
}