weka.core.FastVector Java Examples

The following examples show how to use weka.core.FastVector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarginCurve.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: Sequence.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Updates the support count of a set of Sequence candidates according to a 
  * given set of data sequences.
  * 
  * @param candidates 		the set of candidates
  * @param dataSequences 	the set of data sequences
  */
 public static void updateSupportCount(FastVector candidates, FastVector dataSequences) {
   Enumeration canEnumeration = candidates.elements();

   while(canEnumeration.hasMoreElements()){
     Enumeration dataSeqEnumeration = dataSequences.elements();
     Sequence candidate = (Sequence) canEnumeration.nextElement();

     while(dataSeqEnumeration.hasMoreElements()) {
Instances dataSequence = (Instances) dataSeqEnumeration.nextElement();

if (candidate.isSubsequenceOf(dataSequence)) {
  candidate.setSupportCount(candidate.getSupportCount() + 1);
}
     }
   }
 }
 
Example #3
Source File: ND.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
    * Inserts a class index into the tree. 
    * 
    * @param classIndex the class index to insert
    */
   protected void insertClassIndex(int classIndex) {

     // Create new nodes
     NDTree right = new NDTree();
     if (m_left != null) {
m_right.m_parent = right;
m_left.m_parent = right;
right.m_right = m_right;
right.m_left = m_left;
     }
     m_right = right;
     m_right.m_indices = (FastVector)m_indices.copy();
     m_right.m_parent = this;
     m_left = new NDTree();
     m_left.insertClassIndexAtNode(classIndex);
     m_left.m_parent = this; 

     // Propagate class Index
     propagateClassIndex(classIndex);
   }
 
Example #4
Source File: PrincipalComponents.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set up the header for the PC->original space dataset
 * 
 * @return            the output format
 * @throws Exception  if something goes wrong
 */
private Instances setOutputFormatOriginal() throws Exception {
  FastVector attributes = new FastVector();
  
  for (int i = 0; i < m_numAttribs; i++) {
    String att = m_trainInstances.attribute(i).name();
    attributes.addElement(new Attribute(att));
  }
  
  if (m_hasClass) {
    attributes.addElement(m_trainHeader.classAttribute().copy());
  }

  Instances outputFormat = 
    new Instances(m_trainHeader.relationName()+"->PC->original space",
                  attributes, 0);
  
  // set the class to be the last attribute if necessary
  if (m_hasClass) {
    outputFormat.setClassIndex(outputFormat.numAttributes()-1);
  }

  return outputFormat;
}
 
Example #5
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/** space out set of nodes evenly between left and right most node in the list
 * @param nodes list of indexes of nodes to space out
 */
public void spaceHorizontal(FastVector nodes) {
	// update undo stack
	if (m_bNeedsUndoAction) {
		addUndoAction(new spaceHorizontalAction(nodes));
	}
	int nMinX = -1;
	int nMaxX = -1;
	for (int iNode = 0; iNode < nodes.size(); iNode++) {
		int nX = getPositionX((Integer) nodes.elementAt(iNode));
		if (nX < nMinX || iNode == 0) {
			nMinX = nX;
		}
		if (nX > nMaxX || iNode == 0) {
			nMaxX = nX;
		}
	}
	for (int iNode = 0; iNode < nodes.size(); iNode++) {
		int nNode = (Integer) nodes.elementAt(iNode);
		m_nPositionX.setElementAt((int) (nMinX + iNode * (nMaxX - nMinX) / (nodes.size() - 1.0)), nNode);
	}
}
 
Example #6
Source File: CaRuleGeneration.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * generates a consequence of length 1 for a class association rule.
  * @param instances the instances under consideration
  * @return FastVector with consequences of length 1
  */  
 public static FastVector singleConsequence(Instances instances){

   ItemSet consequence;
   FastVector consequences = new FastVector();

   for (int j = 0; j < (instances.classAttribute()).numValues(); j++) {
     consequence = new ItemSet(instances.numInstances());
     int[] consequenceItems = new int[instances.numAttributes()];
     consequence.setItem(consequenceItems);
     for (int k = 0; k < instances.numAttributes(); k++) 
consequence.setItemAt(-1,k);
     consequence.setItemAt(j,instances.classIndex());
     consequences.addElement(consequence);
   }
   return consequences;

 }
 
Example #7
Source File: GeneralizedSequentialPatterns.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Extracts the data sequences out of the original data set according to 
  * their sequence id attribute, which is removed after extraction.
  * 
  * @param originalDataSet 	the original data set
  * @param dataSeqID		the squence ID to use
  * @return 			set of distinct data sequences
  */
 protected FastVector extractDataSequences (Instances originalDataSet, int dataSeqID) {
   FastVector dataSequences = new FastVector();
   int firstInstance = 0;
   int lastInstance = 0;
   Attribute seqIDAttribute = originalDataSet.attribute(dataSeqID);

   for (int i = 0; i < seqIDAttribute.numValues(); i++) {
     double sequenceID = originalDataSet.instance(firstInstance).value(dataSeqID);
     while (lastInstance < originalDataSet.numInstances()
  && sequenceID == originalDataSet.instance(lastInstance).value(dataSeqID)) {
lastInstance++;
     }
     Instances dataSequence = new Instances(originalDataSet, firstInstance, (lastInstance)-firstInstance);
     dataSequence.deleteAttributeAt(dataSeqID);
     dataSequences.addElement(dataSequence);
     firstInstance = lastInstance;
   }
   return dataSequences;
 }
 
Example #8
Source File: RuleGeneration.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * generates a consequence of length 1 for an association rule.
  * @param instances the instances under consideration
  * @param attNum an item that does not occur in the premise
  * @param consequences FastVector that possibly already contains other consequences of length 1
  * @return FastVector with consequences of length 1
  */  
 public static FastVector singleConsequence(Instances instances, int attNum, FastVector consequences){

   ItemSet consequence;

   for (int i = 0; i < instances.numAttributes(); i++) {
     if( i == attNum){
for (int j = 0; j < instances.attribute(i).numValues(); j++) {
  consequence = new ItemSet(instances.numInstances());
  consequence.m_items = new int[instances.numAttributes()];
  for (int k = 0; k < instances.numAttributes(); k++) 
    consequence.m_items[k] = -1;
  consequence.m_items[i] = j;
  consequences.addElement(consequence);
}
     }
   }
   return consequences;

 }
 
Example #9
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
DelValueAction(int nTargetNode, String sValue) {
	try {
		m_nTargetNode = nTargetNode;
		m_sValue = sValue;
		m_att = m_Instances.attribute(nTargetNode);
		SerializedObject so = new SerializedObject(m_Distributions[nTargetNode]);
		m_CPT = (Estimator[]) so.getObject();
		;
		m_children = new FastVector();
		for (int iNode = 0; iNode < getNrOfNodes(); iNode++) {
			if (m_ParentSets[iNode].contains(nTargetNode)) {
				m_children.addElement(iNode);
			}
		}
		m_childAtts = new Estimator[m_children.size()][];
		for (int iChild = 0; iChild < m_children.size(); iChild++) {
			int nChild = (Integer) m_children.elementAt(iChild);
			m_childAtts[iChild] = m_Distributions[nChild];
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #10
Source File: LabeledItemSet.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Converts the header info of the given set of instances into a set of item
 * sets (singletons). The ordering of values in the header file determines the
 * lexicographic order. Each item set knows its class label.
 * 
 * @return a set of item sets, each containing a single item
 * @param instancesNoClass instances without the class attribute
 * @param classes the values of the class attribute sorted according to
 *          instances
 * @exception Exception if singletons can't be generated successfully
 */
public static FastVector singletons(Instances instancesNoClass,
    Instances classes) throws Exception {

  FastVector cSet, setOfItemSets = new FastVector();
  LabeledItemSet current;

  // make singletons
  for (int i = 0; i < instancesNoClass.numAttributes(); i++) {
    if (instancesNoClass.attribute(i).isNumeric())
      throw new Exception("Can't handle numeric attributes!");
    for (int j = 0; j < instancesNoClass.attribute(i).numValues(); j++) {
      for (int k = 0; k < (classes.attribute(0)).numValues(); k++) {
        current = new LabeledItemSet(instancesNoClass.numInstances(), k);
        current.m_items = new int[instancesNoClass.numAttributes()];
        for (int l = 0; l < instancesNoClass.numAttributes(); l++)
          current.m_items[l] = -1;
        current.m_items[i] = j;
        setOfItemSets.addElement(current);
      }
    }
  }
  return setOfItemSets;
}
 
Example #11
Source File: ChangeDateFormat.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Set the output format. Changes the format of the specified date
  * attribute.
  */
 private void setOutputFormat() {
   
   // Create new attributes
   FastVector newAtts = new FastVector(getInputFormat().numAttributes());
   for (int j = 0; j < getInputFormat().numAttributes(); j++) {
     Attribute att = getInputFormat().attribute(j);
     if (j == m_AttIndex.getIndex()) {
newAtts.addElement(new Attribute(att.name(), getDateFormat().toPattern()));  
     } else {
newAtts.addElement(att.copy()); 
     }
   }
     
   // Create new header
   Instances newData = new Instances(getInputFormat().relationName(), newAtts, 0);
   newData.setClassIndex(getInputFormat().classIndex());
   m_OutputAttribute = newData.attribute(m_AttIndex.getIndex());
   setOutputFormat(newData);
 }
 
Example #12
Source File: Apriori.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Method that finds all class association rules.
 * 
 * @throws Exception if an attribute is numeric
 */
private void findCarRulesQuickly() throws Exception {

  FastVector[] rules;

  // Build rules
  for (int j = 0; j < m_Ls.size(); j++) {
    FastVector currentLabeledItemSets = (FastVector) m_Ls.elementAt(j);
    Enumeration enumLabeledItemSets = currentLabeledItemSets.elements();
    while (enumLabeledItemSets.hasMoreElements()) {
      LabeledItemSet currentLabeledItemSet = (LabeledItemSet) enumLabeledItemSets
          .nextElement();
      rules = currentLabeledItemSet.generateRules(m_minMetric, false);
      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));
      }
    }
  }
}
 
