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


Java RealVector类代码示例

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


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

示例1: centerKernelMatrix

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
private static RealMatrix
        centerKernelMatrix(final RealMatrix kernelMatrix) {
    // get size of kernelMatrix
    final int n = kernelMatrix.getRowDimension();

    // get mean values for each row/column
    final RealVector columnMeans =
            MatrixFunctions.columnMeans(kernelMatrix);
    final double matrixMean = MatrixFunctions.mean(kernelMatrix);

    RealMatrix centeredKernelMatrix = kernelMatrix.copy();

    for (int k = 0; k < n; k++) {
        centeredKernelMatrix.setRowVector(k,
                centeredKernelMatrix.getRowVector(k).subtract(columnMeans));
        centeredKernelMatrix.setColumnVector(k, centeredKernelMatrix
                .getColumnVector(k).subtract(columnMeans));
    }

    centeredKernelMatrix = centeredKernelMatrix.scalarAdd(matrixMean);

    return centeredKernelMatrix;
}
 
开发者ID:knime,项目名称:knime-activelearning,代码行数:24,代码来源:KNFST.java

示例2: score

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
private NoveltyScores score(final RealMatrix kernelMatrix) {
    // projected test samples:
    final RealMatrix projectionVectors =
            kernelMatrix.transpose().multiply(m_projection);

    // differences to the target value:
    final RealMatrix diff = projectionVectors.subtract(
            MatrixFunctions.ones(kernelMatrix.getColumnDimension(), 1)
                    .scalarMultiply(m_targetPoints.getEntry(0, 0)));

    // distances to the target value:
    final RealVector scoresVector = MatrixFunctions.sqrt(MatrixFunctions
            .rowSums(MatrixFunctions.multiplyElementWise(diff, diff)));

    return new NoveltyScores(scoresVector.toArray(), projectionVectors);
}
 
开发者ID:knime,项目名称:knime-activelearning,代码行数:17,代码来源:OneClassKNFST.java

示例3: unmarshall

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
private RealVector unmarshall(Document doc, int limit) {
    if (!metadata.isBinary()) {
        throw new UnsupportedOperationException("Can't consume non-binary models.");
    }

    try {
        final Binary binary = doc.get(VECTOR_FIELD_NAME, Binary.class);
        final byte[] b = binary.getData();

        if (metadata.getLoaderId().equalsIgnoreCase("legacy")) {
            return BinaryCodecs.legacyUnmarshall(b, limit, metadata.isSparse(), metadata.getDimensions());
        }
        else {
            return BinaryCodecs.unmarshall(b, metadata.isSparse(), metadata.getDimensions());
        }
    }
    catch (Exception e) {
        logger.error("Error unmarshalling vector", e);
    }

    return null;
}
 
开发者ID:Lambda-3,项目名称:Indra,代码行数:23,代码来源:MongoVectorSpace.java

示例4: sim

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
@Override
public double sim(RealVector r1, RealVector r2, boolean sparse) {
    if (r1.getDimension() != r2.getDimension()) {
        return 0;
    }

    double min = 0.0;
    double sum = 0.0;

    for (int i = 0; i < r1.getDimension(); ++i) {
        if (r1.getEntry(i) > r2.getEntry(i)) {
            min += r2.getEntry(i);
        } else {
            min += r1.getEntry(i);
        }
        sum += r1.getEntry(i) + r2.getEntry(i);
    }

    if (sum == 0) {
        return 0;
    }

    double result = 2 * min / sum;
    return Math.abs(result);
}
 
开发者ID:Lambda-3,项目名称:Indra,代码行数:26,代码来源:DiceRelatednessFunction.java

示例5: sim

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
@Override
public double sim(RealVector r1, RealVector r2, boolean sparse) {
    if (r1.getDimension() != r2.getDimension()) {
        return 0;
    }

    double max = 0;
    double tmp;

    for (int i = 0; i < r1.getDimension(); ++i) {
        tmp = Math.abs((r1.getEntry(i) - r2.getEntry(i)));
        max = (tmp > max ? tmp : max);
    }

    double result = 1 / (1 + (max == Double.NaN ? 0 : max));
    return Math.abs(result);
}
 
开发者ID:Lambda-3,项目名称:Indra,代码行数:18,代码来源:ChebyshevRelatednessFunction.java

