亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? concurrentkmeans.java

?? java 語言編寫的kmeans聚類算法源代碼
?? JAVA
?? 第 1 頁 / 共 3 頁
字號:
package kmeans;

import java.util.*;
import java.util.concurrent.*;

/**
 * The version of K-means clustering adapted for true concurrency
 * or simultaneous multithreading (SMT).  The subtasks of
 * computing distances and making assignments are delegate to
 * a subtask manager which oversees a thread pool.
 */
public class ConcurrentKMeans implements KMeans {

    // Temporary clusters used during the clustering process.  Converted to
    // an array of the simpler class Cluster at the conclusion.
    private ProtoCluster[] mProtoClusters;

    // Cache of coordinate-to-cluster distances. Number of entries = 
    // number of clusters X number of coordinates.
    private double[][] mDistanceCache;

    // Used in makeAssignments() to figure out how many moves are made
    // during each iteration -- the cluster assignment for coordinate n is
    // found in mClusterAssignments[n] where the N coordinates are numbered
    // 0 ... (N-1)
    private int[] mClusterAssignments;

    // 2D array holding the coordinates to be clustered.
    private double[][] mCoordinates;
    // The desired number of clusters and maximum number
    // of iterations.
    private int mK, mMaxIterations;
    // Seed for the random number generator used to select
    // coordinates for the initial cluster centers.
    private long mRandomSeed;
    // The number of threads used to perform the subtasks.
    private int mThreadCount;
    // Subtask manager that handles the thread pool to which
    // time-consuming tasks are delegated.
    private SubtaskManager mSubtaskManager;
    
    // An array of Cluster objects: the output of k-means.
    private Cluster[] mClusters;

    // Listeners to be notified of significant happenings.
    private List<KMeansListener> mListeners = new ArrayList<KMeansListener>(1);
    
    /**
     * Constructor
     * 
     * @param coordinates two-dimensional array containing the coordinates to be clustered.
     * @param k  the number of desired clusters.
     * @param maxIterations the maximum number of clustering iterations.
     * @param randomSeed seed used with the random number generator.
     * @param threadCount the number of threads to be used for computing time-consuming steps.
     */
    public ConcurrentKMeans(double[][] coordinates, int k, int maxIterations, 
            long randomSeed, int threadCount) {
        mCoordinates = coordinates;
        // Can't have more clusters than coordinates.
        mK = Math.min(k, mCoordinates.length);
        mMaxIterations = maxIterations;
        mRandomSeed = randomSeed;
        mThreadCount = threadCount;
    }

    /**
     * Constructor that uses the return from 
     * <tt>Runtime.getRuntime().availableProcessors()</tt> as the number
     * of threads for time-consuming steps.
     * 
     * @param coordinates two-dimensional array containing the coordinates to be clustered.
     * @param k  the number of desired clusters.
     * @param maxIterations the maximum number of clustering iterations.
     * @param randomSeed seed used with the random number generator.
     */
    public ConcurrentKMeans(double[][] coordinates, int k, int maxIterations, 
            long randomSeed) {
        this (coordinates, k, maxIterations, randomSeed, 
                Runtime.getRuntime().availableProcessors());
    }
    
    /** 
     * Adds a KMeansListener to be notified of significant happenings.
     * 
     * @param l  the listener to be added.
     */
    public void addKMeansListener(KMeansListener l) {
        synchronized (mListeners) {
            if (!mListeners.contains(l)) {
                mListeners.add(l);
            }
        }
    }
    
    /**
     * Removes a KMeansListener
     * 
     * @param l the listener to be removed.
     */
    public void removeKMeansListener(KMeansListener l) {
        synchronized (mListeners) {
            mListeners.remove(l);
        }
    }
    
    /**
     * Posts a message to registered KMeansListeners.
     * 
     * @param message
     */
    private void postKMeansMessage(String message) {
        if (mListeners.size() > 0) {
            synchronized (mListeners) {
                int sz = mListeners.size();
                for (int i=0; i<sz; i++) {
                    mListeners.get(i).kmeansMessage(message);
                }
            }
        }
    }
    
