Skip to content

Commit

Permalink
- minor initialization fixes
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11111 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Feb 14, 2012
1 parent 29256d6 commit b3f7152
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions SimulationRuntime/c/math-support/initialization.c
Expand Up @@ -75,7 +75,7 @@ static double leastSquareWithLambda(DATA* data, long nz, double* z, double* zNom
int indz = 0;
fortran_integer i = 0;
long j = 0;
double funcValue = 0;
double funcValue = 0.0;
double scalingCoefficient;

for(i=0; i<data->modelData.nStates; ++i)
Expand Down Expand Up @@ -272,7 +272,7 @@ static void NelderMeadOptimization(long N,
long x = 0;
long i = 0;

double lambda = 0.0;
double lambda = *pLambda;
long iteration = 0;

/* check Memory */
Expand All @@ -297,15 +297,14 @@ static void NelderMeadOptimization(long N,
simplex[i*N + i] += 1.0; /* canonical simplex */
}

/*DEBUG_INFO3(LOG_INIT, "NelderMeadOptimization | increasing lambda to %g in step %d at f=%g", lambda, (int)iteration, leastSquare(data, N, simplex, scale, initialResidualScalingCoefficients, lambda, initialResiduals));*/
computeInitialResidualScalingCoefficients(data, N, simplex, scale, initialResidualScalingCoefficients);

do
{
/* lambda-control */
double sigma = 0.0;
double average = 0.0;
double g = 0.00001;
double g = 1e-8;

iteration++;

Expand All @@ -321,6 +320,12 @@ static void NelderMeadOptimization(long N,
xb = x;
}

if(fvalues[xb] < acc)
break;

if(maxIt < iteration)
break;

xs = xb;
xz = xb;
for(x=0; x<N+1; x++)
Expand All @@ -345,16 +350,19 @@ static void NelderMeadOptimization(long N,

/* dump every dump-th step */
if(dump && !(iteration % dump))
INFO4("NelderMeadOptimization | lambda=%g / step=%d / f=%g [%g]", lambda, (int)iteration, fvalues[xb], fvalues[xz]);
INFO4("NelderMeadOptimization | lambda=%g / step=%d / f=%g [%g]", lambda, (int)iteration, fvalues[xb], fvalues[xs]);

if((sigma < (g*g)) && (lambda < 1.0))
if(sigma < g)
{
lambda += lambda_step;
if(lambda > 1.0)
lambda = 1.0;
if(lambda < 1.0)
{
lambda += lambda_step;
if(lambda >= 1.0)
break;

DEBUG_INFO3(LOG_INIT, "NelderMeadOptimization | increasing lambda to %g in step %d at f=%g", lambda, (int)iteration, fvalues[xb]);
continue;
DEBUG_INFO3(LOG_INIT, "NelderMeadOptimization | increasing lambda to %g in step %d at f=%g", lambda, (int)iteration, fvalues[xb]);
continue;
}
}

/* calculate central point for the n best vertices */
Expand Down Expand Up @@ -441,11 +449,11 @@ static void NelderMeadOptimization(long N,
/* not possible to be here */
INFO("not possible to be here");
}
}while((lambda < 1.0 || fvalues[xb] > acc) && iteration < maxIt);
}while(1.0);

/* copying solution */
for(i=0; i<N; i++)
var[i] = simplex[xs*N+i];
var[i] = simplex[xb*N+i];

if(pLambda)
*pLambda = lambda;
Expand Down Expand Up @@ -506,9 +514,9 @@ static int reportResidualValue(DATA* data, double funcValue, double* initialResi
*/
static int nelderMeadEx_initialization(DATA *data, long nz, double *z, char** zName, double *zNominal, double* initialResiduals)
{
double STOPCR = 1.e-16;
double lambda_step = 0.1;
long NLOOP = 10000 * nz;
double STOPCR = 1.e-12;
double lambda_step = 0.2;
long NLOOP = 1000 * nz;

double funcValue;

Expand Down Expand Up @@ -538,7 +546,7 @@ static int nelderMeadEx_initialization(DATA *data, long nz, double *z, char** zN

for(l=0; l<100 && funcValue > STOPCR; l++)
{
DEBUG_INFO1(LOG_INIT, "initialization-nr. %d", (int)l);
DEBUG_INFO1(LOG_INIT, "initialization-nr. %ld", l);

NelderMeadOptimization(nz, z, zNominal, initialResidualScalingCoefficients, lambda_step, STOPCR, NLOOP, DEBUG_FLAG(LOG_INIT) ? 10000 : 0, &lambda, &iteration, leastSquareWithLambda, data, initialResiduals);

Expand Down

0 comments on commit b3f7152

Please sign in to comment.