00001
00002
00004
00005 #include "LowDimensionalCostFunctionMapper.h"
00006
00008
00010
00011 CLowDimensionalCostFunctionMapper::CLowDimensionalCostFunctionMapper()
00012 {
00013 m_pMO = new CMatrixOperations();
00014 }
00015
00016 CLowDimensionalCostFunctionMapper::~CLowDimensionalCostFunctionMapper()
00017 {
00018 delete m_pMO;
00019 }
00020
00021 void CLowDimensionalCostFunctionMapper::Map(Minimizable *pMin, CParameterFilter *pFilter, double *p1, double *p2, double a, double b, int nPts)
00022 {
00023
00024 fstream *pfLine = new fstream("line.par",ios::out);
00025 *pfLine << "##################################################################" << endl;
00026 *pfLine << "# LINE EVALUATION OF COST FUNCTION" << endl;
00027 *pfLine << "# LAMBDA COST" << endl;
00028 *pfLine << "##################################################################" << endl;
00029
00030 int nParameters = pMin->GetNParameters();
00031
00032 double *v = new double[nParameters];
00033
00034 pFilter->ForwardTransformation(p1,nParameters);
00035 pFilter->ForwardTransformation(p2,nParameters);
00036
00037 double lambda = a;
00038 for(int i = 0; i < nPts; i++)
00039 {
00040
00041 lambda = a + (b - a)*(i/(nPts - 1.0));
00042
00043 m_pMO->TwoVectorLC(1.0-lambda,p1,lambda,p2,v,nParameters);
00044
00045 pFilter->BackwardTransformation(v,nParameters);
00046 double cost = pMin->ObjectiveFunction(v);
00047 pFilter->ForwardTransformation(v,nParameters);
00048
00049 *pfLine << lambda << "\t" << cost << endl;
00050 }
00051
00052 pfLine->close();
00053 delete pfLine;
00054 delete [] v;
00055 }
00056
00057 void CLowDimensionalCostFunctionMapper::Map(Minimizable *pMin,CParameterFilter *pFilter, double *p1, double *p2, double *p3, double a, double b, double c, double d, int nPts)
00058 {
00059
00060 fstream *pfPlane = new fstream("plane.par",ios::out);
00061 *pfPlane << "##################################################################" << endl;
00062 *pfPlane << "# PLANE EVALUATION OF COST FUNCTION" << endl;
00063 *pfPlane << "# BETA1 BETA2 COST" << endl;
00064 *pfPlane << "##################################################################" << endl;
00065
00066 int nParameters = pMin->GetNParameters();
00067
00068 double *v = new double[nParameters];
00069 double *vint = new double[nParameters];
00070
00071 double *b1diff = new double[nParameters];
00072 double *b2diff = new double[nParameters];
00073
00074 pFilter->ForwardTransformation(p1,nParameters);
00075 pFilter->ForwardTransformation(p2,nParameters);
00076 pFilter->ForwardTransformation(p3,nParameters);
00077
00078
00079
00080 double beta1 = 0.0;
00081 double beta2 = 0.0;
00082 int Nx = (int) sqrt((double)nPts);
00083 int Ny = (int) sqrt((double)nPts);
00084 for(int x = 0; x < Nx; x++)
00085 {
00086 beta1 = a + (b - a)*(x/(Nx - 1.0));
00087
00088 m_pMO->TwoVectorLC(beta1,p3,-beta1,p1,b1diff,nParameters);
00089 m_pMO->TwoVectorLC(1.0,p1,1.0,b1diff,vint,nParameters);
00090
00091 for(int y = 0; y < Ny; y++)
00092 {
00093 beta2 = c + (d - c)*(y/(Ny - 1.0));
00094
00095 m_pMO->TwoVectorLC(beta2,p2,-beta2,p1,b2diff,nParameters);
00096
00097 m_pMO->TwoVectorLC(1.0,vint,1.0,b2diff,v,nParameters);
00098
00099 pFilter->BackwardTransformation(v,nParameters);
00100 double cost = pMin->ObjectiveFunction(v);
00101 pFilter->ForwardTransformation(v,nParameters);
00102
00103 *pfPlane << beta1 << "\t" << beta2 << "\t" << cost << endl;
00104 }
00105 }
00106
00107 pfPlane->close();
00108 delete pfPlane;
00109 delete [] v;
00110 delete [] vint;
00111 delete [] b1diff;
00112 delete [] b2diff;
00113 }