#!/bin/awk # Conversion script for watermark_optimizer output (nohup.out) # (c) Eric Thibodeau juin 2009 # Synopsys: # call with pgawk (gawk profiler)...it runs faster for some reason O_o... # pgawk -f # Specifications are in ../Doc/STM-tracing-tool.odt # Data Chunk format: # CSTMPSOptimizer::STMBasedRecall - Re-evaluating new image using STM. -> Start of STM marker # CSTMPSOptimizer::STMBasedRecall - m_Objective->GetFitness(i) - 1.17173 -> Fitness_{CI} # CSTMPSOptimizer::STMBasedRecall - m_Objective->GetIndividualFitness(i,j) - 0.0172674 # CSTMPSOptimizer::STMBasedRecall - m_Objective->GetIndividualFitness(i,j) - 1.05763 # CSTMPSOptimizer::STMBasedRecall - m_Objective->GetIndividualFitness(i,j) - 1.61938 # CSTMPSOptimizer::STMBasedRecall - m_Objective->GetIndividualFitness(i,j) - 1.24634 # CSTMPSOptimizer::STMBasedRecall - m_Objective->GetIndividualFitness(i,j) - 1.91803 # CSTMPSOptimizer::STMBasedRecall - m_ShortTermMemory[i]->GetLocalBestFitness() - 1.17131 -> Fitness_{PI} # CSTMPSOptimizer::STMBasedRecall - m_ShortTermMemory[0] # X[0]:0 X[1]:0 (...)1 X[59]:1 # P[0]:0 P[1]:0 (...) P[59]:1 -------------------------------------------------------------> BestParam # V[0]:-1.86553 V[1]:-1.86559 (...) V[59]:1.19964 # Local best fitness: 1.17131 # # m_Swarm->GetPopulationOfSubSwarm(i) 10 -> PopSize # ... Block repeated # CSTMPSOptimizer::STMBasedRecall - mean: 1.13615 var_diff 1.2005e-05 degrees of freedom 6 ctdist 2.447 max_diff 0.00346131 # ^^^^^^^^-->> End of STM marker # Constraints: # * Minimal Swarm size > 1 : PopSize > 1 # * BestParam must be unique for ALL images but we must keep their appearance in each image search (compute at END{} and BestParam is a hash key): # OccurenceInImage[BestParam]={image1,image2,image...} (bool) # FitnessInImage[BestParam]={fit_1,fit_2,fit_...} (real, 0=did not fit) # Occurrences[BestParam]++ (int) # # NOTE: # First STM printout is used for image info of image 1 (Fitness_{PI}) and 2 (Fitness_{CI}). # Subsequent STM printouts only convey info for the current image (Fitness_{CI}) BEGIN{imagecount=2} # STM blocks are printed at image 2 (we need some evolution to have a memory) #/CSTMPSOptimizer::STMBasedRecall - Re-evaluating new image using STM./ {imagecount++} # not very useful come to think of it, do post increment. /CSTMPSOptimizer::STMBasedRecall - m_Objective->GetFitness/ {Fitness_CI=$NF; next} /CSTMPSOptimizer::STMBasedRecall - m_ShortTermMemory\[i\]->GetLocalBestFitness/ {Fitness_PI=$NF; next} / P\[/ { gsub(/ P\[[0-9]+\]:/,""); BestParam=$0; next} # converts " P[0]:0 P[1]:0 (...) P[59]:1" to "00110...110" (cool :P) #/m_Swarm->GetPopulationOfSubSwarm/ && $NF > 1 && imagecount == 2 { # first STM contains info for image 1 _and_ 2 # FitnessInImage[1,BestParam]=Fitness_PI # } /m_Swarm->GetPopulationOfSubSwarm/ && $NF > 1 { if (imagecount == 2) FitnessInImage[1,BestParam]=Fitness_PI Occurrences[BestParam]++ FitnessInImage[imagecount,BestParam]=Fitness_CI next } /CSTMPSOptimizer::STMBasedRecall - mean:/ {imagecount++} END{ #Print CSV format: #TABLE 1: (bits converted to values) # Each entry key 'BestParam' contains a bitfield as follows: # 1 9 16 3234 38 45 # 000010001101111000000111100000101100101111010110110101011101 # | bs | Q | α Fragile | | ss| ΔQ | α Robust | # int int real (0-1) ^ int int real (0-1) # 8 6 15 ^ 3 6 15 # ^->SNDM Window Size (int) 2 #Solution - Block Size - Q Fragile - α Fragile - SNDM Window Size - Shuffling Seed - Δ Q - α Robust - Occurrences #BestParam0 #BestParam1 #BestParam2 #... OFS="," print "Solution,Block Size,Q Fragile,α Fragile,SNDM Window Size,Shuffling Seed,Δ Q,α Robust,Occurrences" cnt=0 for (s in Occurrences){ cnt++ bs=substr(s, 1 , 8) QF=substr(s, 9 , 6) aF=substr(s, 16,15) Ws=substr(s, 32, 2) ss=substr(s, 34, 3) dQ=substr(s, 38, 6) aR=substr(s, 45,15) # print "raw: " s # print cnt,bs,QF,aF,Ws,ss,dQ,aR print cnt , b2i(bs,8) , (b2i(QF,6)+1)*2 , b2r(aF,15) , b2i(Ws,2)*2+3 , b2i(ss,3) , (b2i(dQ,6)+1)*2 , b2r(aR,15),Occurrences[s] } #TABLE 2: (graphic) # Solution 0, Solution 1, Solution 2, Solution 3, Solution 4, Solution 5, Solution 6, (BestParam 0, 1, 2,...) #img1 Fitness #img2 Fitness #img3 Fitness #img4 #... #Print table header: print "" printf("Image,") i=1 for (s in Occurrences){ printf("Solution%s,",i) i++ } print "" # Print lines: for (i=1;iMSB) # len = length of stream # out: # integer value function b2i(bin,len){ val=0 split(bin,vec,"") #vectorize the binary stream # Vector index start at 1, so we use (i-1) for the 2^i exponent [2^(i-1)] for(i=1;iMSB) # len = length of stream # out: # real value function b2r(bin,len){ integer=b2i(bin,len) return (integer/2^16) }