source: src/htune_convertDesign.R @ 158

Last change on this file since 158 was 49, checked in by htune, 8 years ago

Changes to param2R.sh and htune_convertDesign.R which allows when NLHC=1 generate a simple Latin Hypercube design which is much faster than than the k-Extended Latin Hypercube version.

File size: 3.2 KB
Line 
1#############################################################################
2# Purpose : generate a sequence of parameter vectors sampling a Latin
3#           hypercube in intervals [-1,1]. Stored into ParUS_Wave[N].RData
4#           [N] is the "wave" or iteration counter.
5#           Transform the normalized values into effective parameters values
6#           for SCM simulations. Stored in Par1D_Wave[N].asc.
7# Auteur(e)s : Najda Villefranque & Daniel Williamson
8# Modif : F. Hourdin
9#    The procedure is generalized and shared by MUSC and LMDZ
10#    The specification of the model specific parameters is taken from
11#    ModelParam.R
12#############################################################################
13
14library("lhs")
15source("kLHC.R")
16source('htune_convert.R')
17
18#------------
19#---- INPUT :
20# If 1st wave ; nothing
21# Otherwise, file with set of sampled parameters in [-1,1]^Nparams
22#---- OUTPUT :
23# Set of sampled parameters in [-1 , 1 ]^Nparams
24# Set of converted parameters into [min_p , max_p]^Nparams
25#------------
26
27print("--------------------------------")
28print("Generating or scaling parameters")
29print("--------------------------------")
30
31WAVEN=1
32source('ModelParam.R')
33
34# 0.1 generate or load parameters sample
35# PFILE : file to write [-1 , 1]^NPARA sampled parameters
36# UFILE : file to write [min_p, max_p]^NPARA sampled parameters
37# DFILE : file to read [-1 , 1]^NPARA from previous wave
38if (WAVEN == 1) {
39  print("Sample parameters")
40  PFILE=paste("Wave",WAVEN,".RData",sep="")
41  UFILE=paste("Par1D_Wave",WAVEN,".asc",sep="")
42 
43  #if ( 1 == 0 ) { # First version of htune
44  if ( NLHC == 1) {
45     newDesign <- 2*maximinLHS(LHCSIZE,NPARA)-1
46     #newDesign <- 2*randomLHS(NSCMS,NPARA)-1
47  } else
48  {
49     testcubeSCM <- MakeRankExtensionCubes(n=LHCSIZE,m=NPARA,k=NLHC,w=0.2, FAC_t=0.05,Imax=500)
50     newDesign <- NewExtendingLHS(testcubeSCM)*2 - 1
51  }
52
53} else {
54  print("Load parameters : PROPOSITION CI-DESSOUS")
55  PFILE=paste("Wave",WAVEN,".RData",sep="")
56  UFILE=paste("Par1D_Wave",WAVEN,".asc",sep="")
57  load(file=PFILE)
58  newDesign <- WaveNext
59}
60
61
62
63# 3. Convert newDesign which is Design on [-1,1]
64  print("Scale parameters")
65  # 3.1 Convert [-1,1] LHC to above scale
66  SCMGo <- DesignConvert(newDesign)
67  # 3.2 Create IDs
68  tID1 <- "SCM"
69  labels <- c("0","1","2","3","4","5","6","7","8","9")
70  counter <- 1
71  first <- 2
72  second <- 1
73  third <- 1
74  t_IDs <- rep(tID1,nrow(newDesign))
75  twave <- paste(WAVEN,sep="")
76  while(counter<=nrow(newDesign)){
77    tnew <- paste(labels[third],labels[second],labels[first],sep="")
78    t_IDs[counter] <- paste(t_IDs[counter],twave,sep="_")
79    t_IDs[counter] <- paste(t_IDs[counter],tnew,sep="-")
80    first <- first + 1
81    if(first>10){
82      second <- second+1
83      first <- 1
84      if(second > 10){
85        third <- third+1
86        second <- 1
87      }
88    }
89    counter <- counter + 1
90  }
91
92  wave_param_1D <- cbind(t_IDs, SCMGo)
93  wave_param_US <- cbind(t_IDs, as.data.frame(newDesign))
94  names(wave_param_US)[-1] <- param.names
95
96# 4. Save scaled and unscaled param to data files
97  print("Save data")
98  # si WAVEN>1 already saved=output from htune_EmulatingSCM.R
99  #if (WAVEN == 1) {save(wave_param_US,file=PFILE)}
100  save(wave_param_US,file=PFILE)
101  write.table(wave_param_1D, file=UFILE,row.names=FALSE,col.names=TRUE)
102
103  print("---OK!---")
Note: See TracBrowser for help on using the repository browser.