//************************************************************* // Sample script provided "as is" by Applied Maths. // You are free to use and modify this script for your // own purposes. // Please notice that improper use of script commands may // corrupt your database. Running this script is entirely at // your own responsibility. Applied Maths accepts no // liability for any damage that results from using // this script. //************************************************************* // FINDS EXEMPLARS FOR GROUPS IN COMPARISON //$MENU window=comparison;popup=groups;insertafter=group separation;name=Find exemplar... integer i,j,groupnr,grpmemb[],grpsize,n,bestnr,datafound,emptygroup; float vl,simil,maxsimil; DIALOG dlg; string experlist,expername,report; //Check if a comparison is opened if not(CmpIsPresent) then CmpAttach; if not(CmpIsPresent) then { message("No comparison is currently open"); stop; } // Select experiment for which exemplar has to be found for i=1 to DbGetExperCount do experlist=experlist+DbGetExperName(i)+" "; expername=experlist;expername=splitstring(expername," "); DlgAddText(dlg,"Select the experiment to use:",15,15,150,20); DlgAddList(dlg,experlist,expername,15,40,150,150,"LIST"); if not(DlgShow(dlg,"Find exemplar",400,400)) then stop; for i=1 to CmpGetEntryCount do DbSetSel(CmpGetEntryKey(i),0); // Get groups and group entries // Find exemplar for each group datafound=0; emptygroup=0; for groupnr=1 to 30 do { grpsize=0; for i=1 to CmpGetEntryCount do if CmpGetGroup(i)=groupnr then { grpsize=grpsize+1; grpmemb[grpsize]=i; } maxsimil=-100;bestnr=0; if grpsize=0 then emptygroup = emptygroup+1; if grpsize = 1 then { report=report+"Group "+str(groupnr-emptygroup,0,0)+"~n"; report=report+" 1 entry ~n "; report=report+" key: "+CmpGetEntryKey(grpmemb[1])+"~n~n"; } else for i=1 to grpsize do { simil=0.0;n=0; for j=1 to grpsize do if j <> i then { vl=CmpGetSimil(expername,grpmemb[i],grpmemb[j]); if vl>-200 then { simil=simil+vl; n=n+1; } } if n>0 then { simil=simil/n; if simil>maxsimil then { maxsimil=simil; bestnr=i; } datafound=1; } } if bestnr>0 then DbSetSel(CmpGetEntryKey(grpmemb[bestnr]),1); // Create report if grpsize>0 and bestnr>0 then { report=report+"Group "+str(groupnr-emptygroup,0,0)+"~n"; report=report+" "+str(grpsize,0,0)+" entries ~n "; report=report+" exemplar key: "+CmpGetEntryKey(grpmemb[bestnr])+"~n"; report=report+" average similarity: "+str(grpsize,4,2)+"~n~n "; } } if datafound=0 then message("ERROR: no similarity matrix present for experiment '"+expername+"'"); else { DlgReset(dlg); DlgAddEdit(dlg,report,10,10,400,300); DlgShow(dlg,"Find exemplar: report",520,360); }