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


Java Transforms.exp方法代码示例

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


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

示例1: fetchCopyRatioMaxLikelihoodEstimateData

import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
/**
 * Fetches the maximum likelihood estimate of copy ratios and their precisions from compute blocks.
 * The result is output as a pair of target-by-sample matrices.
 *
 * @param logScale if true, the max likelihood estimate is reported in natural log scale
 * @return a pair of {@link INDArray}
 */
private ImmutablePair<INDArray, INDArray> fetchCopyRatioMaxLikelihoodEstimateData(final boolean logScale) {
    final INDArray M_Psi_inv_st = fetchFromWorkers(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.M_Psi_inv_st, 1);
    final INDArray log_n_st = fetchFromWorkers(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.log_n_st, 1);
    final INDArray m_t = fetchFromWorkers(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.m_t, 1);

    /* calculate the required quantities */
    final INDArray copyRatioMaxLikelihoodEstimate;
    if (biasCovariatesEnabled) {
        final INDArray Wz_st = fetchFromWorkers(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.Wz_st, 1);
        copyRatioMaxLikelihoodEstimate = log_n_st.sub(Wz_st).subiRowVector(m_t).subiColumnVector(sampleMeanLogReadDepths);
    } else {
        copyRatioMaxLikelihoodEstimate = log_n_st.subRowVector(m_t).subiColumnVector(sampleMeanLogReadDepths);
    }

    if (!logScale) {
        Transforms.exp(copyRatioMaxLikelihoodEstimate, false);
    }

    return ImmutablePair.of(copyRatioMaxLikelihoodEstimate.transpose(), M_Psi_inv_st.transpose());
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:28,代码来源:CoverageModelEMWorkspace.java

示例2: getCopyRatioSegmentsLocal

import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
private List<List<HiddenStateSegmentRecord<STATE, Target>>> getCopyRatioSegmentsLocal() {
    final List<List<CoverageModelCopyRatioEmissionData>> copyRatioEmissionData = fetchCopyRatioEmissionDataLocal();
    final INDArray sampleReadDepths = Transforms.exp(sampleMeanLogReadDepths, true);
    return sampleIndexStream()
            .mapToObj(si -> {
                final CopyRatioCallingMetadata metadata = CopyRatioCallingMetadata.builder()
                        .sampleName(processedSampleNameList.get(si))
                        .sampleSexGenotypeData(processedSampleSexGenotypeData.get(si))
                        .sampleCoverageDepth(sampleReadDepths.getDouble(si))
                        .emissionCalculationStrategy(EmissionCalculationStrategy.HYBRID_POISSON_GAUSSIAN)
                        .build();
                return copyRatioExpectationsCalculator.getCopyRatioHMMResults(metadata,
                        processedTargetList, copyRatioEmissionData.get(si));
            })
            /* segment each sample individually */
            .map(result -> {
                final HMMSegmentProcessor<CoverageModelCopyRatioEmissionData, STATE, Target> processor =
                        new HMMSegmentProcessor<>(
                                Collections.singletonList(result.getMetaData().getSampleName()),
                                Collections.singletonList(result.getMetaData().getSampleSexGenotypeData()),
                                referenceStateFactory,
                                Collections.singletonList(new HashedListTargetCollection<>(processedTargetList)),
                                Collections.singletonList(result.getForwardBackwardResult()),
                                Collections.singletonList(result.getViterbiResult()));
                return processor.getSegmentsAsList();
            })
            .collect(Collectors.toList());
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:29,代码来源:CoverageModelEMWorkspace.java

示例3: testExp

import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
@Test
public void testExp() {
    INDArray n = Nd4j.create(new float[]{1, 2, 3, 4});
    INDArray assertion = Nd4j.create(new float[]{2.71828183f, 7.3890561f, 20.08553692f, 54.59815003f});
    INDArray exped = Transforms.exp(n);
    assertEquals(assertion,exped);
}
 
开发者ID:wlin12,项目名称:JNN,代码行数:8,代码来源:NDArrayTests.java

示例4: testExp

import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
@Test
public void testExp() {
    INDArray n = Nd4j.create(new double[] {1, 2, 3, 4});
    INDArray assertion = Nd4j.create(new double[] {2.71828183f, 7.3890561f, 20.08553692f, 54.59815003f});
    INDArray exped = Transforms.exp(n);
    assertEquals(assertion, exped);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:8,代码来源:Nd4jTestsC.java

示例5: sample

import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
/**
 * sample a sequence of integers from the model
 * h is memory state, seed_ix is seed letter for first time step
 * @param h
 * @param seedIdx
 * @param n
 * @return
 */
private int[] sample(INDArray h, int seedIdx, int n) {

    // Use a seed character to start the sampling from
    INDArray x =  oneHotEncoding(seedIdx);
    int[] ixes = new int[n];

    // Do forward pass
    for (int t = 0; t < n; t++) {
        // Input to hidden
        INDArray dot1 = Wxh.mmul(x);
        // Hidden layer to hidden
        INDArray dot2 = Whh.mmul(h).add(bh);
        // Hidden state step, squash with tanh to -1 to 1
        h = Transforms.tanh(dot1.add(dot2));

        // Output - Y
        // Dot product between weights from h to y and hidden state, plus bias
        INDArray y = Why.mmul(h).add(by);

        // Normalised Probabilities - P
        INDArray exp = Transforms.exp(y);
        INDArray cumExp = Nd4j.sum(exp);
        INDArray p = exp.div(cumExp);

        int[] to_select = new int[vocabSize];
        for (int i = 0; i < vocabSize; i++){
            to_select[i] = i;
        }

        // Given the probabilities of the characters, pick "random characters" to generate the text
        int idx = randChoice(to_select, p);

        // Next character in the sequence
        x = oneHotEncoding(idx);
        // Store the chosen character
        ixes[t] = idx;
    }

    return ixes;
}
 
开发者ID:guilherme-pombo,项目名称:JavaRNN,代码行数:49,代码来源:CharRNN.java

示例6: map

import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
@Override
public NDArrayWritable map(Writable w) {
    NDArrayWritable n = (NDArrayWritable) w;
    INDArray i = n.get();
    if (i == null) {
        return n;
    }

    NDArrayWritable o;
    switch (mathFunction) {
        case ABS:
            o = new NDArrayWritable(Transforms.abs(i, DUP));
            break;
        case ACOS:
            o = new NDArrayWritable(Transforms.acos(i, DUP));
            break;
        case ASIN:
            o = new NDArrayWritable(Transforms.asin(i, DUP));
            break;
        case ATAN:
            o = new NDArrayWritable(Transforms.atan(i, DUP));
            break;
        case CEIL:
            o = new NDArrayWritable(Transforms.ceil(i, DUP));
            break;
        case COS:
            o = new NDArrayWritable(Transforms.cos(i, DUP));
            break;
        case COSH:
            //No cosh operation in ND4J
            throw new UnsupportedOperationException("sinh operation not yet supported for NDArray columns");
        case EXP:
            o = new NDArrayWritable(Transforms.exp(i, DUP));
            break;
        case FLOOR:
            o = new NDArrayWritable(Transforms.floor(i, DUP));
            break;
        case LOG:
            o = new NDArrayWritable(Transforms.log(i, DUP));
            break;
        case LOG10:
            o = new NDArrayWritable(Transforms.log(i, 10.0, DUP));
            break;
        case SIGNUM:
            o = new NDArrayWritable(Transforms.sign(i, DUP));
            break;
        case SIN:
            o = new NDArrayWritable(Transforms.sin(i, DUP));
            break;
        case SINH:
            //No sinh op in ND4J
            throw new UnsupportedOperationException("sinh operation not yet supported for NDArray columns");
        case SQRT:
            o = new NDArrayWritable(Transforms.sqrt(i, DUP));
            break;
        case TAN:
            //No tan op in ND4J yet - but tan(x) = sin(x)/cos(x)
            INDArray sinx = Transforms.sin(i, true);
            INDArray cosx = Transforms.cos(i, true);
            o = new NDArrayWritable(sinx.divi(cosx));
            break;
        case TANH:
            o = new NDArrayWritable(Transforms.tanh(i, DUP));
            break;
        default:
            throw new RuntimeException("Unknown function: " + mathFunction);
    }

    //To avoid threading issues...
    Nd4j.getExecutioner().commit();

    return o;

}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:75,代码来源:NDArrayMathFunctionTransform.java

示例7: updateCopyRatioPosteriorExpectationsLocal

import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
/**
 * Local implementation of the E-step update of copy ratio posteriors
 *
 * @return a {@link SubroutineSignal} containing the update size (key: "error_norm")
 */
public SubroutineSignal updateCopyRatioPosteriorExpectationsLocal(final double admixingRatio) {
    /* step 1. fetch copy ratio emission data */
    final List<List<CoverageModelCopyRatioEmissionData>> copyRatioEmissionData = fetchCopyRatioEmissionDataLocal();

    /* step 2. run the forward-backward algorithm and calculate copy ratio posteriors */
    final INDArray sampleReadDepths = Transforms.exp(sampleMeanLogReadDepths, true);
    final List<CopyRatioExpectations> copyRatioPosteriorResults = sampleIndexStream()
            .parallel()
            .mapToObj(si -> copyRatioExpectationsCalculator.getCopyRatioPosteriorExpectations(
                    CopyRatioCallingMetadata.builder()
                            .sampleName(processedSampleNameList.get(si))
                            .sampleSexGenotypeData(processedSampleSexGenotypeData.get(si))
                            .sampleCoverageDepth(sampleReadDepths.getDouble(si))
                            .emissionCalculationStrategy(EmissionCalculationStrategy.HYBRID_POISSON_GAUSSIAN)
                            .build(),
                    processedTargetList,
                    copyRatioEmissionData.get(si)))
            .collect(Collectors.toList());

    /* update log chain posterior expectation */
    sampleLogChainPosteriors.assign(Nd4j.create(copyRatioPosteriorResults.stream()
            .mapToDouble(CopyRatioExpectations::getLogChainPosteriorProbability)
            .toArray(), new int[] {numSamples, 1}));

    /* sent the results back to workers */
    final ImmutablePair<INDArray, INDArray> copyRatioPosteriorDataPair =
            convertCopyRatioLatentPosteriorExpectationsToNDArray(copyRatioPosteriorResults);
    final INDArray log_c_st = copyRatioPosteriorDataPair.left;
    final INDArray var_log_c_st = copyRatioPosteriorDataPair.right;

    /* partition the pair of (log_c_st, var_log_c_st), sent the result to workers via broadcast-hash-map */
    pushToWorkers(mapINDArrayPairToBlocks(log_c_st.transpose(), var_log_c_st.transpose()),
            (p, cb) -> cb.cloneWithUpdatedCopyRatioPosteriors(
                    p.get(cb.getTargetSpaceBlock()).left.transpose(),
                    p.get(cb.getTargetSpaceBlock()).right.transpose(),
                    admixingRatio));
    cacheWorkers("after E-step update of copy ratio posteriors");

    /* collect subroutine signals */
    final List<SubroutineSignal> sigs = mapWorkersAndCollect(CoverageModelEMComputeBlock::getLatestMStepSignal);

    final double errorNormInfinity = Collections.max(sigs.stream()
            .map(sig -> sig.<Double>get(StandardSubroutineSignals.RESIDUAL_ERROR_NORM))
            .collect(Collectors.toList()));

    return SubroutineSignal.builder()
            .put(StandardSubroutineSignals.RESIDUAL_ERROR_NORM, errorNormInfinity)
            .build();
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:55,代码来源:CoverageModelEMWorkspace.java

示例8: apply

import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
@Override
public INDArray apply(INDArray input) {
	return Transforms.exp(input.dup());
}
 
开发者ID:wlin12,项目名称:JNN,代码行数:5,代码来源:ExpTransform.java

示例9: extractComponents

import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
public MixtureDensityComponents extractComponents(INDArray output) {
    int outputSize = output.size(1);
    if (outputSize != (mLabelWidth + 2) * mMixtures) {
        throw new IllegalArgumentException(
                        "Network output size " + outputSize + " must be (labels+2)*mixtures where labels = "
                                        + mLabelWidth + " and mixtures = " + mMixtures);
    }

    MixtureDensityComponents mdc = new MixtureDensityComponents();

    // Output is 2 dimensional (samples, labels)
    //
    // For each label vector of length 'labels', we will have
    // an output vector of length '(labels + 2) * nMixtures.
    // The first nMixtures outputs will correspond to the 'alpha' for each mixture.
    // The second nMixtures outputs will correspond to the 'sigma' and the last nMixtures*labels
    // will correspond to the 'mu' (mean) of the output.

    // Reorganize these.
    // alpha = samples, 0 to nMixtures
    // mu = samples, nMixtures to 2*nMixtures
    // sigma = samples, 2*nMixtures to (labels + 2)*nMixtures
    // Alpha is then sub-divided through reshape by mixtures per label and samples.

    mdc.alpha = output.get(NDArrayIndex.all(), NDArrayIndex.interval(0, mMixtures));
    mdc.sigma = output.get(NDArrayIndex.all(), NDArrayIndex.interval(mMixtures, 2 * mMixtures));
    mdc.mu = output.get(NDArrayIndex.all(), NDArrayIndex.interval(2 * mMixtures, (mLabelWidth + 2) * mMixtures))
                    .reshape(output.size(0), mMixtures, mLabelWidth);

    // Alpha is a softmax because
    // the alpha should all sum to 1 for a given gaussian mixture.
    mdc.alpha = Nd4j.getExecutioner().execAndReturn(new OldSoftMax(mdc.alpha));

    // Mu comes directly from the network as an unmolested value.
    // Note that this effectively means that the output layer of
    // the network should have an activation function at least as large as
    // the expected values.  It is best for the output
    // layer to be an IDENTITY activation function.
    //mdc.mu = mdc.mu;

    // Sigma comes from the network as an exponential in order to
    // ensure that it is positive-definite.
    mdc.sigma = Transforms.exp(mdc.sigma);

    return mdc;
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:47,代码来源:LossMixtureDensity.java


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