📄 checkscheme.java
字号:
} /** * sets the number of nominal attributes * * @param value the number of nominal attributes */ public void setNumNominal(int value) { m_NumNominal = value; } /** * returns the current number of nominal attributes * * @return the number of nominal attributes */ public int getNumNominal() { return m_NumNominal; } /** * sets the number of numeric attributes * * @param value the number of numeric attributes */ public void setNumNumeric(int value) { m_NumNumeric = value; } /** * returns the current number of numeric attributes * * @return the number of numeric attributes */ public int getNumNumeric() { return m_NumNumeric; } /** * sets the number of string attributes * * @param value the number of string attributes */ public void setNumString(int value) { m_NumString = value; } /** * returns the current number of string attributes * * @return the number of string attributes */ public int getNumString() { return m_NumString; } /** * sets the number of data attributes * * @param value the number of date attributes */ public void setNumDate(int value) { m_NumDate = value; } /** * returns the current number of date attributes * * @return the number of date attributes */ public int getNumDate() { return m_NumDate; } /** * sets the number of relational attributes * * @param value the number of relational attributes */ public void setNumRelational(int value) { m_NumRelational = value; } /** * returns the current number of relational attributes * * @return the number of relational attributes */ public int getNumRelational() { return m_NumRelational; } /** * sets the number of instances in relational/bag attributes to produce * * @param value the number of instances */ public void setNumInstancesRelational(int value) { m_NumInstancesRelational = value; } /** * returns the current number of instances in relational/bag attributes to produce * * @return the number of instances */ public int getNumInstancesRelational() { return m_NumInstancesRelational; } /** * turns the comma-separated list into an array * * @param value the list to process * @return the list as array */ protected static String[] listToArray(String value) { StringTokenizer tok; Vector list; list = new Vector(); tok = new StringTokenizer(value, ","); while (tok.hasMoreTokens()) list.add(tok.nextToken()); return (String[]) list.toArray(new String[list.size()]); } /** * turns the array into a comma-separated list * * @param value the array to process * @return the array as list */ protected static String arrayToList(String[] value) { String result; int i; result = ""; for (i = 0; i < value.length; i++) { if (i > 0) result += ","; result += value[i]; } return result; } /** * returns a string representation of the attribute type * * @param type the attribute type to get a string rerpresentation for * @return the string representation */ public static String attributeTypeToString(int type) { String result; switch (type) { case Attribute.NUMERIC: result = "numeric"; break; case Attribute.NOMINAL: result = "nominal"; break; case Attribute.STRING: result = "string"; break; case Attribute.DATE: result = "date"; break; case Attribute.RELATIONAL: result = "relational"; break; default: result = "???"; } return result; } /** * Sets the comma-separated list of words to use for generating strings. The * list must contain at least 2 words, otherwise an exception will be thrown. * * @param value the list of words * @throws IllegalArgumentException if not at least 2 words are provided */ public void setWords(String value) { if (listToArray(value).length < 2) throw new IllegalArgumentException("At least 2 words must be provided!"); m_Words = listToArray(value); } /** * returns the words used for assembling strings in a comma-separated list. * * @return the words as comma-separated list */ public String getWords() { return arrayToList(m_Words); } /** * sets the word separators (chars) to use for assembling strings. * * @param value the characters to use as separators */ public void setWordSeparators(String value) { m_WordSeparators = value; } /** * returns the word separators (chars) to use for assembling strings. * * @return the current separators */ public String getWordSeparators() { return m_WordSeparators; } /** * Compare two datasets to see if they differ. * * @param data1 one set of instances * @param data2 the other set of instances * @throws Exception if the datasets differ */ protected void compareDatasets(Instances data1, Instances data2) throws Exception { if (!data2.equalHeaders(data1)) { throw new Exception("header has been modified"); } if (!(data2.numInstances() == data1.numInstances())) { throw new Exception("number of instances has changed"); } for (int i = 0; i < data2.numInstances(); i++) { Instance orig = data1.instance(i); Instance copy = data2.instance(i); for (int j = 0; j < orig.numAttributes(); j++) { if (orig.isMissing(j)) { if (!copy.isMissing(j)) { throw new Exception("instances have changed"); } } else if (orig.value(j) != copy.value(j)) { throw new Exception("instances have changed"); } if (orig.weight() != copy.weight()) { throw new Exception("instance weights have changed"); } } } } /** * Add missing values to a dataset. * * @param data the instances to add missing values to * @param level the level of missing values to add (if positive, this * is the probability that a value will be set to missing, if negative * all but one value will be set to missing (not yet implemented)) * @param predictorMissing if true, predictor attributes will be modified * @param classMissing if true, the class attribute will be modified */ protected void addMissing(Instances data, int level, boolean predictorMissing, boolean classMissing) { int classIndex = data.classIndex(); Random random = new Random(1); for (int i = 0; i < data.numInstances(); i++) { Instance current = data.instance(i); for (int j = 0; j < data.numAttributes(); j++) { if (((j == classIndex) && classMissing) || ((j != classIndex) && predictorMissing)) { if (Math.abs(random.nextInt()) % 100 < level) current.setMissing(j); } } } } /** * Provides a hook for derived classes to further modify the data. * * @param data the data to process * @return the processed data * @see #m_PostProcessor */ protected Instances process(Instances data) { if (getPostProcessor() == null) return data; else return getPostProcessor().process(data); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -