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


Java Matrix.set方法代码示例

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


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

示例1: classifyInstance

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Classifies a given instance.
 * 
 * @param inst the instance to be classified
 * @return the classification
 * @throws Exception if instance could not be classified successfully
 */
@Override
public double classifyInstance(Instance inst) throws Exception {

  // Filter instance
  inst = filterInstance(inst);

  // Build K vector
  Matrix k = new Matrix(m_NumTrain, 1);
  for (int i = 0; i < m_NumTrain; i++) {
    k.set(i, 0, m_kernel.eval(-1, i, inst));
  }

  double result = k.transpose().times(m_t).get(0, 0) + m_avg_target;
  result = (result - m_Blin) / m_Alin;

  return result;

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

示例2: logDensity

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Returns natural logarithm of density estimate for given value based on
 * given instance.
 * 
 * @param instance the instance to make the prediction for.
 * @param value the value to make the prediction for.
 * @return the natural logarithm of the density estimate
 * @exception Exception if the density cannot be computed
 */
@Override
public double logDensity(Instance inst, double value) throws Exception {

  inst = filterInstance(inst);

  // Build K vector (and Kappa)
  Matrix k = new Matrix(m_NumTrain, 1);
  for (int i = 0; i < m_NumTrain; i++) {
    k.set(i, 0, m_kernel.eval(-1, i, inst));
  }

  double estimate = k.transpose().times(m_t).get(0, 0) + m_avg_target;

  double sigma = computeStdDev(inst, k);

  // transform to GP space
  value = value * m_Alin + m_Blin;
  // center around estimate
  value = value - estimate;
  double z = -Math.log(sigma * Math.sqrt(2 * Math.PI)) - value * value
    / (2.0 * sigma * sigma);

  return z + Math.log(m_Alin);
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:34,代码来源:GaussianProcesses.java

示例3: classifyInstance

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Classifies a given instance.
 * 
 * @param inst
 *            the instance to be classified
 * @return the classification
 * @throws Exception
 *             if instance could not be classified successfully
 */
public double classifyInstance(Instance inst) throws Exception {

  // Filter instance
  inst = filterInstance(inst);

  // Build K vector
  Matrix k = new Matrix(m_NumTrain, 1);
  for (int i = 0; i < m_NumTrain; i++) {
    k.set(i, 0, m_kernel.eval(-1, i, inst));
  }

  double result = k.transpose().times(m_t).get(0, 0) + m_avg_target;
  result = (result - m_Blin) / m_Alin;

  return result;

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

示例4: logDensity

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Returns natural logarithm of density estimate for given value based on given instance.
 *   
 * @param instance the instance to make the prediction for.
 * @param value the value to make the prediction for.
 * @return the natural logarithm of the density estimate
 * @exception Exception if the density cannot be computed
 */
public double logDensity(Instance inst, double value) throws Exception {
  
  inst = filterInstance(inst);

  // Build K vector (and Kappa)
  Matrix k = new Matrix(m_NumTrain, 1);
  for (int i = 0; i < m_NumTrain; i++) {
    k.set(i, 0, m_kernel.eval(-1, i, inst));
  }
  
  double estimate = k.transpose().times(m_t).get(0, 0) + m_avg_target;

  double sigma = computeStdDev(inst, k);
  
  // transform to GP space
  value = value * m_Alin + m_Blin;
  // center around estimate
  value = value - estimate;
  double z = -Math.log(sigma * Math.sqrt(2 * Math.PI)) 
    - value * value /(2.0*sigma*sigma); 
  
  return z + Math.log(m_Alin);
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:32,代码来源:GaussianProcesses.java

示例5: productVector

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Compute the product among the matrix and the vector
 *
 * @param current
 *            The matrix.
 * @param vectorX
 *            The vector.
 */
public void productVector(Matrix current, double[] vectorX) {

	for (int m = 0; m < vectorX.length; m++) {
		for (int nn = 0; nn < vectorX.length; nn++) {
			current.set(m, nn, vectorX[m] * vectorX[nn]);
		}
	}
}
 
开发者ID:ogreyesp,项目名称:JCLAL,代码行数:17,代码来源:VarianceReductionQueryStrategy.java

示例6: getStandardDeviation

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Gives standard deviation of the prediction at the given instance.
 * 
 * @param inst the instance to get the standard deviation for
 * @return the standard deviation
 * @throws Exception if computation fails
 */
public double getStandardDeviation(Instance inst) throws Exception {

  inst = filterInstance(inst);

  // Build K vector (and Kappa)
  Matrix k = new Matrix(m_NumTrain, 1);
  for (int i = 0; i < m_NumTrain; i++) {
    k.set(i, 0, m_kernel.eval(-1, i, inst));
  }

  return computeStdDev(inst, k) / m_Alin;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:20,代码来源:GaussianProcesses.java

示例7: calculateCovariance

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/** Calculate covariance and value means */
private void calculateCovariance() {

  double sumValues = 0, sumConds = 0;
  for (int i = 0; i < m_Values.size(); i++) {
    sumValues += m_Values.elementAt(i).doubleValue()
      * m_Weights.elementAt(i).doubleValue();
    sumConds += m_CondValues.elementAt(i).doubleValue()
      * m_Weights.elementAt(i).doubleValue();
  }
  m_ValueMean = sumValues / m_SumOfWeights;
  m_CondMean = sumConds / m_SumOfWeights;
  double c00 = 0, c01 = 0, c10 = 0, c11 = 0;
  for (int i = 0; i < m_Values.size(); i++) {
    double x = m_Values.elementAt(i).doubleValue();
    double y = m_CondValues.elementAt(i).doubleValue();
    double weight = m_Weights.elementAt(i).doubleValue();
    c00 += (x - m_ValueMean) * (x - m_ValueMean) * weight;
    c01 += (x - m_ValueMean) * (y - m_CondMean) * weight;
    c11 += (y - m_CondMean) * (y - m_CondMean) * weight;
  }
  c00 /= (m_SumOfWeights - 1.0);
  c01 /= (m_SumOfWeights - 1.0);
  c10 = c01;
  c11 /= (m_SumOfWeights - 1.0);
  m_Covariance = new Matrix(2, 2);
  m_Covariance.set(0, 0, c00);
  m_Covariance.set(0, 1, c01);
  m_Covariance.set(1, 0, c10);
  m_Covariance.set(1, 1, c11);
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:32,代码来源:NNConditionalEstimator.java

示例8: normalKernel

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Returns value for normal kernel
 *
 * @param x the argument to the kernel function
 * @param variance the variance
 * @return the value for a normal kernel
 */
private double normalKernel(double x) {
  
  Matrix thisPoint = new Matrix(1, 2);
  thisPoint.set(0, 0, x);
  thisPoint.set(0, 1, m_ConstDelta);
  return Math.exp(-thisPoint.times(m_CovarianceInverse).
      times(thisPoint.transpose()).get(0, 0) 
      / 2) / (Math.sqrt(TWO_PI) * m_Determinant);
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:17,代码来源:MahalanobisEstimator.java

示例9: EM

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Performs the expectation maximization (EM) algorithm to find the maximum 
 * likelihood estimate (or posterior mode if ridge prior is being used)
 * for the multivariate normal parameters of a dataset with missing values. 
 * @param data          preprocessed dataset with missing values
 * @param t_obs         the complete data sufficient statistics for the observed values
 * @return theta        the maximum likelihood estimate for the parameters of the multivariate normal distribution
 * @throws Exception    if processing goes wrong
 */
private Matrix EM(Instances data, Matrix t_obs) throws Exception {
  
  int p = m_numAttributes; // number of columns
  Matrix theta = new Matrix(p+1, p+1); // parameter matrix
  
  // if numIterations is -1, change to largest int
  int numIterations = m_numIterations;
  if (numIterations < 0) {
    numIterations = Integer.MAX_VALUE;
  }
  
  // starting theta value (means and variances of each column, correlations left at zero)
  // values are standardized so means are 0 and variances are 1
  theta.set(0, 0, -1);
  for (int i = 1; i < data.numAttributes(); i++) {
    theta.set(0, i, 0); // mu_i
    theta.set(i, 0, 0);
    theta.set(i, i, 1); // sigma_ii
  }
  
  double likelihood = logLikelihood(data, theta);
  double deltaLikelihood = Double.MAX_VALUE;
  for (int i = 0; i < numIterations && deltaLikelihood > m_LogLikelihoodThreshold; i++) {
    theta = doEMIteration(data, theta, t_obs);
    double newLikelihood = logLikelihood(data, theta);
    deltaLikelihood = newLikelihood - likelihood;
    likelihood = newLikelihood;
  }
  
  return theta;
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:41,代码来源:EMImputation.java

示例10: 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

示例11: getStandardDeviation

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Gives standard deviation of the prediction at the given instance.
 * 
 * @param inst
 *            the instance to get the standard deviation for
 * @return the standard deviation
 * @throws Exception
 *             if computation fails
 */
public double getStandardDeviation(Instance inst) throws Exception {

  inst = filterInstance(inst);

  // Build K vector (and Kappa)
  Matrix k = new Matrix(m_NumTrain, 1);
  for (int i = 0; i < m_NumTrain; i++) {
    k.set(i, 0, m_kernel.eval(-1, i, inst));
  }

  return computeStdDev(inst, k) / m_Alin;
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:22,代码来源:GaussianProcesses.java

示例12: calculateCovariance

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/** Calculate covariance and value means */
 private void calculateCovariance() {
   
   double sumValues = 0, sumConds = 0;
   for(int i = 0; i < m_Values.size(); i++) {
     sumValues += ((Double)m_Values.elementAt(i)).doubleValue()
* ((Double)m_Weights.elementAt(i)).doubleValue();
     sumConds += ((Double)m_CondValues.elementAt(i)).doubleValue()
* ((Double)m_Weights.elementAt(i)).doubleValue();
   }
   m_ValueMean = sumValues / m_SumOfWeights;
   m_CondMean = sumConds / m_SumOfWeights;
   double c00 = 0, c01 = 0, c10 = 0, c11 = 0;
   for(int i = 0; i < m_Values.size(); i++) {
     double x = ((Double)m_Values.elementAt(i)).doubleValue();
     double y = ((Double)m_CondValues.elementAt(i)).doubleValue();
     double weight = ((Double)m_Weights.elementAt(i)).doubleValue();
     c00 += (x - m_ValueMean) * (x - m_ValueMean) * weight;
     c01 += (x - m_ValueMean) * (y - m_CondMean) * weight;
     c11 += (y - m_CondMean) * (y - m_CondMean) * weight;
   }
   c00 /= (m_SumOfWeights - 1.0);
   c01 /= (m_SumOfWeights - 1.0);
   c10 = c01;
   c11 /= (m_SumOfWeights - 1.0);
   m_Covariance = new Matrix(2, 2);
   m_Covariance.set(0, 0, c00);
   m_Covariance.set(0, 1, c01);
   m_Covariance.set(1, 0, c10);
   m_Covariance.set(1, 1, c11);
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:32,代码来源:NNConditionalEstimator.java

示例13: getTransposedNormedMatrix

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
private Matrix getTransposedNormedMatrix(Instances data) {
   Matrix matrix = new Matrix(data.numAttributes(), data.numInstances());
   for(int i = 0; i < data.numInstances(); i++){
     double[] vals = data.instance(i).toDoubleArray();
     double sum = Utils.sum(vals);
     for (int v = 0; v < vals.length; v++) {
vals[v] /= sum;
matrix.set(v, i, vals[v]);
     }      
   }
   return matrix;
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:13,代码来源:sIB.java

示例14: main

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Main method for testing this class.
 *
 * @param argv should contain a sequence of numeric values
 */
public static void main(String [] argv) {
  
  try {
    double delta = 0.5;
    double xmean = 0;
    double lower = 0;
    double upper = 10;
    Matrix covariance = new Matrix(2, 2);
    covariance.set(0, 0, 2);
    covariance.set(0, 1, -3);
    covariance.set(1, 0, -4);
    covariance.set(1, 1, 5);
    if (argv.length > 0) {
      covariance.set(0, 0, Double.valueOf(argv[0]).doubleValue());
    }
    if (argv.length > 1) {
      covariance.set(0, 1, Double.valueOf(argv[1]).doubleValue());
    }
    if (argv.length > 2) {
      covariance.set(1, 0, Double.valueOf(argv[2]).doubleValue());
    }
    if (argv.length > 3) {
      covariance.set(1, 1, Double.valueOf(argv[3]).doubleValue());
    }
    if (argv.length > 4) {
      delta = Double.valueOf(argv[4]).doubleValue();
    }
    if (argv.length > 5) {
      xmean = Double.valueOf(argv[5]).doubleValue();
    }
    
    MahalanobisEstimator newEst = new MahalanobisEstimator(covariance,
        delta, xmean);
    if (argv.length > 6) {
      lower = Double.valueOf(argv[6]).doubleValue();
      if (argv.length > 7) {
        upper = Double.valueOf(argv[7]).doubleValue();
      }
      double increment = (upper - lower) / 50;
      for(double current = lower; current <= upper; current+= increment)
        System.out.println(current + "  " + newEst.getProbability(current));
    } else {
      System.out.println("Covariance Matrix\n" + covariance);
      System.out.println(newEst);
    }
  } catch (Exception e) {
    System.out.println(e.getMessage());
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:55,代码来源:MahalanobisEstimator.java

示例15: getTObs

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Calculates T_obs (complete data sufficient statistics for the observed values). 
 * @param data        preprocessed dataset with missing values
 * @return t          T_obs
 * @throws Exception  if processing goes wrong
 */
private Matrix getTObs(Instances data) throws Exception {
  
  int p = m_numAttributes; // number of columns
  
  // matrix of complete-data sufficient statistics for observed values
  Matrix t = new Matrix(p+1, p+1);
  
  // initialize T for observed data (T_obs)
  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);
    t.set(0, 0, t.get(0,0) + numInCurrentPattern);
    for (int i = 1; i < p + 1; i++) {
      // if current column is not missing in this pattern
      if (!data.instance(currentPatternStart).isMissing(i)) {
        // add values in this column for this pattern
        for (int k = 0; k < numInCurrentPattern; k++) {
          t.set(0, i, t.get(0, i) + data.instance(currentPatternStart + k).value(i));
        }
        // iterate through columns to add appropriate squares and crossproducts
        for (int j = i; j < p + 1; j++) {
          // if this column is also not missing in the current missingness pattern
          if (!data.instance(currentPatternStart).isMissing(j)) {
            for (int k = 0; k < numInCurrentPattern; k++) {
              t.set(i, j, t.get(i, j) + 
                    data.instance(currentPatternStart + k).value(i) * 
                    data.instance(currentPatternStart + k).value(j));
            } // end iterating through instances in currrent missingness pattern
          }
        } // end iterating through column indices (inner loop) 
      }
    } // end iterating through column indices (outer loop)
    
    // move counter to start of next missingness pattern (or end of dataset)
    currentPatternStart += numInCurrentPattern;
  } // end iterating through missingness patterns
  
  // copy to symmetric lower triangular portion
  for (int i = 0; i < p + 1; i++) {
    for (int j = 1; j < p + 1; j++) {
      t.set(j, i, t.get(i, j));
    }
  }
  
  return t;
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:54,代码来源:EMImputation.java


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