Algorithm To Calcule Objective Function of PUYEAR

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

/*Algorithm to calcule Objective Function of PUYEAR & CASTAGNAS equation (2008) * Spectral Inversion Method */ #include <iostream> #include

<fstream> #include <cmath> #include <cstdio> #include <cstdlib> #include <stdio.h> #include <stdlib.h> Using namespace std; #define PI 3.14159265358979323846 /METHODS/ //decomp method Int decomp (float xx [],float yy[], int zz, float kk [], double pe [], double po[]); FILE * readecon, *imadecon; //Simpson numerical integration method double calcularSimpson (double FX[], int N, double h); double Simpson38 (int n, double FX[], double h); double Simpson13 (int n, int N, double FX[], double h); /MAIN/ int main (int argc, char **argv) /LOCAL ATTRIBUTES/ float thickIn[150], refCoef[150], timeIn[150];//Files with reflection coefficients and time int sRC; //Size of ref coef and time FILE *rc; //Files with reflection coefficients int i=0, j=0, pos, fsamp; //Auxiliar Values ofstream outEv; //Output files ofstream out0d; // Equation values double readec [100], imadec [100]; //Arrays with real and imaginary part of deconvolutin double dato_modRE [100],dato_modI0 [100];//Data minos model of both components double alfaev=0.5; //Weighting function of components (Escalar) double f[50]; //Frecuency double ObjFun, pot0F; //Objetive Function

// Even and Odd part decomposition int size; float thickness [50];

//Size of ref coef and time //Array of time

double peven [50], podd [50]; float T [150], r[150], t [150]; double pe [150], po [150];

//Arrays with even and odd components of pairs of ref coef

// Local attributes for Simpson numerical integration method int SegT, segF; //Amount of intervals double intF, intT; //Interval dt and df double infT, supT, infF, SupF; //Integration boundaries t (ms) and f (Hz) double IEvInter[50]; //Array of Integrals by each frecuency even component double I0dInter [50]; //Array of Integrals by each frencuency odd component double funcionfinal [100]; //Final Function to integrate (ReEv + Im0dd) //Local attributes to cubic spline interpolation double espDecEv [100], espDec0d [100]; //Time function without any interpolation double EvCoef [100] [4]; //Array [n] [4] of interpolation coefficients even component double 0dCoef [100] [4]; //Array. [n][4] of interpolation coefficients odd component double fEvInter [150]; //Interpolated array each 2 ms even component double f0dInter [150]; //Interpolated array each 2 ms odd component float hh; int x=0; //Auxiliar Values

/CONDITIONS FOR EXECUTING, OPENING AND READING FILES/ //if (argc!=9) { //cout<</nUse: ./objfunction_cpp \n<<endl; //return 1; //}

readecon=fopen (desretraza.asc , r); if (readecon==NULL) { cout<<Error, cant be opened file: <<desretraza.asc<<endl; return 1; } Imadecon=fopen(desimtraza.asc,r); If (imadecon==NULL) cout<<Error, cant be opened file: <<desimtraza.asc<<endl; return 1; }

// Chage for layers number sRC=5; thickIn [1]=atof(argv[1]); refCoef[1]=atof(argv[2]; thickIn [2]=atof(argv[3]);