    /**
     * Notifies registered listeners that k-means is complete.
     * 
     * @param clusters the output of clustering.
     * @param executionTime the number of milliseconds taken to cluster.
     */
    private void postKMeansComplete(Cluster[] clusters, long executionTime) {
        if (mListeners.size() > 0) {
            synchronized (mListeners) {
                int sz = mListeners.size();
                for (int i=0; i<sz; i++) {
                    mListeners.get(i).kmeansComplete(clusters, executionTime);
                }
            }
        }
    }
    
    /**
     * Notifies registered listeners that k-means has failed because of
     * a Throwable caught in the run method.
     * 
     * @param err 
     */
    private void postKMeansError(Throwable err) {
        if (mListeners.size() > 0) {
            synchronized (mListeners) {
                int sz = mListeners.size();
                for (int i=0; i<sz; i++) {
                    mListeners.get(i).kmeansError(err);
                }
            }
        }
    }
    
    /**
     * Get the clusters computed by the algorithm.  This method should
     * not be called until clustering has completed successfully.
     * 
     * @return an array of Cluster objects.
     */
    public Cluster[] getClusters() {
        return mClusters;
    }
     
    /**
     * Run the clustering algorithm.
     */
    public void run() {

        try {

            // Note the start time.
            long startTime = System.currentTimeMillis();
            
            postKMeansMessage("K-Means clustering started");
            
            // Randomly initialize the cluster centers creating the
            // array mProtoClusters.
            initCenters();
            postKMeansMessage("... centers initialized");

            // Instantiate the subtask manager.
            mSubtaskManager = new SubtaskManager(mThreadCount);

            // Post a message about the state of concurrent subprocessing.
            if (mThreadCount > 1) {
                postKMeansMessage("... concurrent processing mode with "
                            + mThreadCount + " subtask threads");
            } else {
                postKMeansMessage("... non-concurrent processing mode");
            }

            // Perform the initial computation of distances.
            computeDistances();

            // Make the initial cluster assignments.
            makeAssignments();

            // Number of moves in the iteration and the iteration counter.
            int moves = 0, it = 0;
            
            // Main Loop:
            //
            // Two stopping criteria:
            // - no moves in makeAssignments 
            //   (moves == 0)
            // OR
            // - the maximum number of iterations has been reached
            //   (it == mMaxIterations)
            //
            do {
                
                // Compute the centers of the clusters that need updating.
                computeCenters();
                
                // Compute the stored distances between the updated clusters and the
                // coordinates.
                computeDistances();

                // Make this iteration's assignments.
                moves = makeAssignments();

                it++;
                
                postKMeansMessage("... iteration " + it + " moves = " + moves);

            } while (moves > 0 && it < mMaxIterations);

            // Transform the array of ProtoClusters to an array
            // of the simpler class Cluster.
            mClusters = generateFinalClusters();

            long executionTime = System.currentTimeMillis() - startTime;
            
            postKMeansComplete(mClusters, executionTime);
            
        } catch (Throwable t) {
           
            postKMeansError(t);
            
        } finally {

            // Clean up temporary data structures used during the algorithm.
            cleanup();

        }
    }

    /**
     * Randomly select coordinates to be the initial cluster centers.
     */
    private void initCenters() {

        Random random = new Random(mRandomSeed);
        
        int coordCount = mCoordinates.length;

        // The array mClusterAssignments is used only to keep track of the cluster 
        // membership for each coordinate.  The method makeAssignments() uses it
        // to keep track of the number of moves.
        if (mClusterAssignments == null) {
            mClusterAssignments = new int[coordCount];
            // Initialize to -1 to indicate that they haven't been assigned yet.
            Arrays.fill(mClusterAssignments, -1);
        }

        // Place the coordinate indices into an array and shuffle it.
        int[] indices = new int[coordCount];
        for (int i = 0; i < coordCount; i++) {
            indices[i] = i;
        }
        for (int i = 0, m = coordCount; m > 0; i++, m--) {
            int j = i + random.nextInt(m);
            if (i != j) {
                // Swap the indices.
                indices[i] ^= indices[j];
                indices[j] ^= indices[i];
                indices[i] ^= indices[j];
            }
        }

        mProtoClusters = new ProtoCluster[mK];
        for (int i=0; i<mK; i++) {
            int coordIndex = indices[i];
            mProtoClusters[i] = new ProtoCluster(mCoordinates[coordIndex], coordIndex);
            mClusterAssignments[indices[i]] = i;
        }
    }
    
