public void minimalSpanning(int sVertex) // Method to create the edges of the minimal // spanning tree. The weight of the edges is also // saved in the array edgeWeights. { // ToDo for (int i = 0; i < edges.length; i++) { v.add((Integer) i); } vNew.add(sVertex); for (int i = 0; i < graph.length; i++) { LinkedListClass.LinkedListIterator it = graph[i].iterator(); while (it.hasNext()) { Pair p = new Pair(); p.u = i; p.w = (Integer) it.next(); p.weight = weights[p.u][p.w]; e.add(p); } } while (eNew.size() < v.size() - 1) { Pair smallestEdge = new Pair(); smallestEdge.weight = Double.MAX_VALUE; for (Pair edge : e) { if (!eNew.contains(edge) && ((vNew.contains(edge.u) && !vNew.contains(edge.w) || vNew.contains(edge.w) && !vNew.contains(edge.u)))) { if (edge.weight < smallestEdge.weight) { smallestEdge = edge; } } } eNew.add(smallestEdge); if (vNew.contains(smallestEdge.u)) { vNew.add(smallestEdge.w); } else { vNew.add(smallestEdge.u); } } for (Pair edge : eNew) { edges[edge.u] = edge.w; edgeWeights[edge.u] = edge.weight; } } // end minimalSpanning
@Override public Condition[] multiple(Dataset dataset, Instance[] instances, int attribute, int target) { Pair[] candidates = new Pair[dataset.size()]; double[] frequency = new double[dataset.classLength()]; int index = 0; double size = 0; for (int i = 0; i < dataset.size(); i++) { // the dynamc discretisation only considers the instances covered // by the current rule if (instances[i].flag == RULE_COVERED) { double v = dataset.value(i, attribute); if (!Double.isNaN(v)) { Pair pair = new Pair(); pair.value = v; pair.classValue = (dataset.value(i, dataset.classIndex()) == target) ? 1 // positive (target) : 0; // negative pair.weight = instances[i].weight; candidates[index] = pair; size += pair.weight; index++; } } } if (index == 0) { // there are no candidate threshold values return null; } candidates = Arrays.copyOf(candidates, index); Arrays.sort(candidates); Condition[] conditions = create( candidates, 0, candidates.length, frequency, size, IntervalBuilder.minimumCases(dataset, size)); if (conditions == null) { // no interval was created return null; } else { for (Condition c : conditions) { c.attribute = attribute; } return conditions; } }