refCoef[2]=atof(argv[4]; thickIn [3]=atof(argv[5]); refCoef[3]=atof(argv[6]; thickIn [4]=atof(argv[7]); refCoef[4]=atof(argv[8]; //Call even and odd part decomposition method size=decomp (thickIn, refCoef, sRC, thickness, peven, podd);//thickness in seg size=size+1; //Put first and last time, 0 and 127 timeIn[0]=0; refCoef[0]=0; peven[0]=0; podd[0]=0; thickness[0]=0; timeIn[size-1]=127; refCoef[size-1]=0; peven[size-1]=0; podd[size-1]=0; thickness[size-1]=0; for(i=1; i<size-1; i++){ timeIn[i]=timeIn [i-1]+thickness[i]; } X=0; for (i=0; i<size; i++){ while ((x>=timeIn[i]) && (x<=timeIn[i+1])){ if (x<timeIn[i+1]) { t[x]=x; pe[x]=0; po[x]=0; r[x]=0; T[x]=t[x]-timeIn[i]; }else{ If (x==timeIn[i+1]) { t[x]=timeIn[i+1]; pe[x]=peven[i+1]; po[x]=podd[i+1]; r[x]=refCoef[i+1]; } } x++; } }

for (i=0; i<x; i++){ t[i]=t[i]*0.001; T[i]=T[i]*0.001; }// it is in seg //Build new frecuency vector, df Hz between and Hz float fmax=125; nfft=(sample/2)+1; deltaf=(fmax/(sample/2)); for (j=0; j<nfft; j++) { f[j]=j*deltaf; } // Read real and imaginary components of the (s(f)/w(f)) for (i=0; i<nfft; i++) { pos=fscanf (readecon, %l\n, &readec*i+); pos=fscanf(imadecon, %l\n, &imadec*i+); if (feof(imadecon)) {break;} } /FRECUENCY ANALYSIS BAND, BUILD FUNCTION THAT DEPENDS OF TIME, t 4ms (SAMPLE RATE) for(j=0, j<nfft; j++) { for(i=0; i<x; i++) { espDecEv[i]=pe [i]*cos(PI*f[j]*(T[i])); espDec0d[i]=po [i]*sin(PI*f[j]*(T[I])); } //Function by each frecuency outEv.open (fEv.txt, ios::out); out0d.open (f0d.txt,ios::out); for (i=0; i<x; i++) { outEv << t*i+ << \t<< espDecEv*i+ << \n; out0d << t*i+ <<\t<< espDec0d *i+ << \n; } //Integration boundaries dt infT=t[0]; // Inferior boundary of time supT=t[x-1]; //Superior boundary of time intT=0.001; //Interval delta t segT= (supT-infT)/intT; //Amount of integration intervals IEvInter[j]=calcularSimpson (espDecEv, segT, intT)*1000; I0dInter[j]=calcularSimpson (espDec0d, segT, intT)*1000; //Data minos model of both components dato_modRE[j]=alfaev*(readec[j]-IEvInter[j]);

dato_modI0[j]=alfaod*(imadec[j]-I0dInter[j]); //Build final function to integrate funcionfinal[j]=dato_modRE[j]+dato_modI0[j]; //Close files outEv.close(); out0d.close(); } //Integration boundaries df intF=deltaf; intF=f[0]; supF=f[nfft-1]; segF=(supF-infF)/intF;

//Interval delta f //Inferior boundary of frecuency //superior boundary of frecuency //Amount of integration intervals

//Call integration method to calculate objective function 0bjFun=CalcularSimpson (funcionfinal, segF, intF); cout<<0bjFun<<endl; ofstream outfile; outfile.open(0F.txt,ios::out); outfile<< 0bjFun<<\n; outfile.close(); //Close files fclose (readecon); fclose (imadecon); return o; }// End main /SIMPSON INTEGRATION METHODO/ double calcularSimpson (double FX [], int N, double h) { Double I; //If N is odd Simpson 3/8 and 1/3 combination // If N is even, just Simpson 1/3 if (N%2) { I=Simpson38(0,FX,h); I+=Simpson13(3,N-3,FX,h); } else { I=Simpson13 (0,N,FX,h); } Return I;

}//End calcularSimpson double Simpson13 (int n, int N, double FX[], double h) { int i; //Calculate first and last term double I=FX[n]+FX[n+N]; //Calculate terms with i odd for (i=l;i<=N-1;i+=2){ I+= 4*FX[n+i]; } //Calculate terms with I even for (i=2;i<=N-2;i+=2){ I+=2*FX[n+i]; } I*= h/3; return I; }//End Simpson13 double Simpson38 (int n, double FX[], double h) { //Use simpson 3/8 just to resolve there points Return 3*h/8*(FX[n]+3*FX[n+1]+3*FX[n+2]+FX[n+3]) }//End Simpson38 /DE COMPOSITION OF EVEN AND ODD COMPENENTS OF PAIRS OF REFLECTION COEFICIENTS/ int decomp (float thickIn[], float coef [], int sizeRC, float thickness [], double peven [], double pod [l]{ //Local Attributes int i=0; ofstream outeven; ofstream outodd; outeven.open(pevenr, ios::out|ios::trunc); outodd.open (poddr,ios::out|ios::trunk); //Even and 0dd part decomposition and write output for (i=1; i<sizeRC; i=i+2) { peven[i]=(coef[i]+coef[i+1])/2; peven[i+1]=(coef[i+1]+coef[1])/2; podd[i]=(coef[i]-coef[i+1])/2; podd[i+1]=(coef[i+1]-coef[i])/2; thickness[i]=thickIn[i]; thickness[i+1]=thickIn[i+1]; outeven << thickIn*i+ <<\t<<peven*i+<<\n; outeven << thickIn*i+1+ <<\t<<peven*i+1+<<\n; outodd << thickIn*i+ <<\t<<podd*i+ << \n;

outodd << thickIn*i+1+ <<\t<<podd*i+1+ << \n; } outeven.close (); outodd.close(); return (sizeRC); }//End decomp /*-----------------------------------------------------------------------------------------------fftgsl.c Copyright (C) 2009-2010 K. Paola Castao 2009 <ksiopea99@gmail.com> DESCRIPTION: This program Apply Gaussian taper to trace and wavelet and Compute the FFTof time-ordered data, by using the mixed-radix functions For FFTs of any length from GSL. In this convention the half-complex transform of a real sequence is stored with frequencies in increasing order, starting at zero, with the real and imaginary parts of each frequency in neighboring locations. When a value is known to be real the imaginary parts is not stored. The imaginary part of the zero-frequency component is never stored. It is known to be zero (since the zero frequency component is simply the sum of the input data (all real)). For a sequence of even length the imaginary part of the frequency n/2 is not stored either, since the symmetry zk=z* (N-k) implies that this is purely real too. -------------------------------------------------------------------------------------------------*/ #include <stdio.h> #include <math.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_fft_real.h> #include <gsl/gsl_fft_halfcomplex.h> #include <gsl/gsl_complex.h> #include <gsl/gsl_complex_math.h> #include <stdlib.h> #include <iostream> #include <fstream> int main (int argc, char** argv) { //Local variables int n=atoi (argv[2]); double deltaf; double tr [256], tap [256], wt [256], f[128]; double traza_tpd[256], wvlet_tpd [256], mod [128]; FILE *traza, *wavelet, *taper; gsl_complex traza_complex[129],wvlet_complex[129], divi_complex[129]; gsl_fft_real_wavetable *real; gsl_fft_real_workspace *work;

//Execution condition if (argc!=4){ printf (\nUse: ./ffgsl traza.asc n=muestras taper.txt\n); return 1; } //0pen trace ascii format Traza=fopen (argv*1+, r); If (traza==NULL) { printf (Error, cant be opened file : traza.asc\n); return 1; } //0pen wavelet ascii format wavelet=fopen (wavelet.asc,r); if (wavelet==NULL) { printf (Error, cant be opened file : wavelet.asc\n); return 1; } //0pen Gaussian taper ascii format taper=fopen (argv *3+, r); if (tape==NULL) { printf (Error, cant be opened file : taper.txt\n); return 1; } //Read file for (i=0; i<n; i++) { pos=fscanf (traza, %lf\n,&tr*i+); pos=fscanf (wavelet, %lf\n, &wt*i+); pos=fscanf (taper, %lf\n,&tape*i+); } //Apply Gaussian taper for (i = 0; i < n; i++) { traza_tpd[i]= tr[i]*tape [i]; wvlet_tpd[i]=wt[i]*tape[i]; } printf (\n); //The mixed radix algorithms require additional working space to hold the //intermediate steps of the transform, //Allocates a workspace for a real transform of length n work = gsl_fft_real_workspace_alloc (n); //Prepare trigonometric lookup tables for an FFT of size n real elements. real = gsl_fft_real_wavetable_alloc (n);

