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