def extended_distribution(pivotword_i): pivotword=pivotwords[pivotword_i] logphrase=identity+'/'+pivotword try: logger.info(logphrase+' : starting') target_path='/data/nrekabsaz/experiments/randomness/'+simfunction+'/extendeddist/'+pivotword+'/'+identity+'.json' tools._mkdir_recursive(os.path.dirname(target_path)) simword_path='/data/nrekabsaz/experiments/randomness/'+simfunction+'/simword/'+pivotword+'/'+identity+'.json' logphrase=identity+'/'+pivotword logger.info(logphrase+' : '+'loading' + simword_path) with open(simword_path) as frr: data=json.load(frr) meanstd=data.values() logger.info(logphrase+' : '+'calculating meanstdtopdown') meanstdtopdown=[] for meanstd_tuple in meanstd: mean=meanstd_tuple[0] std=meanstd_tuple[1] topbrd=mean+3*std downbrd=mean-3*std meanstdtopdown.append((mean, std, topbrd, downbrd)) meanstdtopdown.sort(key=lambda x: x[2], reverse=True)#sort by topbrd meanstd=None logger.info(logphrase+' : '+'calculating mixture norms') bins = np.arange(1, -0.2, -.001) first_dropin_slide_cnt=0 mixpdflist=[] for bin_i, bin in enumerate(bins): mixpdf=0 if first_dropin_slide_cnt!=-1: meanstdtopdown_cnt=first_dropin_slide_cnt first_dropin_slide_cnt=-1 while (True): if meanstdtopdown_cnt>=len(meanstdtopdown): break meanstdtopdown_tuple=meanstdtopdown[meanstdtopdown_cnt] if meanstdtopdown_tuple[2]>=bin: if meanstdtopdown_tuple[3]<=bin: if first_dropin_slide_cnt==-1: first_dropin_slide_cnt=meanstdtopdown_cnt if meanstdtopdown_tuple[1]!=0: #normdist=norm(loc = meanstdtopdown_tuple[0], scale = meanstdtopdown_tuple[1]) #normdist=normdistlist[meanstdtopdown_cnt] if bin_i+1<len(bins): mixpdf+=(norm.cdf(bins[bin_i+1], loc = meanstdtopdown_tuple[0], scale = meanstdtopdown_tuple[1])- norm.cdf(bins[bin_i], loc = meanstdtopdown_tuple[0], scale = meanstdtopdown_tuple[1])) else: mixpdf+=norm.cdf(bins[bin_i], loc = meanstdtopdown_tuple[0], scale = meanstdtopdown_tuple[1]) else: mixpdf+=1.0 meanstdtopdown_cnt+=1 else: break mixpdflist.append(mixpdf) if bin_i%50==0: logger.info(logphrase+' : calculating mixture value '+str(bin_i)+'/'+str(len(bins))) logger.info(logphrase+' : saving into file') wr=open(target_path,'w') wr.write(' '.join(map(str, mixpdflist))) wr.close() except KeyboardInterrupt: raise KeyboardInterruptError() except Exception as e: msgText=identity+' : extended_distribution('+simfunction+') error!'+'\n'+traceback.format_exc() mail.sendemail_error(msgText) logger.error(msgText)
simfunction=argv[0] outputcode=argv[1] simwordtype=argv[2] if simwordtype=='orig': simword_dir_path='/data/nrekabsaz/similarity/result/randomness/'+simfunction+'/simword/' target_dir_path='/data/nrekabsaz/similarity/result/randomness/'+simfunction+'/simwordspan/' elif values_ready[1]=='norm': simword_dir_path='/data/nrekabsaz/similarity/result/randomness/'+simfunction+'/simwordnorm/' target_dir_path='/data/nrekabsaz/similarity/result/randomness/'+simfunction+'/simwordspannorm/' tools._mkdir_recursive(target_dir_path) try: logger.info('simwordspan_calc ('+str(outputcode)+') '+simfunction+' started...') simwordspan_calc(outputcode) msgText='simwordspan_calc ('+str(outputcode)+') '+simfunction+' finished!' logger.info(msgText) except Exception as e: msgText='run_simwordspan_calc('+str(outputcode)+') '+simfunction+'\n'+traceback.format_exc() logger.error(msgText) mail.sendemail_error(msgText) logger.info('email sent!') dur = datetime.now() - begin_time logger.info('Whole Duration: '+str(dur)) logger.info('fertig!');
import sys from src.misc import mail if __name__ == "__main__": argv=sys.argv[1:] msgtype=argv[0] msg=argv[1] if msgtype=='suc': mail.sendemail_success(msg) elif msgtype=='err': mail.sendemail_error(msg)