Codota Logo
CostMatrix.getCell
Code IndexAdd Codota to your IDE (free)

How to use
getCell
method
in
weka.classifiers.CostMatrix

Best Java code snippets using weka.classifiers.CostMatrix.getCell (Showing top 20 results out of 315)

  • Common ways to obtain CostMatrix
private void myMethod () {
CostMatrix c =
  • Codota Iconnew CostMatrix(int1)
  • Smart code suggestions by Codota
}
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Normalizes the matrix so that the diagonal contains zeros.
 * 
 */
public void normalize() {
 for (int y = 0; y < m_size; y++) {
  double diag = ((Double) getCell(y, y)).doubleValue();
  for (int x = 0; x < m_size; x++) {
   setCell(x, y, new Double(((Double) getCell(x, y)).doubleValue() - diag));
  }
 }
}
origin: Waikato/weka-trunk

/**
 * Returns a value at the specified position in the cost matrix.
 * 
 * @param row the row position
 * @param column the column position
 * @return the value
 */
@Override
public Object getValueAt(int row, int column) {
 // return new Double(m_matrix.getElement(row, column));
 try {
  return m_matrix.getCell(row, column);
 } catch (Exception ex) {
  ex.printStackTrace();
 }
 return new Double(0.0);
}
origin: Waikato/weka-trunk

/**
 * Normalizes the matrix so that the diagonal contains zeros.
 * 
 */
public void normalize() {
 for (int y = 0; y < m_size; y++) {
  double diag = ((Double) getCell(y, y)).doubleValue();
  for (int x = 0; x < m_size; x++) {
   setCell(x, y, new Double(((Double) getCell(x, y)).doubleValue() - diag));
  }
 }
}
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Returns a value at the specified position in the cost matrix.
 * 
 * @param row the row position
 * @param column the column position
 * @return the value
 */
@Override
public Object getValueAt(int row, int column) {
 // return new Double(m_matrix.getElement(row, column));
 try {
  return m_matrix.getCell(row, column);
 } catch (Exception ex) {
  ex.printStackTrace();
 }
 return new Double(0.0);
}
origin: nz.ac.waikato.cms.weka/weka-stable

private boolean replaceStrings(Instances dataset) throws Exception {
 boolean nonDouble = false;
 for (int i = 0; i < m_size; i++) {
  for (int j = 0; j < m_size; j++) {
   if (getCell(i, j) instanceof String) {
    setCell(i, j, new InstanceExpression((String) getCell(i, j), dataset));
    nonDouble = true;
   } else if (getCell(i, j) instanceof InstanceExpression) {
    nonDouble = true;
   }
  }
 }
 return nonDouble;
}
origin: Waikato/weka-trunk

private boolean replaceStrings(Instances dataset) throws Exception {
 boolean nonDouble = false;
 for (int i = 0; i < m_size; i++) {
  for (int j = 0; j < m_size; j++) {
   if (getCell(i, j) instanceof String) {
    setCell(i, j, new InstanceExpression((String) getCell(i, j), dataset));
    nonDouble = true;
   } else if (getCell(i, j) instanceof InstanceExpression) {
    nonDouble = true;
   }
  }
 }
 return nonDouble;
}
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Gets the maximum cost for a particular class value.
 * 
 * @param classVal the class value.
 * @return the maximum cost.
 * @exception Exception if cost matrix contains non-fixed costs
 */
public double getMaxCost(int classVal) throws Exception {
 double maxCost = Double.NEGATIVE_INFINITY;
 for (int i = 0; i < m_size; i++) {
  Object element = getCell(classVal, i);
  if (!(element instanceof Double)) {
   throw new Exception("Can't use non-fixed costs when "
    + "getting max cost.");
  }
  double cost = ((Double) element).doubleValue();
  if (cost > maxCost)
   maxCost = cost;
 }
 return maxCost;
}
origin: Waikato/weka-trunk

/**
 * Gets the maximum cost for a particular class value.
 * 
 * @param classVal the class value.
 * @return the maximum cost.
 * @exception Exception if cost matrix contains non-fixed costs
 */
public double getMaxCost(int classVal) throws Exception {
 double maxCost = Double.NEGATIVE_INFINITY;
 for (int i = 0; i < m_size; i++) {
  Object element = getCell(classVal, i);
  if (!(element instanceof Double)) {
   throw new Exception("Can't use non-fixed costs when "
    + "getting max cost.");
  }
  double cost = ((Double) element).doubleValue();
  if (cost > maxCost)
   maxCost = cost;
 }
 return maxCost;
}
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Writes out a matrix. The format can be read via the CostMatrix(Reader)
 * constructor. (FracPete: taken from old weka.core.Matrix class)
 * 
 * @param w the output Writer
 * @throws Exception if an error occurs
 */
public void write(Writer w) throws Exception {
 w.write("% Rows\tColumns\n");
 w.write("" + m_size + "\t" + m_size + "\n");
 w.write("% Matrix elements\n");
 for (int i = 0; i < m_size; i++) {
  for (int j = 0; j < m_size; j++) {
   w.write("" + getCell(i, j) + "\t");
  }
  w.write("\n");
 }
 w.flush();
}
origin: Waikato/weka-trunk

/**
 * Writes out a matrix. The format can be read via the CostMatrix(Reader)
 * constructor. (FracPete: taken from old weka.core.Matrix class)
 * 
 * @param w the output Writer
 * @throws Exception if an error occurs
 */
public void write(Writer w) throws Exception {
 w.write("% Rows\tColumns\n");
 w.write("" + m_size + "\t" + m_size + "\n");
 w.write("% Matrix elements\n");
 for (int i = 0; i < m_size; i++) {
  for (int j = 0; j < m_size; j++) {
   w.write("" + getCell(i, j) + "\t");
  }
  w.write("\n");
 }
 w.flush();
}
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Calculates the expected misclassification cost for each possible class
 * value, given class probability estimates.
 * 
 * @param classProbs the class probability estimates.
 * @return the expected costs.
 * @exception Exception if the wrong number of class probabilities is
 *              supplied.
 */
public double[] expectedCosts(double[] classProbs) throws Exception {
 if (classProbs.length != m_size) {
  throw new Exception("Length of probability estimates don't "
   + "match cost matrix");
 }
 double[] costs = new double[m_size];
 for (int x = 0; x < m_size; x++) {
  for (int y = 0; y < m_size; y++) {
   Object element = getCell(y, x);
   if (!(element instanceof Double)) {
    throw new Exception("Can't use non-fixed costs in "
     + "computing expected costs.");
   }
   costs[x] += classProbs[y] * ((Double) element).doubleValue();
  }
 }
 return costs;
}
origin: Waikato/weka-trunk

/**
 * Calculates the expected misclassification cost for each possible class
 * value, given class probability estimates.
 * 
 * @param classProbs the class probability estimates.
 * @return the expected costs.
 * @exception Exception if the wrong number of class probabilities is
 *              supplied.
 */
public double[] expectedCosts(double[] classProbs) throws Exception {
 if (classProbs.length != m_size) {
  throw new Exception("Length of probability estimates don't "
   + "match cost matrix");
 }
 double[] costs = new double[m_size];
 for (int x = 0; x < m_size; x++) {
  for (int y = 0; y < m_size; y++) {
   Object element = getCell(y, x);
   if (!(element instanceof Double)) {
    throw new Exception("Can't use non-fixed costs in "
     + "computing expected costs.");
   }
   costs[x] += classProbs[y] * ((Double) element).doubleValue();
  }
 }
 return costs;
}
origin: Waikato/weka-trunk

/**
 * converts the Matrix into a single line Matlab string: matrix is enclosed by
 * parentheses, rows are separated by semicolon and single cells by blanks,
 * e.g., [1 2; 3 4].
 * 
 * @return the matrix in Matlab single line format
 */
public String toMatlab() {
 StringBuffer result;
 int i;
 int n;
 result = new StringBuffer();
 result.append("[");
 for (i = 0; i < m_size; i++) {
  if (i > 0) {
   result.append("; ");
  }
  for (n = 0; n < m_size; n++) {
   if (n > 0) {
    result.append(" ");
   }
   result.append(getCell(i, n));
  }
 }
 result.append("]");
 return result.toString();
}
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * converts the Matrix into a single line Matlab string: matrix is enclosed by
 * parentheses, rows are separated by semicolon and single cells by blanks,
 * e.g., [1 2; 3 4].
 * 
 * @return the matrix in Matlab single line format
 */
public String toMatlab() {
 StringBuffer result;
 int i;
 int n;
 result = new StringBuffer();
 result.append("[");
 for (i = 0; i < m_size; i++) {
  if (i > 0) {
   result.append("; ");
  }
  for (n = 0; n < m_size; n++) {
   if (n > 0) {
    result.append(" ");
   }
   result.append(getCell(i, n));
  }
 }
 result.append("]");
 return result.toString();
}
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Creates a cost matrix that is a copy of another.
 * 
 * @param toCopy the matrix to copy.
 */
public CostMatrix(CostMatrix toCopy) {
 this(toCopy.size());
 for (int i = 0; i < m_size; i++) {
  for (int j = 0; j < m_size; j++) {
   setCell(i, j, toCopy.getCell(i, j));
  }
 }
}
origin: Waikato/weka-trunk

/**
 * Creates a cost matrix that is a copy of another.
 * 
 * @param toCopy the matrix to copy.
 */
public CostMatrix(CostMatrix toCopy) {
 this(toCopy.size());
 for (int i = 0; i < m_size; i++) {
  for (int j = 0; j < m_size; j++) {
   setCell(i, j, toCopy.getCell(i, j));
  }
 }
}
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Gets the maximum cost for a particular class value.
 * 
 * @param classVal the class value.
 * @return the maximum cost.
 * @exception Exception if cost matrix contains non-fixed costs
 */