Example #13
Source File: ThresholdCurve.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests the ThresholdCurve generation from the command line.
 * The classifier is currently hardcoded. Pipe in an arff file.
 *
 * @param args currently ignored
 */
public static void main(String [] args) {

  try {
    
    Instances inst = new Instances(new java.io.InputStreamReader(System.in));
    if (false) {
      System.out.println(ThresholdCurve.getNPointPrecision(inst, 11));
    } else {
      inst.setClassIndex(inst.numAttributes() - 1);
      ThresholdCurve tc = new ThresholdCurve();
      EvaluationUtils eu = new EvaluationUtils();
      Classifier classifier = new weka.classifiers.functions.Logistic();
      FastVector predictions = new FastVector();
      for (int i = 0; i < 2; i++) { // Do two runs.
        eu.setSeed(i);
        predictions.appendElements(eu.getCVPredictions(classifier, inst, 10));
        //System.out.println("\n\n\n");
      }
      Instances result = tc.getCurve(predictions);
      System.out.println(result);
    }
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}
 
Example #14
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
AddArcAction(int nParent, int nChild) {
	try {
		m_nParent = nParent;
		m_children = new FastVector();
		m_children.addElement(nChild);
		//m_nChild = nChild;
		SerializedObject so = new SerializedObject(m_Distributions[nChild]);
		m_CPT = new Estimator[1][];
		m_CPT[0] = (Estimator[]) so.getObject();
		;
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #15
Source File: SpecPragmaticCreateDataset_posteriori.java    From TableDisentangler with GNU General Public License v3.0 5 votes vote down vote up
public void ProcessTables(String tableType)
{
	
	DataBase();
	int execCount = 0;
	try {
		String SQL = "SELECT * from ArtTable where HasXML='yes' and specPragmatic='"+tableType+"' order by RAND() limit 200";
		Statement st = conn.createStatement();
		Instances instances = CreateInstances();
		FastVector fvWekaAttributes = new FastVector(128);
		rs = st.executeQuery(SQL);
		while (rs.next()) {
			Instance iExample = processTable(rs.getInt(1));
			instances.add(iExample);
			

			execCount ++;
			if(execCount>10000){
				conn.close();
				DataBase();
				execCount = 0;	
			}

		}
		System.out.println(instances.toString());
		ArffSaver saver = new ArffSaver();
		 saver.setInstances(instances);
		 saver.setFile(new File("spptest.arff"));
		 //saver.setDestination(new File("./data/test.arff"));   // **not** necessary in 3.5.4 and later
		 saver.writeBatch();
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
Example #16
Source File: PropositionalToMultiInstance.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 the input format can't be set 
 * successfully
 */
public boolean setInputFormat(Instances instanceInfo) 
  throws Exception {

  if (instanceInfo.attribute(0).type()!= Attribute.NOMINAL) {
    throw new Exception("The first attribute type of the original propositional instance dataset must be Nominal!");
  }
  super.setInputFormat(instanceInfo);

  /* create a new output format (multi-instance format) */
  Instances newData = instanceInfo.stringFreeStructure();
  Attribute attBagIndex = (Attribute) newData.attribute(0).copy();
  Attribute attClass = (Attribute) newData.classAttribute().copy();
  // remove the bagIndex attribute
  newData.deleteAttributeAt(0);
  // remove the class attribute
  newData.setClassIndex(-1);
  newData.deleteAttributeAt(newData.numAttributes() - 1);

  FastVector attInfo = new FastVector(3); 
  attInfo.addElement(attBagIndex);
  attInfo.addElement(new Attribute("bag", newData)); // relation-valued attribute
  attInfo.addElement(attClass);
  Instances data = new Instances("Multi-Instance-Dataset", attInfo, 0); 
  data.setClassIndex(data.numAttributes() - 1);

  super.setOutputFormat(data.stringFreeStructure());

  m_BagStringAtts = new StringLocator(data.attribute(1).relation());
  m_BagRelAtts    = new RelationalLocator(data.attribute(1).relation());
  
  return true;
}
 
Example #17
Source File: Sequence.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prints a set of Sequences as String output.
 * 
 * @param setOfSequences	the set of sequences
 */
public static void printSetOfSequences(FastVector setOfSequences) {
  Enumeration seqEnum = setOfSequences.elements();
  int i = 1;

  while(seqEnum.hasMoreElements()) {
    Sequence seq = (Sequence) seqEnum.nextElement();
    System.out.print("[" + i++ + "]" + " " + seq.toString());
  }
}
 
Example #18
Source File: EvaluationUtils.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generate a bunch of predictions ready for processing, by performing a
 * evaluation on a test set assuming the classifier is already trained.
 *
 * @param classifier the pre-trained Classifier to evaluate
 * @param test the test dataset
 * @exception Exception if an error occurs
 */
public FastVector getTestPredictions(Classifier classifier, 
                                     Instances test) 
  throws Exception {
  
  FastVector predictions = new FastVector();
  for (int i = 0; i < test.numInstances(); i++) {
    if (!test.instance(i).classIsMissing()) {
      predictions.addElement(getPrediction(classifier, test.instance(i)));
    }
  }
  return predictions;
}
 
Example #19
Source File: CheckKernel.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks whether nominal schemes can handle more than two classes.
 * If a scheme is only designed for two-class problems it should
 * throw an appropriate exception for multi-class problems.
 *
 * @param nominalPredictor if true use nominal predictor attributes
 * @param numericPredictor if true use numeric predictor attributes
 * @param stringPredictor if true use string predictor attributes
 * @param datePredictor if true use date predictor attributes
 * @param relationalPredictor if true use relational predictor attributes
 * @param multiInstance whether multi-instance is needed
 * @param numClasses the number of classes to test
 * @return index 0 is true if the test was passed, index 1 is true if test 
 *         was acceptable
 */
protected boolean[] canHandleNClasses(
    boolean nominalPredictor,
    boolean numericPredictor, 
    boolean stringPredictor, 
    boolean datePredictor,
    boolean relationalPredictor,
    boolean multiInstance,
    int numClasses) {
  
  print("more than two class problems");
  printAttributeSummary(
      nominalPredictor, numericPredictor, stringPredictor, datePredictor, relationalPredictor, multiInstance, Attribute.NOMINAL);
  print("...");
  FastVector accepts = new FastVector();
  accepts.addElement("number");
  accepts.addElement("class");
  int numTrain = getNumInstances(), missingLevel = 0;
  boolean predictorMissing = false, classMissing = false;
  
  return runBasicTest(nominalPredictor, numericPredictor, stringPredictor, 
                      datePredictor, relationalPredictor, 
                      multiInstance,
                      Attribute.NOMINAL,
                      missingLevel, predictorMissing, classMissing,
                      numTrain, numClasses, 
                      accepts);
}
 
Example #20
Source File: RDG1.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes the format for the dataset produced. 
 *
 * @return the output data format
 * @throws Exception data format could not be defined 
 */
public Instances defineDataFormat() throws Exception {
  Instances dataset;
  Random random = new Random (getSeed());
  setRandom(random);

  m_DecisionList = new FastVector();

  // number of examples is the same as given per option
  setNumExamplesAct(getNumExamples());

  // define dataset
  dataset = defineDataset(random);
  return dataset; 
}
 
Example #21
Source File: ItemSet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates counters for a set of item sets and a set of instances.
 * 
 * @param itemSets the set of item sets which are to be updated
 * @param instances the instances to be used for updating the counters
 */
public static void upDateCounters(FastVector itemSets, Instances instances) {

  for (int i = 0; i < instances.numInstances(); i++) {
    Enumeration enu = itemSets.elements();
    while (enu.hasMoreElements())
      ((ItemSet) enu.nextElement()).upDateCounter(instances.instance(i));
  }
}
 
Example #22
Source File: SpecPragmaticCreateDataset_posteriori_10.java    From TableDisentangler with GNU General Public License v3.0 5 votes vote down vote up
public void ProcessTables(int[] table_array)
{
	
	DataBase();
	int execCount = 0;
	try {
		String SQL = "SELECT * from ArtTable where HasXML='yes' and idTable in "+Arrays.toString(table_array);
		SQL = SQL.replace("[", "(").replace("]", ")");
		Statement st = conn.createStatement();
		Instances instances = CreateInstances();
		FastVector fvWekaAttributes = new FastVector(48);
		rs = st.executeQuery(SQL);
		while (rs.next()) {
			Instance iExample = processTable(rs.getInt(1));
			instances.add(iExample);
			

			execCount ++;
			if(execCount>10000){
				conn.close();
				DataBase();
				execCount = 0;	
			}

		}
		System.out.println(instances.toString());
		ArffSaver saver = new ArffSaver();
		 saver.setInstances(instances);
		 saver.setFile(new File("spptest10.arff"));
		 //saver.setDestination(new File("./data/test.arff"));   // **not** necessary in 3.5.4 and later
		 saver.writeBatch();
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
Example #23
Source File: ItemSet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return a hashtable filled with the given item sets.
 * 
 * @param itemSets the set of item sets to be used for filling the hash table
 * @param initialSize the initial size of the hashtable
 * @return the generated hashtable
 */
public static Hashtable getHashtable(FastVector itemSets, int initialSize) {

  Hashtable hashtable = new Hashtable(initialSize);

  for (int i = 0; i < itemSets.size(); i++) {
    ItemSet current = (ItemSet) itemSets.elementAt(i);
    hashtable.put(current, new Integer(current.m_counter));
  }
  return hashtable;
}
 
Example #24
Source File: ItemSet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Deletes all item sets that don't have minimum support.
 * 
 * @return the reduced set of item sets
 * @param maxSupport the maximum support
 * @param itemSets the set of item sets to be pruned
 * @param minSupport the minimum number of transactions to be covered
 */
public static FastVector deleteItemSets(FastVector itemSets, int minSupport,
    int maxSupport) {

  FastVector newVector = new FastVector(itemSets.size());

  for (int i = 0; i < itemSets.size(); i++) {
    ItemSet current = (ItemSet) itemSets.elementAt(i);
    if ((current.m_counter >= minSupport)
        && (current.m_counter <= maxSupport))
      newVector.addElement(current);
  }
  return newVector;
}
 
Example #25
Source File: EditableBayesNet.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/** Set position of node. Move set of nodes with the same displacement
 * as a specified node.
 * @param nNode index of node to set position for
 * @param nX x position of new position
 * @param nY y position of new position
 * @param nodes array of indexes of nodes to move
 */
public void setPosition(int nNode, int nX, int nY, FastVector nodes) {
	int dX = nX - getPositionX(nNode);
	int dY = nY - getPositionY(nNode);
	// update undo stack
	if (m_bNeedsUndoAction) {
		boolean isUpdate = false;
		try {
			UndoAction undoAction = null;
			if (m_undoStack.size() > 0) {
				undoAction = (UndoAction) m_undoStack.elementAt(m_undoStack.size() - 1);
					SetGroupPositionAction posAction = (SetGroupPositionAction) undoAction;
					isUpdate = true;
					int iNode = 0;
					while (isUpdate && iNode < posAction.m_nodes.size()) {
						if ((Integer)posAction.m_nodes.elementAt(iNode) != (Integer) nodes.elementAt(iNode)) {
							isUpdate = false;
						}
						iNode++;
					}
					if (isUpdate == true) {
						posAction.setUndoPosition(dX, dY);
					}
			}
		} catch (Exception e) {
			// ignore. it's not a SetPositionAction
		}
		if (!isUpdate) {
			addUndoAction(new SetGroupPositionAction(nodes, dX, dY));
		}
	}
	for (int iNode = 0; iNode < nodes.size(); iNode++) {
		nNode = (Integer) nodes.elementAt(iNode);
		m_nPositionX.setElementAt(getPositionX(nNode) + dX, nNode);
		m_nPositionY.setElementAt(getPositionY(nNode) + dY, nNode);
	}
}
 
Example #26
Source File: MarginCurve.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates an Instances object with the attributes we will be calculating.
 *
 * @return the Instances structure.
 */
private Instances makeHeader() {

  FastVector fv = new FastVector();
  fv.addElement(new Attribute("Margin"));
  fv.addElement(new Attribute("Current"));
  fv.addElement(new Attribute("Cumulative"));
  return new Instances("MarginCurve", fv, 100);
}
 
Example #27
Source File: Apriori.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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));
        }
      }
    }
  }
}
 