//Compute the transforms of time-ordered real data gsl_fft_real_transform (traza_tpd, 1, n, real, work); gsl_fft_real_transform (wvlet_tpd,1,n,real, work); //Free the memory associated with the wavetable //can be freed if no further FFTs of the same length will be needed gsl_fft_real_wavetable_free (real); //Frees the memory associated with the workspace and //can be freed if no further FFTs of the same length will be needed gsl_fft_real_workspace_free (work); GSL_SET_COMPLEX (&traza_complex[1], traza_tpd[0], 0); GSL_SET_COMPLEX (&wvlet_complex [1], wvlet_tpd[0], 0); j=2; for (i = 1; i <=n; i=i+2)
{ GSL_SET_COMPLEX (&traza_complex[j], traza_tpd[i], traza_tpd [i+1]) GSL_SET_COMPLEX (&traza_complex[j], traza_tpd[i], traza_tpd [i+1]) j++; } GSL_SET_COMPLEX (&traza_complex[nfft], traza_tpd[n-1], 0); GSL_SET_COMPLEX (&wvlet_complex[nfft], wvlet_tpd[n-1], 0); printf (\n); for (i = 1; i <=nfft; 1++) { //This function returns the quotient of the complex numbers a and b, z = a/b. divi_complex[i] = gsl_complex_div ((traza_complex[i]), (wvlet_complex[i])); } GSL_SET_COMPLEX (&divi_complex[1], GSL_REAL (divi_complex [1]), 0); GSL_SET_COMPLEX (&divi_complex [nfft], GSL REAL (divi_complex[nfft]), 0); /****** CREATING AND WRITING OUTPUT ***/ FILE *refile, *imfile; FILE *imtraza, *retraza, *imwave, *remave, *ampTraza; Imfile=fopen (desimtraza.asc, w); refile=fopen (desretraza.asc, w); imtraza=fopen (imtraza.asc, w); retraza=fopen (retraza.asc,w); imwave=fopen (imwave.asc,w); ampTraza=fopen (ampTraza.asc, w); float fmax=125;//Nyquist for sample rate 4ms deltaf=(fmax/(n/2));

for (i = 1; i <=nfft; i++) { f[i]=(i-1)*deltaf; mod [i]=sgrt (pow(GSL_REAL (traza_complex[i]),2)+pow(GSL_IMAG(traza_complex[i]), 2)); fprintf (ampTraza, %g\t%g\n f*i],mod[i]; //fprintf (rewave, %g\t%g\n, f*i+, GSL_REAL(wvlet_complex [i]));

//fprintf (imwave, %g\t%g\n, f*i+, GSL_IMAG(wvlet_complex *i+)); //fprintf (retraza, %g\t%g\n, f*i+, GSL_REAL(traza_complex *i+)); //fprintf (imtraza, %g\t%g\n, f*i+, GSL_IMAG(traza_complex *i+)); } /****** FRECUENCY ANALYSIS BAND DELTA F *****/ for (int i=1; i<=nfft; i++) { fprintf (refile, %g/n, GSL_REAL (divi_complex*i+)); fprintf (imfile, %g/n, GSL_IMAG (divi_complex*i+)); printf (%g,%g\n, GSL_REAL (divi_complex[i]), GSL_IMAG (divi_complex [i])); } //fclose (ampTraza); fclose (refile); fclose (imfile); fclose (rewave); fclose (inwave); fclose (retraza); fclose (imtraza); fclose (traza); fclose (wavelet); fclose (taper); return 0; }// End main

#! /bin/sh #sintetico.sh by K. Paola Castao ksiopea99@gmail.com #Scrip que lee un archive con una serie de reflectividad, #y genera la traza sinttica, mediante la convulacin #con una wavelet tipo Ricker 30Hz por defecto. #Uso: ./sintetico.sh filename trace_name #Fichero con la serie de reflectividad filename=$1 trace_name=$2 #Contadores num=1 cuenta=0 tmin=0 tmax=124 #Es decir, 256 ms y 64 muestras #Comienza la serie acumulada de reflectores con tmin y amplitud cero suspike nt=124 dt=0.001 ntr=1 offset=0 ix1=1 itl=$tmin suweight a=0 b=0 > acumu0.su #Lee el fichero linea porlinea while read time coef do echo time_ $time RC: $coef #Se construye un reflector con cada tiempo y amplitude leidas Suspike nt=124 dt=0.001 ntr=1 offset=0 ix1=1 itl=$time suweight a=$coef b=0 > temp$nun.su #Contador de la serie acumulada name=expr $num 1 #Suma el reflector ledo con la serie acumulada susum temp$num.su acumu$name.su> acumu$num.su sushw < acumu$num.su > rcl.su #Contador de cada reflector num= expr $num + 1 done < $filename echo Tiempo minimo $tmin ms echo Tiempo mximo $tmax ms suwind < rcl.su tmin=0 tmax=0.123 > rc.su sushw < rc.su > rc$trace_name.su key=tracr, fldr, cdp, offset, scalco, sx, sy infile=binary_file suascii < rc.su bare=1 > rc.asc #Genera la wavelet Suwaveform type=ricker1 fpeak=30 dt=0.001 sugain pbal=1 > sinwave.su #Convolucion entre rc y wavelet suconv < rc$trace_name.su sufile=wavelet64.su > tempsinl.su #Ventana de datos entre tmin y tmax, longitud de ventana potencia de 2

suwind < tempsinl.su tmin=0 tmax=0.123 > tempsin2.su suresamp < tempsin2.su dt=0.001 nt=124> sinte$trace_name.su #Genera archivos de imagen supswigp < sinte$trace_name.su > sinte$trace_name.eps supswigp < rc$trace_name.su > rc$trace_name.eps #Remover archivos temporales rm temp*.su rm acumu* .su /*-----------------------------------------------------------------------------------------------------optimizar.C Copyright (C) 2009-2010 K. Paola Castao 2009 <ksiopea99@gmail.com DESCRIPTION: This program tries to minimize the objective function of Spectral Inversion method, PUYEAR & CASTAGNA (2008) By using a Genetic Algorithm to resolve the optimization problem ----------------------------------------------------------------------------------------------------------*/

#include <iostream> #include <fstream> #include <cmath> #include <cstdio> #include <cstdlib> #include <stdio.h> #include <stdlib.h> #include <ga/ga.h> #include <ga/std_stream.h> #define cout STD_COUT #define end STD_ENDL #define ostream STD_OSTREAM #define ofstream STD_OFSTREAM Using namespace std; #ifnder M_PI #define M_PI 3.14159265358979323846 # endif /METHODS/ //decom method Int decomp (float xx[], float yy[], int zz, float kk[], double pe [], double po []; //Files with real and imaginary part of deconvolution FILE *readecon, *imadecon; Int sample; //Simpson numerical integration method double calcularSimpson (double FX [], int N, double h); double Simpson38 (int n, double FX [], double h); double Simpson13 (int n, int N, double FX [], double h);

//0bjetive Function Float Objective (GAGenome &); //ofstream fileOF; /MAIN GA/ Int main (int argc, char** argv){ /OPENING AND READING FILES/ readecon=fopen (desretraza.asc,r); if (readecon==NULL) { cout<<Error, cant be opened file : desretraza.asc<<endl; return 1; } imadecon=fopen (desimtraza.asc,r); if (imadecon==NULL) { cout<<Error, cant be opened file: desimtraza.asc<<endl; return 1; } /GA/ //See if weve been given a seed to use (for testing purposes). When you //specify a random seed, the evolution will be exactly the same each time //you use that seed number. Unsigned int seed = 0; For (int ii=1; ii<argc; ii++) { if (strcmp (argv *ii+++, seed) == 0) , seed = atoi (argv [ii]); } } //Time and reflection coefficients arrays of possible values // Search Space float thickset [100]; float refleSet [100]; int thicksamp=0, reflesamp=0; int tmin, tmax; tmin = atoi (argv [1]); tmax = atoi (argv [2]); sample = atoi (argv [3]); cout << tmin : << tmin << endl; cout << tmax : << tmax << endl; thickSet [0]=1; //Allele of time must be variable between tmin and tmax // Values of time in the Genome will not be out of the analysis window for (int i= ; I; i++) { thickSet [i]=thickSet [i-1]+1;// (Thickness in ms) thicksamp++; //Size or array

//Allele of Reflexion coefficients -0.20 and 0.20 for (int i=0; i<60; i++){ refleSet [i]=(i-30)*0.01;//(Amplitud of Reflexion coefficients) reflesamp++; //Size of array }// Whit Zero //Define and built alleles GAAlleleSet<float> thickAlleles (thicksamp, thickSet); GAAlleleSet<float> refleSetAlleles (reflesamp, refleSet); //Define and built alleles array GAAlleleSetArray<float>alleles; alleles.add (thickAlleles); alleles.add (refleSetAlleles); alleles.add (thickAlleles); alleles.add (refleSetAlleles); alleles.add (thickAlleles); alleles.add (refleSetAlleles); alleles.add (thickAlleles); alleles.add (refleSetAlleles); int n=alleles.size(); cout << size Alleles: << n << endl; file0F.open (scoreOF.txt, (STD_IOS_OUT STD_IOS_TRUNC)); //Define genome with several layers (2 to 10) and two variables, //thickness and reflection coefficients GA2DArrayAlleleGenome<float>genome (2,4, alleles, 0bjective9;// fixed 4 layers // Resize Behaviour, minx, maxx, miny, maxy // genome.resizeBehaviour (2,2,6,6); // Now that we have the genomes, create a parameter list that will be used for // the genetic algorithm //gASteadyStateGA ga (genome); GASimpleGA ga (genome); GASigmaTruncationScaling scale; Ga.scaling (scale); //GARouletteWheelSelector select; GATournamentSelector select; //GADSSelector select; //GASRSSelector select; ga.selector (select); ga. minimize (); ga.populationSize (100); ga.nGenerations (1000); ga.pMutation (0.0001); //by default to minimize the objective // how many individuals in the population // number of generations to evolve // Likelihood of mutating new offspring

ga.pCrossover (0.1); ga.scoreFilename (scores.dat); ga.scoreFrequency (10); ga.flushFrequency (10); ga.selectScores(GAStatistics::Minimun); ga.initialize ();

// Licelihood of crossing over parents // name of file for scores // keep the scores of every generation // specify how often to write the score to disk

//Dump the initial population to file Ofstream outfile; cout << Printing initial population to file <<endl; outfile.open (popi.dat, (STD_IOS_OUT STD_IOS_TRUNC)); for (int ii=0; ii<ga.population ().size (); ii++){ genome = ga.population (). Individual (ii); outfile << genome.gene (0,0) <<\t<< genome.gene (1,0) << \t <<genome.gene(0,1) << \t << genome.gene (1,1) << \t <<genome.gene(0,2) << \t << genome.gene (1,2) << \t <<genome.gene(0,3) << \t << genome.gene (1,3) << \t } outfile.close (); cout << \nrunning Ga << endl; ga.evolve (); while (!ga.done()) ga.step (); /PRINT RESULTS TO FILE/ float bestTime [50]; int layer = genome.height (); cout << The ga generated:\n << ga.statistics (). bestIndividual () << endl: //Print the best individual to file Outfile.open (rc0ut.txt, ios ::out ios::app); genome = ga.statistics ().bestIndividual (); bestTime[0]=genome.gene(0,0)+tmin; cout << bestTime *0+ : \n <<bestTime *0+ << endl; for (int i=1; i<layer; i++){ bestTime [i]=bestTime[i-1]+genome.gene (0,i); cout << bestTime *i+:\n <<bestTime*i+ << endl; } //Write output time and rc for (int i=0; i<layer; i++){ outfile << bestTime *i+ << \t <<genome.gene (1,i) <<\n; } outfile.close (); //Dump the final population to file Cout << Printing final population to file <<endl; outfile.open (popf.dat, (STD_IOS_OUT STD_IOS_TRUC)); for (int i=0; i<ga.population ().size (); i++){ genome = ga.population ().size (); i++){ outfile << genome.gene (0,0) << \t <<genome.gene (1,0) << \t << genome.gene (0,1) << \t <<genome.gene (1,1) << \t

<< genome.gene (0,2) << \t <<genome.gene (1,2) << \t << genome.gene (0,3) << \t <<genome.gene (1,3) << \t } Outfile.close (); Close files fclose (readecon); fclose (imadecon); return 0; }// End main //0bjective function Float Objective (gAGenome & c) { // Calls objective Function return (ObjFun); }//End 0bjective //force instantiations for compilers that do not do auto instantiation // for some compilers (e.g.metrowerks) this must come after any // specializations or you will get multiply-defined errors when you compile. #if !defined (GALIB_USE_AUTO_INST) #include <ga/GAAllele.c> #include <ga/GA2DArrayGenome.c> GALIB INSTANTIATION_PREFIX gAAlleleSet<int>; GALIB INSTANTIATION_PREFIX gAAlleleSetCore<int>; GALIB INSTANTIATION_PREFIX gAArray<int>; GALIB INSTANTIATION_PREFIX gA2DArrayGenome<int>; GALIB INSTANTIATION_PREFIX gA2DArrayalleleGenome<int>; #endif

