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

📄 exampletesttools.java

📁 著名的开源仿真软件yale
💻 JAVA
字号:
/* *  YALE - Yet Another Learning Environment *  Copyright (C) 2002, 2003 *      Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,  *          Katharina Morik, Oliver Ritthoff *      Artificial Intelligence Unit *      Computer Science Department *      University of Dortmund *      44221 Dortmund,  Germany *  email: yale@ls8.cs.uni-dortmund.de *  web:   http://yale.cs.uni-dortmund.de/ * *  This program is free software; you can redistribute it and/or *  modify it under the terms of the GNU General Public License as  *  published by the Free Software Foundation; either version 2 of the *  License, or (at your option) any later version.  * *  This program is distributed in the hope that it will be useful, but *  WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *  General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *  USA. */package edu.udo.cs.yale.example.test;import edu.udo.cs.yale.example.*;import edu.udo.cs.yale.tools.Ontology;import java.util.*;/** Provides factory methods for text fixtures. * *  @version $Id: ExampleTestTools.java,v 1.5 2003/05/15 13:36:06 fischer Exp $ */public class ExampleTestTools {    /** Returns a DataRowReader returning the given values. */    public static DataRowReader createDataRowReader(DataRowFactory factory, Attribute[] attributes, String[][] values) {	List dataRows = new LinkedList();	for (int i = 0; i < values.length; i++) {	    dataRows.add(factory.create(values[i], attributes));	}	return new ListDataRowReader(dataRows.iterator());    }    /** Returns a DataRowReader returning the given values. */    public static DataRowReader createDataRowReader(double[][] values) {	List dataRows = new LinkedList();	for (int i = 0; i < values.length; i++) {	    dataRows.add(new DoubleArrayDataRow(values[i]));	}	return new ListDataRowReader(dataRows.iterator());    }    /** Returns a DataRowReader returning random values (generated with fixed random seed). */    public static DataRowReader createDataRowReader(int size, Attribute[] attributes) {	Random random = new Random(0);	List dataRows = new LinkedList();	for (int i = 0; i < size; i++) {	    double[] data = new double[attributes.length];	    for (int j = 0; j < data.length; j++) {		if (attributes[j].isNominal()) {		    data[j] = random.nextInt(attributes[j].getNumberOfClasses()) + Attribute.FIRST_CLASS_INDEX;		} if (attributes[j].getValueType() == Ontology.INTEGER) {		    data[j] = random.nextInt(200)-100;		} else {		    data[j] = 20.0*random.nextDouble()-10.0;		}	    }	    dataRows.add(new DoubleArrayDataRow(data));	}	return new ListDataRowReader(dataRows.iterator());    }    public static MemoryExampleTable createMemoryExampleTable(int size) {	Attribute[] attributes = createFourAttributes();	return new MemoryExampleTable(Arrays.asList(attributes), 				      createDataRowReader(size, attributes));    }    public static Attribute attributeDogCatMouse() {	Attribute a = new Attribute("animal", Ontology.NOMINAL, Ontology.SINGLE_VALUE, 1, null);	a.mapString("dog");	a.mapString("cat");	a.mapString("mouse");	return a;    }    public static Attribute attributeYesNo() {	Attribute a = new Attribute("decision", Ontology.NOMINAL, Ontology.SINGLE_VALUE, 1, null);	a.mapString("yes");	a.mapString("no");	return a;    }    public static Attribute attributeInt() {	Attribute a = new Attribute("integer", Ontology.INTEGER, Ontology.SINGLE_VALUE, 1, null);	return a;    }    public static Attribute attributeReal() {	Attribute a = new Attribute("real", Ontology.REAL, Ontology.SINGLE_VALUE, 1, null);	return a;    }    public static Attribute attributeReal(int index) {	Attribute a = new Attribute("real"+index, Ontology.REAL, Ontology.SINGLE_VALUE, 1, null);	return a;    }    /** Cretaes four attributes: "animal" (dog/cat/mouse), "decision" (yes/no), "int", and "real". */    public static Attribute[] createFourAttributes() {	Attribute[] attributes = new Attribute[4];	attributes = new Attribute[4];	attributes[0] = ExampleTestTools.attributeDogCatMouse();	attributes[1] = ExampleTestTools.attributeYesNo();	attributes[2] = ExampleTestTools.attributeInt();	attributes[3] = ExampleTestTools.attributeReal();	for (int i = 0; i < attributes.length; i++)	    attributes[i].setIndex(i);	return attributes;    }}

⌨️ 快捷键说明

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