final VectorialKeywordSpecification keySpec = (VectorialKeywordSpecification) nodeSpec.getKeywordSpecification(k); comparators[k] = new DerivableVectorialComparatorWrapper(keySpec.getKeyword(), new L1NormComparator(keySpec.getLength()));
break; case 1: keywordSpecs[k] = new VectorialKeywordSpecification( DEFAULTVECTORIALLENGTH, keyword); break;
case VECTOR: { final int D = ((VectorialKeywordSpecification) keywordSpec).getLength(); final double[] content = new double[D]; for (int d = 0; d < D; d++) {
/** * Returns a sensible default comparator for the given KeywordSpecification. * * @param keywordSpec some KeywordSpecification. * * @return a sensible default comparator for the given KeywordSpecification. */ public static ValueComparator getDefaultComparator(@NonNull KeywordSpecification keywordSpec) { switch (keywordSpec.getType()) { case STRING: { return new DerivableStringComparatorWrapper(keywordSpec.getKeyword(), new CharStatComparator()); } case SYMBOLIC: { final Alphabet alphabet = ((SymbolicKeywordSpecification) keywordSpec).getAlphabet(); final DerivableComparator<String, String> comp = new SquareReplacementMatrixComparator<>( new IndexingAlphabetWrapper(alphabet)); return new DerivableSymbolicComparatorWrapper(keywordSpec.getKeyword(), comp); } case VECTOR: { final int dimensions = ((VectorialKeywordSpecification) keywordSpec).getLength(); final DerivableComparator<double[], double[]> comp = new NormalizedL1Comparator(dimensions); return new DerivableVectorialComparatorWrapper(keywordSpec.getKeyword(), comp); } default: throw new IllegalArgumentException( "No defaults defined for value type: " + keywordSpec.getType()); } }
/** * Sets up an AlignmentSpecification for an array of vectorial sequences. * This uses a default comparator (L1 norm and hyperbolic normalization). * * @param dataSpace an array of sequences. * * @return an AlignmentSpecification. */ public static AlignmentSpecification setUpSpecification(Sequence[] dataSpace) { if (dataSpace == null || dataSpace.length == 0) { throw new IllegalArgumentException("The given data space is empty!"); } //construct an array of L1NormComparators. //check for NodeSpecification consistency. final NodeSpecification nodeSpec = dataSpace[0].getNodeSpecification(); for (int s = 1; s < dataSpace.length; s++) { if (!nodeSpec.equals(dataSpace[s].getNodeSpecification())) { throw new IllegalArgumentException("The NodeSpecifications in the given data space are not consistent!"); } } final ValueComparator[] comparators = new ValueComparator[nodeSpec.size()]; for (int k = 0; k < comparators.length; k++) { final VectorialKeywordSpecification keySpec = (VectorialKeywordSpecification) nodeSpec.getKeywordSpecification(k); comparators[k] = new DerivableVectorialComparatorWrapper(keySpec.getKeyword(), new L1NormComparator(keySpec.getLength())); } return setUpSpecification(dataSpace, comparators); }
+ spec.getKeyword(k) + " is not vectorial!"); D += ((VectorialKeywordSpecification) keywordSpec).getLength();
endIdx = propertyDist[k] - 1; keywordSpecs[k] = new VectorialKeywordSpecification( endIdx - startIdx + 1, keywords[k]);
keywordSpecs[k] = new VectorialKeywordSpecification(1, keywords[k]);
final KeywordSpecification[] keywordSpecs = {new VectorialKeywordSpecification(N, STDKEYWORD)}; final NodeSpecification nodeSpec = new NodeSpecification(keywordSpecs); final Sequence[] sequences = new Sequence[arrays.length];
break; case 1: keywordSpecs[k] = new VectorialKeywordSpecification( DEFAULTVECTORIALLENGTH, keyword); break;
/** * Transforms the given arrays to sequences. It is assumed that each * entry arrays[s] is a sequence. * Your sequences are allowed to have different lengths. * * @param arrays an array of double arrays that shall be converted to * sequences. * * @return an array of Sequences. */ public static Sequence[] toSequences(@NonNull double[][] arrays) { final KeywordSpecification[] keywordSpecs = {new VectorialKeywordSpecification(1, STDKEYWORD)}; final NodeSpecification nodeSpec = new NodeSpecification(keywordSpecs); final Sequence[] sequences = new Sequence[arrays.length]; for (int s = 0; s < arrays.length; s++) { sequences[s] = new Sequence(nodeSpec); for (int i = 0; i < arrays[s].length; i++) { final Node node = new Node(sequences[s]); node.setValue(0, new VectorialValue(new double[]{arrays[s][i]})); sequences[s].add(node); } } return sequences; }