src/machinelearning/Dataset.java
protected int heuristicSplit() {
		assert(instances.size() == numYES + numNO);
		assert(numYES > 0 && numNO > 0);
		assert(attributes.size() >= 2);

		TreeMap<Integer,int[]> numYESatt = new TreeMap<Integer,int[]>();
		TreeMap<Integer,int[]> numNOatt = new TreeMap<Integer,int[]>();
		TreeMap<Integer,int[]> numTOTatt = new TreeMap<Integer,int[]>();

		for (int i=0; i<attributes.size(); i++) {
			numYESatt.put(i, new int[2]);
			numNOatt.put(i, new int[2]);
			numTOTatt.put(i, new int[2]);
			for (int j=0; j<2; j++) {
				numYESatt.get(i)[j] = 0;
				numNOatt.get(i)[j] = 0;
				numTOTatt.get(i)[j] = 0;
			}
		}

		for (Instance instance : instances) {
			for (int i=0; i<attributes.size(); i++)
				numTOTatt.get(i)[instance.attValues.get(i)?1:0]++;
			if (instance.classValue) {
				for (int i=0; i<attributes.size(); i++)
					numYESatt.get(i)[instance.attValues.get(i)?1:0]++;
			} else {
				for (int i=0; i<attributes.size(); i++)
					numNOatt.get(i)[instance.attValues.get(i)?1:0]++;
			}
		}

		int bestpoz = 0;
		double best = 0;
		if (numTOTatt.get(0)[0] > 0 && numTOTatt.get(0)[1] > 0) {
			double candidate = ((double) numYESatt.get(0)[0] / numTOTatt.get(0)[0]) +
					((double) numNOatt.get(0)[1] / numTOTatt.get(0)[1]);
			if (candidate > best)
				best = candidate;
			candidate = ((double) numNOatt.get(0)[0] / numTOTatt.get(0)[0]) +
					((double) numYESatt.get(0)[1] / numTOTatt.get(0)[1]);
			if (candidate > best)
				best = candidate;
		}

		for (int i=1; i<attributes.size(); i++)
			if (numTOTatt.get(i)[0] > 0 && numTOTatt.get(i)[1] > 0) {
				double candidate = ((double) numYESatt.get(i)[0] / numTOTatt.get(i)[0]) +
						((double) numNOatt.get(i)[1] / numTOTatt.get(i)[1]);
				if (candidate > best) {
					best = candidate;
					bestpoz = i;
				}
				candidate = ((double) numNOatt.get(i)[0] / numTOTatt.get(i)[0]) +
						((double) numYESatt.get(i)[1] / numTOTatt.get(i)[1]);
				if (candidate > best) {
					best = candidate;
					bestpoz = i;
				}
			}

		if (best == 0) return -1;

		return bestpoz;
	}
/**
	 * Computes which attribute is the best for <br>
	 * splitting the dataset based on a simple heuristic
	 * @return The index of attribute which is best for splitting, <br>
	 * 		   or (-1) if there is no attribute good for splitting
	 */
Computes which attribute is the best for 
splitting the dataset based on a simple heuristic
@return The index of attribute which is best for splitting, 
or (-1) if there is no attribute good for splitting
Computes which attribute is the best for splitting the dataset based on a simple heuristic @return The index of attribute which is best for splitting or ( - 1 ) if there is no attribute good for splitting
protected int heuristicSplit() {
		assert(instances.size() == numYES + numNO);
		assert(numYES > 0 && numNO > 0);
		assert(attributes.size() >= 2);
		TreeMap<Integer,int[]> numYESatt = new TreeMap<Integer,int[]>();
		TreeMap<Integer,int[]> numNOatt = new TreeMap<Integer,int[]>();
		TreeMap<Integer,int[]> numTOTatt = new TreeMap<Integer,int[]>();
		for (int i=0; i<attributes.size(); i++) {
			numYESatt.put(i, new int[2]);
			numNOatt.put(i, new int[2]);
			numTOTatt.put(i, new int[2]);
			for (int j=0; j<2; j++) {
				numYESatt.get(i)[j] = 0;
				numNOatt.get(i)[j] = 0;
				numTOTatt.get(i)[j] = 0;
			}
		}
		for (Instance instance : instances) {
			for (int i=0; i<attributes.size(); i++)
				numTOTatt.get(i)[instance.attValues.get(i)?1:0]++;
			if (instance.classValue) {
				for (int i=0; i<attributes.size(); i++)
					numYESatt.get(i)[instance.attValues.get(i)?1:0]++;
			} else {
				for (int i=0; i<attributes.size(); i++)
					numNOatt.get(i)[instance.attValues.get(i)?1:0]++;
			}
		}
		int bestpoz = 0;
		double best = 0;
		if (numTOTatt.get(0)[0] > 0 && numTOTatt.get(0)[1] > 0) {
			double candidate = ((double) numYESatt.get(0)[0] / numTOTatt.get(0)[0]) +
					((double) numNOatt.get(0)[1] / numTOTatt.get(0)[1]);
			if (candidate > best)
				best = candidate;
			candidate = ((double) numNOatt.get(0)[0] / numTOTatt.get(0)[0]) +
					((double) numYESatt.get(0)[1] / numTOTatt.get(0)[1]);
			if (candidate > best)
				best = candidate;
		}
		for (int i=1; i<attributes.size(); i++)
			if (numTOTatt.get(i)[0] > 0 && numTOTatt.get(i)[1] > 0) {
				double candidate = ((double) numYESatt.get(i)[0] / numTOTatt.get(i)[0]) +
						((double) numNOatt.get(i)[1] / numTOTatt.get(i)[1]);
				if (candidate > best) {
					best = candidate;
					bestpoz = i;
				}
				candidate = ((double) numNOatt.get(i)[0] / numTOTatt.get(i)[0]) +
						((double) numYESatt.get(i)[1] / numTOTatt.get(i)[1]);
				if (candidate > best) {
					best = candidate;
					bestpoz = i;
				}
			}
		if (best == 0) return -1;
		return bestpoz;
	}
