Package weka.clusterers

Examples of weka.clusterers.AbstractClusterer


        final SortedSet<MarkovAttributeSet> round_asets = new TreeSet<MarkovAttributeSet>();
        final Map<MarkovAttributeSet, AbstractClusterer> round_clusterers = new HashMap<MarkovAttributeSet, AbstractClusterer>();

        // The best AttributeSet + Clusterer we've seen thus far
        MarkovAttributeSet best_aset = null;
        AbstractClusterer best_clusterer = null;
        boolean found_new_best = true;
       
        int round = 0;
        while (round++ < this.num_rounds && found_new_best) {
            round_asets.clear();
            round_clusterers.clear();
           
            if (debug.val) {
                Map<String, Object> m0 = new ListOrderedMap<String, Object>();
                m0.put("Round #", String.format("%02d", round));
                m0.put("Number of Partitions", this.all_partitions.size());
                m0.put("Number of Attributes", all_attributes.size());
                m0.put("Best Set", best_aset);
                m0.put("Best Cost", (best_aset != null ? best_aset.getCost() : null));
               
                Map<String, Object> m1 = new ListOrderedMap<String, Object>();
                for (SplitType stype : SplitType.values()) {
                    String key = String.format("# of %s Instances", stype.name());
                    String val = String.format("%-8s [%.02f]", this.split_counts[stype.ordinal()], stype.percentage);
                    m1.put(key, val);   
                } // FOR
               
                LOG.debug("\n" + StringUtil.formatMaps(":", true, true, false, false, true, true, m0, m1));
            }

            final Iterable<Set<Attribute>> it = UniqueCombinationIterator.factory(all_attributes, round);
            final List<Set<Attribute>> sets = (List<Set<Attribute>>)CollectionUtil.addAll(new ArrayList<Set<Attribute>>(), it);

            final int num_sets = sets.size();
            final CountDownLatch latch = new CountDownLatch(num_sets);
            final AtomicInteger aset_ctr = new AtomicInteger(0);
           
            for (final Set<Attribute> s : sets) {
                Runnable r = new Runnable() {
                    @Override
                    public void run() {
                        MarkovAttributeSet aset = new MarkovAttributeSet(s);
                        AbstractClusterer clusterer = null;
//                        if (aset_ctr.get() <= 0) {
                            if (trace.val) LOG.trace("Constructing AttributeSet: " + aset);
                            try {
                                clusterer = FeatureClusterer.this.calculateAttributeSetCost(aset);
                            } catch (Exception ex) {
View Full Code Here


     * @throws Exception
     */
    public AbstractClusterer calculateAttributeSetCost(final MarkovAttributeSet aset) throws Exception {
        // Build our clusterer
        if (debug.val) LOG.debug("Training Clusterer - " + aset);
        AbstractClusterer clusterer = this.createClusterer(aset, this.splits[SplitType.TRAINING.ordinal()]);
       
        // Create an ExecutionState for this run
        ExecutionState state = (ExecutionState)this.state_pool.borrowObject();
        state.init(clusterer);
       
        // Construct the MarkovGraphs for each Partition/Cluster using the Training Data Set
        this.generateMarkovGraphs(state, this.splits[SplitType.TRAINING.ordinal()]);
       
        // Generate the MarkovModels for the different partitions+clusters
        this.generateMarkovCostModels(state);
       
        // Now we need a mapping from TransactionIds -> ClusterIds
        // And then calculate the cost of using our cluster configuration to predict txn paths
        double total_c_cost = 0.0d;
       
        int c_counters[] = state.c_counters;
        int t_counters[] = state.t_counters;
       
//        Map<Pair<Long, Integer>, Histogram> key_to_cluster = new TreeMap<Pair<Long, Integer>, Histogram>();
//        Map<Integer, Histogram> cluster_to_key = new TreeMap<Integer, Histogram>();
       
        Instances validationData = this.splits[SplitType.VALIDATION.ordinal()];
        int validationCnt = this.split_counts[SplitType.VALIDATION.ordinal()];
       
        if (debug.val) LOG.debug(String.format("Estimating prediction rates of clusterer with %d transactions...", validationCnt));
        for (int i = 0; i < validationCnt; i++) {
            if (i > 0 && i % 1000 == 0) LOG.trace(String.format("TransactionTrace %d/%d", i, validationCnt));
           
            Instance inst = validationData.instance(i);
            long txn_id = FeatureUtil.getTransactionId(inst);
            TransactionTrace txn_trace = this.workload.getTransaction(txn_id);
            assert(txn_trace != null);
            Integer base_partition = this.getBasePartition(txn_trace);
            // Skip any txn that executes on a partition that we're not evaluating
            if (this.all_partitions.contains(base_partition) == false) continue;
           
            int c = (int)clusterer.clusterInstance(inst);

            // Debug Stuff
//            Pair<Long, Integer> key = Pair.of((Long)txn_trace.getParam(1), ((Object[])txn_trace.getParam(4)).length);
//            if (key_to_cluster.containsKey(key) == false) key_to_cluster.put(key, new Histogram());
//            key_to_cluster.get(key).put(c);
View Full Code Here

       
        FilteredClusterer filtered_clusterer = new FilteredClusterer();
        filtered_clusterer.setFilter(filter);
        filtered_clusterer.setClusterer(inner_clusterer);
       
        AbstractClusterer clusterer = filtered_clusterer;
        clusterer.buildClusterer(trainingData);
       
        return (clusterer);
    }
View Full Code Here

        // Construct a simple MarkovAttributeSet that only contains the BasePartitionFeature
        MarkovAttributeSet base_aset = new MarkovAttributeSet(data, FeatureUtil.getFeatureKeyPrefix(BasePartitionFeature.class));
        assertFalse(base_aset.isEmpty());
        int base_partition_idx = CollectionUtil.first(base_aset).index();
       
        AbstractClusterer clusterer = this.fclusterer.createClusterer(base_aset, data);
        assertNotNull(clusterer);
       
        // Make sure that each Txn gets mapped to the same cluster as its base partition
        Map<Integer, Histogram<Integer>> p_c_xref = new HashMap<Integer, Histogram<Integer>>();
        for (int i = 0, cnt = data.numInstances(); i < cnt; i++) {
            Instance inst = data.instance(i);
            assertNotNull(inst);
            long txn_id = FeatureUtil.getTransactionId(inst);

            TransactionTrace txn_trace = workload.getTransaction(txn_id);
            assertNotNull(txn_trace);
            Integer base_partition = p_estimator.getBasePartition(txn_trace);
            assertNotNull(base_partition);
            assertEquals(base_partition.intValue(), (int)inst.value(base_partition_idx));

            int c = clusterer.clusterInstance(inst);
            Histogram<Integer> h = p_c_xref.get(base_partition);
            if (h == null) {
                h = new ObjectHistogram<Integer>();
                p_c_xref.put(base_partition, h);
            }
View Full Code Here

TOP

Related Classes of weka.clusterers.AbstractClusterer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.