weka.core.Utils Java Examples

The following examples show how to use weka.core.Utils. 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: ConsistencySubsetEval.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * calculates the level of consistency in a dataset using a subset of
 * features. The consistency of a hash table entry is the total number
 * of instances hashed to that location minus the number of instances in
 * the largest class hashed to that location. The total consistency is
 * 1.0 minus the sum of the individual consistencies divided by the
 * total number of instances.
 * @return the consistency of the hash table as a value between 0 and 1.
 */
private double consistencyCount() {
  Enumeration e = m_table.keys();
  double [] classDist;
  double count = 0.0;
  
  while (e.hasMoreElements()) {
    hashKey tt = (hashKey)e.nextElement();
    classDist = (double []) m_table.get(tt);
    count += Utils.sum(classDist);
    int max = Utils.maxIndex(classDist);
    count -= classDist[max];
  }

  count /= (double)m_numInstances;
  return (1.0 - count);
}
 
Example #2
Source File: GeneticSearch.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * returns a description of the search
 * @return a description of the search as a String
 */
public String toString() {
  StringBuffer GAString = new StringBuffer();
  GAString.append("\tGenetic search.\n\tStart set: ");

  if (m_starting == null) {
    GAString.append("no attributes\n");
  }
  else {
    GAString.append(startSetToString()+"\n");
  }
  GAString.append("\tPopulation size: "+m_popSize);
  GAString.append("\n\tNumber of generations: "+m_maxGenerations);
  GAString.append("\n\tProbability of crossover: "
              +Utils.doubleToString(m_pCrossover,6,3));
  GAString.append("\n\tProbability of mutation: "
              +Utils.doubleToString(m_pMutation,6,3));
  GAString.append("\n\tReport frequency: "+m_reportFrequency);
  GAString.append("\n\tRandom number seed: "+m_seed+"\n");
  GAString.append(m_generationReports.toString());
  return GAString.toString();
}
 
Example #3
Source File: EvaluationStatisticsUtils.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Rank Matrix
 */
public static int[][] rankMatrix(List<EvaluationStatistics> stats, String measurement) {

	double V[][] = valueMatrix(stats,measurement);


	int N = V.length;
	int k = V[0].length;

	int R[][] = new int[N][k];
	for (int i = 0; i < N; i++) {
		int indices[] = Utils.sort(V[i]);
		// add 1 to each
		for (int j = 0; j < k; j++) {
			R[i][indices[j]] = (j+1);
		}
	}


	return R;
}
 
Example #4
Source File: Bagging.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Calculates the class membership probabilities for the given test
  * instance.
  *
  * @param instance the instance to be classified
  * @return predicted class probability distribution
  * @throws Exception if distribution can't be computed successfully 
  */
 public double[] distributionForInstance(Instance instance) throws Exception {

   double [] sums = new double [instance.numClasses()], newProbs; 
   for (int i = 0; i < m_NumIterations; i++) {
     if (instance.classAttribute().isNumeric() == true) {
sums[0] += m_Classifiers[i].classifyInstance(instance);
     } else {
newProbs = m_Classifiers[i].distributionForInstance(instance);
for (int j = 0; j < newProbs.length; j++)
  sums[j] += newProbs[j];
     }
   }
   if (instance.classAttribute().isNumeric() == true) {
     sums[0] /= (double)m_NumIterations;
     return sums;
   } else if (Utils.eq(Utils.sum(sums), 0)) {
     return sums;
   } else {
     Utils.normalize(sums);
     return sums;
   }
 }
 
Example #5
Source File: MINND.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Compute the target function to minimize in gradient descent
 * The formula is:<br/>
 * 1/2*sum[i=1..p](f(X, Xi)-var(Y, Yi))^2 <p/>
 * where p is the number of exemplars and Y is the class label.
 * In the case of X=MU, f() is the Euclidean distance between two
 * exemplars together with the related weights and var() is 
 * sqrt(numDimension)*(Y-Yi) where Y-Yi is either 0 (when Y==Yi)
 * or 1 (Y!=Yi) 
 *
 * @param x the weights of the exemplar in question
 * @param rowpos row index of x in X
 * @param Y the observed class label
 * @return the result of the target function
 */
