Example usage for org.apache.commons.math3.linear ArrayRealVector getDataRef

List of usage examples for org.apache.commons.math3.linear ArrayRealVector getDataRef

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear ArrayRealVector getDataRef.

Prototype

public double[] getDataRef() 

Source Link

Document

Get a reference to the underlying data array.

Usage

From source file:automenta.vivisect.dimensionalize.HyperassociativeMap.java

public static void add(ArrayRealVector target, ArrayRealVector add) {
    double[] a = add.getDataRef();
    double[] t = target.getDataRef();
    int dim = t.length;
    for (int i = 0; i < dim; i++) {
        t[i] += a[i];/*w w  w . jav a 2 s .  c  om*/
    }
}

From source file:automenta.vivisect.dimensionalize.HyperassociativeMap.java

public static void sub(ArrayRealVector target, ArrayRealVector add) {
    double[] a = add.getDataRef();
    double[] t = target.getDataRef();
    int dim = t.length;
    for (int i = 0; i < dim; i++) {
        t[i] -= a[i];/* ww  w  .ja v a2s.  c  o m*/
    }
}

From source file:automenta.vivisect.dimensionalize.HyperassociativeMap.java

public static void add(ArrayRealVector target, ArrayRealVector add, double factor) {
    if (factor == 0)
        return;/*from   w ww .jav  a 2 s  .com*/

    double[] a = add.getDataRef();
    double[] t = target.getDataRef();
    int dim = t.length;
    for (int i = 0; i < dim; i++) {
        t[i] += a[i] * factor;
    }
}

From source file:hivemall.anomaly.ChangeFinder2D.java

@Nonnull
private ArrayRealVector parseX(final Object arg) throws UDFArgumentException {
    ArrayRealVector xVec = xRing.head();
    if (xVec == null) {
        double[] data = HiveUtils.asDoubleArray(arg, listOI, elemOI);
        if (data.length == 0) {
            throw new UDFArgumentException("Dimension of x SHOULD be more than zero");
        }/*  ww  w .  ja  v  a  2  s  .  c  o m*/
        xVec = new ArrayRealVector(data, false);
    } else {
        double[] ref = xVec.getDataRef();
        HiveUtils.toDoubleArray(arg, listOI, elemOI, ref, 0.d);
    }
    return xVec;
}

From source file:gamlss.distributions.NO.java

/** Calculates initial value of sigma.
 * @param y - vector of values of response variable
 * @return vector of initial values of sigma
 *///from w  ww  .  j  a  v  a  2s.  c  o  m
private ArrayRealVector setSigmaInitial(final ArrayRealVector y) {
    tempV = new ArrayRealVector(y.getDimension());
    final double ySD = new StandardDeviation().evaluate(y.getDataRef());
    tempV.set(ySD);
    return tempV;

}

From source file:gamlss.distributions.NO.java

/**  Calculates initial value of mu, by assumption these values lie
between observed data and the trend line.
 * @param y - vector of values of response variable
 * @return vector of initial values of mu
 *//*from   w ww.j av a2  s  .  c o  m*/
private ArrayRealVector setMuInitial(final ArrayRealVector y) {
    size = y.getDimension();
    double[] out = new double[size];
    final double yMean = new Mean().evaluate(y.getDataRef());
    for (int i = 0; i < size; i++) {
        out[i] = (y.getEntry(i) + yMean) / 2;
    }
    return new ArrayRealVector(out, false);
}

From source file:gamlss.distributions.GA.java

/**  Calculates initial value of mu, by assumption these
  * values lie between observed data and the trend line.
 * @param y - vector of values of response variable
 * @return  a vector of initial values of mu
 *//*  w  w  w  .j av a2s.com*/
private ArrayRealVector setMuInitial(final ArrayRealVector y) {
    //mu.initial = expression({mu <- (y+mean(y))/2})
    size = y.getDimension();
    double[] out = new double[size];
    Mean mean = new Mean();
    double yMean = mean.evaluate(y.getDataRef());
    for (int i = 0; i < size; i++) {
        out[i] = (y.getEntry(i) + yMean) / 2;
    }
    return new ArrayRealVector(out, false);
}

From source file:automenta.vivisect.dimensionalize.HyperassociativeMap.java

private ArrayRealVector getThePosition(V n, ArrayRealVector v) {
    getPosition(n, v.getDataRef());
    return (ArrayRealVector) v.mapMultiply(1.0 / scale);
}

From source file:automenta.vivisect.dimensionalize.HyperassociativeMap.java

public double magnitude(ArrayRealVector x) {
    return distanceFunction.getDistance(zero, x.getDataRef());
}

From source file:nars.concept.util.BeliefClusterer.java

/**
 * Get a random point from the {@link Cluster} with the largest distance variance.
 *
 * @param clusters the {@link Cluster}s to search
 * @return a random point from the selected cluster
 * @throws ConvergenceException if clusters are all empty
 *///from w  w w.  j  av  a 2s  .c o m
@NotNull
private ArrayRealVector getPointFromLargestVarianceCluster(@NotNull final Collection<Cluster> clusters)
        throws ConvergenceException {

    double maxVariance = Double.NEGATIVE_INFINITY;
    Cluster selected = null;
    for (final Cluster cluster : clusters) {
        if (!cluster.getPoints().isEmpty()) {

            // compute the distance variance of the current cluster
            final ArrayRealVector center = cluster.pos;
            final Variance stat = new Variance();
            for (final T point : cluster.getPoints()) {
                stat.increment(distance(point, center.getDataRef()));
            }
            final double variance = stat.getResult();

            // select the cluster with the largest variance
            if (variance > maxVariance) {
                maxVariance = variance;
                selected = cluster;
            }

        }
    }

    // did we find at least one non-empty cluster ?
    if (selected == null) {
        throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS);
    }

    // extract a random point from the cluster
    final List<T> selectedPoints = selected.getPoints();
    return p(selectedPoints.remove(random.nextInt(selectedPoints.size())));

}