test_Li09_constrained.sh 3.13 KB
Newer Older
Tom Lampert's avatar
Tom Lampert committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/bin/bash

matlab_path=	# Path to Matlab executable

n_proc=1	# Number of processes to execute in parallel, -1 unlimited

trap "trap - SIGTERM && kill -- -$$ && exit" SIGINT SIGTERM EXIT

function limitjobs {
   	if [ "${n_proc}" != "-1" ]
	then
		while [ `jobs -rp | wc -l` -ge ${n_proc} ]
		do
			sleep 5
		done
	fi
}


subdir=Li09
data_path=./datasets
test_type=test

outdir=./methods/${subdir}/clusterings/constrained
resdir=./results/${subdir}/constrained
26
satdir=./constraint_satisfaction/${subdir}
Tom Lampert's avatar
Tom Lampert committed
27 28 29

mkdir -p ${outdir}
mkdir -p ${resider}
30
mkdir -p ${satdir}
Tom Lampert's avatar
Tom Lampert committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

for d in ${data_path}/*/
do
	dataname=`basename ${d}`
	echo ${dataname}

	# Algorithm parameter values
	case "$dataname" in
		ECG5000)
			sigma=1
			eig_no=2
	 	;;
	 	ElectricDevices)
			sigma=0.5
			eig_no=1
	 	;;
	 	FacesUCR)
			sigma=5
			eig_no=9
	 	;;
	 	InsectWingbeatSound)
			sigma=1
			eig_no=7
	 	;;
	 	MALLAT)
			sigma=1
			eig_no=9
	 	;;
	 	StarLightCurves)
			sigma=1
			eig_no=3
	 	;;
	 	TwoPatterns)
			sigma=0.5
			eig_no=3
	 	;;
	 	UWaveGestureLibraryAll)
			sigma=20
			eig_no=7
	 	;;
	 	uWaveGestureLibraryX)
			sigma=20
			eig_no=10
	 	;;
	esac

	distancefilename=${data_path}/${dataname}/${test_type}/${dataname}.distances
	kfilename=${data_path}/${dataname}/${test_type}/${dataname}.k
	labelsfilename=${data_path}/${dataname}/${test_type}/${dataname}.labels

	resultdir=./methods/${subdir}/results/${test_type}/constrained
82
	satisfactiondir=./methods/${subdir}/constraint_satisfaction/${test_type}
Tom Lampert's avatar
Tom Lampert committed
83
	mkdir -p ${resultdir}
84
	mkdir -p ${satisfactiondir}
Tom Lampert's avatar
Tom Lampert committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

	for constraintsfilename in $(find ${data_path}/${dataname}/${test_type} -name '*.constraints')
	do

		limitjobs

		{
			IN=`basename ${constraintsfilename%.*}`
			arrIN=(${IN//_/ })
			cnstrnt_frac=${arrIN[1]}
			cnstrnt_iter=${arrIN[2]}

			filenamepattern=${dataname}_${test_type}_${cnstrnt_frac}_${cnstrnt_iter}
			outfilename=${outdir}/${filenamepattern}.clustering
			resultfilename=${resultdir}/${filenamepattern}.results
100
			satisfactionfilename=${satisfactiondir}/${filenamepattern}.satisfaction
Tom Lampert's avatar
Tom Lampert committed
101 102 103 104 105 106 107 108 109 110 111 112

			if [ ! -f ${resultfilename} ]
			then
				echo ${resultfilename}

				rm -f ${outfilename}

				${matlab_path}matlab -nojvm -nodisplay -nosplash -r "addpath(genpath('methods/${subdir}')); addpath(genpath('utils'));   test_clustering_Li09('${distancefilename}', '${constraintsfilename}', '${kfilename}', '${outfilename}', '${sigma}', '${eig_no}');quit"

				if [ -f ${outfilename} ]
				then
					Rscript --vanilla ./utils/cluster_index.R ${labelsfilename} ${outfilename} ${resultfilename}
113
					python ./utils/constraint_satisfaction.py -r ${outfilename} -c ${constraintsfilename} -o ${satisfactionfilename} -i 1
Tom Lampert's avatar
Tom Lampert committed
114 115 116 117 118 119 120 121 122 123 124 125
				fi
			fi

		} &

	done

	wait

	for cnstrnt_frac in 0.05 0.1 0.15 0.5
	do
		outfilename=${resdir}/${dataname}_${test_type}_${cnstrnt_frac}.results
126
		satoutfilename=${satdir}/${dataname}_${test_type}_${cnstrnt_frac}.satisfaction
Tom Lampert's avatar
Tom Lampert committed
127 128

		rm -f ${outfilename}
129
		rm -f ${satoutfilename}
Tom Lampert's avatar
Tom Lampert committed
130 131

		Rscript --vanilla ./utils/summarise_results.R ${resultdir} ${dataname} ${test_type} ${cnstrnt_frac} ${outfilename}
132 133
		Rscript --vanilla ./utils/summarise_satisfaction_results.R ${resultdir} ${dataname} ${test_type} ${cnstrnt_frac} ${satoutfilename}
		
Tom Lampert's avatar
Tom Lampert committed
134 135
	done
done