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


Java MatrixUtils.createRealVector方法代码示例

本文整理汇总了Java中org.apache.commons.math3.linear.MatrixUtils.createRealVector方法的典型用法代码示例。如果您正苦于以下问题:Java MatrixUtils.createRealVector方法的具体用法?Java MatrixUtils.createRealVector怎么用?Java MatrixUtils.createRealVector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.linear.MatrixUtils的用法示例。


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

示例1: makeDataMatrix

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
private RealMatrix makeDataMatrix(List<double[]> X, double[] meanX) {
	if (meanX == null) {
		return makeDataMatrix(X);
	}
	final int m = X.size();
	final int n = X.get(0).length;
	RealMatrix M = MatrixUtils.createRealMatrix(n, m);
	RealVector mean = MatrixUtils.createRealVector(meanX);
	int i = 0;
	for (double[] x : X) {
		RealVector xi = MatrixUtils.createRealVector(x).subtract(mean);
		M.setColumnVector(i, xi);
		i++;
	}
	return M;
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:17,代码来源:ProcrustesFit.java

示例2: getVectorVarByName

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
public List<RealVector> getVectorVarByName(String name) {
    String varName = "V_" + name;
    JsonNode obj = redisService.getValue(spaceIdentifier, varName);
    int size = obj.get("size").asInt();
    int dim = obj.get("dim").asInt();
    double initial = obj.get("initial").asDouble();
    boolean randomize = obj.get("randomize").asBoolean();
    boolean normalize = obj.get("normalize").asBoolean();
    List<RealVector> vars = new ArrayList<>(size);
    for (int i=0; i<size; i++) {
        RealVector var = MatrixUtils.createRealVector(new double[dim]);
        initializeVector(var, initial, randomize, normalize);
        vars.add(var);
    }
    String varIdxName = "IDX_V_" + name + "_";
    List<String> keys = redisService.keysWithPrefixPattern(spaceIdentifier, varIdxName);
    List<JsonNode> values = redisService.bulkGet(keys);
    for (JsonNode one : values) {
        setValue(vars, one, dim);
    }
    return vars;
}
 
开发者ID:grouplens,项目名称:samantha,代码行数:23,代码来源:RedisVariableSpace.java

示例3: ensureVectorVar

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
final public void ensureVectorVar(String name, int size, int dim, double initial,
        boolean randomize, boolean normalize) {
    writeLock.lock();
    try {
        int curSize = vectorVars.get(name).size();
        if (curSize < size) {
            for (int i=curSize; i<size; i++) {
                RealVector vec = MatrixUtils.createRealVector(new double[dim]);
                initializeVector(vec, initial, randomize, normalize);
                vectorVars.get(name).add(vec);
            }
        }
        curSize = readLocks.size();
        SpaceUtilities.fillReadWriteLocks(readLocks, writeLocks, curSize, size);
    } finally {
        writeLock.unlock();
    }
}
 
开发者ID:grouplens,项目名称:samantha,代码行数:19,代码来源:SynchronizedVariableSpace.java

示例4: getStochasticOracle

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
public List<StochasticOracle> getStochasticOracle(List<LearningInstance> instances) {
    List<StochasticOracle> oracles = new ArrayList<>(instances.size());
    for (LearningInstance inIns : instances) {
        SVDFeatureInstance ins = (SVDFeatureInstance) inIns;
        StochasticOracle orc = new StochasticOracle();
        RealVector ufactSum = MatrixUtils.createRealVector(new double[factDim]);
        RealVector ifactSum = MatrixUtils.createRealVector(new double[factDim]);
        double pred = predict(ins, orc, ufactSum, ifactSum);
        RealVector leftGrad = ifactSum;
        RealVector rightGrad = ufactSum;
        for (int i = 0; i < ins.ufeas.size(); i++) {
            orc.addVectorOracle(SVDFeatureKey.FACTORS.get(),
                    ins.ufeas.get(i).getIndex(),
                    leftGrad.mapMultiply(ins.ufeas.get(i).getValue()));
        }
        for (int i = 0; i < ins.ifeas.size(); i++) {
            orc.addVectorOracle(SVDFeatureKey.FACTORS.get(),
                    ins.ifeas.get(i).getIndex(),
                    rightGrad.mapMultiply(ins.ifeas.get(i).getValue()));
        }
        orc.setValues(pred, ins.label, ins.weight);
        oracles.add(orc);
    }
    return oracles;
}
 
开发者ID:grouplens,项目名称:samantha,代码行数:26,代码来源:SVDFeature.java

示例5: realmat2vector

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
public static RealVector realmat2vector(RealMatrix inMatrix, int dimWalk){
    RealVector retVector = null;

    int ncols = inMatrix.getColumnDimension();
    int nrows = inMatrix.getRowDimension();

    switch (dimWalk){
        case 1:
        {
            retVector = MatrixUtils.createRealVector(inMatrix.getRow(0));
            for(int i=1;i<nrows;i++){
                retVector = retVector.append(inMatrix.getRowVector(i));
            }
        }
        default:
        {
            retVector = MatrixUtils.createRealVector(inMatrix.getColumn(0));
            for(int i=1;i<ncols;i++){
                retVector = retVector.append(inMatrix.getColumnVector(i));
            }
        }
    }

    return(retVector);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:SME_ENS_Utils.java

示例6: realmatSelectVector

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
public static RealVector realmatSelectVector(RealMatrix inMatrix,RealMatrix selectMatrix, double valueSelect){
    RealVector retVector = MatrixUtils.createRealVector(new double[0]);

    int ncols = inMatrix.getColumnDimension();
    int nrows = inMatrix.getRowDimension();

    for(int j=0;j<ncols;j++){
        for(int i=0;i<nrows;i++){
                if(inMatrix.getEntry(i,j)==valueSelect) {
                    retVector = retVector.append(selectMatrix.getEntry(i,j));
                }
        }
    }


    return(retVector);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:18,代码来源:SME_ENS_Utils.java

示例7: initStepEnergyOpt

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
public void initStepEnergyOpt(){
    foregroundPixelVal      = MatrixUtils.createRealVector(new double[1]);
    Boolean vecInitialised  = Boolean.FALSE;

    for(int i=0;i<edgeflag2.getRowDimension();i++){
        for(int j=0;j<edgeflag2.getColumnDimension();j++){
            if(edgeflag2.getEntry(i,j)>0){
                if(!vecInitialised){
                    foregroundPixelVal.setEntry(0,idmax.getEntry(i,j));
                    vecInitialised = Boolean.TRUE;
                }else {
                    foregroundPixelVal = foregroundPixelVal.append(idmax.getEntry(i, j));
                }
            }

        }
    }


    KE= foregroundPixelVal.getMaxValue()-foregroundPixelVal.getMinValue()+1;
    step=KE/100;

    //step     = sme_pluginGetManifold.getStack1().getSize()/(double)stepNumber;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:25,代码来源:SME_ENS_EnergyOptimisation.java

示例8: ProjectiveMapping

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
/**
 * Constructor for more than 4 point pairs, finds a least-squares solution
 * for the homography parameters.
 * NOTE: this is UNFINISHED code!
 * @param P sequence of points (source)
 * @param Q sequence of points (target)
 * @param dummy unused (only to avoid duplicate signature)
 */
public ProjectiveMapping(Point2D[] P, Point2D[] Q, boolean dummy) {
	final int n = P.length;
	double[] ba = new double[2 * n];
	double[][] Ma = new double[2 * n][];
	for (int i = 0; i < n; i++) {
		double x = P[i].getX();
		double y = P[i].getY();
		double u = Q[i].getX();
		double v = Q[i].getY();
		ba[2 * i + 0] = u;
		ba[2 * i + 1] = v;
		Ma[2 * i + 0] = new double[] { x, y, 1, 0, 0, 0, -u * x, -u * y };
		Ma[2 * i + 1] = new double[] { 0, 0, 0, x, y, 1, -v * x, -v * y };
	}
	
	RealMatrix M = MatrixUtils.createRealMatrix(Ma);
	RealVector b = MatrixUtils.createRealVector(ba);
	DecompositionSolver solver = new SingularValueDecomposition(M).getSolver();
	RealVector h = solver.solve(b);
	a00 = h.getEntry(0);
	a01 = h.getEntry(1);
	a02 = h.getEntry(2);
	a10 = h.getEntry(3);
	a11 = h.getEntry(4);
	a12 = h.getEntry(5);
	a20 = h.getEntry(6);
	a21 = h.getEntry(7);
	a22 = 1;
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:38,代码来源:ProjectiveMapping.java

示例9: solve

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
public static double[] solve(final double[][] A, double[] b) {
	RealMatrix AA = MatrixUtils.createRealMatrix(A);
	RealVector bb = MatrixUtils.createRealVector(b);
	DecompositionSolver solver = new LUDecomposition(AA).getSolver();
	double[] x = null;
	try {
		x = solver.solve(bb).toArray();
	} catch (SingularMatrixException e) {}
	return x;
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:11,代码来源:Matrix.java

示例10: getScalarVarByName

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
public RealVector getScalarVarByName(String name) {
    String varName = "S_" + name;
    JsonNode obj = redisService.getValue(spaceIdentifier, varName);
    String varIdxName = "IDX_S_" + name + "_";
    List<String> keys = redisService.keysWithPrefixPattern(spaceIdentifier, varIdxName);
    int size = obj.get("size").asInt();
    RealVector vars = MatrixUtils.createRealVector(new double[size]);
    initializeVector(vars, obj.get("initial").asDouble(), obj.get("randomize").asBoolean(), false);
    List<JsonNode> values = redisService.bulkGet(keys);
    for (JsonNode one : values) {
        vars.setEntry(one.get(0).asInt(), one.get(1).asDouble());
    }
    return vars;
}
 
开发者ID:grouplens,项目名称:samantha,代码行数:15,代码来源:RedisVariableSpace.java

示例11: getState

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
private RealVector getState(IndexedVectorModel stateModel, ObjectNode state) {
    String stateKey = getStateKey(state);
    RealVector curVal;
    if (stateModel.hasKey(stateKey)) {
        curVal = stateModel.getKeyVector(stateKey);
    } else {
        curVal = MatrixUtils.createRealVector(new double[actionAttrs.size() + 1]);
    }
    return curVal;
}
 
开发者ID:grouplens,项目名称:samantha,代码行数:11,代码来源:SimpleAverageUserState.java

示例12: getActionStateValue

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
private RealVector getActionStateValue(ObjectNode action) {
    RealVector vec = MatrixUtils.createRealVector(new double[actionAttrs.size()]);
    for (int i=0; i< actionAttrs.size(); i++) {
        vec.setEntry(i, action.get(actionAttrs.get(i)).asDouble());
    }
    return vec;
}
 
开发者ID:grouplens,项目名称:samantha,代码行数:8,代码来源:SimpleAverageUserState.java

示例13: getStateValue

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
private RealVector getStateValue(ObjectNode state) {
    RealVector vec = MatrixUtils.createRealVector(new double[actionAttrs.size() + 1]);
    double cnt = state.get(modelName + "-state-cnt").asDouble();
    vec.setEntry(0, cnt);
    for (int i=0; i< actionAttrs.size(); i++) {
        vec.setEntry(i + 1, state.get("state-" + actionAttrs.get(i)).asDouble() * cnt);
    }
    return vec;
}
 
开发者ID:grouplens,项目名称:samantha,代码行数:10,代码来源:SimpleAverageUserState.java

示例14: requestVectorVar

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
final public void requestVectorVar(String name, int size, int dim, double initial,
                                   boolean randomize, boolean normalize) {
    List<RealVector> var = new ArrayList<>(size);
    for (int i=0; i<size; i++) {
        RealVector vec = MatrixUtils.createRealVector(new double[dim]);
        initializeVector(vec, initial, randomize, normalize);
        var.add(vec);
    }
    writeLock.lock();
    try {
        vectorVars.put(name, var);
    } finally {
        writeLock.unlock();
    }
}
 
开发者ID:grouplens,项目名称:samantha,代码行数:16,代码来源:SynchronizedVariableSpace.java

示例15: getScalarVarByName

import org.apache.commons.math3.linear.MatrixUtils; //导入方法依赖的package包/类
final public RealVector getScalarVarByName(String name) {
    readLock.lock();
    try {
        DoubleList var = scalarVars.get(name);
        double[] newVar = new double[var.size()];
        setDoubleList(newVar, var);
        return MatrixUtils.createRealVector(newVar);
    } finally {
        readLock.unlock();
    }
}
 
开发者ID:grouplens,项目名称:samantha,代码行数:12,代码来源:SynchronizedVariableSpace.java


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