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


Java ArrayRealVector类代码示例

本文整理汇总了Java中org.apache.commons.math.linear.ArrayRealVector的典型用法代码示例。如果您正苦于以下问题:Java ArrayRealVector类的具体用法?Java ArrayRealVector怎么用?Java ArrayRealVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createAvgProductVector

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
public double[] createAvgProductVector(List<Long> recentitemInteractions,Map<Long,float[]> productFeatures)
  {
  	int numLatentFactors = productFeatures.values().iterator().next().length;
  	double[] userFeatures = new double[numLatentFactors];
  	for (Long item : recentitemInteractions) 
{
  		float[] productFactors = productFeatures.get(item);
  		if (productFactors != null)
  		{
  			for (int feature = 0; feature < numLatentFactors; feature++) 
  			{
  				userFeatures[feature] += productFactors[feature];
  			}
  		}
}
  	RealVector  userFeaturesAsVector = new ArrayRealVector(userFeatures);
  	RealVector normalised =  userFeaturesAsVector.mapDivide(userFeaturesAsVector.getL1Norm());

  	return normalised.getData();
  }
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:21,代码来源:RecentMfRecommender.java

示例2: StarTreeTraces

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
public StarTreeTraces(RealVector state, RealMatrix conditionalNonsynonymous, RealMatrix conditionalSynonymous, RealMatrix unconditionalNonsynonymous, RealMatrix unconditionalSynonymous, double[] coverage, RealMatrix totalBranchLength) {
    checkDimensions(conditionalNonsynonymous, conditionalSynonymous);
    checkDimensions(conditionalNonsynonymous, unconditionalNonsynonymous);
    checkDimensions(conditionalNonsynonymous, unconditionalSynonymous);
    Preconditions.checkArgument(conditionalNonsynonymous.getRowDimension() == state.getDimension());
    Preconditions.checkArgument(conditionalNonsynonymous.getColumnDimension() == coverage.length);
    checkDimensions(conditionalNonsynonymous, totalBranchLength);

    this.conditionalNonsynonymous = conditionalNonsynonymous;
    this.conditionalSynonymous = conditionalSynonymous;
    this.unconditionalNonsynonymous = unconditionalNonsynonymous;
    this.unconditionalSynonymous = unconditionalSynonymous;
    this.state = state;
    this.coverage = new ArrayRealVector(coverage);
    this.totalBranchLength = totalBranchLength;
    this.dNdS = computeDNdSMatrix();
}
 
开发者ID:cmccoy,项目名称:startreerenaissance,代码行数:18,代码来源:StarTreeTraces.java

示例3: equationFromString

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
/**
 * Converts a test string to a {@link LinearConstraint}.
 * Ex: x0 + x1 + x2 + x3 - x12 = 0
 */
private LinearConstraint equationFromString(int numCoefficients, String s) {
    Relationship relationship;
    if (s.contains(">=")) {
        relationship = Relationship.GEQ;
    } else if (s.contains("<=")) {
        relationship = Relationship.LEQ;
    } else if (s.contains("=")) {
        relationship = Relationship.EQ;
    } else {
        throw new IllegalArgumentException();
    }

    String[] equationParts = s.split("[>|<]?=");
    double rhs = Double.parseDouble(equationParts[1].trim());

    RealVector lhs = new ArrayRealVector(numCoefficients);
    String left = equationParts[0].replaceAll(" ?x", "");
    String[] coefficients = left.split(" ");
    for (String coefficient : coefficients) {
        double value = coefficient.charAt(0) == '-' ? -1 : 1;
        int index = Integer.parseInt(coefficient.replaceFirst("[+|-]", "").trim());
        lhs.setEntry(index, value);
    }
    return new LinearConstraint(lhs, relationship, rhs);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:SimplexSolverTest.java

示例4: newSampleData

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
/**
 * Loads model x and y sample data from a flat array of data, overriding any previous sample.
 * Assumes that rows are concatenated with y values first in each row.
 *
 * @param data input data array
 * @param nobs number of observations (rows)
 * @param nvars number of independent variables (columns, not counting y)
 */
public void newSampleData(double[] data, int nobs, int nvars) {
    double[] y = new double[nobs];
    double[][] x = new double[nobs][nvars + 1];
    int pointer = 0;
    for (int i = 0; i < nobs; i++) {
        y[i] = data[pointer++];
        x[i][0] = 1.0d;
        for (int j = 1; j < nvars + 1; j++) {
            x[i][j] = data[pointer++];
        }
    }
    this.X = new Array2DRowRealMatrix(x);
    this.Y = new ArrayRealVector(y);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:AbstractMultipleLinearRegression.java

示例5: MicrosphereInterpolatingFunction

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
/**
 * @param xval the arguments for the interpolation points.
 * {@code xval[i][0]} is the first component of interpolation point
 * {@code i}, {@code xval[i][1]} is the second component, and so on
 * until {@code xval[i][d-1]}, the last component of that interpolation
 * point (where {@code dimension} is thus the dimension of the sampled
 * space).
 * @param yval the values for the interpolation points
 * @param brightnessExponent Brightness dimming factor.
 * @param microsphereElements Number of surface elements of the
 * microsphere.
 * @param rand Unit vector generator for creating the microsphere.
 * @throws DimensionMismatchException if the lengths of {@code yval} and
 * {@code xval} (equal to {@code n}, the number of interpolation points)
 * do not match, or the the arrays {@code xval[0]} ... {@code xval[n]},
 * have lengths different from {@code dimension}.
 * @throws IllegalArgumentException if there are no data (xval null or zero length)
 */
public MicrosphereInterpolatingFunction(double[][] xval,
                                        double[] yval,
                                        int brightnessExponent,
                                        int microsphereElements,
                                        UnitSphereRandomVectorGenerator rand)
    throws DimensionMismatchException, IllegalArgumentException {
    if (xval.length == 0 || xval[0] == null) {
        throw MathRuntimeException.createIllegalArgumentException("no data");
    }

    if (xval.length != yval.length) {
        throw new DimensionMismatchException(xval.length, yval.length);
    }

    dimension = xval[0].length;
    this.brightnessExponent = brightnessExponent;

    // Copy data samples.
    samples = new HashMap<RealVector, Double>(yval.length);
    for (int i = 0; i < xval.length; ++i) {
        final double[] xvalI = xval[i];
        if ( xvalI.length != dimension) {
            throw new DimensionMismatchException(xvalI.length, dimension);
        }

        samples.put(new ArrayRealVector(xvalI), yval[i]);
    }

    microsphere = new ArrayList<MicrosphereSurfaceElement>(microsphereElements);
    // Generate the microsphere, assuming that a fairly large number of
    // randomly generated normals will represent a sphere.
    for (int i = 0; i < microsphereElements; i++) {
        microsphere.add(new MicrosphereSurfaceElement(rand.nextVector()));
    }

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:55,代码来源:MicrosphereInterpolatingFunction.java

示例6: doOptimize

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected RealPointValuePair doOptimize() {
    // Validity checks.
    setup();

    isMinimize = (getGoalType() == GoalType.MINIMIZE);
    currentBest = new ArrayRealVector(getStartPoint());

    final double value = bobyqa();

    return new RealPointValuePair(currentBest.getDataRef(),
                                  isMinimize ? value : -value);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:15,代码来源:BOBYQAOptimizer.java

示例7: testSolve

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
/** test solve */
public void testSolve() {
    DecompositionSolver solver =
        new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver();
    RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
            { 1, 0 }, { 2, -5 }, { 3, 1 }
    });
    RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] {
            { 19, -71 }, { -6, 22 }, { -2, 9 }
    });

    // using RealMatrix
    assertEquals(0, solver.solve(b).subtract(xRef).getNorm(), 1.0e-13);

    // using double[]
    for (int i = 0; i < b.getColumnDimension(); ++i) {
        assertEquals(0,
                     new ArrayRealVector(solver.solve(b.getColumn(i))).subtract(xRef.getColumnVector(i)).getNorm(),
                     1.0e-13);
    }

    // using ArrayRealVector
    for (int i = 0; i < b.getColumnDimension(); ++i) {
        assertEquals(0,
                     solver.solve(b.getColumnVector(i)).subtract(xRef.getColumnVector(i)).getNorm(),
                     1.0e-13);
    }

    // using RealVector with an alternate implementation
    for (int i = 0; i < b.getColumnDimension(); ++i) {
        ArrayRealVectorTest.RealVectorTestImpl v =
            new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i));
        assertEquals(0,
                     solver.solve(v).subtract(xRef.getColumnVector(i)).getNorm(),
                     1.0e-13);
    }

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:39,代码来源:LUSolverTest.java

示例8: getRandomVector

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
static RealVector getRandomVector(RandomData rd, double stddev, int dim)
{
  RealVector vec = new ArrayRealVector(dim);
  for(int i =0;i < dim;++i)
  {
    vec.setEntry(i, rd.nextGaussian(0, stddev));
    
  }
  return vec;
}
 
开发者ID:apache,项目名称:incubator-datafu,代码行数:11,代码来源:LSHTest.java

示例9: testSolve

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
/** test solve */
public void testSolve() {
    DecompositionSolver solver =
        new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare)).getSolver();
    RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
            { 1, 2, 3 }, { 0, -5, 1 }
    });
    RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] {
            { -8.0 / 25.0, -263.0 / 75.0, -29.0 / 75.0 },
            { 19.0 / 25.0,   78.0 / 25.0,  49.0 / 25.0 }
    });

    // using RealMatrix
    assertEquals(0, solver.solve(b).subtract(xRef).getNorm(), normTolerance);

    // using double[]
    for (int i = 0; i < b.getColumnDimension(); ++i) {
        assertEquals(0,
                     new ArrayRealVector(solver.solve(b.getColumn(i))).subtract(xRef.getColumnVector(i)).getNorm(),
                     1.0e-13);
    }

    // using Array2DRowRealMatrix
    for (int i = 0; i < b.getColumnDimension(); ++i) {
        assertEquals(0,
                     solver.solve(b.getColumnVector(i)).subtract(xRef.getColumnVector(i)).getNorm(),
                     1.0e-13);
    }

    // using RealMatrix with an alternate implementation
    for (int i = 0; i < b.getColumnDimension(); ++i) {
        ArrayRealVectorTest.RealVectorTestImpl v =
            new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i));
        assertEquals(0,
                     solver.solve(v).subtract(xRef.getColumnVector(i)).getNorm(),
                     1.0e-13);
    }

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:40,代码来源:SingularValueSolverTest.java

示例10: RepeatingLSH

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
public RepeatingLSH(List<LSH> lshList) throws MathException
{
  super(lshList.get(0).getDim(), lshList.get(0).getRandomGenerator());
  this.lshList = lshList;
  RandomGenerator rg = lshList.get(0).getRandomGenerator();
  RandomData rd = new RandomDataImpl(rg);
  /*
   * Compute a random vector of lshList.size() with each component taken from U(0,10)
   */
  randomVec = new ArrayRealVector(lshList.size());
  for(int i = 0; i < randomVec.getDimension();++i)
  {
    randomVec.setEntry(i, rd.nextUniform(0, 10.0));
  }
}
 
开发者ID:apache,项目名称:incubator-datafu,代码行数:16,代码来源:RepeatingLSH.java

示例11: calculateZID

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
/**
 * Calculates the ZID vector. (Compare the python code).
 * @return the ZID vector
 */
protected RealVector calculateZID() {
	double[] bSubArray = new double[numberOfCoefficients-1];
	double[] aSubArray = new double[numberOfCoefficients-1];

	System.arraycopy(bCoefficients, 1, bSubArray, 0, bSubArray.length);
	System.arraycopy(aCoefficients, 1, aSubArray, 0, aSubArray.length);

	RealVector bVector = new ArrayRealVector(bSubArray);
	RealVector aVector = new ArrayRealVector(aSubArray);

	RealVector zid = bVector.subtract(aVector.mapMultiply(bCoefficients[0]));
	return zid;
}
 
开发者ID:BrainTech,项目名称:svarog,代码行数:18,代码来源:InitialStateCalculator.java

示例12: getObsPoint

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
public RealVector getObsPoint() {
if (hemisphere) {
    return new ArrayRealVector(new double[] { 0, 0, 1 });
} else {
    return new ArrayRealVector(new double[] { 0, 0, -1 });
}
   }
 
开发者ID:langurmonkey,项目名称:celestial-pole-motion,代码行数:8,代码来源:Parameters.java

示例13: newSampleData

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
/**
 * Loads model x and y sample data from a flat array of data, overriding any previous sample.
 * Assumes that rows are concatenated with y values first in each row.
 * 
 * @param data input data array
 * @param nobs number of observations (rows)
 * @param nvars number of independent variables (columns, not counting y)
 */
public void newSampleData(double[] data, int nobs, int nvars) {
    double[] y = new double[nobs];
    double[][] x = new double[nobs][nvars + 1];
    int pointer = 0;
    for (int i = 0; i < nobs; i++) {
        y[i] = data[pointer++];
        x[i][0] = 1.0d;
        for (int j = 1; j < nvars + 1; j++) {
            x[i][j] = data[pointer++];
        }
    }
    this.X = new Array2DRowRealMatrix(x);
    this.Y = new ArrayRealVector(y);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:AbstractMultipleLinearRegression.java

示例14: addCount

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
public Vec addCount(double[] phi, double x)
{        
    counts.add(new ArrayRealVector(phi).mapMultiplyToSelf(x));
    sum += x;
    return this;
}
 
开发者ID:sinantie,项目名称:Generator,代码行数:7,代码来源:SparseVec.java

示例15: wrap

import org.apache.commons.math.linear.ArrayRealVector; //导入依赖的package包/类
/**
 * @param x An OG vector of doubles, not null
 * @return A Commons vector
 */
public static RealVector wrap(final DoubleMatrix1D x) {
  Validate.notNull(x);
  return new ArrayRealVector(x.getData());
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:9,代码来源:CommonsMathWrapper.java


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