Java Code Examples for weka.core.matrix.Matrix#getColumnDimension()

The following examples show how to use weka.core.matrix.Matrix#getColumnDimension() . 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: sIB.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
  * Compute the sIB score
  * @param m a term-cluster matrix, with m[i, j] is the probability of term i given cluster j  
  * @param Pt an array of cluster prior probabilities
  * @return the sIB score which indicates the quality of the partition
  */
 private double sIB_local_MI(Matrix m, double[] Pt) {
   double Hy = 0.0, Ht = 0.0;
   for (int i = 0; i < Pt.length; i++) {
     Ht += Pt[i] * Math.log(Pt[i]);
   }
   Ht = -Ht;
   
   for (int i = 0; i < m_numAttributes; i++) {
     double Py = 0.0;
     for (int j = 0; j < m_numCluster; j++) {
Py += m.get(i, j) * Pt[j];	
     }     
     if(Py == 0) continue;
     Hy += Py * Math.log(Py);
   }
   Hy = -Hy;
   
   double Hyt = 0.0, tmp = 0.0;
   for (int i = 0; i < m.getRowDimension(); i++) {
     for (int j = 0; j < m.getColumnDimension(); j++) {
if ((tmp = m.get(i, j)) == 0 || Pt[j] == 0) {
  continue;
}
tmp *= Pt[j];
Hyt += tmp * Math.log(tmp);
     }
   }
   return Hy + Ht + Hyt;
 }
 
Example 2
Source File: sIB.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
  * Compute the MI between instances and attributes
  * @param m the term-document matrix
  * @param input object that describes the statistics about the training data
  */
 private void MI(Matrix m, Input input){    
   int minDimSize = m.getColumnDimension() < m.getRowDimension() ? m.getColumnDimension() : m.getRowDimension();
   if(minDimSize < 2){
     System.err.println("Warning : This is not a JOINT distribution");
     input.Hx = Entropy (m);
     input.Hy = 0;
     input.Ixy = 0;
     return;
   }
   
   input.Hx = Entropy(input.Px);
   input.Hy = Entropy(input.Py);
   
   double entropy = input.Hx + input.Hy;    
   for (int i=0; i < m_numInstances; i++) {
     Instance inst = m_data.instance(i);
     for (int v = 0; v < inst.numValues(); v++) {
double tmp = m.get(inst.index(v), i);
if(tmp <= 0) continue;
entropy += tmp * Math.log(tmp);
     }
   }
   input.Ixy = entropy;
   if(m_verbose) {
     System.out.println("Ixy = " + input.Ixy);
   }
 }
 
Example 3
Source File: sIB.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
  * Compute the entropy score based on a matrix
  * @param p a matrix with non-negative and normalized probabilities
  * @return the entropy value
  */
 private double Entropy(Matrix p) {
   double mi = 0;
   for (int i = 0; i < p.getRowDimension(); i++) {
     for (int j = 0; j < p.getColumnDimension(); j++) {
if(p.get(i, j) == 0){
  continue;
}
mi += p.get(i, j) + Math.log(p.get(i, j)); 
     }
   }
   mi = -mi;
   return mi;
 }
 
Example 4
Source File: PLST.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
    * Transforms the predictions of the internal classifier back to the original labels.
    *
    * @param y The predictions that should be transformed back. The array consists only of
    * the predictions as they are returned from the internal classifier.
    * @return The transformed predictions.
    */
   @Override
   public double[] transformPredictionsBack(double[] y){
// y consists of predictions and maxindex, we need only predictions
double[] predictions = new double[y.length/2];

for (int i = 0; i < predictions.length; i++){
    predictions[i] = y[predictions.length+i];
}

double[][] dataArray = new double[1][predictions.length];

dataArray[0] = predictions;

Matrix yMat = new Matrix(dataArray);
       
Matrix multiplied = yMat.times(this.m_v.transpose()).plus(m_Shift);

double[] res = new double[multiplied.getColumnDimension()];

// change back from -1/1 coding to 0/1
for (int i = 0; i < res.length; i++) {
    res[i] = multiplied.getArray()[0][i]<0.0 ? 0.0 : 1.0;
}

return res;
   }
 
Example 5
Source File: PaceMatrix.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/** Construct a PaceMatrix from a Matrix 
    @param X    Matrix 
*/
public PaceMatrix( Matrix X ) {
  super( X.getRowDimension(), X.getColumnDimension() );
  A = X.getArray();
}