00001 // ParameterRandomizer.cpp: implementation of the CParameterRandomizer class. 00002 // 00004 00005 #include "ParameterRandomizer.h" 00006 00008 // Construction/Destruction 00010 00011 CParameterRandomizer::CParameterRandomizer(int seed) 00012 { 00013 m_iSeed = seed; 00014 m_pRNG = new Rand(seed); 00015 } 00016 00017 CParameterRandomizer::~CParameterRandomizer() 00018 { 00019 delete m_pRNG; 00020 } 00021 00022 void CParameterRandomizer::Randomize(double *parameters, int nParameters, double fraction, int nIterations) 00023 { 00024 if(fraction > 1.0) 00025 { 00026 fraction = 1.0; 00027 } 00028 if(fraction < 0.0) 00029 { 00030 fraction = 0.0; 00031 } 00032 00033 for(int iCount = 0; iCount < nIterations; iCount++) 00034 { 00035 for(int i = 0; i < nParameters; i++) 00036 { 00037 parameters[i] += (-1 + 2*(m_pRNG->uniform()))*fraction*parameters[i]; 00038 } 00039 } 00040 }