############################################################################# # Purpose : generate a sequence of parameter vectors sampling a Latin # hypercube in intervals [-1,1]. Stored into ParUS_Wave[N].RData # [N] is the "wave" or iteration counter. # Transform the normalized values into effective parameters values # for SCM simulations. Stored in Par1D_Wave[N].asc. # Auteur(e)s : Najda Villefranque & Daniel Williamson # Modif : F. Hourdin # The procedure is generalized and shared by MUSC and LMDZ # The specification of the model specific parameters is taken from # ModelParam.R ############################################################################# library("lhs") source("kLHC.R") source('htune_convert.R') #------------ #---- INPUT : # If 1st wave ; nothing # Otherwise, file with set of sampled parameters in [-1,1]^Nparams #---- OUTPUT : # Set of sampled parameters in [-1 , 1 ]^Nparams # Set of converted parameters into [min_p , max_p]^Nparams #------------ print("--------------------------------") print("Generating or scaling parameters") print("--------------------------------") WAVEN=1 source('ModelParam.R') # 0.1 generate or load parameters sample # PFILE : file to write [-1 , 1]^NPARA sampled parameters # UFILE : file to write [min_p, max_p]^NPARA sampled parameters # DFILE : file to read [-1 , 1]^NPARA from previous wave if (WAVEN == 1) { print("Sample parameters") PFILE=paste("Wave",WAVEN,".RData",sep="") UFILE=paste("Par1D_Wave",WAVEN,".asc",sep="") #if ( 1 == 0 ) { # First version of htune if ( NLHC == 1) { newDesign <- 2*maximinLHS(LHCSIZE,NPARA)-1 #newDesign <- 2*randomLHS(NSCMS,NPARA)-1 } else { testcubeSCM <- MakeRankExtensionCubes(n=LHCSIZE,m=NPARA,k=NLHC,w=0.2, FAC_t=0.05,Imax=500) newDesign <- NewExtendingLHS(testcubeSCM)*2 - 1 } } else { print("Load parameters : PROPOSITION CI-DESSOUS") PFILE=paste("Wave",WAVEN,".RData",sep="") UFILE=paste("Par1D_Wave",WAVEN,".asc",sep="") load(file=PFILE) newDesign <- WaveNext } # 3. Convert newDesign which is Design on [-1,1] print("Scale parameters") # 3.1 Convert [-1,1] LHC to above scale SCMGo <- DesignConvert(newDesign) # 3.2 Create IDs tID1 <- "SCM" labels <- c("0","1","2","3","4","5","6","7","8","9") counter <- 1 first <- 2 second <- 1 third <- 1 t_IDs <- rep(tID1,nrow(newDesign)) twave <- paste(WAVEN,sep="") while(counter<=nrow(newDesign)){ tnew <- paste(labels[third],labels[second],labels[first],sep="") t_IDs[counter] <- paste(t_IDs[counter],twave,sep="_") t_IDs[counter] <- paste(t_IDs[counter],tnew,sep="-") first <- first + 1 if(first>10){ second <- second+1 first <- 1 if(second > 10){ third <- third+1 second <- 1 } } counter <- counter + 1 } wave_param_1D <- cbind(t_IDs, SCMGo) wave_param_US <- cbind(t_IDs, as.data.frame(newDesign)) names(wave_param_US)[-1] <- param.names # 4. Save scaled and unscaled param to data files print("Save data") # si WAVEN>1 already saved=output from htune_EmulatingSCM.R #if (WAVEN == 1) {save(wave_param_US,file=PFILE)} save(wave_param_US,file=PFILE) write.table(wave_param_1D, file=UFILE,row.names=FALSE,col.names=TRUE) print("---OK!---")