
de.citec.tcs.alignment.ParallelProcessingEngine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algorithms Show documentation
Show all versions of algorithms Show documentation
This module defines the interface for AlignmentAlgorithms as well as some helper classes. An
AlignmentAlgorithm computes an Alignment of two given input sequences, given a Comparator that
works in these sequences.
More details on the AlignmentAlgorithm can be found in the respective interface. More information
on Comparators can be found in the comparators module.
The resulting 'Alignment' may be just a real-valued dissimilarity between the input sequence or
may incorporate additional information, such as a full Alignment, a PathList, a PathMap or a
CooptimalModel. If those results support the calculation of a Gradient, they implement the
DerivableAlignmentDistance interface.
In more detail, the Alignment class represents the result of a backtracing scheme, listing all
Operations that have been applied in one co-optimal Alignment.
A classic AlignmentAlgorithm does not result in a differentiable dissimilarity, because the
minimum function is not differentiable. Therefore, this package also contains utility functions
for a soft approximation of the minimum function, namely Softmin.
For faster (parallel) computation of many different alignments or gradients we also provide the
ParallelProcessingEngine, the SquareParallelProcessingEngine and the ParallelGradientEngine.
The newest version!
/*
* TCS Alignment Toolbox Version 3
*
* Copyright (C) 2016
* Benjamin Paaßen
* AG Theoretical Computer Science
* Centre of Excellence Cognitive Interaction Technology (CITEC)
* University of Bielefeld
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package de.citec.tcs.alignment;
import de.citec.tcs.alignment.parallel.MatrixEngine;
import lombok.NonNull;
import java.util.List;
import java.util.concurrent.Callable;
import lombok.Getter;
/**
* This allows parallel processing of alignment calculations. Given two lists of sequences x_1, ...,
* x_M and y_1, ... y_N this calculates the matrix D = (d(x_i, y_j)) of all pairwise distances.
*
* @param the class of elements in the left input sequences.
* @param the class of elements in the right input sequences.
* @param The result type of the alignment algorithm.
*
* @author Benjamin Paassen - [email protected]
*/
public class ParallelProcessingEngine extends MatrixEngine {
/**
* The AlignmentAlgorithm used for pairwise distance computations.
*
* @return The AlignmentAlgorithm used for pairwise distance computations.
*/
@Getter
@NonNull
private final AlignmentAlgorithm algorithm;
/**
* The list of sequences used as left-hand inputs for the AlignmentAlgorithm.
*
* @return The list of sequences used as left-hand inputs for the AlignmentAlgorithm.
*/
@Getter
@NonNull
private final List extends List> leftSequences;
/**
* The list of sequences used as right-hand inputs for the AlignmentAlgorithm.
*
* @return The list of sequences used as right-hand inputs for the AlignmentAlgorithm.
*/
@Getter
@NonNull
private final List extends List> rightSequences;
/**
* This sets up a ParallelProcessingEngine for the given AlignmentAlgorithm
* and the given Sequences. Given two lists of sequences x_1, ...,
* x_M and y_1, ... y_N this calculates the matrix D = (d(x_i, y_j)) of all pairwise distances.
*
* @param algorithm an AlignmentAlgorithm of your choice.
* @param leftSequences a list of sequences as left input for the given AlignmentAlgorithm.
* @param rightSequences a list of sequences as right input for the given AlignmentAlgorithm.
*/
public ParallelProcessingEngine(@NonNull AlignmentAlgorithm algorithm,
@NonNull List extends List> leftSequences, @NonNull List extends List> rightSequences) {
super(leftSequences.size(), rightSequences.size(), algorithm.getResultClass());
this.algorithm = algorithm;
this.leftSequences = leftSequences;
this.rightSequences = rightSequences;
}
@Override
public Callable createCallable(MatrixCoordinate ident) {
return new AlignmentCallable(ident.i, ident.j);
}
private class AlignmentCallable implements Callable {
private final int leftIdx;
private final int rightIdx;
public AlignmentCallable(int leftIdx, int rightIdx) {
this.leftIdx = leftIdx;
this.rightIdx = rightIdx;
}
@Override
public R call() throws Exception {
return algorithm.calculateAlignment(leftSequences.get(leftIdx), rightSequences.get(rightIdx));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy