train_Cucuringu16_constrained.sh 2.17 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 26 27 28 29 30 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 82
#!/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=Cucuringu16
data_path=./datasets
test_type=train

outdir=./${subdir}/clusterings/constrained
mkdir -p ${outdir}

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

	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=./${subdir}/results/${test_type}/${dataname}/constrained
	mkdir -p ${resultdir}

	for sigma in 0.1 0.5 1 5 10
	do
		for (( alpha=1; alpha<=10; alpha++ ))
		do
			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}_${sigma}_${alpha}_${cnstrnt_iter}
					outfilename=${outdir}/${filenamepattern}.clustering
					resultfilename=${resultdir}/${filenamepattern}.results


					if [ "${cnstrnt_frac}" == "0.05" ]
					then
					if [ ! -f ${resultfilename} ]
					then
						echo ${outfilename}
						date

						rm -f ${outfilename}

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

						if [ -f ${outfilename} ]
						then
							Rscript --vanilla ./cluster_index.R ${labelsfilename} ${outfilename} ${resultfilename}
						fi
					fi
					fi

				} &

			done

			#outfilename=${resdir}/${dataname}_${test_type}_${cnstrnt_frac}.results

83
			#rm -f ${outfilename}
Tom Lampert's avatar
Tom Lampert committed
84 85 86 87 88 89 90 91

			#Rscript --vanilla ./summarise_results.R ./${subdir}/results ${dataname} ${test_type} 0.05 ${outfilename}

		done
	done
done

wait