test_Babaki14_unconstrained.sh 3.46 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
#!/bin/bash

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

pre_cluster=0 	# Use COP-KMeans to initialise the clustering


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=Babaki14
data_path=./datasets
test_type=test

COPKMeansBaseDir=`pwd`/methods/Babaki14/bin/COP-KMeans
COPKMeansDir=${COPKMeansBaseDir}/copkmeans

outdir=./methods/${subdir}/clusterings/unconstrained
resdir=./results/${subdir}/unconstrained
29
satdir=./constraint_satisfaction/${subdir}
Tom Lampert's avatar
Tom Lampert committed
30 31 32

mkdir -p ${resdir}
mkdir -p ${outdir}
33
mkdir -p ${satdir}
Tom Lampert's avatar
Tom Lampert committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

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

	distancemetricfilename=${data_path}/${dataname}/${test_type}/${dataname}.metric
	distance_metric=`cat ${distancemetricfilename}`
	nfeaturesfilename=${data_path}/${dataname}/${test_type}/${dataname}.nfeatures
	nfeatures=`cat ${nfeaturesfilename}`

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

	kvalue=`cat ${kfilename}`

	resultdir=./methods/${subdir}/results/${test_type}/unconstrained
53
	satisfactiondir=./methods/${subdir}/constraint_satisfaction/${test_type}
Tom Lampert's avatar
Tom Lampert committed
54
	mkdir -p ${resultdir}
55
	mkdir -p ${satisfactiondir}
Tom Lampert's avatar
Tom Lampert committed
56 57 58 59 60 61 62 63 64 65 66 67 68

	for (( i=1; i<=10; i++ ))
	do

		limitjobs

		{
			cnstrnt_frac=0
			cnstrnt_iter=${i}

			filenamepattern=${dataname}_${test_type}_${cnstrnt_frac}_${cnstrnt_iter}
			outfilename=${outdir}/${filenamepattern}.clustering
			resultfilename=${resultdir}/${filenamepattern}.results
69
			satisfactionfilename=${satisfactiondir}/${filenamepattern}.satisfaction
Tom Lampert's avatar
Tom Lampert committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
			initialclusterfilename=${COPKMeansBaseDir}/clusterings/unconstrained/${filenamepattern}.clustering

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

				rm -f ${outfilename}

				if [ "${pre_cluster}" == "1" ]
				then
					python methods/${subdir}/bin/cccg-seed.py -d ${datafilename} -k ${kvalue} -c 1 -t 9999999 -copdir ${COPKMeansDir} -f ${nfeatures} -p ${distance_metric} --ofile=${outfilename} --distfile=${distancefilename} --l=1 #--init=${initialclusterfilename}
				else
					python methods/${subdir}/bin/cccg-seed.py -d ${datafilename} -k ${kvalue} --consfile=${constraintsfilename} -c 1 -t 9999999 -copdir ${COPKMeansDir} -f ${nfeatures} -p ${distance_metric} --ofile=${outfilename} --distfile=${distancefilename} --l=1 --init=-1
				fi

				if [ -f ${outfilename} ]
				then
					Rscript --vanilla ./utils/cluster_index.R ${labelsfilename} ${outfilename} ${resultfilename}
88 89 90

					constraintsfilename=${data_path}/${dataname}/${test_type}/${dataname}_${test_type}_0.5_${cnstrnt_iter}.constraints
					python ./utils/constraint_satisfaction.py -r ${outfilename} -c ${constraintsfilename} -o ${satisfactionfilename} -i 1
Tom Lampert's avatar
Tom Lampert committed
91 92 93 94 95 96 97 98 99 100
				fi
			fi
		} &
	done

	wait

	for cnstrnt_frac in 0
	do
		outfilename=${resdir}/${dataname}_${test_type}_${cnstrnt_frac}.results
101
		satfilename=${satdir}/${dataname}_${test_type}_${cnstrnt_frac}.satisfaction
Tom Lampert's avatar
Tom Lampert committed
102 103

		rm -f ${outfilename}
104
		rm -f ${satfilename}
Tom Lampert's avatar
Tom Lampert committed
105

106 107
		Rscript --vanilla ./utils/summarise_results.R ${resultdir} ${dataname} ${test_type} ${cnstrnt_frac} ${outfilename}
		Rscript --vanilla ./utils/summarise_satisfaction_results.R ${resultdir} ${dataname} ${test_type} ${cnstrnt_frac} ${satfilename}
Tom Lampert's avatar
Tom Lampert committed
108 109
	done
done