⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clustering.java

📁 常用机器学习算法,java编写源代码,内含常用分类算法,包括说明文档
💻 JAVA
字号:
/* Copyright (C) 2003 Univ. of Massachusetts Amherst, Computer Science Dept.   This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).   http://www.cs.umass.edu/~mccallum/mallet   This software is provided under the terms of the Common Public License,   version 1.0, as published by http://www.opensource.org.  For further   information, see the file `LICENSE' included with this distribution. *//** A clustering of a set of points (instances).    @author Jerod Weinman <A HREF="mailto:weinman@cs.umass.edu">weinman@cs.umass.edu</A>*/package edu.umass.cs.mallet.base.cluster;import edu.umass.cs.mallet.base.types.Instance;import edu.umass.cs.mallet.base.types.InstanceList;import java.lang.IllegalArgumentException;public class Clustering {    int numLabels;    int labels[];    InstanceList instances;    /** Clustering constructor.     *     * @param instances Instances that are clustered     * @param numLabels Number of clusters     * @param labels Assignment of instances to clusters; many-to-one with      *               range [0,numLabels).     */    public Clustering( InstanceList instances, int numLabels, int[] labels )    {	if ( instances.size() != labels.length )	    throw new IllegalArgumentException("Instance list length does not match cluster labeling");	if (numLabels<1)	    throw new IllegalArgumentException("Number of labels must be strictly positive.");		for (int i=0 ; i<labels.length ; i++)	    if (labels[i]<0 || labels[i]>=numLabels)		throw new IllegalArgumentException("Label mapping must have range [0,numLabels).");	this.instances = instances;	this.numLabels = numLabels;	this.labels = labels;    }    public int getNumClusters() { return numLabels; }    /** Get the cluster label for a particular instance. */    public int getLabel(int index) { return labels[index]; }    /** Return an list of instances with a particular label. */    public InstanceList getCluster(int label) {	InstanceList cluster = new InstanceList(instances.getPipe() );	for (int n=0 ; n<instances.size() ; n++ ) {	    if ( labels[n] == label)		cluster.add( instances.getInstance(n) );	}	return cluster;    }    /** Returns an array of instance lists corresponding to clusters. */    public InstanceList[] getClusters() {		InstanceList[] clusters = new InstanceList[numLabels];	for (int c= 0 ; c<numLabels ; c++ )	    clusters[c] = getCluster(c);		return clusters;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -