24 MinimTransformFunction::MinimTransformFunction (
const IMultiGradFunction * f,
const std::vector<EMinimVariableType> & types,
25 const std::vector<double> & values,
26 const std::map<
unsigned int, std::pair<double, double> > & bounds) :
34 unsigned int ntot = NTot();
35 assert ( types.size() == ntot );
36 fVariables.reserve(ntot);
38 for (
unsigned int i = 0; i < ntot; ++i ) {
39 if (types[i] == kFix )
40 fVariables.push_back( MinimTransformVariable( values[i]) );
44 if ( types[i] == kDefault)
45 fVariables.push_back( MinimTransformVariable() );
47 std::map<unsigned int, std::pair<double,double> >::const_iterator itr = bounds.find(i);
48 assert ( itr != bounds.end() );
49 double low = itr->second.first;
50 double up = itr->second.second;
51 if (types[i] == kBounds )
52 fVariables.push_back( MinimTransformVariable( low, up,
new SinVariableTransformation()));
53 else if (types[i] == kLowBound)
54 fVariables.push_back( MinimTransformVariable( low,
new SqrtLowVariableTransformation()));
55 else if (types[i] == kUpBound)
56 fVariables.push_back( MinimTransformVariable( up,
new SqrtUpVariableTransformation()));
63 void MinimTransformFunction::Transformation(
const double * x,
double * xext)
const {
66 unsigned int nfree = fIndex.size();
72 for (
unsigned int i = 0; i < nfree; ++i ) {
73 unsigned int extIndex = fIndex[i];
74 const MinimTransformVariable & var = fVariables[ extIndex ];
76 xext[ extIndex ] = var.InternalToExternal( x[i] );
78 xext[ extIndex ] = x[i];
87 void MinimTransformFunction::InvTransformation(
const double * xExt,
double * xInt)
const {
89 for (
unsigned int i = 0; i < NDim(); ++i ) {
90 unsigned int extIndex = fIndex[i];
91 const MinimTransformVariable & var = fVariables[ extIndex ];
92 assert ( !var.IsFixed() );
94 xInt[ i ] = var.ExternalToInternal( xExt[extIndex] );
96 xInt[ i ] = xExt[extIndex];
100 void MinimTransformFunction::InvStepTransformation(
const double * x,
const double * sExt,
double * sInt)
const {
102 for (
unsigned int i = 0; i < NDim(); ++i ) {
103 unsigned int extIndex = fIndex[i];
104 const MinimTransformVariable & var = fVariables[ extIndex ];
105 assert ( !var.IsFixed() );
106 if (var.IsLimited() ) {
108 double x2 = x[extIndex] + sExt[extIndex];
109 if (var.HasUpperBound() && x2 >= var.UpperBound() )
110 x2 = x[extIndex] - sExt[extIndex];
112 double xint = var.ExternalToInternal ( x[extIndex] );
113 double x2int = var.ExternalToInternal( x2 );
114 sInt[i] = std::abs( x2int - xint);
117 sInt[ i ] = sExt[extIndex];
121 void MinimTransformFunction::GradientTransformation(
const double * x,
const double *gExt,
double * gInt)
const {
123 unsigned int nfree = fIndex.size();
124 for (
unsigned int i = 0; i < nfree; ++i ) {
125 unsigned int extIndex = fIndex[i];
126 const MinimTransformVariable & var = fVariables[ extIndex ];
127 assert (!var.IsFixed() );
128 if (var.IsLimited() )
129 gInt[i] = gExt[ extIndex ] * var.DerivativeIntToExt( x[i] );
131 gInt[i] = gExt[ extIndex ];
136 void MinimTransformFunction::MatrixTransformation(
const double * x,
const double *covInt,
double * covExt)
const {
140 unsigned int nfree = fIndex.size();
141 unsigned int ntot = NTot();
142 for (
unsigned int i = 0; i < nfree; ++i ) {
143 unsigned int iext = fIndex[i];
144 const MinimTransformVariable & ivar = fVariables[ iext ];
145 assert (!ivar.IsFixed());
146 double ddi = ( ivar.IsLimited() ) ? ivar.DerivativeIntToExt( x[i] ) : 1.0;
148 for (
unsigned int j = 0; j < nfree; ++j ) {
149 unsigned int jext = fIndex[j];
150 const MinimTransformVariable & jvar = fVariables[ jext ];
151 double ddj = ( jvar.IsLimited() ) ? jvar.DerivativeIntToExt( x[j] ) : 1.0;
152 assert (!jvar.IsFixed() );
153 covExt[ iext * ntot + jext] = ddi * ddj * covInt[ i * nfree + j];