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

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

Best Java code snippets using eu.monnetproject.math.sparse.Vector.length (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 int length() {
  return v.length();
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> void sub(Vector<M> vector) {
  assert (vector.length() == data.length);
  if (vector instanceof IntVector) {
    final int[] data2 = ((IntVector) vector).data;
    for (int i = 0; i < data.length; i++) {
      data[i] -= data2[i];
    }
  } else {
    for (Map.Entry<Integer, M> e : vector.entrySet()) {
      data[e.getKey()] -= e.getValue().intValue();
    }
  }
}
origin: com.github.monnetproject/bliss.sparsemath

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

@Override
public <M extends Number> void add(Vector<M> vector) {
  assert (vector.length() == data.length);
  if (vector instanceof IntVector) {
    final int[] data2 = ((IntVector) vector).data;
    for (int i = 0; i < data.length; i++) {
      data[i] += data2[i];
    }
  } else {
    for (Map.Entry<Integer, M> e : vector.entrySet()) {
      data[e.getKey()] += e.getValue().intValue();
    }
  }
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> void sub(Vector<M> vector) {
  assert (vector.length() == data.length);
  if (vector instanceof RealVector) {
    final double[] data2 = ((RealVector) vector).data;
    for (int i = 0; i < data.length; i++) {
      data[i] -= data2[i];
    }
  } else {
    for (Map.Entry<Integer, M> e : vector.entrySet()) {
      data[e.getKey()] -= e.getValue().doubleValue();
    }
  }
}
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> void sub(Vector<M> vector) {
  assert (vector.length() == n);
  for (Map.Entry<Integer, M> e : vector.entrySet()) {
    sub(e.getKey(), e.getValue().intValue());
  }
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> void add(Vector<M> vector) {
  assert (vector.length() == n);
  for (Map.Entry<Integer, M> e : vector.entrySet()) {
    add(e.getKey(), e.getValue().doubleValue());
  }
}
origin: com.github.monnetproject/bliss.sparsemath

@Override
public <M extends Number> void sub(Vector<M> vector) {
  assert (vector.length() == n);
  for (Map.Entry<Integer, M> e : vector.entrySet()) {
    sub(e.getKey(), e.getValue().doubleValue());
  }
}
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> void add(Vector<M> vector) {
  assert (vector.length() == n);
  for (Map.Entry<Integer, M> e : vector.entrySet()) {
    add(e.getKey(), e.getValue().intValue());
  }
}
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 static double rogersTanimoto(Vector<Integer> vec1, Vector<Integer> vec2, final StopWordList stopWordList) {
  final int N = vec1.length();
  assert (vec2.length() == vec1.length());
  int diff = 0;
  for (Integer i : vec1.keySet()) {
    if (stopWordList.contains(i)) {
      continue;
    }
    if (!vec2.containsKey(i)) {
      diff++;
    }
  }
  for (Integer i : vec2.keySet()) {
    if (stopWordList.contains(i)) {
      continue;
    }
    if (!vec1.containsKey(i)) {
      diff++;
    }
  }
  return (double) (N - diff) / (double) (N + diff);
}
origin: com.github.monnetproject/bliss.betalm

public static Vector<Integer> filter(final IntSet salients, final Vector<Integer> source) {
  final SparseIntArray filtered = new SparseIntArray(source.length());
  for (int i : salients) {
    filtered.add(i, source.value(i));
  }
  return filtered;
}

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() == n);
  double[] product = new double[m];
  if (x instanceof RealVector) {
    final double[] x2 = ((RealVector) x).data();
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        product[i] += data[i][j] * x2[j];
      }
    }
  } else if (x instanceof IntVector) {
    final int[] x2 = ((IntVector) x).data();
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        product[i] += data[i][j] * x2[j];
      }
    }
  } else {
    for (int i = 0; i < m; i++) {
      for (Map.Entry<Integer, M> e : x.entrySet()) {
        product[i] += data[i][e.getKey()] * e.getValue().doubleValue();
      }
    }
  }
  return using.make(product);
}
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

@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 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.sparseVectorlength

Javadoc

Get the length (i.e., number of sparse and non-sparse values) of the array

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
  • doubleValue
    The value at the given index. Note the default value will be returned at sparse indexes
  • keySet
    Get the set of indices with non-default value
  • 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

  • Running tasks concurrently on multiple threads
  • getSupportFragmentManager (FragmentActivity)
  • startActivity (Activity)
  • addToBackStack (FragmentTransaction)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Runner (org.openjdk.jmh.runner)
  • Option (scala)
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