Codota Logo
Vector.doubleValue
Code IndexAdd Codota to your IDE (free)

How to use
doubleValue
method
in
eu.monnetproject.math.sparse.Vector

Best Java code snippets using eu.monnetproject.math.sparse.Vector.doubleValue (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
OutputStreamWriter o =
  • Codota IconOutputStream out;new OutputStreamWriter(out)
  • Codota IconOutputStream out;String charsetName;new OutputStreamWriter(out, charsetName)
  • Codota IconHttpURLConnection connection;new OutputStreamWriter(connection.getOutputStream())
  • Smart code suggestions by Codota
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public double doubleValue(int i, int j) {
  if (arr[i] == null) {
    return defaultValue;
  } else {
    return arr[i].doubleValue(j);
  }
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public double doubleValue(int idx) {
  return v.doubleValue(idx);
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> double innerProduct(Vector<M> y) {
  final ByteBuffer d = data();
  double ip = 0.0;
  for (int i = 0; i < length; i += SIZE_OF_DOUBLE) {
    d.position(i);
    double v = d.getDouble();
    d.putDouble(v * y.doubleValue(i / SIZE_OF_DOUBLE));
  }
  return ip;
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> void sub(Vector<M> vector) {
  assert (vector.length() != length / SIZE_OF_DOUBLE);
  final ByteBuffer d = data();
  for (int i = 0; i < length; i += SIZE_OF_DOUBLE) {
    d.position(i);
    double v = d.getDouble();
    d.position(i);
    d.putDouble(v - vector.doubleValue(i / SIZE_OF_DOUBLE));
  }
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number, O extends Number> Vector<O> mult(Vector<M> x, Vectors.Factory<O> using) {
  assert (x.length() == alpha.length);
  final Vector<O> product = using.make(alpha.length, 0.0);
  for (int i = 0; i < alpha.length; i++) {
    double value = 0.0;
    if (i > 0) {
      value += x.doubleValue(i - 1) * beta[i - 1];
    }
    value += x.doubleValue(i) * alpha[i];
    if (i < beta.length) {
      value += x.doubleValue(i + 1) * beta[i];
    }
    product.put(i, value);
  }
  return product;
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> void add(Vector<M> vector) {
  assert (vector.length() != length / SIZE_OF_DOUBLE);
  final ByteBuffer d = data();
  for (int i = 0; i < length; i += SIZE_OF_DOUBLE) {
    d.position(i);
    double v = d.getDouble();
    d.position(i);
    d.putDouble(v + vector.doubleValue(i / SIZE_OF_DOUBLE));
  }
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> Vector<N> multTransposed(Vector<M> x) {
  assert (m == cols());
  double[] result = new double[m];
  Arrays.fill(result, m * defaultValue);
  for (int i = 0; i < arr.length; i++) {
    for (Map.Entry<Integer, N> e : arr[i].entrySet()) {
      result[e.getKey().intValue()] += x.doubleValue(i) * e.getValue().doubleValue() - defaultValue;
    }
  }
  return using.make(result);
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> double innerProduct(Vector<M> y) {
  assert (y.length() == data.length);
  if (y instanceof RealVector) {
    final RealVector y2 = (RealVector) y;
    double innerProduct = 0.0;
    for (int i = 0; i < data.length; i++) {
      innerProduct += data[i] * y2.data[i];
    }
    return innerProduct;
  } else if (y.defaultValue().doubleValue() == 0.0) {
    double innerProduct = 0.0;
    for (Map.Entry<Integer, M> e : y.entrySet()) {
      innerProduct += data[e.getKey()] * e.getValue().doubleValue();
    }
    return innerProduct;
  } else {
    double innerProduct = 0.0;
    for (int i = 0; i < data.length; i++) {
      innerProduct += data[i] * y.doubleValue(i);
    }
    return innerProduct;
  }
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> double innerProduct(Vector<M> y) {
  assert (y.length() == data.length);
  if (y instanceof IntVector) {
    final IntVector y2 = (IntVector) y;
    int innerProduct = 0;
    for (int i = 0; i < data.length; i++) {
      innerProduct += data[i] * y2.data[i];
    }
    return innerProduct;
  } else if (y.defaultValue().doubleValue() == 0.0) {
    double innerProduct = 0.0;
    for (Map.Entry<Integer, M> e : y.entrySet()) {
      innerProduct += data[e.getKey()] * e.getValue().doubleValue();
    }
    return innerProduct;
  } else {
    double innerProduct = 0.0;
    for (int i = 0; i < data.length; i++) {
      innerProduct += data[i] * y.doubleValue(i);
    }
    return innerProduct;
  }
}
origin: com.github.monnetproject/bliss.betalm

  public double[] calculateSalience(Vector<Integer> termVec, int l) {
    double[] salience = new double[J];
    for (int j = 0; j < J; j++) {
      final double xDocLength = x[j][l].sum().doubleValue();
      for (int w : x[j][l].keySet()) {
        if (ctTotal[l][w] != 0) {
          salience[j] += termVec.doubleValue(w) * x[j][l].doubleValue(w) / ctTotal[l][w];
        }
      }
      if (xDocLength != 0.0) {
        salience[j] /= xDocLength;
      }
    }
    // print(topKwords(salience, 10));
    return salience;
  }
//
origin: com.github.monnetproject/bliss.sparsemath

/**
 * Calculate AA^T where A is this matrix
 *
 * @param outerProduct The matrix to store the result in
 * @return
 */
public void selfOuterProduct(Matrix<N> outerProduct) {
  assert (outerProduct.cols() == m);
  assert (outerProduct.rows() == m);
  for (int i = 0; i < m; i++) {
    for (Map.Entry<Integer, N> e : arr[i].entrySet()) {
      for (int j = 0; j < m; j++) {
        final double v = arr[j].doubleValue(e.getKey()) * e.getValue().doubleValue();
        if (v != 0.0) {
          outerProduct.add(i, j, v);
        }
      }
    }
  }
}
origin: com.github.monnetproject/bliss.sparsemath

/**
 * Calculate A^TA where A is this matrix
 *
 * @param innerProduct The matrix to store the result in
 * @return
 */
public void selfInnerProduct(Matrix<N> innerProduct) {
  assert (innerProduct.cols() == n);
  assert (innerProduct.rows() == n);
  for (int k = 0; k < n; k++) {
    for (Map.Entry<Integer, N> e : arr[k].entrySet()) {
      final int j = e.getKey();
      for (int i = 0; i < n; i++) {
        final double v = arr[k].doubleValue(i) * e.getValue().doubleValue();
        if (v != 0) {
          innerProduct.add(i, j, v);
        }
      }
    }
  }
}
origin: com.github.monnetproject/bliss.betalm

public static double dfDiceCoefficient(Vector<Integer> vec1, Vector<Integer> vec2, Vector<Double> df, final StopWordList stopWordList) {
  double num = 0.0, denom = 0.0;
  for (Integer i : vec1.keySet()) {
    if (stopWordList.contains(i)) {
      continue;
    }
    if (i >= df.size()) {
      continue;
    }
    if (vec2.containsKey(i)) {
      num += (1.0 - df.doubleValue(i));
    }
    denom += (1.0 - df.doubleValue(i));
  }
  for (int i : vec2.keySet()) {
    if (stopWordList.contains(i)) {
      continue;
    }
    if (i >= df.size()) {
      continue;
    }
    denom += (1.0 - df.doubleValue(i));
  }
  return denom == 0.0 ? 0.0 : (2.0 * num / denom);
}
origin: com.github.monnetproject/bliss.sparsemath

/**
 * Compute the householder vector of a given vector
 *
 * Complexity: O(sparsity(n))
 *
 * @return A vector with v(1) = 1 and (I - 2vv^T /v^Tv)x is zero in all but
 * first component
 */
public static Vector<Double> house(Vector<Double> x, int j) {
  final int n = x.length();
  double mu = 0.0;
  final double[] x2 = x.toDoubleArray();
  for (int i = j; i < n; i++) {
    mu += x2[i] * x2[i];
  }
  mu = Math.sqrt(mu);
  final Vector<Double> v = x.clone();
  if (mu != 0.0) {
    final double beta = x.doubleValue(0) + Math.signum(x.doubleValue(0)) * mu;
    for (int i = 1; i < v.length(); i++) {
      v.divide(i, beta);
    }
  }
  v.put(0, 1);
  return v;
}
origin: com.github.monnetproject/bliss.sparsemath

public static Vector<Double> solveT(SparseMatrix<Double> a, Vector<Double> b) {
  assert (a.cols() == b.length());
  final int N = b.length();
  Vector<Double> y = new SparseRealArray(N);
  for (int i = N - 1; i >= 0; i--) {
    double sum = b.doubleValue(i);
    for (int j = i + 1; j < N; j++) {
      sum -= a.doubleValue(j, i) * y.doubleValue(j);
    }
    y.put(i, sum / a.doubleValue(i, i));
  }
  return y;
}
origin: com.github.monnetproject/bliss.sparsemath

public static Vector<Double> solve(SparseMatrix<Double> a, Vector<Double> b) {
  assert (a.cols() == b.length());
  final int N = b.length();
  Vector<Double> y = new SparseRealArray(N);
  for (int i = 0; i < N; i++) {
    double sum = b.doubleValue(i);
    for (int j = 0; j < i; j++) {
      sum -= a.doubleValue(i, j) * y.doubleValue(j);
    }
    y.put(i, sum / a.doubleValue(i, i));
  }
  return y;
}
origin: com.github.monnetproject/bliss.sparsemath

public static void chol(SparseMatrix<Double> l, int k, int i, SparseMatrix<Double> a) throws IllegalArgumentException {
  double sum = 0;
  final Vector<Double> l_k = l.row(k);
  for (int j : l_k.keySet()) {
    sum += l.doubleValue(i, j) * l_k.doubleValue(j);
  }
  double a_ii = a.doubleValue(i, i);
  if (i == k) {
    if (a_ii - sum < 0) {
      throw new IllegalArgumentException("Matrix not positive definite");
    }
    l.set(i, k, Math.sqrt(a_ii - sum));
  } else {
    l.set(i, k, (a.doubleValue(i, k) - sum) / l.doubleValue(k, k));
  }
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
@SuppressWarnings("unchecked")
public <M extends Number, O extends Number> Matrix<O> outerProduct(Vector<M> y, Factory<O> using) {
  if (using == Vectors.AS_INTS) {
    int[][] data2 = new int[data.length][y.length()];
    for (int i = 0; i < data.length; i++) {
      for (int j = 0; j < y.length(); j++) {
        data2[i][j] = data[i] * y.intValue(j);
      }
    }
    return (Matrix<O>) new IntArrayMatrix(data2);
  } else if (using == Vectors.AS_REALS) {
    double[][] data2 = new double[data.length][y.length()];
    for (int i = 0; i < data.length; i++) {
      for (int j = 0; j < y.length(); j++) {
        data2[i][j] = y.doubleValue(j) * data[i];
      }
    }
    return (Matrix<O>) new DoubleArrayMatrix(data2);
  } else {
    final SparseMatrix<O> matrix = new SparseMatrix<O>(data.length, y.length(), using);
    for (int i = 0; i < data.length; i++) {
      for (Map.Entry<Integer, M> e : y.entrySet()) {
        matrix.set(i, e.getKey(), e.getValue().doubleValue() * data[i]);
      }
    }
    return matrix;
  }
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> Matrix<N> product(Matrix<M> B) {
  if (this.cols() != B.rows()) {
    throw new IllegalArgumentException("Matrix dimensions not suitable for product");
  }
  if (defaultValue != 0.0 || (B instanceof SparseMatrix && ((SparseMatrix) B).defaultValue != 0.0)) {
    throw new UnsupportedOperationException();
  }
  Vector<N>[] res = new Vector[this.rows()];
  for (int i = 0; i < this.rows(); i++) {
    res[i] = using.make(B.cols(), 0.0);
    for (int j : this.arr[i].keySet()) {
      final Vector<M> r = B.row(j);
      for (int k : r.keySet()) {
        res[i].add(k, this.arr[i].doubleValue(j) * B.doubleValue(j, k));
      }
    }
  }
  return new SparseMatrix<N>(this.rows(), res, using);
}
origin: com.github.monnetproject/bliss.sparsemath

  @Override
  public Vector<Double> apply(Vector<Double> v) {
    double[] mid = new double[W];
    int n = 0;
    IntIterator data = corpus.iterator();
    while (data.hasNext()) {
      int i = data.nextInt();
      if (i != 0) {
        mid[i - 1] += v.doubleValue(n);
      } else {
        n++;
      }
    }
    n = 0;
    double[] a = new double[v.length()];
    data = corpus.iterator();
    while (data.hasNext()) {
      int i = data.nextInt();
      if (i != 0) {
        a[n] += mid[i - 1];
      } else {
        n++;
      }
    }
    return new RealVector(a);
  }
}
eu.monnetproject.math.sparseVectordoubleValue

Javadoc

The value at the given index. Note the default value will be returned at sparse indexes

Popular methods of Vector

  • entrySet
    Get all non-sparse values in the array
  • sum
    Get the sum of all the values in this vector
  • add
    Add a vector to this vector. This will automatically remove an element if it results in the value at
  • containsKey
    Is the following index in range and with non-default value
  • divide
    Divide a value by a value in the sparse array. This will automatically remove an element if it resul
  • keySet
    Get the set of indices with non-default value
  • length
    Get the length (i.e., number of sparse and non-sparse values) of the array
  • size
    Get the number of non-sparse values in the array
  • value
    The value at the given index. Note the default value will be returned at sparse indexes
  • clone
    Creates a copy of this vector
  • defaultValue
    Get the default value of the array
  • factory
    The factory for making more of this type of vector
  • defaultValue,
  • factory,
  • innerProduct,
  • intValue,
  • multiply,
  • norm,
  • outerProduct,
  • put,
  • sub

Popular in Java

  • Reading from database using SQL prepared statement
  • getApplicationContext (Context)
  • setContentView (Activity)
  • getSharedPreferences (Context)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • BufferedReader (java.io)
    Reads text from a character-input stream, buffering characters so as to provide for the efficient re
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • JOptionPane (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now