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

📄 distancemeasure.java

📁 著名的开源仿真软件yale
💻 JAVA
字号:
package edu.udo.cs.yale.operator.clusterer.upgma;import edu.udo.cs.yale.example.Example;import edu.udo.cs.yale.example.ExampleSet;import edu.udo.cs.yale.example.ExampleReader;public abstract class DistanceMeasure {    public static final String[] CLUSTER_TYPE_NAMES = new String[] {"minimum", "maximum", "average", "unweighted_average" };    public static final int TYPE_MINIMUM = 0;    public static final int TYPE_MAXIMUM = 1;    public static final int TYPE_AVERAGE = 2;    public static final int TYPE_UNWEIGHTED = 3;    public static final String[] TYPE_NAMES = new String[] {"euklidian", "nominal"};    public static final int TYPE_EUKLIDIAN = 0;    public static final int TYPE_NOMINAL   = 1;    public static ClusterDistanceMeasure createClusterDistanceMeasure(int type) {	switch (type) {	case TYPE_MINIMUM: return new MinClusterDistanceMeasure();	case TYPE_MAXIMUM: return new MaxClusterDistanceMeasure();	case TYPE_AVERAGE: return new AverageClusterDistanceMeasure();	case TYPE_UNWEIGHTED: return new UnweightedClusterDistanceMeasure();	default:	    throw new IllegalArgumentException("Illegal ClusterDistanceMeasure type: "+type);	}    }    public static DistanceMeasure createDistanceMeasure(int type) {	switch (type) {	case TYPE_EUKLIDIAN: return new EuklidianDistanceMeasure();	case TYPE_NOMINAL:   return new NominalDistanceMeasure();	default:	    throw new IllegalArgumentException("Illegal DistanceMeasure type: "+type);	}    }    public abstract double calculateDistance(Example e1, Example e2);    public DistanceMatrix calculateDistanceMatrix(ExampleSet exampleSet) {	DistanceMatrix matrix = new DistanceMatrix(exampleSet.getSize());	ExampleReader r = exampleSet.getExampleReader();	int i = 0;	while (r.hasNext()) {	    Example e = r.next();	    String name = "?";	    if (e.getIdAttribute() != null) {		String idString = e.getIdAsString();		if (idString.length() > 15)		    name = idString.substring(0,15) + "...";		else name = idString;		if (e.getLabelAttribute() != null) {		    name += "\n(" + e.getLabelAsString() + ")";		}	    } else if (e.getLabelAttribute() != null) {		name = e.getLabelAsString();	    }	    matrix.setName(i, name);	    ExampleReader s = exampleSet.getExampleReader();	    int j = 0;	    while (s.hasNext()) {		matrix.setDistance(i, j, calculateDistance(e, s.next()));				j++;	    }	    i++;	}	return matrix;    }}

⌨️ 快捷键说明

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