当前位置: 首页>>代码示例>>Java>>正文


Java Matrix.get方法代码示例

本文整理汇总了Java中weka.core.matrix.Matrix.get方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.get方法的具体用法?Java Matrix.get怎么用?Java Matrix.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weka.core.matrix.Matrix的用法示例。


在下文中一共展示了Matrix.get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeStdDev

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Computes standard deviation for given instance, without transforming target
 * back into original space.
 */
protected double computeStdDev(Instance inst, Matrix k) throws Exception {

  double kappa = m_kernel.eval(-1, -1, inst) + m_deltaSquared;

  double s = 0;
  int n = m_L.length;
  for (int i = 0; i < n; i++) {
    double t = 0;
    for (int j = 0; j < n; j++) {
      t -= k.get(j, 0) * (i > j ? m_L[i][j] : m_L[j][i]);
    }
    s += t * k.get(i, 0);
  }

  double sigma = m_delta;
  if (kappa > s) {
    sigma = Math.sqrt(kappa - s);
  }

  return sigma;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:26,代码来源:GaussianProcesses.java

示例2: computeStdDev

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Computes standard deviation for given instance, without
 * transforming target back into original space.
 */
protected double computeStdDev(Instance inst, Matrix k) throws Exception {

  double kappa = m_kernel.eval(-1, -1, inst) + m_delta * m_delta;

  double s = 0;
  int n = m_L.length;
  for (int i = 0; i < n; i++) {
    double t = 0;
    for (int j = 0; j < n; j++) {
      t -= k.get(j,0) * (i>j? m_L[i][j] : m_L[j][i]);
    }			
    s += t * k.get(i,0);
  }

  double sigma = m_delta;
  if (kappa > s) {
    sigma = Math.sqrt(kappa - s);
  }

  return sigma;
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:26,代码来源:GaussianProcesses.java

示例3: toInstances

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
  * returns the X and Y matrix again as Instances object, based on the given
  * header (must have a class attribute set).
  * 
  * @param header	the format of the instance object
  * @param x		the X matrix (data)
  * @param y		the Y matrix (class)
  * @return		the assembled data
  */
 protected Instances toInstances(Instances header, Matrix x, Matrix y) {
   double[]	values;
   int		i;
   int		n;
   Instances	result;
   int		rows;
   int		cols;
   int		offset;
   int		clsIdx;
   
   result = new Instances(header, 0);
   
   rows   = x.getRowDimension();
   cols   = x.getColumnDimension();
   clsIdx = header.classIndex();
   
   for (i = 0; i < rows; i++) {
     values = new double[cols + 1];
     offset = 0;

     for (n = 0; n < values.length; n++) {
if (n == clsIdx) {
  offset--;
  values[n] = y.get(i, 0);
}
else {
  values[n] = x.get(i, n + offset);
}
     }
     
     result.add(new DenseInstance(1.0, values));
   }
   
   return result;
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:45,代码来源:PLSFilter.java

示例4: normalizeVector

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * normalizes the given vector (inplace) 
 * 
 * @param v		the vector to normalize
 */
protected void normalizeVector(Matrix v) {
  double	sum;
  int		i;
  
  // determine length
  sum = 0;
  for (i = 0; i < v.getRowDimension(); i++)
    sum += v.get(i, 0) * v.get(i, 0);
  sum = StrictMath.sqrt(sum);
  
  // normalize content
  for (i = 0; i < v.getRowDimension(); i++)
    v.set(i, 0, v.get(i, 0) / sum);
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:20,代码来源:PLSFilter.java

示例5: sIB_local_MI

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
  * 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;
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:36,代码来源:sIB.java

示例6: MI

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
  * 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(Thread.currentThread().getStackTrace()[1].getClassName() +"Ixy = " + input.Ixy);
   }
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:33,代码来源:sIB.java

示例7: Entropy

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
  * 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;
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:19,代码来源:sIB.java

示例8: toInstances

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
  * returns the X and Y matrix again as Instances object, based on the given
  * header (must have a class attribute set).
  * 
  * @param header	the format of the instance object
  * @param x		the X matrix (data)
  * @param y		the Y matrix (class)
  * @return		the assembled data
  */
 protected Instances toInstances(Instances header, Matrix x, Matrix y) {
   double[]	values;
   int		i;
   int		n;
   Instances	result;
   int		rows;
   int		cols;
   int		offset;
   int		clsIdx;
   
   result = new Instances(header, 0);
   
   rows   = x.getRowDimension();
   cols   = x.getColumnDimension();
   clsIdx = header.classIndex();
   
   for (i = 0; i < rows; i++) {
     values = new double[cols + 1];
     offset = 0;

     for (n = 0; n < values.length; n++) {
if (n == clsIdx) {
  offset--;
  values[n] = y.get(i, 0);
}
else {
  values[n] = x.get(i, n + offset);
}
     }
     
     result.add(new Instance(1.0, values));
   }
   
   return result;
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:45,代码来源:PLSFilter.java

示例9: impute

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Performs the imputation. Draws Y_mis(i+1) as the expected value of (Y_mis | Y_obs, theta(i)).
 * @param data          preprocessed dataset with missing values
 * @param theta         a matrix containing the multivariate normal parameters
 * @throws Exception    if processing goes wrong
 */
private void impute(Instances data, Matrix theta) throws Exception {
  
  int p = m_numAttributes; // number of columns
  
  // go through each pattern
  int currentPatternStart = 0;
  while (currentPatternStart < data.numInstances()) {
    // number of instances in current missingness pattern is held in 1st attribute
    int numInCurrentPattern = (int) data.instance(currentPatternStart).value(0);
    // set up binary flags for if column is observed in this pattern
    boolean [] r = new boolean[p + 1];
    int [] observedColumns = new int[p + 1]; // indices of observed columns
    int [] missingColumns = new int[p + 1]; // indices of missing columns
    int numMissing = 0; // number of missing columns
    int numObserved = 0; // number of observed columns
    for (int l = 1; l < p + 1; l++) {
      if (data.instance(currentPatternStart).isMissing(l)) {
        missingColumns[numMissing++] = l;
      } else {
        observedColumns[numObserved++] = l;
        r[l] = true;
      }
    }
    observedColumns[numObserved] = -1; // list end indicator
    missingColumns[numMissing] = -1; // list end indicator
    
    for (int j = 1; j < p + 1; j++) {
      if (r[j] == true && theta.get(j, j) > 0) {
        theta = swp(theta, j);
      } else if (r[j] == false && theta.get(j, j) < 0) {
        theta = rsw(theta, j);
      }
    }
    
    for (int i = 0; i < numInCurrentPattern; i++) {
      for (int jCounter = 0, j = missingColumns[jCounter]; j != -1; 
           jCounter++, j = missingColumns[jCounter]) {
        // impute the missing values
        data.instance(currentPatternStart + i).setValue(j, theta.get(0, j));
        for (int kCounter = 0, k = observedColumns[kCounter]; k != -1;
             kCounter++, k = observedColumns[kCounter]) {
          double y_ij = data.instance(currentPatternStart + i).value(j);
          double y_ik = data.instance(currentPatternStart + i).value(k);
          double theta_kj = theta.get(k, j);
          data.instance(currentPatternStart + i).setValue(j, y_ij + theta_kj * y_ik);
        }
      }
    } // end iterating through instances in pattern
    // move counter to start of next missingness pattern (or end of dataset)
    currentPatternStart += numInCurrentPattern;
    if(Thread.interrupted())
 break;
  } // end iterating through missingness patterns
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:61,代码来源:EMImputation.java

示例10: doSweep

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Performs the sweep operation on a matrix at the given position. 
 * @param g           a matrix
 * @param k           the pivot position
 * @param dir         the direction to do the sweep in (1 = normal sweep, -1 = reverse sweep)
 * @return h          the matrix after being swept on position k
 * @throws Exception  if processing goes wrong
 */
private static Matrix doSweep(Matrix g, int k, int dir) throws Exception {
  
  // number of rows/columns
  int p = g.getRowDimension();
  
  // check if k is in range
  if (k < 0 || k >= p) {
    throw new Exception("Position to be swept on must be within range.");
  }
  
  // check if dir is 1 or -1
  if (dir != 1 && dir != -1) {
    throw new Exception("Sweep direction must be 1 or -1.");
  }
  
  // result matrix
  Matrix h = g.copy();
  
  // check that pivot value is not zero
  double kkValue = g.get(k, k);
  if (kkValue == 0) {
    throw new Exception("Sweep: Division by zero (pivot value).");
  }
  
  // process elements
  for (int i = 0; i < p; i++) {
    for (int j = i; j < p; j++) {
      if (i == k && j == k) { // pivot position
        h.set(i, j, -1.0 / kkValue);
      } else if (i == k || j == k) { // value in row or column k
        h.set(i, j, (double)dir * g.get(i, j) / kkValue);
        h.set(j, i, h.get(i, j)); // copy to symmetric value
      } else {
        h.set(i, j, g.get(i, j) - g.get(i, k) * g.get(k, j) / kkValue);
        h.set(j, i, h.get(i, j)); // copy to symmetric value
      }
    }
    if(Thread.interrupted())
 break;
  }
  
  return h;
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:52,代码来源:EMImputation.java

示例11: convertInstance

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Transform an instance in original (unnormalized) format
 * @param instance an instance in the original (unnormalized) format
 * @return a transformed instance
 * @throws Exception if instance can't be transformed
 */
public Instance convertInstance(Instance instance) throws Exception {
  if (m_s == null) {
    throw new Exception("convertInstance: Latent Semantic Analysis not " +
                         "performed yet.");
  }
  
  // array to hold new attribute values
  double [] newValues = new double[m_outputNumAttributes];
  
  // apply filters so new instance is in same format as training instances
  Instance tempInstance = (Instance)instance.copy();
  if (!instance.dataset().equalHeaders(m_trainHeader)) {
    throw new Exception("Can't convert instance: headers don't match: " +
    "LatentSemanticAnalysis");
  }
  // replace missing values
  m_replaceMissingFilter.input(tempInstance);
  m_replaceMissingFilter.batchFinished();
  tempInstance = m_replaceMissingFilter.output();
  // normalize
  if (m_normalize) {
    m_normalizeFilter.input(tempInstance);
    m_normalizeFilter.batchFinished();
    tempInstance = m_normalizeFilter.output();
  }
  // convert nominal attributes to binary
  m_nominalToBinaryFilter.input(tempInstance);
  m_nominalToBinaryFilter.batchFinished();
  tempInstance = m_nominalToBinaryFilter.output();
  // remove class/other attributes
  if (m_attributeFilter != null) {
    m_attributeFilter.input(tempInstance);
    m_attributeFilter.batchFinished();
    tempInstance = m_attributeFilter.output();
  }
  
  // record new attribute values
  if (m_hasClass) { // copy class value
    newValues[m_outputNumAttributes - 1] = instance.classValue();
  }
  double [][] oldInstanceValues = new double[1][m_numAttributes];
  oldInstanceValues[0] = tempInstance.toDoubleArray();
  Matrix instanceVector = new Matrix(oldInstanceValues); // old attribute values
  instanceVector = instanceVector.times(m_transformationMatrix); // new attribute values
  for (int i = 0; i < m_actualRank; i++) {
    newValues[i] = instanceVector.get(0, i);
  }
  
  // return newly transformed instance
  if (instance instanceof SparseInstance) {
    return new SparseInstance(instance.weight(), newValues);
  } else {
    return new Instance(instance.weight(), newValues);
  }
}
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:62,代码来源:LatentSemanticAnalysis.java


注:本文中的weka.core.matrix.Matrix.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。