本文整理汇总了Java中weka.core.FastVector类的典型用法代码示例。如果您正苦于以下问题:Java FastVector类的具体用法?Java FastVector怎么用?Java FastVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FastVector类属于weka.core包,在下文中一共展示了FastVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canHandleZeroTraining
import weka.core.FastVector; //导入依赖的package包/类
/**
* Checks whether the scheme can handle zero training instances.
*
* @param attrTypes attribute types that can be estimated
* @param classType the class type (NUMERIC, NOMINAL, etc.)
* @return index 0 is true if the test was passed, index 1 is true if test
* was acceptable
*/
protected boolean[] canHandleZeroTraining(AttrTypes attrTypes, int classType) {
print("handle zero training instances");
printAttributeSummary(attrTypes, classType);
print("...");
FastVector accepts = new FastVector();
accepts.addElement("train");
accepts.addElement("value");
int numTrain = 0, numTest = getNumInstances(), numClasses = 2,
missingLevel = 0;
boolean attributeMissing = false, classMissing = false;
int numAtts = 1;
int attrIndex = 0;
return runBasicTest(
attrTypes, numAtts, attrIndex,
classType,
missingLevel, attributeMissing, classMissing,
numTrain, numTest, numClasses,
accepts);
}
示例2: defineClustersRANDOM
import weka.core.FastVector; //导入依赖的package包/类
/**
* Defines the clusters if pattern is RANDOM
*
* @param random random number generator
* @return the cluster definitions
* @throws Exception if something goes wrong
*/
private FastVector defineClustersRANDOM(Random random)
throws Exception {
FastVector clusters = new FastVector(m_NumClusters);
double diffInstNum = (double) (m_MaxInstNum - m_MinInstNum);
double minInstNum = (double) m_MinInstNum;
double diffRadius = m_MaxRadius - m_MinRadius;
Cluster cluster;
for (int i = 0; i < m_NumClusters; i++) {
int instNum = (int) (random.nextDouble() * diffInstNum
+ minInstNum);
double radius = (random.nextDouble() * diffRadius) + m_MinRadius;
// center is defined in the constructor of cluster
cluster = new Cluster(instNum, radius, random);
clusters.addElement((Object) cluster);
}
return clusters;
}
示例3: makeADTree
import weka.core.FastVector; //导入依赖的package包/类
/**
* create sub tree
*
* @param iNode index of the lowest node in the tree
* @param nRecords set of records in instances to be considered
* @param instances data set
* @return ADNode representing an ADTree
*/
public static ADNode makeADTree(int iNode, FastVector nRecords, Instances instances) {
ADNode _ADNode = new ADNode();
_ADNode.m_nCount = nRecords.size();
_ADNode.m_nStartNode = iNode;
if (nRecords.size() < MIN_RECORD_SIZE) {
_ADNode.m_Instances = new Instance[nRecords.size()];
for (int iInstance = 0; iInstance < nRecords.size(); iInstance++) {
_ADNode.m_Instances[iInstance] = instances.instance(((Integer) nRecords.elementAt(iInstance)).intValue());
}
} else {
_ADNode.m_VaryNodes = new VaryNode[instances.numAttributes() - iNode];
for (int iNode2 = iNode; iNode2 < instances.numAttributes(); iNode2++) {
_ADNode.m_VaryNodes[iNode2 - iNode] = makeVaryNode(iNode2, nRecords, instances);
}
}
return _ADNode;
}
示例4: layoutGraph
import weka.core.FastVector; //导入依赖的package包/类
void layoutGraph() {
if (m_BayesNet.getNrOfNodes() == 0) {
return;
}
try {
FastVector m_nodes = new FastVector();
FastVector m_edges = new FastVector();
BIFParser bp = new BIFParser(m_BayesNet.toXMLBIF03(), m_nodes, m_edges);
bp.parse();
updateStatus();
m_layoutEngine = new HierarchicalBCEngine(m_nodes, m_edges, m_nPaddedNodeWidth, m_nNodeHeight);
m_layoutEngine.addLayoutCompleteEventListener(this);
m_layoutEngine.layoutGraph();
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: findRulesQuickly
import weka.core.FastVector; //导入依赖的package包/类
/**
* Method that finds all association rules.
*
* @throws Exception if an attribute is numeric
*/
private void findRulesQuickly() throws Exception {
FastVector[] rules;
// Build rules
for (int j = 1; j < m_Ls.size(); j++) {
FastVector currentItemSets = (FastVector)m_Ls.elementAt(j);
Enumeration enumItemSets = currentItemSets.elements();
while (enumItemSets.hasMoreElements()) {
AprioriItemSet currentItemSet = (AprioriItemSet)enumItemSets.nextElement();
//AprioriItemSet currentItemSet = new AprioriItemSet((ItemSet)enumItemSets.nextElement());
rules = currentItemSet.generateRules(m_minMetric, m_hashtables, j + 1);
for (int k = 0; k < rules[0].size(); k++) {
m_allTheRules[0].addElement(rules[0].elementAt(k));
m_allTheRules[1].addElement(rules[1].elementAt(k));
m_allTheRules[2].addElement(rules[2].elementAt(k));
if (rules.length > 3) {
m_allTheRules[3].addElement(rules[3].elementAt(k));
m_allTheRules[4].addElement(rules[4].elementAt(k));
m_allTheRules[5].addElement(rules[5].elementAt(k));
}
}
}
}
}
示例6: timeInstances
import weka.core.FastVector; //导入依赖的package包/类
public Instances timeInstances(SortedSet orders){
FastVector attributes = new FastVector(1);
attributes.addElement(new Attribute("time"));
Instances cInstances = new Instances("wiki", attributes,orders.size());
for(Iterator it = orders.iterator(); it.hasNext();){
// System.out.println("class: " + data.instance(i).getClass());
MyInstance instance = (MyInstance) it.next();
double [] values = new double[1]; //instance.toDoubleArray();
values[values.length - 1] = instance.getTime();
Instance newInstance = new Instance(1, values);
newInstance = new MyInstance(newInstance, instance.getTime());
cInstances.add(newInstance);
}
return cInstances;
}
示例7: tearDown
import weka.core.FastVector; //导入依赖的package包/类
/** Called by JUnit after each test method */
protected void tearDown() {
m_Classifier = null;
m_Tester = null;
m_OptionTester = null;
m_GOETester = null;
m_updateableClassifier = false;
m_weightedInstancesHandler = false;
m_NominalPredictors = new boolean[LAST_CLASSTYPE + 1];
m_NumericPredictors = new boolean[LAST_CLASSTYPE + 1];
m_StringPredictors = new boolean[LAST_CLASSTYPE + 1];
m_DatePredictors = new boolean[LAST_CLASSTYPE + 1];
m_RelationalPredictors = new boolean[LAST_CLASSTYPE + 1];
m_handleMissingPredictors = new boolean[LAST_CLASSTYPE + 1];
m_handleMissingClass = new boolean[LAST_CLASSTYPE + 1];
m_handleClassAsFirstAttribute = new boolean[LAST_CLASSTYPE + 1];
m_handleClassAsSecondAttribute = new boolean[LAST_CLASSTYPE + 1];
m_RegressionResults = new FastVector[LAST_CLASSTYPE + 1];
m_NClasses = 4;
}
示例8: getInstances
import weka.core.FastVector; //导入依赖的package包/类
private Instances getInstances() {
Attribute rleRateAttr = new Attribute(ARFFAttributes.DATA_COMPRESSION_RATE_BY_RLE_ATTRIBUTE);
Attribute rleRateVwAttr = new Attribute(ARFFAttributes.DATA_COMPRESSION_RATE_OF_VERTICALLY_WINDING_TEXT_BY_RLE_ATTRIBUTE);
Attribute linesAttr = new Attribute(ARFFAttributes.NUMBER_OF_LINES_ATTRIBUTE);
Attribute sizeAttr = new Attribute(ARFFAttributes.TEXT_SIZE_ATTRIBUTE);
// Create nominal attribute "class"
FastVector my_nominal_values = new FastVector(2);
my_nominal_values.addElement(ARFFAttributes.ASCIIART_CLASS_NAME);
my_nominal_values.addElement(ARFFAttributes.NON_ASCIIART_CLASS_NAME);
Attribute className = new Attribute(ARFFAttributes.CLASS_ATTRIBUTE, my_nominal_values);
FastVector attributes = new FastVector(5);
attributes.addElement(rleRateAttr);
attributes.addElement(rleRateVwAttr);
attributes.addElement(linesAttr);
attributes.addElement(sizeAttr);
attributes.addElement(className);
// Create the empty dataset "textart" with above attributes
Instances instances = new Instances(ARFFAttributes.ASCIIART_CLASS_NAME, attributes, 0);
instances.setClassIndex(className.index());
return instances;
}
示例9: buildVarInstances
import weka.core.FastVector; //导入依赖的package包/类
public TrialInstances buildVarInstances(InferenceRule ir, List allVars) {
FastVector attributes = new FastVector();
WekaInterface.addAllPairs(attributes, allVars);
attributes.addElement(new weka.core.Attribute("score"));
int capacity = 30;
OrderTranslator filter = new FilterTranslator(allVars);
TrialInstances data = new TrialInstances("Var Ordering Constraints", attributes, capacity);
if (allVars.size() <= 1) return data;
for (Iterator i = allTrials.iterator(); i.hasNext();) {
EpisodeCollection tc2 = (EpisodeCollection) i.next();
InferenceRule ir2 = tc2.getRule(solver);
if (ir != ir2) continue;
addToInstances(data, tc2, filter);
}
data.setClassIndex(data.numAttributes() - 1);
return data;
}
示例10: canEstimate
import weka.core.FastVector; //导入依赖的package包/类
/**
* Checks basic estimation of one attribute of the scheme, for simple non-troublesome
* datasets.
*
* @param attrTypes the types the estimator can work with
* @param classType the class type (NOMINAL, NUMERIC, etc.)
* @return index 0 is true if the test was passed, index 1 is true if test
* was acceptable
*/
protected boolean[] canEstimate(AttrTypes attrTypes, boolean supervised, int classType) {
// supervised is ignored, no supervised estimators used yet
print("basic estimation");
printAttributeSummary(attrTypes, classType);
print("...");
FastVector accepts = new FastVector();
accepts.addElement("nominal");
accepts.addElement("numeric");
accepts.addElement("string");
accepts.addElement("date");
accepts.addElement("relational");
accepts.addElement("not in classpath");
int numTrain = getNumInstances(), numTest = getNumInstances(),
numClasses = 2, missingLevel = 0;
boolean attributeMissing = false, classMissing = false;
int numAtts = 1, attrIndex = 0;
return runBasicTest(attrTypes, numAtts, attrIndex,
classType,
missingLevel, attributeMissing, classMissing,
numTrain, numTest, numClasses,
accepts);
}
示例11: makeHeader
import weka.core.FastVector; //导入依赖的package包/类
/**
* generates the header
*
* @return the header
*/
private Instances makeHeader() {
FastVector fv = new FastVector();
fv.addElement(new Attribute(TRUE_POS_NAME));
fv.addElement(new Attribute(FALSE_NEG_NAME));
fv.addElement(new Attribute(FALSE_POS_NAME));
fv.addElement(new Attribute(TRUE_NEG_NAME));
fv.addElement(new Attribute(FP_RATE_NAME));
fv.addElement(new Attribute(TP_RATE_NAME));
fv.addElement(new Attribute(PRECISION_NAME));
fv.addElement(new Attribute(RECALL_NAME));
fv.addElement(new Attribute(FALLOUT_NAME));
fv.addElement(new Attribute(FMEASURE_NAME));
fv.addElement(new Attribute(SAMPLE_SIZE_NAME));
fv.addElement(new Attribute(LIFT_NAME));
fv.addElement(new Attribute(THRESHOLD_NAME));
return new Instances(RELATION_NAME, fv, 100);
}
示例12: getInstances
import weka.core.FastVector; //导入依赖的package包/类
private Instances getInstances() {
Attribute rleRateAttr = new Attribute(ARFFAttributes.DATA_COMPRESSION_RATE_BY_RLE_ATTRIBUTE);
Attribute linesAttr = new Attribute(ARFFAttributes.NUMBER_OF_LINES_ATTRIBUTE);
Attribute sizeAttr = new Attribute(ARFFAttributes.TEXT_SIZE_ATTRIBUTE);
Attribute ngramAttr = new Attribute(ARFFAttributes.NUMBER_OF_NGRAMS_ATTRIBUTE);
// Create nominal attribute "class"
FastVector my_nominal_values = new FastVector(2);
my_nominal_values.addElement(ARFFAttributes.ASCIIART_CLASS_NAME);
my_nominal_values.addElement(ARFFAttributes.NON_ASCIIART_CLASS_NAME);
Attribute className = new Attribute(ARFFAttributes.CLASS_ATTRIBUTE, my_nominal_values);
FastVector attributes = new FastVector(5);
attributes.addElement(rleRateAttr);
attributes.addElement(linesAttr);
attributes.addElement(sizeAttr);
attributes.addElement(ngramAttr);
attributes.addElement(className);
// Create the empty dataset "textart" with above attributes
Instances instances = new Instances(ARFFAttributes.RELATION_NAME, attributes, 0);
instances.setClassIndex(className.index());
return instances;
}
示例13: getCurve
import weka.core.FastVector; //导入依赖的package包/类
/**
* Calculates the cumulative margin distribution for the set of
* predictions, returning the result as a set of Instances. The
* structure of these Instances is as follows:<p> <ul>
* <li> <b>Margin</b> contains the margin value (which should be plotted
* as an x-coordinate)
* <li> <b>Current</b> contains the count of instances with the current
* margin (plot as y axis)
* <li> <b>Cumulative</b> contains the count of instances with margin
* less than or equal to the current margin (plot as y axis)
* </ul> <p>
*
* @return datapoints as a set of instances, null if no predictions
* have been made.
*/
public Instances getCurve(FastVector predictions) {
if (predictions.size() == 0) {
return null;
}
Instances insts = makeHeader();
double [] margins = getMargins(predictions);
int [] sorted = Utils.sort(margins);
int binMargin = 0;
int totalMargin = 0;
insts.add(makeInstance(-1, binMargin, totalMargin));
for (int i = 0; i < sorted.length; i++) {
double current = margins[sorted[i]];
double weight = ((NominalPrediction)predictions.elementAt(sorted[i]))
.weight();
totalMargin += weight;
binMargin += weight;
if (true) {
insts.add(makeInstance(current, binMargin, totalMargin));
binMargin = 0;
}
}
return insts;
}
示例14: layoutCompleted
import weka.core.FastVector; //导入依赖的package包/类
/**
* This method is an implementation for LayoutCompleteEventListener class.
* It sets the size appropriate for m_GraphPanel GraphPanel and and revalidates it's
* container JScrollPane once a LayoutCompleteEvent is received from the
* LayoutEngine. Also, it updates positions of the Bayesian network stored
* in m_BayesNet.
*/
public void layoutCompleted(LayoutCompleteEvent le) {
LayoutEngine layoutEngine = m_layoutEngine; // (LayoutEngine) le.getSource();
FastVector nPosX = new FastVector(m_BayesNet.getNrOfNodes());
FastVector nPosY = new FastVector(m_BayesNet.getNrOfNodes());
for (int iNode = 0; iNode < layoutEngine.getNodes().size(); iNode++) {
GraphNode gNode = (GraphNode) layoutEngine.getNodes().elementAt(iNode);
if (gNode.nodeType == GraphNode.NORMAL) {
nPosX.addElement(gNode.x);
nPosY.addElement(gNode.y);
}
}
m_BayesNet.layoutGraph(nPosX, nPosY);
m_jStatusBar.setText("Graph layed out");
a_undo.setEnabled(true);
a_redo.setEnabled(false);
setAppropriateSize();
m_GraphPanel.invalidate();
m_jScrollPane.revalidate();
m_GraphPanel.repaint();
}
示例15: setInputFormat
import weka.core.FastVector; //导入依赖的package包/类
/**
* Sets the format of the input instances.
*
* @param instanceInfo an Instances object containing the input instance
* structure (any instances contained in the object are ignored - only the
* structure is required).
* @return true if the outputFormat may be collected immediately
* @throws Exception if a problem occurs setting the input format
*/
public boolean setInputFormat(Instances instanceInfo) throws Exception {
super.setInputFormat(instanceInfo);
FastVector attributes = new FastVector();
int outputClass = -1;
m_SelectedAttributes = determineIndices(instanceInfo.numAttributes());
for (int i = 0; i < m_SelectedAttributes.length; i++) {
int current = m_SelectedAttributes[i];
if (instanceInfo.classIndex() == current) {
outputClass = attributes.size();
}
Attribute keep = (Attribute)instanceInfo.attribute(current).copy();
attributes.addElement(keep);
}
initInputLocators(instanceInfo, m_SelectedAttributes);
Instances outputFormat = new Instances(instanceInfo.relationName(),
attributes, 0);
outputFormat.setClassIndex(outputClass);
setOutputFormat(outputFormat);
return true;
}