1
2
3
4 package yawn.nn.committee.functions;
5
6 import java.util.HashMap;
7 import java.util.Iterator;
8 import java.util.Map;
9
10 import yawn.util.Pattern;
11
12 /***
13 *
14 * <p>$Id: Popularity.java,v 1.5 2005/04/20 18:55:19 supermarti Exp $</p>
15 *
16 * @author Luis Martí (luis dot marti at uc3m dot es)
17 * @version $Revision: 1.5 $
18 */
19 public class Popularity extends CommitteeFunction {
20
21 /***
22 *
23 * @see yawn.nn.committee.functions.CommitteeFunction#piecewise(double[])
24 */
25 protected double piecewise(double[] x) {
26 throw new UnsupportedOperationException();
27 }
28
29
30
31
32
33
34 public Pattern assamble(Pattern[] x) {
35
36 HashMap frecuencier = new HashMap();
37
38 for (int i = 0; i < x.length; i++) {
39 if (frecuencier.containsKey(x[i])) {
40 Integer intt = (Integer) frecuencier.get(x[i]);
41 frecuencier.remove(x[i]);
42 frecuencier.put(x[i], new Integer(intt.intValue() + 1));
43 } else {
44 frecuencier.put(x[i], new Integer(1));
45 }
46 }
47
48 Pattern mostPopular = null;
49 int maxVote = Integer.MIN_VALUE;
50
51 for (Iterator i = frecuencier.entrySet().iterator(); i.hasNext();) {
52 Map.Entry entry = (Map.Entry) i.next();
53 if (((Integer) entry.getValue()).intValue() > maxVote) {
54 maxVote = ((Integer) entry.getValue()).intValue();
55 mostPopular = (Pattern) entry.getKey();
56 }
57 }
58
59 return mostPopular;
60 }
61 }