本文整理汇总了Java中weka.core.Utils类的典型用法代码示例。如果您正苦于以下问题:Java Utils类的具体用法?Java Utils怎么用?Java Utils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Utils类属于weka.core包,在下文中一共展示了Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WekaMatchingRule
import weka.core.Utils; //导入依赖的package包/类
/**
* Create a MatchingRule, which can be trained using the Weka library for
* identity resolution.
*
* @param finalThreshold
* determines the confidence level, which needs to be exceeded by
* the classifier, so that it can classify a record as match.
*
* @param classifierName
* Has the name of a specific classifier from the Weka library.
*
* @param parameters
* Hold the parameters to tune the classifier.
*/
public WekaMatchingRule(double finalThreshold, String classifierName, String parameters[]) {
super(finalThreshold);
this.parameters = parameters;
// create classifier
try {
this.classifier = (Classifier) Utils.forName(Classifier.class, classifierName, parameters);
} catch (Exception e) {
e.printStackTrace();
}
// create list for comparators
this.comparators = new LinkedList<>();
}
示例2: classifySentence
import weka.core.Utils; //导入依赖的package包/类
public SentenceType classifySentence(Sentence sentence) {
SpeechActsClassifier.Features features = speechActsClassifier.classifyFeatures(sentence);
Instance inst = new DenseInstance(6);
inst.setDataset(dataSet);
inst.setValue(0, features.getSentenceLength());
inst.setValue(1, features.getNumberOfNouns());
inst.setValue(2, (features.isEndingInNounOrAdjective() ? 1 : 0));
inst.setValue(3, (features.isBeginningInVerb() ? 1 : 0));
inst.setValue(4, features.getCountOfWhMarkers());
inst.setValue(5, Utils.missingValue());
try {
return SentenceType.valueOf(classifier.classifyInstance(inst));
} catch (Exception e) {
throw new RuntimeException("Can't classify");
}
}
示例3: classifyQuestion
import weka.core.Utils; //导入依赖的package包/类
public QuestionType classifyQuestion(Sentence sentence) {
if (!sentence.isQuestion()) {
return QuestionType.NA;
}
QuestionTypeClassifier.Features features = questionTypeClassifier.classifyFeatures(sentence);
Instance inst = new DenseInstance(5);
inst.setDataset(dataSet);
inst.setValue(0, features.getWhWord());
inst.setValue(1, features.getWhWordPos());
inst.setValue(2, features.getPosOfNext());
inst.setValue(3, features.getRootPos());
inst.setValue(4, Utils.missingValue());
try {
int ndx = (int) classifier.classifyInstance(inst);
return QuestionType.valueOf(ndx);
} catch (Exception e) {
throw new RuntimeException("Not classified");
}
}
示例4: getClustererAssignmentsPlotInstances
import weka.core.Utils; //导入依赖的package包/类
/**
* Returns an instance of the class used for generating plot instances for
* displaying the cluster assignments.
*
* @return an instance of the class
*/
public static ClustererAssignmentsPlotInstances getClustererAssignmentsPlotInstances() {
ClustererAssignmentsPlotInstances result;
String classname;
String[] options;
try {
options = Utils.splitOptions(get("ClustererAssignmentsPlotInstances",
"weka.gui.explorer.ClustererAssignmentsPlotInstances"));
classname = options[0];
options[0] = "";
result = (ClustererAssignmentsPlotInstances) Utils.forName(
ClustererAssignmentsPlotInstances.class, classname, options);
} catch (Exception e) {
e.printStackTrace();
result = new ClustererAssignmentsPlotInstances();
}
return result;
}
示例5: chooseRandomIndexBasedOnProportions
import weka.core.Utils; //导入依赖的package包/类
/**
* returns a random index based on the given proportions
*
* @param proportionArray the proportions
* @param random the random number generator to use
* @return the random index
*/
protected int chooseRandomIndexBasedOnProportions(double[] proportionArray,
Random random) {
double probSum;
double val;
int index;
double sum;
probSum = Utils.sum(proportionArray);
val = random.nextDouble() * probSum;
index = 0;
sum = 0.0;
while ((sum <= val) && (index < proportionArray.length)) {
sum += proportionArray[index++];
}
return index - 1;
}
示例6: toString
import weka.core.Utils; //导入依赖的package包/类
/**
* Returns description of the bagged classifier.
*
* @return description of the bagged classifier as a string
*/
@Override
public String toString() {
if (m_Classifiers == null) {
return "Bagging: No model built yet.";
}
StringBuffer text = new StringBuffer();
text.append("All the base classifiers: \n\n");
for (int i = 0; i < m_Classifiers.length; i++)
text.append(m_Classifiers[i].toString() + "\n\n");
if (m_CalcOutOfBag) {
text.append("Out of bag error: "
+ Utils.doubleToString(m_OutOfBagError, 4)
+ "\n\n");
}
return text.toString();
}
示例7: chooseLastIndex
import weka.core.Utils; //导入依赖的package包/类
/**
* Choose last index (ie. choose rule).
*/
public final int chooseLastIndex() {
int minIndex = 0;
double estimated, min = Double.MAX_VALUE;
if (!m_isLeaf) {
for (int i = 0; i < m_sons.length; i++) {
if (son(i) != null) {
if (Utils.grOrEq(localModel().distribution().perBag(i), m_minNumObj)) {
estimated = son(i).getSizeOfBranch();
if (Utils.sm(estimated, min)) {
min = estimated;
minIndex = i;
}
}
}
}
}
return minIndex;
}
示例8: getAreaUnderLearningCurve
import weka.core.Utils; //导入依赖的package包/类
/**
* Calculates the area under the learning curve (ALC).
*
* @param ds
* an array of values
* @param xDelta
* The step
*
* @return The area under learning curve
*/
public static double getAreaUnderLearningCurve(double[] ds, double xDelta) {
final int n = ds.length;
if (n == 0) {
return Double.NaN;
}
double area = 0;
double total = 0;
for (int i = n - 2; i >= 0; i--) {
total += xDelta;
area += (ds[i] * xDelta);
}
if (area == 0) {
return Utils.missingValue();
}
return area / total;
}
示例9: splitEnt
import weka.core.Utils; //导入依赖的package包/类
/**
* Help method for computing the split entropy.
*/
private final double splitEnt(Distribution bags, double totalnoInst) {
double returnValue = 0;
double noUnknown;
int i;
noUnknown = totalnoInst - bags.total();
if (Utils.gr(bags.total(), 0)) {
for (i = 0; i < bags.numBags(); i++) {
returnValue = returnValue - lnFunc(bags.perBag(i));
}
returnValue = returnValue - lnFunc(noUnknown);
returnValue = returnValue + lnFunc(totalnoInst);
}
return returnValue / ContingencyTables.log2;
}
示例10: toStringKey
import weka.core.Utils; //导入依赖的package包/类
/**
* returns a key for all the col names, for better readability if
* the names got cut off.
*
* @return the key
*/
public String toStringKey() {
String result;
int i;
result = "Key,\n";
for (i = 0; i < getColCount(); i++) {
if (getColHidden(i))
continue;
result += LEFT_PARENTHESES + (i+1) + RIGHT_PARENTHESES
+ "," + Utils.quote(removeFilterName(m_ColNames[i])) + "\n";
}
return result;
}
示例11: priorEntropy
import weka.core.Utils; //导入依赖的package包/类
/**
* Calculate the entropy of the prior distribution.
*
* @return the entropy of the prior distribution
* @throws Exception if the class is not nominal
*/
public final double priorEntropy() throws Exception {
if (!m_ClassIsNominal) {
throw new Exception("Can't compute entropy of class prior: "
+ "class numeric!");
}
if (m_NoPriors) {
return Double.NaN;
}
double entropy = 0;
for (int i = 0; i < m_NumClasses; i++) {
entropy -=
m_ClassPriors[i] / m_ClassPriorsSum
* Utils.log2(m_ClassPriors[i] / m_ClassPriorsSum);
}
return entropy;
}
示例12: distributionForInstance
import weka.core.Utils; //导入依赖的package包/类
/**
* Classifies the given test instance. The instance has to belong to a
* dataset when it's being classified.
*
* @param inst the instance to be classified
* @return the predicted most likely class for the instance or
* Utils.missingValue() if no prediction is made
* @exception Exception if an error occurred during the prediction
*/
public double[] distributionForInstance(Instance inst) throws Exception {
if (!m_initialized) {
mapToMiningSchema(inst.dataset());
}
double[] preds = null;
if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
preds = new double[1];
} else {
preds = new double[m_miningSchema.getFieldsAsInstances().classAttribute().numValues()];
}
double[] incoming = m_fieldsMap.instanceToSchema(inst, m_miningSchema);
preds = m_ruleSet.score(incoming,
m_miningSchema.getFieldsAsInstances().classAttribute());
if (m_miningSchema.getFieldsAsInstances().classAttribute().isNominal()) {
Utils.normalize(preds);
}
return preds;
}
示例13: setup
import weka.core.Utils; //导入依赖的package包/类
@Override
public void setup(Context context) throws IOException {
m_task = new CSVToARFFHeaderReduceTask();
Configuration conf = context.getConfiguration();
String taskOpts =
conf.get(CSVToArffHeaderHadoopMapper.CSV_TO_ARFF_HEADER_MAP_TASK_OPTIONS);
if (taskOpts != null && taskOpts.length() > 0) {
try {
String[] options = Utils.splitOptions(taskOpts);
m_estimateQuantiles = Utils.getFlag("compute-quartiles", options);
} catch (Exception ex) {
throw new IOException(ex);
}
}
}
示例14: setT2T1BasedOnStdDev
import weka.core.Utils; //导入依赖的package包/类
/**
* Pretty hokey heuristic to try and set t2 distance automatically based on
* standard deviation
*
* @param trainingBatch the training instances
* @throws Exception if a problem occurs
*/
protected void setT2T1BasedOnStdDev(Instances trainingBatch) throws Exception {
double normalizedStdDevSum = 0;
for (int i = 0; i < trainingBatch.numAttributes(); i++) {
if (trainingBatch.attribute(i).isNominal()) {
normalizedStdDevSum += 0.25;
} else if (trainingBatch.attribute(i).isNumeric()) {
AttributeStats stats = trainingBatch.attributeStats(i);
if (trainingBatch.numInstances() - stats.missingCount > 2) {
double stdDev = stats.numericStats.stdDev;
double min = stats.numericStats.min;
double max = stats.numericStats.max;
if (!Utils.isMissingValue(stdDev) && max - min > 0) {
stdDev = 0.5 * stdDev / (max - min);
normalizedStdDevSum += stdDev;
}
}
}
}
normalizedStdDevSum = Math.sqrt(normalizedStdDevSum);
if (normalizedStdDevSum > 0) {
m_t2 = normalizedStdDevSum;
}
}
示例15: getOptions
import weka.core.Utils; //导入依赖的package包/类
/**
* Gets the current settings of the datagenerator RDG1. Removing of
* blacklisted options has to be done in the derived class, that defines the
* blacklist-entry.
*
* @return an array of strings suitable for passing to setOptions
* @see #removeBlacklist(String[])
*/
@Override
public String[] getOptions() {
Vector<String> result = new Vector<String>();
// to avoid endless loop
if (!m_CreatingRelationName) {
result.add("-r");
result.add(Utils.quote(getRelationNameToUse()));
}
if (getDebug()) {
result.add("-d");
}
result.add("-S");
result.add("" + getSeed());
return result.toArray(new String[result.size()]);
}