public double getMaxCost(int classVal, Instance inst) throws Exception {
 if (!replaceStrings(inst.dataset())) {
  return getMaxCost(classVal);
 }
 double maxCost = Double.NEGATIVE_INFINITY;
 double cost;
 for (int i = 0; i < m_size; i++) {
  Object element = getCell(classVal, i);
  if (!(element instanceof Double)) {
   cost = ((InstanceExpression) element).evaluate(inst);
  } else {
   cost = ((Double) element).doubleValue();
  }
  if (cost > maxCost)
   maxCost = cost;
 }
 return maxCost;
}
origin: Waikato/weka-trunk

/**
 * Gets the maximum cost for a particular class value.
 * 
 * @param classVal the class value.
 * @return the maximum cost.
 * @exception Exception if cost matrix contains non-fixed costs
 */
public double getMaxCost(int classVal, Instance inst) throws Exception {
 if (!replaceStrings(inst.dataset())) {
  return getMaxCost(classVal);
 }
 double maxCost = Double.NEGATIVE_INFINITY;
 double cost;
 for (int i = 0; i < m_size; i++) {
  Object element = getCell(classVal, i);
  if (!(element instanceof Double)) {
   cost = ((InstanceExpression) element).evaluate(inst);
  } else {
   cost = ((Double) element).doubleValue();
  }
  if (cost > maxCost)
   maxCost = cost;
 }
 return maxCost;
}
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * adds the given CostMatrix to a DOM structure.
 *
 * @param parent the parent of this object, e.g. the class this object is a
 *          member of
 * @param o the Object to describe in XML
 * @param name the name of the object
 * @return the node that was created
 * @throws Exception if the DOM creation fails
 * @see weka.classifiers.CostMatrix
 */
public Element writeCostMatrix(Element parent, Object o, String name)
 throws Exception {
 weka.classifiers.CostMatrix matrix = (weka.classifiers.CostMatrix) o;
 Element node;
 // for debugging only
 if (DEBUG) {
  trace(new Throwable(), name);
 }
 m_CurrentNode = parent;
 node = addElement(parent, name, o.getClass().getName(), false);
 Object[][] m = new Object[matrix.size()][matrix.size()];
 for (int i = 0; i < matrix.size(); i++) {
  for (int j = 0; j < matrix.size(); j++) {
   m[i][j] = matrix.getCell(i, j);
  }
 }
 invokeWriteToXML(node, m, VAL_CELLS);
 return node;
}
origin: Waikato/weka-trunk

/**
 * adds the given CostMatrix to a DOM structure.
 *
 * @param parent the parent of this object, e.g. the class this object is a
 *          member of
 * @param o the Object to describe in XML
 * @param name the name of the object
 * @return the node that was created
 * @throws Exception if the DOM creation fails
 * @see weka.classifiers.CostMatrix
 */
public Element writeCostMatrix(Element parent, Object o, String name)
 throws Exception {
 weka.classifiers.CostMatrix matrix = (weka.classifiers.CostMatrix) o;
 Element node;
 // for debugging only
 if (DEBUG) {
  trace(new Throwable(), name);
 }
 m_CurrentNode = parent;
 node = addElement(parent, name, o.getClass().getName(), false);
 Object[][] m = new Object[matrix.size()][matrix.size()];
 for (int i = 0; i < matrix.size(); i++) {
  for (int j = 0; j < matrix.size(); j++) {
   m[i][j] = matrix.getCell(i, j);
  }
 }
 invokeWriteToXML(node, m, VAL_CELLS);
 return node;
}
weka.classifiersCostMatrixgetCell

Javadoc

Return the contents of a particular cell. Note: this method returns the Object stored at a particular cell.

Popular methods of CostMatrix

  • <init>
    Creates a cost matrix that is a copy of another.
  • applyCostMatrix
    Applies the cost matrix to a set of instances. If a random number generator is supplied the instance
  • setCell
    Set the value of a particular cell in the matrix
  • initialize
    Initializes the matrix
  • expectedCosts
    Calculates the expected misclassification cost for each possible class value, given class probabilit
  • getElement
    Return the value of a cell as a double. Computes the value for non-fixed costs using the supplied In
  • getMaxCost
    Gets the maximum cost for a particular class value.
  • normalize
    Normalizes the matrix so that the diagonal contains zeros.
  • numColumns
    Same as size
  • numRows
    Same as size
  • parseMatlab
    creates a matrix from the given Matlab string.
  • readOldFormat
    Loads a cost matrix in the old format from a reader. Adapted from code once sitting in Instances.jav
  • parseMatlab,
  • readOldFormat,
  • replaceStrings,
  • size,
  • toMatlab,
  • toString,
  • write,
  • setElement

Popular in Java

  • Making http requests using okhttp
  • startActivity (Activity)
  • addToBackStack (FragmentTransaction)
  • orElseThrow (Optional)
  • ObjectMapper (com.fasterxml.jackson.databind)
    This mapper (or, data binder, or codec) provides functionality for converting between Java objects (
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate(i
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now