no.uib.cipr.matrix.Vector类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中no.uib.cipr.matrix.Vector类的一些代码示例,展示了Vector类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector类的具体详情如下:
包路径:no.uib.cipr.matrix.Vector
类名称:Vector

Vector介绍

[英]Basic vector interface. It holds doubles in an array, and is used alongside Matrix in numerical computations. Implementing classes decides on the actual storage.

Basic operations

Use size to get the vector size. get(int) gets an element, and there are corresponding set(int,double) and add(int,double) methods as well. Note that vector indices are zero-based (typical for Java and C). This means that they range from 0 to size-1. It is legal to have size equal zero.

Other basic operations are zero which zeros all the entries of the vector, which can be cheaper than either zeroing the vector manually, or creating a new vector, and the operation copy which creates a deep copy of the vector. This copy has separate storage, but starts with the same contents as the current vector.

Iterators

The vector interface extends Iterable, and the iterator returns a VectorEntry which contains current index and entry value. Note that the iterator may skip non-zero entries. Using an iterator, many simple and efficient algorithms can be created. The iterator also permits changing values in the vector, however only non-zero entries can be changed.

Basic linear algebra

A selection of basic linear algebra operations are available. To ensure high efficiency, little or no internal memory allocation is done, and the user is required to supply the output arguments.

The operations available include:
Additions Vectors can be added to each other, even if their underlying vector structures are incompatible Scaling Scalar multiplication (scaling) of a whole vector Norms Both innerproducts and norms can be computed. Several common norms are supported
[中]基本向量接口。它在一个数组中容纳doubles,在数值计算中与Matrix一起使用。实现类取决于实际存储。
#####基本操作
使用size获取向量大小。get(int)获取一个元素,还有相应的set(int,double)add(int,double)方法。请注意,向量索引是基于零的(Java和C的典型情况)。这意味着它们的范围从0到[$6$]。size等于零是合法的。
其他基本操作包括zero将向量的所有条目归零,这比手动将向量归零或创建新向量更便宜,以及copy创建向量的深度副本。此副本有单独的存储空间,但从与当前向量相同的内容开始。
#####迭代器
向量接口扩展Iterable,迭代器返回一个VectorEntry,其中包含当前索引和条目值。请注意,迭代器可能会跳过非零项。使用迭代器,可以创建许多简单高效的算法。迭代器还允许更改向量中的值,但只能更改非零项。
#####基本线性代数
可以选择一些基本的线性代数运算。为了确保高效率,很少或根本不进行内部内存分配,用户需要提供输出参数。
可用的操作包括:
加法向量可以相互相加,即使它们的基本向量结构不兼容,也可以计算内积和范数。支持几种常见规范

代码示例

代码示例来源:origin: de.tudarmstadt.ukp.similarity.algorithms/de.tudarmstadt.ukp.similarity.algorithms.sspace-gpl

@Override
public double add(int aParamInt, double aParamDouble)
{
  wrapped.add(aParamInt, aParamDouble);
  return wrapped.get(aParamInt);
}

代码示例来源:origin: fommil/matrix-toolkits-java

/**
 * Populates a vector with random numbers drawn from a uniform distribution
 * between 0 and 1
 * 
 * @param x
 *            Vector to populate
 */
public static Vector random(Vector x) {
  for (int i = 0; i < x.size(); ++i)
    x.set(i, Math.random());
  return x;
}

代码示例来源:origin: openimaj/openimaj

private static Point2d end(Vector origin, Vector dir) {
  final Vector ret = origin.copy().add(10000, dir);
  return new Point2dImpl((float) ret.get(0), (float) ret.get(1));
}

代码示例来源:origin: openimaj/openimaj

private Vector project(Vector v, Vector u){
  return u.copy().scale((v.dot(u) / u.dot(u)));
}

代码示例来源:origin: fommil/matrix-toolkits-java

public Vector solve(Matrix A, Vector b, Vector x)
    throws IterativeSolverNotConvergedException {
  checkSizes(A, b, x);
  double alpha = 0, beta = 0, rho = 0, rho_1 = 0;
  A.multAdd(-1, x, r.set(b));
  for (iter.setFirst(); !iter.converged(r, x); iter.next()) {
    M.apply(r, z);
    rho = r.dot(z);
    if (iter.isFirst())
      p.set(z);
    else {
      beta = rho / rho_1;
      p.scale(beta).add(z);
    }
    A.mult(p, q);
    alpha = rho / p.dot(q);
    x.add(alpha, p);
    r.add(-alpha, q);
    rho_1 = rho;
  }
  return x;
}

代码示例来源:origin: openimaj/openimaj