    /**
     * Recompute the centers of the protoclusters with 
     * update flags set to true.
     */
    private void computeCenters() {
        
        int numClusters = mProtoClusters.length;
        
        // Sets the update flags of the protoclusters that haven't been deleted and
        // whose memberships have changed in the iteration just completed.
        //
        for (int c = 0; c < numClusters; c++) {
            ProtoCluster cluster = mProtoClusters[c];
            if (cluster.getConsiderForAssignment()) {
                if (!cluster.isEmpty()) {
                    // This sets the protocluster's update flag to
                    // true only if its membership changed in last call
                    // to makeAssignments().  
                    cluster.setUpdateFlag();
                    // If the update flag was set, update the center.
                    if (cluster.needsUpdate()) {
                        cluster.updateCenter(mCoordinates);
                    }
                } else {
                    // When a cluster loses all of its members, it
                    // falls out of contention.  So it is possible for
                    // k-means to return fewer than k clusters.
                    cluster.setConsiderForAssignment(false);
                }
            }
        }
    }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲免费在线播放| 亚洲日本乱码在线观看| 亚洲成人久久影院| 在线看日本不卡| 亚洲国产欧美在线| 在线成人免费视频| 麻豆国产欧美一区二区三区| 日韩欧美高清一区| 国产成人午夜视频| 国产精品久久夜| 在线观看区一区二| 男女男精品视频| 亚洲国产电影在线观看| 色婷婷狠狠综合| 日韩av高清在线观看| 欧美成人vr18sexvr| 国产成人午夜片在线观看高清观看| 国产人成一区二区三区影院| 99vv1com这只有精品| 日韩精品亚洲专区| 精品91自产拍在线观看一区| av在线综合网| 日韩中文字幕av电影| 国产偷国产偷精品高清尤物| 97se亚洲国产综合自在线观| 亚洲福利视频一区| 久久综合国产精品| 色婷婷亚洲一区二区三区| 日韩av网站在线观看| 国产精品欧美综合在线| 在线成人午夜影院| 成人av免费观看| 日韩1区2区日韩1区2区| 国产精品久久久久久福利一牛影视| 欧美视频中文一区二区三区在线观看 | 99re8在线精品视频免费播放| 亚洲精品国产一区二区精华液| 欧美精品久久一区| 国产成人av一区二区| 丝袜诱惑亚洲看片| 中文字幕日韩一区| 欧美精品一区二区三区蜜桃| 色综合色综合色综合色综合色综合| 麻豆91在线播放免费| 国产精品久久久久一区| 亚洲精品一线二线三线无人区| 欧美电影免费观看高清完整版在线 | 日韩一区二区麻豆国产| 国产成人av福利| 五月天亚洲精品| 国产精品美女视频| 日韩免费福利电影在线观看| 色偷偷成人一区二区三区91| 极品少妇一区二区三区精品视频| 一区二区三区四区乱视频| 一区二区三区在线看| 欧美成人官网二区| 欧美日韩国产天堂| 97国产一区二区| 国产精品一品视频| 久久电影网站中文字幕| 国产一区在线视频| 亚洲高清在线视频| 亚洲三级在线看| 日本一区二区三区高清不卡 | 丁香天五香天堂综合| 看片的网站亚洲| 日韩成人精品在线| 日韩精品免费专区| 亚洲国产中文字幕在线视频综合| 亚洲欧洲美洲综合色网| 中文字幕av在线一区二区三区| 欧美大片顶级少妇| 欧美一级夜夜爽| 91精品国产一区二区人妖| 欧美日韩中文字幕精品| 在线免费不卡视频| 欧美日韩一区二区在线视频| 91国产成人在线| 欧洲一区二区三区在线| 91福利在线看| 欧美日韩在线亚洲一区蜜芽| 欧美日韩一级二级三级| 欧美日韩一区二区三区免费看| 欧美日韩一级视频| 欧美一区二区三区视频免费| 日韩欧美国产一区在线观看| 日韩精品中午字幕| 欧美精品一区二区三区高清aⅴ| 精品日产卡一卡二卡麻豆| 欧美大片在线观看一区二区| 精品久久久网站| 久久精品人人做人人爽97| 中文字幕av在线一区二区三区| 国产精品午夜电影| 亚洲欧美韩国综合色| 亚洲18女电影在线观看| 蜜乳av一区二区| 国产二区国产一区在线观看| 风间由美中文字幕在线看视频国产欧美 | 日韩欧美国产综合在线一区二区三区 | 91精品国产综合久久精品app| 日韩欧美色综合| 国产日本欧美一区二区| 亚洲人一二三区| 日韩精品一二三四| 国产一区二区三区蝌蚪| www.激情成人| 欧美人伦禁忌dvd放荡欲情| 欧美一区日韩一区| 国产农村妇女精品| 亚洲午夜电影在线观看| 狠狠色2019综合网| 91色在线porny| 3atv一区二区三区| 中文在线资源观看网站视频免费不卡 | 最新国产成人在线观看| 午夜精品久久久久| 国产精品白丝av| 欧洲人成人精品| 久久久久久久久久久99999| 亚洲欧洲制服丝袜| 六月婷婷色综合| 一本大道久久a久久综合婷婷| 日韩三级在线免费观看| 国产精品国产三级国产aⅴ原创| 日韩高清欧美激情| eeuss鲁片一区二区三区在线观看| 欧美男女性生活在线直播观看| 久久精品一级爱片| 天堂一区二区在线| 本田岬高潮一区二区三区| 日韩欧美123| 亚洲一区二区综合| 成人中文字幕电影| 日韩一区二区麻豆国产| 亚洲精品欧美在线| 国产999精品久久久久久绿帽| 884aa四虎影成人精品一区| 亚洲日本护士毛茸茸| 国产一二精品视频| 日韩一区二区在线观看视频播放| 亚洲婷婷在线视频| 国v精品久久久网| 精品国精品自拍自在线| 午夜精品123| 在线免费观看一区| 中文字幕佐山爱一区二区免费| 久久精品国产一区二区| 欧美区在线观看| 亚洲午夜一区二区三区| 91视频观看免费| 中文字幕中文字幕在线一区| 国产米奇在线777精品观看| 亚洲精品视频在线观看免费 | 久久久久久久久久看片| 日韩和的一区二区| 欧美日韩一区二区三区视频| 亚洲视频网在线直播| 成人午夜在线免费| 国产欧美日韩卡一| 国产高清亚洲一区| 久久久精品天堂| 国产精品一区不卡| 国产欧美精品一区aⅴ影院 | 国产精华液一区二区三区| 欧美一卡二卡在线观看| 青青国产91久久久久久 | 国产成人午夜视频| 久久精品人人做人人爽人人| 国产一区美女在线| 亚洲精品一区二区三区精华液| 青青草视频一区| 日韩精品在线网站| 国产一本一道久久香蕉| 国产日韩欧美精品电影三级在线 | 亚洲一卡二卡三卡四卡无卡久久 | 一区二区在线观看av| 色8久久精品久久久久久蜜| 亚洲欧美偷拍卡通变态| 日本丰满少妇一区二区三区| 一区二区三区日本| 欧美精品亚洲一区二区在线播放| 亚洲成av人片一区二区梦乃| 91精品在线观看入口| 日韩电影在线免费| 欧美精品一区二区在线播放| 国产麻豆视频一区二区| 国产精品伦理在线| 色综合久久中文字幕综合网| 亚洲精品高清在线观看| 在线观看91精品国产麻豆| 久久国产精品99久久人人澡| 国产欧美一区二区精品性| 99精品国产99久久久久久白柏| 亚洲一区二区三区四区在线观看| 欧美一区二区三区影视| 国产成人精品1024| 亚洲一区二区三区视频在线| 精品黑人一区二区三区久久|