示例6: sim

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
@Override
public double sim(RealVector r1, RealVector r2, boolean sparse) {
    if (r1.getDimension() != r2.getDimension()) {
        return 0;
    }

    double alpha = 0.99;
    double divergence = 0.0;

    for (int i = 0; i < r1.getDimension(); ++i) {
        if (r1.getEntry(i) > 0.0 && r2.getEntry(i) > 0.0) {
            divergence += r1.getEntry(i) * Math.log(r1.getEntry(i) / ((1 - alpha) * r1.getEntry(i) + alpha * r2.getEntry(i)));
        }
    }

    double result = (1 - (divergence / Math.sqrt(2 * Math.log(2))));
    return Math.abs(result);
}
 
开发者ID:Lambda-3,项目名称:Indra,代码行数:19,代码来源:AlphaSkewRelatednessFunction.java

示例7: sim

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
@Override
public double sim(RealVector r1, RealVector r2, boolean sparse) {
    if (r1.getDimension() != r2.getDimension()) {
        return 0;
    }

    double min = 0.0;
    double max = 0.0;

    for (int i = 0; i <r1.getDimension(); ++i) {
        if (r1.getEntry(i) > r2.getEntry(i)) {
            min +=r2.getEntry(i);
            max += r1.getEntry(i);
        } else {
            min += r1.getEntry(i);
            max += r2.getEntry(i);
        }
    }

    if (max == 0) {
        return 0;
    }

    return Math.abs(min / max);
}
 
开发者ID:Lambda-3,项目名称:Indra,代码行数:26,代码来源:Jaccard2RelatednessFunction.java

示例8: unmarshall

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
/**
 * Vector deserialization.
 */
public static RealVector unmarshall(byte[] bytes, boolean sparse, int dimensions) throws IOException {
    RealVector realVector = !sparse ? new ArrayRealVector(dimensions) : new OpenMapRealVector(dimensions);

    if (!sparse) {
        try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes))) {
            for (int i = 0; i < dimensions; i++) {
                realVector.setEntry(i, dis.readDouble());
            }
        }
    }
    else {
        try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes))) {
            while (true) {
                try {
                    realVector.setEntry(dis.readInt(), dis.readDouble());
                }
                catch (EOFException e) {
                    break;
                }
            }
        }
    }

    return realVector;
}
 
开发者ID:Lambda-3,项目名称:Indra,代码行数:29,代码来源:BinaryCodecs.java

示例9: getRelatedness

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
public Map<String, Double> getRelatedness(String one, List<String> many, boolean translated) {
    List<? extends AnalyzedTerm> analyzedTerms = doAnalyze(one, many);

    Map<String, RealVector> vectors;
    if(translated) {
        vectors = vectorSpace.getTranslatedVectors((List<MutableTranslatedTerm>) analyzedTerms);
    } else {
        vectors = vectorSpace.getVectors((List<AnalyzedTerm>) analyzedTerms);
    }
    Map<String, Double> results = new LinkedHashMap<>();

    RealVector oneVector = vectors.get(one);

    for (String m : many) {
        RealVector mVector = vectors.get(m);
        if (oneVector != null && mVector != null) {
            double score = func.sim(oneVector, mVector, vectorSpace.getMetadata().isSparse());
            results.put(m, score);
        } else {
            results.put(m, 0d);
        }
    }

    return results;
}
 
开发者ID:Lambda-3,项目名称:Indra,代码行数:26,代码来源:RelatednessClient.java

示例10: getVectors

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
@Override
public Map<String, RealVector> getVectors(List<AnalyzedTerm> terms) {
    if (terms == null) {
        throw new IllegalArgumentException("terms can't be null");
    }

    Set<String> allTerms = new HashSet<>();
    terms.forEach(t -> allTerms.addAll(t.getAnalyzedTokens()));

    collectVectors(allTerms, getMetadata().getDimensions());

    Map<String, RealVector> vectors = new HashMap<>();

    for (AnalyzedTerm term : terms) {
        RealVector vector = composeVectors(term.getAnalyzedTokens(), getTermComposer());
        vectors.put(term.getTerm(), vector);
    }

    return vectors;
}
 
开发者ID:Lambda-3,项目名称:Indra,代码行数:21,代码来源:CachedVectorSpace.java

示例11: compose

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
@Override
public RealVector compose(List<RealVector> vectors) {
    logger.trace("Composing {} vectors", vectors.size());

    if (vectors.isEmpty()) {
        return null;
    } else if (vectors.size() == 1) {
        return vectors.get(0);
    } else {
        RealVector sum = vectors.get(0).add(vectors.get(1));
        for (int i = 2; i < vectors.size(); i++) {
            sum = sum.add(vectors.get(i));
        }
        return sum;
    }
}
 
开发者ID:Lambda-3,项目名称:Indra,代码行数:17,代码来源:SumVectorComposer.java