#Copyringth (C) 2010 K. Paola Castao ksiopea99@gmail.com 1; #obj.fn.:no gradient Function obj_value = objective2 (theta, location) T1=theta (1); r1=theta (2); T2= theta (3); r2=theta (4); T3=theta (5); r3=theta (6); T4=theta (7); r4=theta (8); cmmd.str=sprint (./obj function_cpp%.1f%.2f%.1f%.2f%.1f%.2f%.1f% 2f,T1,r1, T2, r2, T3, r3, T4,r4); #Execute objective Function printf (s\n, cmmd.str); printf (My_f\n); system (cmmd.str); # Define and open files Filein = ./0F.txt; Ecuacion=fopen (filein, r; #Read result Coste = fscanf (ecuacion, %f,1); obj_value=coste; # Close files fclose (ecuacin); endfunction #tmin = str2num (argv(){1}); #initial values dim = 7; # dimension of function parameters theta0=[10;0;10;0;10;0;10;0]; printg (Minimize, using Simmulated AnneaLing\n); #SA controls ub = [60:0.2;60;0.2;60;0.2;60;0.2];#vector of upper bounds lb = [1;-0.2;1;-0.2;1;-0.2;1;-0.2]; #vector of lower bounds nt = 20; #Num of iterations between temperature reductions ns = 20; #Num of iterations between bounds adjustments rt = 0.5; # careful this is too low for many problems, (0 < rt <1): temperature reduction factor maxevals = 2e5; # integer: limit on function evaluations neps = 5; # integer: number of values final results is compared to functol = le-4; # (> 0) : the required tolerance level for function value comparisons paramtol = le-3; # (> 0) : the required tolerance level for parameters verbosity = 1; # only final results. Inc #scalar: 0, 1, or 2.

#* 0 = no screen output #*1=only final results to screen #*2=summary every temperature change Minarg = 1; #integer : which of function args is minimization over? control = {lb, ub, nt, ns, rt, maxevals, neps, functol, paramtol, verbosity, 1}; location = ones (dim+1,1); printf (Running Minimize \n\n); *theta, obj_value, convergence, details+ = samin (objective2, ,theta0, location}, control); fflus (1); #Define and open files filef = rcfinal.txt; rcfinal=fopen (filef, a); thetafinal=ones (dim+1,1); #Write thickness and rc thetafinal (1) = theta(1); thetafinal (2) = theta(2); for i=3:2:7 j=i-2; k=i+1; thetafinal (i)=theta(i)+thetafinal(j); thetafinal (k)=theta(k); end fprintf (rcfinal,%f\t%f\n%f\t%f\n%f\t%f\n%f\t%f\n%f\t%f\n%f\t%f\n,thetafinal); #Close files fclose (rcfinal);

You might also like