File: validate-model

package info (click to toggle)
spamassassin 3.1.7-2etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 5,404 kB
  • ctags: 2,123
  • sloc: perl: 39,706; ansic: 3,133; sh: 2,009; sql: 170; makefile: 168
file content (128 lines) | stat: -rwxr-xr-x 3,227 bytes parent folder | download | duplicates (3)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/sh

# set SCORESET
. config

RUNS=10
PASSES=`seq 1 ${RUNS}`

NAME="set$SCORESET"
LOGDIR="vm-$NAME-$HAM_PREFERENCE-$THRESHOLD-$EPOCHS"
CACHEDIR="vm-cache/$NAME"

if [ "$NOTE" != "" ]; then
	LOGDIR="$LOGDIR-$NOTE"
fi

if [ ! -d $CACHEDIR ]; then
	mkdir -p $CACHEDIR
fi

if [ ! -f "ORIG/ham-$NAME.log" -o ! -f "ORIG/spam-$NAME.log" ]; then
	echo "Couldn't find logs for $NAME" >&2
	exit 1
fi


echo "[Doing a scoreset $SCORESET score-generation run]"

# clear out the old logs
rm -rf $LOGDIR
# Create a directory to organize the logs with this group of settings
mkdir $LOGDIR

(
echo "[config]"
cat config
) | tee -a $LOGDIR/log

for PASS in $PASSES; do
	# Clean out old runs
	echo "[Cleaning up for pass $PASS]"
	rm -rf spam-validate.log ham-validate.log spam.log ham.log \
		NSBASE SPBASE tmp freqs perceptron.scores
	make clean >/dev/null

	# revert to the previous scoring
	svn revert ../rules/50_scores.cf

	if [ ! -d $CACHEDIR/$PASS ]; then
		# Generate 90/10 split logs
		echo "[Generating 90/10 split ham]"
		mkdir NSBASE SPBASE
		cd NSBASE
		../tenpass/split-log-into-buckets 10 < ../ORIG/ham-$NAME.log > /dev/null
		for p in $PASSES; do
			if [ "$p" != "$PASS" ]; then
				cat split-$p.log >> ham.log
			else
				mv split-$p.log ham-validate.log
			fi
		done
		rm -f split-*.log

		echo "[Generating 90/10 split spam]"
		cd ../SPBASE
		../tenpass/split-log-into-buckets 10 < ../ORIG/spam-$NAME.log > /dev/null
		for p in $PASSES; do
			if [ "$p" != "$PASS" ]; then
				cat split-$p.log >> spam.log
			else
				mv split-$p.log spam-validate.log
			fi
		done
		rm -f split-*.log
		cd ..

		echo "[Setting up for pass $PASS]"
		# Ok, setup for a run
		ln -s SPBASE/spam.log .
		ln -s NSBASE/ham.log .
		ln -s SPBASE/spam-validate.log .
		ln -s NSBASE/ham-validate.log .

		# try to find number of processors
		numcpus=`cpucount 2>/dev/null || egrep -c '^processor\b' /proc/cpuinfo 2>/dev/null || echo 1`
	else
		echo "[Retrieving from $CACHEDIR/$PASS]"
		ln -s $CACHEDIR/$PASS/SPBASE .
		ln -s $CACHEDIR/$PASS/NSBASE .
		ln -s $CACHEDIR/$PASS/tmp .
		ln -s $CACHEDIR/$PASS/freqs .

		ln -s SPBASE/spam.log .
		ln -s NSBASE/ham.log .
		ln -s SPBASE/spam-validate.log .
		ln -s NSBASE/ham-validate.log .
	fi
	
	echo "[Generating perceptron]"
	# Generate perceptron with full logs
	make -j $numcpus SCORESET=$SCORESET > $LOGDIR/make.output 2>&1

	(
	echo "[pass $PASS start]"
	pwd
	date
	./perceptron -p $HAM_PREFERENCE -t $THRESHOLD -e $EPOCHS
	mv perceptron.scores $LOGDIR/scores.$PASS
	echo "[pass $PASS end]"
	) | tee -a $LOGDIR/log
	./rewrite-cf-with-new-scores $SCORESET ../rules/50_scores.cf $LOGDIR/scores.$PASS > /tmp/runGA.$$
	mv /tmp/runGA.$$ ../rules/50_scores.cf
	echo "[evaluating performance]" | tee -a $LOGDIR/log
	./fp-fn-statistics --ham ham-validate.log --spam spam-validate.log --scoreset $SCORESET --fnlog $LOGDIR/false_negatives.$PASS --fplog $LOGDIR/false_positives.$PASS > $LOGDIR/validate.$PASS 2> /dev/null

	if [ ! -d $CACHEDIR/$PASS ]; then
		echo "[Saving object files in $CACHEDIR/$PASS for faster runs]"
		mkdir -p $CACHEDIR/$PASS
		mv tmp freqs SPBASE NSBASE $CACHEDIR/$PASS
	fi

done

./extract-results $LOGDIR/validate.* > $LOGDIR/validate

./model-statistics $LOGDIR/validate

exit 0