@Override
public Vector[] apply(double[] in) {
  Vector[] vmat = new Vector[in.length];
  
  vmat[0] = new DenseVector(in);
  double norm = vmat[0].norm(Norm.Two);
  vmat[0].scale(1/norm);
  for (int j = 1; j < in.length; j++) {
    Vector randvec = randvec(vmat[0].size(),norm);
    vmat[j] = new DenseVector(vmat[0]).add(randvec);
    for (int i = 0; i < j; i++) {
      vmat[j].add(-1, project(vmat[j],vmat[i]));
    }
    vmat[j].scale(1/vmat[j].norm(Norm.Two));
  }
  return vmat;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Returns the log of the density value for the given vector.
 *
 * @param valuePassed input vector
 * @return log density based on given distribution
 */
@Override
public double logDensity(double[] valuePassed) {
 // calculate mean subtractions
 Vector x = new DenseVector(valuePassed);
 return lnconstant - 0.5 * x.dot(covarianceInverse.mult(x.add(-1.0, mean), new DenseVector(x.size())));
}

代码示例来源:origin: nz.ac.waikato.cms.weka/discriminantAnalysis

Vector diff = centroids[0].copy().add(-1.0, centroids[1]);
m_Weights.scale(1.0 / m_Weights.norm(Vector.Norm.Two));
m_Threshold = 0.5 * m_Weights.dot(centroids[0].copy().add(centroids[1]));

代码示例来源:origin: gov.sandia.foundry/gov-sandia-cognition-common-core

@Override
public int getDimensionality()
{
  return this.internalVector.size();
}

代码示例来源:origin: de.tudarmstadt.ukp.similarity.algorithms/de.tudarmstadt.ukp.similarity.algorithms.sspace-gpl

@Override
public void set(int aParamInt, double aParamDouble)
{
  wrapped.set(aParamInt, aParamDouble);
}

代码示例来源:origin: com.googlecode.matrix-toolkits-java/mtj

public Vector solve(Matrix A, Vector b, Vector x)
    throws IterativeSolverNotConvergedException {
  checkSizes(A, b, x);
  A.multAdd(-1, x, r.set(b));
  for (iter.setFirst(); !iter.converged(r, x); iter.next()) {
    M.apply(r, z);
    x.add(z);
    A.multAdd(-1, x, r.set(b));
  }
  return x;
}

代码示例来源:origin: gov.sandia.foundry/gov-sandia-cognition-common-core

@Override
public double get(
  final int index)
{
  return this.internalVector.get(index);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * 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
 Vector k = new DenseVector(m_NumTrain);
 for (int i = 0; i < m_NumTrain; i++) {
  k.set(i, m_weights[i] * m_actualKernel.eval(-1, i, inst));
 }
 double result = (k.dot(m_t) + m_avg_target - m_Blin) / m_Alin;
 return result;
}

代码示例来源:origin: openimaj/openimaj

@Override
public IndependentPair<double[], PerceptronClass> generate() {
  double decide = Math.signum(rng.nextDouble() - 0.5);
  if(decide == 0) decide = 1;
  PerceptronClass dec = PerceptronClass.fromSign(decide);
  while(true){			
    double[] randomPoint = new double[this.dims];
    
    for (int i = 0; i < randomPoint.length; i++) {
      randomPoint[i] = nextRandomValue(); 
    }
    
    Vector v = new DenseVector(randomPoint);
    v.add(-1, origin);
    Vector d = direction.copy();
    double dot = v.dot(d);
    double sgn = Math.signum(dot);
    if(sgn == 0) sgn = 1;
    if(rng.nextDouble() <this.error){
      sgn = -sgn; 
    }
    PerceptronClass sgnClass = PerceptronClass.fromSign(sgn);
    if(sgnClass.equals(dec)) {
      return IndependentPair.pair(randomPoint, sgnClass);
    }
  }
}

代码示例来源:origin: de.tudarmstadt.ukp.similarity.algorithms/de.tudarmstadt.ukp.similarity.algorithms.vsm-asl

@Override
public Vector get()
{
  return vector.copy();
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Computes standard deviation for given instance, without transforming target
 * back into original space.
 */
protected double computeStdDev(Instance inst, Vector k) throws Exception {
 double kappa = m_actualKernel.eval(-1, -1, inst) + m_deltaSquared;
 double s = m_L.mult(k, new DenseVector(k.size())).dot(k);
 double sigma = m_delta;
 if (kappa > s) {
  sigma = Math.sqrt(kappa - s);
 }
 return sigma;
}

代码示例来源:origin: org.dkpro.similarity/dkpro-similarity-algorithms-vsm-asl

@Override
public void add(int aTimes, Vector aVector)
{
  vector.add(aTimes, aVector);
}

代码示例来源:origin: gov.sandia.foundry/gov-sandia-cognition-common-core

@Override
public double norm2()
{
  return this.internalVector.norm(
    no.uib.cipr.matrix.Vector.Norm.Two );
}

代码示例来源:origin: gov.sandia.foundry/gov-sandia-cognition-common-core

@Override
public void scaleEquals(
  final double scaleFactor)
{
  this.internalVector.scale( scaleFactor );   
}

代码示例来源:origin: nz.ac.waikato.cms.weka/discriminantAnalysis

/**
 * Computes the mean vector for the given dataset.
 */
protected Vector computeMean(Instances data, double[] totalWeight, int aI) {
 Vector meanVector = new DenseVector(data.numAttributes() - 1);
 totalWeight[aI] = 0;
 for (Instance inst : data) {
  if (!inst.classIsMissing()) {
   meanVector.add(inst.weight(), instanceToVector(inst));
   totalWeight[aI] += inst.weight();
  }
 }
 meanVector.scale(1.0 / totalWeight[aI]);
 return meanVector;
}

相关文章