protected int heuristicSplit ( ) { assert ( instances . size ( ) == numYES + numNO ) ; assert ( numYES > 0 && numNO > 0 ) ; assert ( attributes . size ( ) >= 2 ) ; TreeMap < Integer , int [ ] > numYESatt = new TreeMap < Integer , int [ ] > ( ) ; TreeMap < Integer , int [ ] > numNOatt = new TreeMap < Integer , int [ ] > ( ) ; TreeMap < Integer , int [ ] > numTOTatt = new TreeMap < Integer , int [ ] > ( ) ; for ( int i = 0 ; i < attributes . size ( ) ; i ++ ) { numYESatt . put ( i , new int [ 2 ] ) ; numNOatt . put ( i , new int [ 2 ] ) ; numTOTatt . put ( i , new int [ 2 ] ) ; for ( int j = 0 ; j < 2 ; j ++ ) { numYESatt . get ( i ) [ j ] = 0 ; numNOatt . get ( i ) [ j ] = 0 ; numTOTatt . get ( i ) [ j ] = 0 ; } } for ( Instance instance : instances ) { for ( int i = 0 ; i < attributes . size ( ) ; i ++ ) numTOTatt . get ( i ) [ instance . attValues . get ( i ) ? 1 : 0 ] ++ ; if ( instance . classValue ) { for ( int i = 0 ; i < attributes . size ( ) ; i ++ ) numYESatt . get ( i ) [ instance . attValues . get ( i ) ? 1 : 0 ] ++ ; } else { for ( int i = 0 ; i < attributes . size ( ) ; i ++ ) numNOatt . get ( i ) [ instance . attValues . get ( i ) ? 1 : 0 ] ++ ; } } int bestpoz = 0 ; double best = 0 ; if ( numTOTatt . get ( 0 ) [ 0 ] > 0 && numTOTatt . get ( 0 ) [ 1 ] > 0 ) { double candidate = ( ( double ) numYESatt . get ( 0 ) [ 0 ] / numTOTatt . get ( 0 ) [ 0 ] ) + ( ( double ) numNOatt . get ( 0 ) [ 1 ] / numTOTatt . get ( 0 ) [ 1 ] ) ; if ( candidate > best ) best = candidate ; candidate = ( ( double ) numNOatt . get ( 0 ) [ 0 ] / numTOTatt . get ( 0 ) [ 0 ] ) + ( ( double ) numYESatt . get ( 0 ) [ 1 ] / numTOTatt . get ( 0 ) [ 1 ] ) ; if ( candidate > best ) best = candidate ; } for ( int i = 1 ; i < attributes . size ( ) ; i ++ ) if ( numTOTatt . get ( i ) [ 0 ] > 0 && numTOTatt . get ( i ) [ 1 ] > 0 ) { double candidate = ( ( double ) numYESatt . get ( i ) [ 0 ] / numTOTatt . get ( i ) [ 0 ] ) + ( ( double ) numNOatt . get ( i ) [ 1 ] / numTOTatt . get ( i ) [ 1 ] ) ; if ( candidate > best ) { best = candidate ; bestpoz = i ; } candidate = ( ( double ) numNOatt . get ( i ) [ 0 ] / numTOTatt . get ( i ) [ 0 ] ) + ( ( double ) numYESatt . get ( i ) [ 1 ] / numTOTatt . get ( i ) [ 1 ] ) ; if ( candidate > best ) { best = candidate ; bestpoz = i ; } } if ( best == 0 ) return - 1 ; return bestpoz ; }
Computes which attribute is the best for <br>
 splitting the dataset based on a simple heuristic
 @return The index of attribute which is best for splitting, <br>
                 or (-1) if there is no attribute good for splitting
Computes which attribute is the best for <br > splitting the dataset based on a simple heuristic @return The index of attribute which is best for splitting <br > or ( - 1 ) if there is no attribute good for splitting