#!/bin/bash # ##### USES NEW VERSION OF DANIEL CODES #### set -eu # exit on most (not all!) error codes, and error on unset variables export LC_ALL=C # set locale for computation with awk ## D'ABORD FAIRE # svn checkout --username htune https://svn.lmd.jussieu.fr/HighTune/trunk HighTune # cd HighTune && bash setup.sh seed="-seed 123" # seed pseudo random numbers generators nsondes=100 meanFun="constant" # | "consant"|"fitted" (will be forced to constant for map expe) htune_dir="$(pwd)/../.." install_dir="$htune_dir/../install_shared" local=$(pwd) src="$htune_dir/src" wave_two_metrics=9999 # starting from this wave, a second metric will be added if [[ $# -eq 4 ]] ; then wave_two_metrics=$4 fi wave=1 clean=0 setup=0 map=0 while (($# > 0)); do case $1 in "-h"|"--help") echo "Usage: $0 [clean|setup|map] [-wave NWAVE] htune_dir"; exit 0 ;; "-htune") htune_dir=$(readlink -f "$2"); shift; shift;; "-installdir") install_dir=$2; shift; shift;; "-wave") wave=$2 ; shift; shift;; "clean") clean=1 ; shift;; "setup") setup=1 ; shift;; "map") map=1 ; shift;; *) $0 -h; exit 1 esac done source "$install_dir/env.sh" if [[ $clean = 1 ]] ; then echo "-----------------------------------" echo "clean : menage des précédents runs" echo "-----------------------------------" # Pourquoi ce -- ? #rm -r -- param ModelParam.R *.csv *Rdata *RData *asc *pdf Remain* WAVE* rm -r param ModelParam.R *.csv *Rdata *RData *asc *pdf Remain* WAVE* exemple_image.txt param_after_wave* echo Apres ; exit exit 0 fi if [[ $setup = 1 ]] ; then echo "-----------------------------------" echo "setup : recuperation des logiciels" echo "-----------------------------------" cd "$src" ### REMOVE cp for ALL OLD FILES # cp -f HistoryMatching_addon.R htune_Emulating_Multi_Metric_Multi_LHS_new.R "$local/" cp -f htune_emulating_multimetric_new.R tinydancer_plots.R "$local/" cp -f htune_convertDesign.R kLHC.R htune_convert.R param2R.sh htune_csv2Rdata.R "$local/" cp -f htune_emulator_predictions.R "$local/" # the following files are specific to the "map" experiment cp -f plot_map_emulated.py map_make_files.sh exemple_image.txt "$local/" cd - #cp -r "$install_dir/ExeterUQ_MOGP/BuildEmulator" . #cp -f "$src/BuildEmulator_tmp.R" BuildEmulator/BuildEmulator.R #ln -sf "$install_dir/ExeterUQ_MOGP/HistoryMatching" . #ln -sf "$install_dir/mogp_emulator" . exit 0 else # On force le setup #if [ ! -d BuildEmulator ] ; then ./exemple.sh setup ; fi if [ ! -f htune_convertDesign.R ] ; then bash exemple.sh setup ; fi fi echo "------------------" echo "Work : WAVE $wave" echo "------------------" mkdir "WAVE${wave}" set -x # print commands used echo "-------------------------------------------------------------" echo "[min,max] des parametres" echo "-------------------------------------------------------------" if [[ $map -eq 1 ]] ; then im=$(head -1 exemple_image.txt | awk ' { print $1 } ') jm=$(head -1 exemple_image.txt | awk ' { print $2 } ') cat > param < param < cibles.csv < cibles.csv <| tmp # Reading image dimensions from the first line # find the line number in exemple_image.txt from i,j read in the param file lin=$(tail -n +2 "Par1D_Wave${wave}.asc"|awk '{ printf "%i ", (int($2)-1)*'$jm'+int($3) + 1 }') for l in $lin ; do sed -n "${l}p" exemple_image.txt|awk '{print $1}' >> tmp done echo SIM >| names tail -n +2 "Par1D_Wave${wave}.asc"|awk '{print $1}' |sed 's/"//g' >> names paste -d, names tmp > Metrics.csv } awk_model() { echo SIM,F > Metrics.csv tail -n +2 "Par1D_Wave${wave}.asc" | awk ' { sim=$1 ; a=$2 ; b=$3 ; F=10*log(2*a-1)+238; print sim","F } ' | sed -e 's/"//g' >> Metrics.csv } if [[ $wave -lt $wave_two_metrics ]] ; then if [[ $map -eq 1 ]]; then map_model else awk_model fi else echo SIM,F,G > Metrics.csv tail -n +2 "Par1D_Wave${wave}.asc" | awk ' { sim=$1 ; a=$2 ; b=$3 ; F=10*log(2*a-1)+238; G=(220*a)+0.1*sin(b*200); print sim","F","G } ' | sed -e 's/"//g' >> Metrics.csv #tail -n +2 Par1D_Wave${wave}.asc | awk ' { sim=$1 ; a=$2 ; b=$3 ; c=$4 ; F=exp(-a*a)+0.01*cos(b*1000); G=a+0.05*sin(a*200); print sim","F","G } ' | sed -e 's/"//g' >> Metrics.csv fi cp -f "Par1D_Wave${wave}.asc" Params.asc Rscript --vanilla htune_csv2Rdata.R "$wave" -dir . -par Params.asc -sim Metrics.csv $seed echo "-------------------------------------------------------------" echo "Emulateur + history matching" echo "-------------------------------------------------------------" cp -f Params.asc Metrics.csv "Wave${wave}.RData" P"ar1D_Wave${wave}.asc" "Wave${wave}_SCM.Rdata" "Wave${wave}_REF.Rdata" "WAVE${wave}/" # force constant fun for map experiment if [[ $map -eq 1 ]] ; then meanFun="constant" ; fi #time Rscript htune_Emulating_Multi_Metric_Multi_LHS_new.R -wave "$wave" -cutoff 3 -sample_size 30000 -sample_size_next_design 10 -meanFun $meanFun $seed time Rscript htune_emulating_multimetric_new.R -wave "$wave" -cutoff 3 -sample_size 1000 -sample_size_next_design 10 $seed #evince InputSpace_wave${wave}.pdf