Example #28
Source File: Apriori.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method that finds all association rules and performs significance test.
 * 
 * @throws Exception if an attribute is numeric
 */
private void findRulesBruteForce() 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.generateRulesBruteForce(m_minMetric,
          m_metricType, m_hashtables, j + 1, m_instances.numInstances(),
          m_significanceLevel);
      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));

        m_allTheRules[3].addElement(rules[3].elementAt(k));
        m_allTheRules[4].addElement(rules[4].elementAt(k));
        m_allTheRules[5].addElement(rules[5].elementAt(k));
      }
    }
  }
}
 
Example #29
Source File: CheckClassifier.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Runs a text on the datasets with the given characteristics.
 *
 * @param nominalPredictor if true use nominal predictor attributes
 * @param numericPredictor if true use numeric predictor attributes
 * @param stringPredictor if true use string predictor attributes
 * @param datePredictor if true use date predictor attributes
 * @param relationalPredictor if true use relational predictor attributes
 * @param multiInstance whether multi-instance is needed
 * @param classType the class type (NUMERIC, NOMINAL, etc.)
 * @param missingLevel the percentage of missing values
 * @param predictorMissing true if the missing values may be in
 * the predictors
 * @param classMissing true if the missing values may be in the class
 * @param numTrain the number of instances in the training set
 * @param numTest the number of instaces in the test set
 * @param numClasses the number of classes
 * @param accepts the acceptable string in an exception
 * @return index 0 is true if the test was passed, index 1 is true if test
 *         was acceptable
 */
protected boolean[] runBasicTest(boolean nominalPredictor,
    boolean numericPredictor,
    boolean stringPredictor,
    boolean datePredictor,
    boolean relationalPredictor,
    boolean multiInstance,
    int classType,
    int missingLevel,
    boolean predictorMissing,
    boolean classMissing,
    int numTrain,
    int numTest,
    int numClasses,
    FastVector accepts) {

  return runBasicTest(
      nominalPredictor,
      numericPredictor,
      stringPredictor,
      datePredictor,
      relationalPredictor,
      multiInstance,
      classType,
      TestInstances.CLASS_IS_LAST,
      missingLevel,
      predictorMissing,
      classMissing,
      numTrain,
      numTest,
      numClasses,
      accepts);
}
 
Example #30
Source File: RuleNode.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
  * Return a list containing all the leaves in the tree
  *
  * @param v a single element array containing a vector of leaves
  */
 public void returnLeaves(FastVector[] v) {
   if (m_isLeaf) {
     v[0].addElement(this);
   } else {
     if (m_left != null) {
m_left.returnLeaves(v);
     } 

     if (m_right != null) {
m_right.returnLeaves(v);
     } 
   } 
 }