示例12: getComposedTranslatedVectorsTest

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
@Test
public void getComposedTranslatedVectorsTest() {
    IndraAnalyzer ptAnalyzer = new IndraAnalyzer("PT", ModelMetadata.createTranslationVersion(vectorSpace.getMetadata()));
    List<String> terms = Arrays.asList("mãe computador", "pai avaliação");
    List<MutableTranslatedTerm> analyzedTerms = terms.stream().map(t -> new MutableTranslatedTerm(t,
            ptAnalyzer.analyze(t))).collect(Collectors.toList());

    analyzedTerms.get(0).putAnalyzedTranslatedTokens("mãe", Arrays.asList("mother", "mom", "matriarch"));
    analyzedTerms.get(0).putAnalyzedTranslatedTokens("computador", Arrays.asList("machine", "computer"));

    analyzedTerms.get(1).putAnalyzedTranslatedTokens("pai", Arrays.asList("father", "dad", "patriarch"));
    analyzedTerms.get(1).putAnalyzedTranslatedTokens("avaliação", Arrays.asList("test", "evaluation"));

    Map<String, RealVector> vectorPairs = vectorSpace.getTranslatedVectors(analyzedTerms);
    Assert.assertEquals(vectorPairs.size(), 2);

    Assert.assertEquals(vectorPairs.get(terms.get(0)), MockCachedVectorSpace.TWO_VECTOR);
    Assert.assertEquals(vectorPairs.get(terms.get(1)), MockCachedVectorSpace.NEGATIVE_TWO_VECTOR);
}
 
开发者ID:Lambda-3,项目名称:Indra,代码行数:20,代码来源:CachedVectorSpaceTest.java

示例13: MixModel

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
public MixModel(MethyModel tumor, MethyModel normal, RealVector thetas, int nBetas, int MYTHREADS) throws InterruptedException {
	int nFeatures=tumor.getNaRatio().getDimension();
	this.nBetas = nBetas;
	RealVector betas = new ArrayRealVector(nBetas);
	for (int i=0; i<nBetas; i++) {
		betas.setEntry(i,i/(nBetas-1.0));
	}
	mixDens = new RealMatrix[nFeatures];
	ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS);

	for(int i = 0; i < nFeatures; i++) {
		double tumorAlpha = tumor.getAlpha().getEntry(i);
		double tumorBeta = tumor.getBeta().getEntry(i);
		BetaDistribution tumorDist = new BetaDistribution(tumorAlpha,tumorBeta);
		double normalAlpha = normal.getAlpha().getEntry(i);
		double normalBeta = normal.getBeta().getEntry(i);
		BetaDistribution normalDist = new BetaDistribution(normalAlpha,normalBeta);
		Runnable worker = new CalMixDens(tumorDist,normalDist,thetas,betas,nPoints,i,mixDens);
		executor.execute(worker);
	}
	executor.shutdown();
	while (!executor.isTerminated()) {
		Thread.sleep(10000);
	}
}
 
开发者ID:jasminezhoulab,项目名称:CancerLocator,代码行数:26,代码来源:MixModel.java

示例14: makeDataMatrix

import org.apache.commons.math3.linear.RealVector; //导入依赖的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

示例15: compute

import org.apache.commons.math3.linear.RealVector; //导入依赖的package包/类
/**
 * Runs the regression model for the given dependent and independent variables
 * The Y and X variables must be transformed, if necessary, to meet Gauss Markov assumptions
 * @param y     the dependent variable, which may be a transformed version of the raw data
 * @param x     the independent variable(s), which may be a transformed version of the raw data
 */
protected void compute(RealVector y, RealMatrix x) {
    final int n = frame.rows().count();
    final int p = regressors.size() + (hasIntercept() ? 1 : 0);
    final int dfModel = regressors.size();
    final RealMatrix betaMatrix = computeBeta(y, x);
    final RealVector betaCoefficients = betaMatrix.getColumnVector(0);
    final RealVector betaVariance = betaMatrix.getColumnVector(1);
    this.tss = computeTSS(y);
    this.ess = tss - rss;
    this.fValue = (ess / dfModel) / (rss / (n - p));
    this.fValueProbability = 1d - new FDistribution(dfModel, n-p).cumulativeProbability(fValue);
    this.rSquared = 1d - (rss / tss);
    this.rSquaredAdj = 1d - (rss * (n - (hasIntercept() ? 1 : 0))) / (tss * (n - p));
    this.computeParameterStdErrors(betaVariance);
    this.computeParameterSignificance(betaCoefficients);
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:23,代码来源:XDataFrameLeastSquares.java


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