本文整理汇总了Java中weka.core.matrix.Matrix.getColumnDimension方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.getColumnDimension方法的具体用法?Java Matrix.getColumnDimension怎么用?Java Matrix.getColumnDimension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.getColumnDimension方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
}
示例4: 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;
}
示例5: 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;
}
示例6: PaceMatrix
import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/** Construct a PaceMatrix from a Matrix
@param X Matrix
*/
public PaceMatrix( Matrix X ) {
super( X.getRowDimension(), X.getColumnDimension() );
A = X.getArray();
}