public double target(double[] x, double[][] X, int rowpos, double[] Y){
  double y = Y[rowpos], result=0;

  for(int i=0; i < X.length; i++){
    if((i != rowpos) && (X[i] != null)){
      double var = (y==Y[i]) ? 0.0 : Math.sqrt((double)m_Dimension - 1);
      double f=0;
      for(int j=0; j < m_Dimension; j++)
        if(Utils.gr(m_Variance[rowpos][j], 0.0)){
          f += x[j]*(X[rowpos][j]-X[i][j]) * (X[rowpos][j]-X[i][j]);     
          //System.out.println("i:"+i+" j: "+j+" row: "+rowpos);
        }
      f = Math.sqrt(f);
      //System.out.println("???distance between "+rowpos+" and "+i+": "+f+"|y:"+y+" vs "+Y[i]);
      if(Double.isInfinite(f))
        System.exit(1);
      result += 0.5 * (f - var) * (f - var);
    }
  }
  //System.out.println("???target: "+result);
  return result;
}
 
Example #6
Source File: sIB.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
public String toString(){
   StringBuffer text = new StringBuffer();
   text.append("\nsIB\n===\n");
   text.append("\nNumber of clusters: " + m_numCluster + "\n");
   
   for (int j = 0; j < m_numCluster; j++) {
     text.append("\nCluster: " + j + " Size : " + bestT.size(j) + " Prior probability: " 
	  + Utils.doubleToString(bestT.Pt[j], 4) + "\n\n");
     for (int i = 0; i < m_numAttributes; i++) {
text.append("Attribute: " + m_data.attribute(i).name() + "\n");
text.append("Probability given the cluster = " 
      + Utils.doubleToString(bestT.Py_t.get(i, j), 4) 
      + "\n");
     }
   }
   return text.toString();
 }
 
Example #7
Source File: LocalScoreSearchAlgorithm.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->
 * Valid options are: <p/>
 * 
 * <pre> -mbc
 *  Applies a Markov Blanket correction to the network structure, 
 *  after a network structure is learned. This ensures that all 
 *  nodes in the network are part of the Markov blanket of the 
 *  classifier node.</pre>
 * 
 * <pre> -S [BAYES|MDL|ENTROPY|AIC|CROSS_CLASSIC|CROSS_BAYES]
 *  Score type (BAYES, BDeu, MDL, ENTROPY and AIC)</pre>
 * 
 <!-- options-end -->
 *
 * @param options the list of options as an array of strings
 * @throws Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {

  	setMarkovBlanketClassifier(Utils.getFlag("mbc", options));

	String sScore = Utils.getOption('S', options);

	if (sScore.compareTo("BAYES") == 0) {
		setScoreType(new SelectedTag(Scoreable.BAYES, TAGS_SCORE_TYPE));
	}
	if (sScore.compareTo("BDeu") == 0) {
		setScoreType(new SelectedTag(Scoreable.BDeu, TAGS_SCORE_TYPE));
	}
	if (sScore.compareTo("MDL") == 0) {
		setScoreType(new SelectedTag(Scoreable.MDL, TAGS_SCORE_TYPE));
	}
	if (sScore.compareTo("ENTROPY") == 0) {
		setScoreType(new SelectedTag(Scoreable.ENTROPY, TAGS_SCORE_TYPE));
	}
	if (sScore.compareTo("AIC") == 0) {
		setScoreType(new SelectedTag(Scoreable.AIC, TAGS_SCORE_TYPE));
	}
}
 
Example #8
Source File: LogisticBase.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
    * Returns the fraction of all attributes in the data that are used in the 
    * logistic model (in percent). 
    * An attribute is used in the model if it is used in any of the models for 
    * the different classes.
    * 
    * @return the fraction of all attributes that are used
    */
   public double percentAttributesUsed(){	
boolean[] attributes = new boolean[m_numericDataHeader.numAttributes()];

double[][] coefficients = getCoefficients();
for (int j = 0; j < m_numClasses; j++){
    for (int i = 1; i < m_numericDataHeader.numAttributes() + 1; i++) {
	//attribute used if it is used in any class, note coefficients are shifted by one (because
	//of constant term).
	if (!Utils.eq(coefficients[j][i],0)) attributes[i - 1] = true;
    }
}

//count number of used attributes (without the class attribute)
double count = 0;
for (int i = 0; i < attributes.length; i++) if (attributes[i]) count++;
return count / (double)(m_numericDataHeader.numAttributes() - 1) * 100.0;
   }
 
Example #9
Source File: AdaBoostM1.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Calculates the class membership probabilities for the given test instance.
  *
  * @param instance the instance to be classified
  * @return predicted class probability distribution
  * @throws Exception if instance could not be classified
  * successfully
  */
 public double [] distributionForInstance(Instance instance) 
   throws Exception {
     
   // default model?
   if (m_ZeroR != null) {
     return m_ZeroR.distributionForInstance(instance);
   }
   
   if (m_NumIterationsPerformed == 0) {
     throw new Exception("No model built");
   }
   double [] sums = new double [instance.numClasses()]; 
   
   if (m_NumIterationsPerformed == 1) {
     return m_Classifiers[0].distributionForInstance(instance);
   } else {
     for (int i = 0; i < m_NumIterationsPerformed; i++) {
sums[(int)m_Classifiers[i].classifyInstance(instance)] += m_Betas[i];
     }
     return Utils.logs2probs(sums);
   }
 }
 
Example #10
Source File: RandomCommittee.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Calculates the class membership probabilities for the given test
  * instance.
  *
  * @param instance the instance to be classified
  * @return preedicted class probability distribution
  * @exception Exception if distribution can't be computed successfully 
  */
 public double[] distributionForInstance(Instance instance) throws Exception {

   double [] sums = new double [instance.numClasses()], newProbs; 
   
   for (int i = 0; i < m_NumIterations; i++) {
     if (instance.classAttribute().isNumeric() == true) {
sums[0] += m_Classifiers[i].classifyInstance(instance);
     } else {
newProbs = m_Classifiers[i].distributionForInstance(instance);
for (int j = 0; j < newProbs.length; j++)
  sums[j] += newProbs[j];
     }
   }
   if (instance.classAttribute().isNumeric() == true) {
     sums[0] /= (double)m_NumIterations;
     return sums;
   } else if (Utils.eq(Utils.sum(sums), 0)) {
     return sums;
   } else {
     Utils.normalize(sums);
     return sums;
   }
 }
 
Example #11
Source File: RegressionByDiscretization.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses a given list of options. <p/>
 *
 <!-- options-start -->
 <!-- options-end -->
 *
 * @param options the list of options as an array of strings
 * @throws Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {

  String binsString = Utils.getOption('B', options);
  if (binsString.length() != 0) {
    setNumBins(Integer.parseInt(binsString));
  } else {
    setNumBins(10);
  }

  setDeleteEmptyBins(Utils.getFlag('E', options));
  setUseEqualFrequency(Utils.getFlag('F', options));
  setMinimizeAbsoluteError(Utils.getFlag('A', options));

  String tmpStr = Utils.getOption('K', options);
  if (tmpStr.length() != 0)
    setEstimatorType(new SelectedTag(Integer.parseInt(tmpStr), TAGS_ESTIMATOR));
  else
    setEstimatorType(new SelectedTag(ESTIMATOR_HISTOGRAM, TAGS_ESTIMATOR));

  super.setOptions(options);
}
 
Example #12
Source File: SingleAssociatorEnhancer.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses a given list of options. Valid options are:<p>
 *
 * -W classname <br>
 * Specify the full class name of the base associator.<p>
 *
 * Options after -- are passed to the designated associator.<p>
 *
 * @param options 	the list of options as an array of strings
 * @throws Exception 	if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
  String	tmpStr;
  
  tmpStr = Utils.getOption('W', options);
  if (tmpStr.length() > 0) { 
    // This is just to set the associator in case the option 
    // parsing fails.
    setAssociator(AbstractAssociator.forName(tmpStr, null));
    setAssociator(AbstractAssociator.forName(tmpStr, Utils.partitionOptions(options)));
  }
  else {
    // This is just to set the associator in case the option 
    // parsing fails.
    setAssociator(AbstractAssociator.forName(defaultAssociatorString(), null));
    setAssociator(AbstractAssociator.forName(defaultAssociatorString(), Utils.partitionOptions(options)));
  }
}
 
Example #13
Source File: LogisticBase.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
    * Returns a description of the logistic model (i.e., attributes and 
    * coefficients).
    * 
    * @return the description of the model
    */
   public String toString(){

StringBuffer s = new StringBuffer();	

//get used attributes
int[][] attributes = getUsedAttributes();

//get coefficients
double[][] coefficients = getCoefficients();

for (int j = 0; j < m_numClasses; j++) {
    s.append("\nClass "+j+" :\n");
    //constant term
    s.append(Utils.doubleToString(coefficients[j][0],4,2)+" + \n");
    for (int i = 0; i < attributes[j].length; i++) {		
	//attribute/coefficient pairs
	s.append("["+m_numericDataHeader.attribute(attributes[j][i]).name()+"]");
	s.append(" * " + Utils.doubleToString(coefficients[j][attributes[j][i]+1],4,2));
	if (i != attributes[j].length - 1) s.append(" +");
	s.append("\n");	    
    }
}	
return new String(s);
   }
 
Example #14
Source File: PruneableClassifierTree.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Computes estimated errors for tree.
  *
  * @return the estimated errors
  * @throws Exception if error estimate can't be computed
  */
 private double errorsForTree() throws Exception {

   double errors = 0;

   if (m_isLeaf)
     return errorsForLeaf();
   else{
     for (int i = 0; i < m_sons.length; i++)
if (Utils.eq(localModel().distribution().perBag(i), 0)) {
  errors += m_test.perBag(i)-
    m_test.perClassPerBag(i,localModel().distribution().
			maxClass());
} else
  errors += son(i).errorsForTree();

     return errors;
   }
 }
 
Example #15
Source File: EvaluationStatisticsFileChooser.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Performs the actual initialization of the filters.
 */
@Override
protected void doInitializeFilters() {
	List<String> filters = PluginManager.getPluginNamesOfTypeList(FileBasedEvaluationStatisticsHandler.class.getName());
	m_FileFilters = new ArrayList<>();
	for (String filter: filters) {
		try {
			FileBasedEvaluationStatisticsHandler handler = (FileBasedEvaluationStatisticsHandler) Utils.forName(
					FileBasedEvaluationStatisticsHandler.class, filter, new String[0]);
			m_FileFilters.add(new ExtensionFileFilterWithClass(
					handler.getFormatExtensions(),
					handler.getFormatDescription() + " (" + ObjectUtils.flatten(handler.getFormatExtensions(), ", ") + ")",
					filter));
		}
		catch (Exception e) {
			System.err.println("Failed to instantiate file filter: " + filter);
			e.printStackTrace();
		}
	}
}
 
Example #16
Source File: ResidualSplit.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Prints the condition satisfied by instances in a subset.
  */
 public final String rightSide(int index,Instances data) {

   StringBuffer text;

   text = new StringBuffer();
   if (data.attribute(m_attIndex).isNominal())
     text.append(" = "+
  data.attribute(m_attIndex).value(index));
   else
     if (index == 0)
text.append(" <= "+
    Utils.doubleToString(m_splitPoint,6));
     else
text.append(" > "+
    Utils.doubleToString(m_splitPoint,6));
   return text.toString();
 }
 
Example #17
Source File: BinC45Split.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Returns index of subset instance is assigned to.
  * Returns -1 if instance is assigned to more than one subset.
  *
  * @exception Exception if something goes wrong
  */

 public final int whichSubset(Instance instance) throws Exception {
   
   if (instance.isMissing(m_attIndex))
     return -1;
   else{
     if (instance.attribute(m_attIndex).isNominal()){
if ((int)m_splitPoint == (int)instance.value(m_attIndex))
  return 0;
else
  return 1;
     }else
if (Utils.smOrEq(instance.value(m_attIndex),m_splitPoint))
  return 0;
else
  return 1;
   }
 }
 
Example #18
Source File: InfoGainSplitCrit.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method computes the information gain in the same way 
 * C4.5 does.
 *
 * @param bags the distribution
 * @param totalNoInst weight of ALL instances 
 * @param oldEnt entropy with respect to "no-split"-model.
 */
public final double splitCritValue(Distribution bags,double totalNoInst,
                                   double oldEnt) {
  
  double numerator;
  double noUnknown;
  double unknownRate;
  int i;
  
  noUnknown = totalNoInst-bags.total();
  unknownRate = noUnknown/totalNoInst;
  numerator = (oldEnt-newEnt(bags));
  numerator = (1-unknownRate)*numerator;
  
  // Splits with no gain are useless.
  if (Utils.eq(numerator,0))
    return 0;
  
  return numerator/bags.total();
}
 
Example #19
Source File: MakeDecList.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/** 
  * Classifies an instance.
  *
  * @exception Exception if instance can't be classified
  */
 public double classifyInstance(Instance instance) 
      throws Exception {

   double maxProb = -1;
   double [] sumProbs;
   int maxIndex = 0;

   sumProbs = distributionForInstance(instance);
   for (int j = 0; j < sumProbs.length; j++) {
     if (Utils.gr(sumProbs[j],maxProb)){
maxIndex = j;
maxProb = sumProbs[j];
     }
   }

   return (double)maxIndex;
 }
 
Example #20
Source File: NaiveBayesMultinomial.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Calculates the class membership probabilities for the given test 
  * instance.
  *
  * @param instance the instance to be classified
  * @return predicted class probability distribution
  * @throws Exception if there is a problem generating the prediction
  */
 public double [] distributionForInstance(Instance instance) throws Exception 
 {
   double[] probOfClassGivenDoc = new double[m_numClasses];

   //calculate the array of log(Pr[D|C])
   double[] logDocGivenClass = new double[m_numClasses];
   for(int h = 0; h<m_numClasses; h++)
     logDocGivenClass[h] = probOfDocGivenClass(instance, h);

   double max = logDocGivenClass[Utils.maxIndex(logDocGivenClass)];
   double probOfDoc = 0.0;

   for(int i = 0; i<m_numClasses; i++) 
     {
probOfClassGivenDoc[i] = Math.exp(logDocGivenClass[i] - max) * m_probOfClass[i];
probOfDoc += probOfClassGivenDoc[i];
     }

   Utils.normalize(probOfClassGivenDoc,probOfDoc);

   return probOfClassGivenDoc;
 }
 
Example #21
Source File: MOA.java    From moa with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Predicts the class memberships for a given instance. If
 * an instance is unclassified, the returned array elements
 * must be all zero. If the class is numeric, the array
 * must consist of only one element, which contains the
 * predicted value.
 *
 * @param instance the instance to be classified
 * @return an array containing the estimated membership
 * probabilities of the test instance in each class
 * or the numeric prediction
 * @throws Exception if distribution could not be
 * computed successfully
 */
public double[] distributionForInstance(Instance instance) throws Exception {
	double[]	result;

	result = m_ActualClassifier.getVotesForInstance(instanceConverter.samoaInstance(instance));
      // ensure that the array has as many elements as there are
      // class values!
      if (result.length < instance.numClasses()) {
        double[] newResult = new double[instance.numClasses()];
        System.arraycopy(result, 0, newResult, 0, result.length);
        result = newResult;
      }

	try {
		Utils.normalize(result);
	}
	catch (Exception e) {
		result = new double[instance.numClasses()];
	}

	return result;
}
 
Example #22
Source File: Test.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gives a string representation of the test in Prolog notation, starting
 * from the comparison symbol.
 *
 * @return a string representing the test in Prolog notation
 */   
private String testPrologComparisonString() {
  Attribute att = m_Dataset.attribute(m_AttIndex);
  if (att.isNumeric()) {
    return ((m_Not ? ">= " : "< ") + Utils.doubleToString(m_Split,3));
  }
  else {
    if (att.numValues() != 2) 
      return ((m_Not ? "!= " : "= ") + att.value((int)m_Split));
    else return ("= " 
                 + (m_Not ? att.value((int)m_Split == 0 ? 1 : 0) 
                        : att.value((int)m_Split)));
  }
}
 
Example #23
Source File: ADTree.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
  * Finds the nominal attribute value to split on that results in the lowest Z-value.
  *
  * @param posInstances the positive-class instances to split
  * @param negInstances the negative-class instances to split
  * @param attIndex the index of the nominal attribute to find a split for
  * @return a double array, index[0] contains the value to split on, index[1] contains
  * the Z-value of the split
  */
 private double[] findLowestZNominalSplit(Instances posInstances, Instances negInstances,
				   int attIndex)
 {
   
   double lowestZ = Double.MAX_VALUE;
   int bestIndex = 0;

   // set up arrays
   double[] posWeights = attributeValueWeights(posInstances, attIndex);
   double[] negWeights = attributeValueWeights(negInstances, attIndex);
   double posWeight = Utils.sum(posWeights);
   double negWeight = Utils.sum(negWeights);

   int maxIndex = posWeights.length;
   if (maxIndex == 2) maxIndex = 1; // avoid repeating due to 2-way symmetry

   for (int i = 0; i < maxIndex; i++) {
     // calculate Z
     double w1 = posWeights[i] + 1.0;
     double w2 = negWeights[i] + 1.0;
     double w3 = posWeight - w1 + 2.0;
     double w4 = negWeight - w2 + 2.0;
     double wRemainder = m_trainTotalWeight + 4.0 - (w1 + w2 + w3 + w4);
     double newZ = (2.0 * (Math.sqrt(w1 * w2) + Math.sqrt(w3 * w4))) + wRemainder;

     // record best option
     if (newZ < lowestZ) { 
lowestZ = newZ;
bestIndex = i;
     }
   }

   // return result
   double[] indexAndZ = new double[2];
   indexAndZ[0] = (double) bestIndex;
   indexAndZ[1] = lowestZ;
   return indexAndZ; 
 }
 
Example #24
Source File: Ridor.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
    * Private function to compute default number of accurate instances
    * in the specified data for m_Class
    * 
    * @param data the data in question
    * @return the default accuracy number
    */
   private double computeDefAccu(Instances data){ 
     double defAccu=0;
     for(int i=0; i<data.numInstances(); i++){
Instance inst = data.instance(i);
if(Utils.eq(inst.classValue(), m_Class))
  defAccu += inst.weight();
     }
     return defAccu;
   }
 
Example #25
Source File: MexicanHat.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the upper and lower boundary for the range of x
 *
 * @return the string containing the upper and lower boundary for
 *         the range of x, separated by ..
 */
protected String getRange() {
  String fromTo = "" 
                  + Utils.doubleToString(getMinRange(), 2) + ".."
                  + Utils.doubleToString(getMaxRange(), 2);
  return fromTo;
}
 
Example #26
Source File: C45PruneableClassifierTreeG.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
  * Computes estimated errors for leaf.
  *
  * @param theDistribution the distribution to use
  * @return the estimated errors
  */
 private double getEstimatedErrorsForDistribution(Distribution 
					   theDistribution){

   if (Utils.eq(theDistribution.total(),0))
     return 0;
   else
     return theDistribution.numIncorrect()+
Stats.addErrs(theDistribution.total(),
	      theDistribution.numIncorrect(),m_CF);
 }
 
Example #27
Source File: sIB.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
    * Output the current partition
    * @param insts
    * @return a string that describes the partition
    */
   public String toString() {
     StringBuffer text = new StringBuffer();
     text.append("score (L) : " + Utils.doubleToString(L, 4) + "\n");
     text.append("number of changes : " + counter +"\n");
     for (int i = 0; i < m_numCluster; i++) {
text.append("\nCluster "+i+"\n");
text.append("size : "+size(i)+"\n");
text.append("prior prob : "+Utils.doubleToString(Pt[i], 4)+"\n");
     }
     return text.toString();
   }
 
Example #28
Source File: MergeManyValues.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parses a given list of options. <p/>
 * 
 <!-- options-start -->
 * Valid options are: <p/>
 * 
 * <pre> -C &lt;col&gt;
 *  Sets the attribute index
 *  (default: last)</pre>
 * 
 * <pre> -L &lt;label&gt;
 *  Sets the label of the newly merged classes
 *  (default: 'merged')</pre>
 * 
 * <pre> -R &lt;range&gt;
 *  Sets the merge range. 'first and 'last' are accepted as well.'
 *  E.g.: first-5,7,9,20-last
 *  (default: 1,2)</pre>
 * 
 <!-- options-end -->
 *
 * @param options 	the list of options as an array of strings
 * @throws Exception 	if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
  String	tmpStr;
  
  tmpStr = Utils.getOption('C', options);
  if (tmpStr.length() != 0) {
    setAttributeIndex(tmpStr);
  } else {
    setAttributeIndex("last");
  }

  tmpStr = Utils.getOption('L', options);
  if (tmpStr.length() != 0) {
    setLabel(tmpStr);
  } else {
    setLabel("merged");
  }

  tmpStr = Utils.getOption('R', options);
  if (tmpStr.length() != 0) {
    setMergeValueRange(tmpStr);
  } else {
    setMergeValueRange("1,2");
  }

  if (getInputFormat() != null) {
    setInputFormat(getInputFormat());
  }
}
 
Example #29
Source File: HierarchicalClusterer.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the current settings of the clusterer.
 *
 * @return an array of strings suitable for passing to setOptions()
 */
public String [] getOptions() {

  String [] options = new String [14];
  int current = 0;

  options[current++] = "-N";
  options[current++] = "" + getNumClusters();

  options[current++] = "-L";
  switch (m_nLinkType) {
  case (SINGLE) :options[current++] = "SINGLE";break;
  case (COMPLETE) :options[current++] = "COMPLETE";break;
  case (AVERAGE) :options[current++] = "AVERAGE";break;
  case (MEAN) :options[current++] = "MEAN";break;
  case (CENTROID) :options[current++] = "CENTROID";break;
  case (WARD) :options[current++] = "WARD";break;
  case (ADJCOMLPETE) :options[current++] = "ADJCOMLPETE";break;
  case (NEIGHBOR_JOINING) :options[current++] = "NEIGHBOR_JOINING";break;
  }
  if (m_bPrintNewick) {
    options[current++] = "-P";
  }
  if (getDebug()) {
    options[current++] = "-D";
  }
  if (getDistanceIsBranchLength()) {
    options[current++] = "-B";
  }

  options[current++] = "-A";
  options[current++] = (m_DistanceFunction.getClass().getName() + " " +
      Utils.joinOptions(m_DistanceFunction.getOptions())).trim();

  while (current < options.length) {
    options[current++] = "";
  }

  return options;
}
 
Example #30
Source File: SPegasos.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prints out the classifier.
 *
 * @return a description of the classifier as a string
 */
public String toString() {
  if (m_weights == null) {
    return "SPegasos: No model built yet.\n";
  }
  StringBuffer buff = new StringBuffer();
  buff.append("Loss function: ");
  if (m_loss == HINGE) {
    buff.append("Hinge loss (SVM)\n\n");
  } else {
    buff.append("Log loss (logistic regression)\n\n");
  }
  int printed = 0;
  
  for (int i = 0 ; i < m_weights.length - 1; i++) {
    if (i != m_data.classIndex()) {
      if (printed > 0) {
        buff.append(" + ");
      } else {
        buff.append("   ");
      }

      buff.append(Utils.doubleToString(m_weights[i], 12, 4) +
          " " + ((m_normalize != null) ? "(normalized) " : "") 
          + m_data.attribute(i).name() + "\n");

      printed++;
    }
  }
  
  if (m_weights[m_weights.length - 1] > 0) {
    buff.append(" + " + Utils.doubleToString(m_weights[m_weights.length - 1], 12, 4));
  } else {
    buff.append(" - " + Utils.doubleToString(-m_weights[m_weights.length - 1], 12, 4));
  }
  
  return buff.toString();
}