use of org.broadinstitute.hellbender.tools.coveragemodel.linalg.FourierLinearOperatorNDArray in project gatk-protected by broadinstitute.
the class CoverageModelEMWorkspace method getBiasCovariatesRegularizedLinearOperators.
/**
* Returns the pair of (linear operator, preconditioner) invoked in the M-step update of bias
* covariates in w/ regularization
*
* @return a pair of linear operators
*/
@EvaluatesRDD
private ImmutablePair<GeneralLinearOperator<INDArray>, GeneralLinearOperator<INDArray>> getBiasCovariatesRegularizedLinearOperators() {
final INDArray Q_ll, Q_tll, Z_ll;
final GeneralLinearOperator<INDArray> linop, precond;
final FourierLinearOperatorNDArray regularizerFourierLinearOperator = createRegularizerFourierLinearOperator();
switch(config.getWSolverType()) {
case LOCAL:
/* fetch the required INDArrays */
Q_ll = mapWorkersAndReduce(cb -> cb.getINDArrayFromCache(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.sum_Q_ll), INDArray::add).div(numTargets);
Q_tll = fetchFromWorkers(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.Q_tll, 0);
Z_ll = sampleBiasLatentPosteriorSecondMoments.sum(0);
/* instantiate the local implementation of linear operators */
linop = new CoverageModelWLinearOperatorLocal(Q_tll, Z_ll, regularizerFourierLinearOperator);
precond = new CoverageModelWPreconditionerLocal(Q_ll, Z_ll, regularizerFourierLinearOperator, numTargets);
return ImmutablePair.of(linop, precond);
case SPARK:
if (!sparkContextIsAvailable) {
throw new UserException("The Spark W solver is only available in the Spark mode");
}
/* fetch the required INDArrays */
Q_ll = mapWorkersAndReduce(cb -> cb.getINDArrayFromCache(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.sum_Q_ll), INDArray::add).div(numTargets);
Z_ll = sampleBiasLatentPosteriorSecondMoments.sum(0);
/* instantiate the spark implementation of linear operators */
linop = new CoverageModelWLinearOperatorSpark(Z_ll, regularizerFourierLinearOperator, numTargets, ctx, computeRDD, targetBlocks);
precond = new CoverageModelWPreconditionerSpark(Q_ll, Z_ll, regularizerFourierLinearOperator, numTargets, ctx, numTargetBlocks);
return ImmutablePair.of(linop, precond);
default:
throw new IllegalArgumentException("The solver type for M-step update of bias covariates" + " is not properly set");
}
}
use of org.broadinstitute.hellbender.tools.coveragemodel.linalg.FourierLinearOperatorNDArray in project gatk-protected by broadinstitute.
the class CoverageModelEMWorkspace method updateFilteredBiasCovariates.
/**
* This method applies the Fourier filter on a given bias covariates matrix, applies the Fourier filter on it,
* partitions the result, and pushes it to compute block(s)
*
* @param biasCovariates any T x D bias covariates matrix
*/
@UpdatesRDD
private void updateFilteredBiasCovariates(@Nonnull final INDArray biasCovariates) {
final INDArray filteredBiasCovariates = Nd4j.create(biasCovariates.shape());
/* instantiate the Fourier filter */
final FourierLinearOperatorNDArray regularizerFourierLinearOperator = createRegularizerFourierLinearOperator();
/* FFT by resolving W_tl on l */
for (int li = 0; li < numLatents; li++) {
final INDArrayIndex[] slice = { NDArrayIndex.all(), NDArrayIndex.point(li) };
filteredBiasCovariates.get(slice).assign(regularizerFourierLinearOperator.operate(biasCovariates.get(slice)));
}
/* sent the new W to workers */
switch(config.getBiasCovariatesComputeNodeCommunicationPolicy()) {
case BROADCAST_HASH_JOIN:
pushToWorkers(mapINDArrayToBlocks(filteredBiasCovariates), (W, cb) -> cb.cloneWithUpdatedPrimitive(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.F_W_tl, W.get(cb.getTargetSpaceBlock())));
break;
case RDD_JOIN:
joinWithWorkersAndMap(chopINDArrayToBlocks(filteredBiasCovariates), p -> p._1.cloneWithUpdatedPrimitive(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.F_W_tl, p._2));
break;
}
}
use of org.broadinstitute.hellbender.tools.coveragemodel.linalg.FourierLinearOperatorNDArray in project gatk by broadinstitute.
the class CoverageModelEMWorkspace method updateFilteredBiasCovariates.
/**
* This method applies the Fourier filter on a given bias covariates matrix, applies the Fourier filter on it,
* partitions the result, and pushes it to compute block(s)
*
* @param biasCovariates any T x D bias covariates matrix
*/
@UpdatesRDD
private void updateFilteredBiasCovariates(@Nonnull final INDArray biasCovariates) {
final INDArray filteredBiasCovariates = Nd4j.create(biasCovariates.shape());
/* instantiate the Fourier filter */
final FourierLinearOperatorNDArray regularizerFourierLinearOperator = createRegularizerFourierLinearOperator();
/* FFT by resolving W_tl on l */
for (int li = 0; li < numLatents; li++) {
final INDArrayIndex[] slice = { NDArrayIndex.all(), NDArrayIndex.point(li) };
filteredBiasCovariates.get(slice).assign(regularizerFourierLinearOperator.operate(biasCovariates.get(slice)));
}
/* sent the new W to workers */
switch(config.getBiasCovariatesComputeNodeCommunicationPolicy()) {
case BROADCAST_HASH_JOIN:
pushToWorkers(mapINDArrayToBlocks(filteredBiasCovariates), (W, cb) -> cb.cloneWithUpdatedPrimitive(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.F_W_tl, W.get(cb.getTargetSpaceBlock())));
break;
case RDD_JOIN:
joinWithWorkersAndMap(chopINDArrayToBlocks(filteredBiasCovariates), p -> p._1.cloneWithUpdatedPrimitive(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.F_W_tl, p._2));
break;
}
}
use of org.broadinstitute.hellbender.tools.coveragemodel.linalg.FourierLinearOperatorNDArray in project gatk by broadinstitute.
the class CoverageModelEMWorkspace method getBiasCovariatesRegularizedLinearOperators.
/**
* Returns the pair of (linear operator, preconditioner) invoked in the M-step update of bias
* covariates in w/ regularization
*
* @return a pair of linear operators
*/
@EvaluatesRDD
private ImmutablePair<GeneralLinearOperator<INDArray>, GeneralLinearOperator<INDArray>> getBiasCovariatesRegularizedLinearOperators() {
final INDArray Q_ll, Q_tll, Z_ll;
final GeneralLinearOperator<INDArray> linop, precond;
final FourierLinearOperatorNDArray regularizerFourierLinearOperator = createRegularizerFourierLinearOperator();
switch(config.getWSolverType()) {
case LOCAL:
/* fetch the required INDArrays */
Q_ll = mapWorkersAndReduce(cb -> cb.getINDArrayFromCache(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.sum_Q_ll), INDArray::add).div(numTargets);
Q_tll = fetchFromWorkers(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.Q_tll, 0);
Z_ll = sampleBiasLatentPosteriorSecondMoments.sum(0);
/* instantiate the local implementation of linear operators */
linop = new CoverageModelWLinearOperatorLocal(Q_tll, Z_ll, regularizerFourierLinearOperator);
precond = new CoverageModelWPreconditionerLocal(Q_ll, Z_ll, regularizerFourierLinearOperator, numTargets);
return ImmutablePair.of(linop, precond);
case SPARK:
if (!sparkContextIsAvailable) {
throw new UserException("The Spark W solver is only available in the Spark mode");
}
/* fetch the required INDArrays */
Q_ll = mapWorkersAndReduce(cb -> cb.getINDArrayFromCache(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.sum_Q_ll), INDArray::add).div(numTargets);
Z_ll = sampleBiasLatentPosteriorSecondMoments.sum(0);
/* instantiate the spark implementation of linear operators */
linop = new CoverageModelWLinearOperatorSpark(Z_ll, regularizerFourierLinearOperator, numTargets, ctx, computeRDD, targetBlocks);
precond = new CoverageModelWPreconditionerSpark(Q_ll, Z_ll, regularizerFourierLinearOperator, numTargets, ctx, numTargetBlocks);
return ImmutablePair.of(linop, precond);
default:
throw new IllegalArgumentException("The solver type for M-step update of bias covariates" + " is not properly set");
}
}
Aggregations