|
2 | 2 | Windows |
3 | 3 | ------- |
4 | 4 |
|
5 | | -+----------------------------------+---------------------------------------------------+------------------------+ |
6 | | -| **Window** | Operators | Output sequence length | |
7 | | -+==================================+===================================================+========================+ |
8 | | -| :math:`y = \window{f}{label}\ x` | :math:`f: X \times \textrm{Opt}(X) \rightarrow Y` | :math:`|y| = |x|` | |
9 | | -| +---------------------------------------------------+ | |
10 | | -| | :math:`label: \one \rightarrow L` | | |
11 | | -+----------------------------------+---------------------------------------------------+------------------------+ |
| 5 | ++---------------------------------------+---------------------------------------------------------+------------------------+ |
| 6 | +| **Window** | Operators | Output sequence length | |
| 7 | ++=======================================+=========================================================+========================+ |
| 8 | +| :math:`y = \window{f}{adj}{label}\ x` | :math:`f': X \times \opt{X} \rightarrow Y` | :math:`|y| = |x|` | |
| 9 | +| +---------------------------------------------------------+ | |
| 10 | +| | :math:`adj: \iset{x} \times \iset{x} \rightarrow \bool` | | |
| 11 | +| +---------------------------------------------------------+ | |
| 12 | +| | :math:`label: \one \rightarrow L` | | |
| 13 | ++---------------------------------------+---------------------------------------------------------+------------------------+ |
| 14 | + |
| 15 | +One of the unique capabilities of Phlex is to execute an algorithm on data products that belong to adjacent data-product sets (see :numref:`ch_conceptual_design/registration:Data Products from Adjacent Data-Product Sets`). |
| 16 | +The workflow in :numref:`workflow` shows a such a node :math:`\textit{window(make\_tracks)}`, which is presented with pairs of :cpp:`"GoodHits"` data products, with each data product in the pair belonging to adjacent `APA`\ s. |
| 17 | +It is the user-provided :math:`adj` function which determines whether two data-product sets are adjacent. |
| 18 | + |
| 19 | +For simplicity, imagine that each `APA` identifier (i.e. member of the set :math:`\iset{\text{APA}}`) can be represented as an integer. |
| 20 | +A straightforward :math:`adj` implementation might be to group the :cpp:`"GoodHits"` data products from `APA`\ s with consecutive numbers: |
| 21 | + |
| 22 | +.. only:: html |
| 23 | + |
| 24 | + .. math:: |
| 25 | + |
| 26 | + \isequence{hs}{\text{APA}} = [\ \rlap{\overbracket{\phantom{hs_1 \ \ hs_2}}^{a}\ \ \overbracket{\phantom{hs_3\ \ hs_4}}^{c}}hs_1, \underbracket{hs_2,\ hs_3}_{b},\ hs_4,\ \dots,\ \underbracket{hs_{n-1},\ hs_n}_{m}\ ] |
| 27 | + |
| 28 | +.. only:: latex |
| 29 | + |
| 30 | + .. math:: |
| 31 | + |
| 32 | + \isequence{hs}{\text{APA}} = [\ \rlap{$\overbracket{\phantom{hs_1 \ \ hs_2}}^{a}\ \ \overbracket{\phantom{hs_3\ \ hs_4}}^{c}$}hs_1, \underbracket{hs_2,\ hs_3}_{b},\ hs_4,\ \dots,\ \underbracket{hs_{n-1},\ hs_n}_{m}\ ] |
| 33 | + |
| 34 | +The data products corresponding to windows :math:`a` through :math:`m` are grouped into pairs and presented to the :cpp:`make_tracks` algorithm, which has the signature :math:`\text{Hits} \times \text{Hits} \rightarrow \text{Tracks}`. |
| 35 | +There are, at most, :math:`n-1` unique pairs that can be presented to the function :cpp:`make_tracks` such that: |
| 36 | + |
| 37 | +.. math:: |
| 38 | + |
| 39 | + \left[ts_i\right]_{i \in \iset{\text{APA}}'} = \left[make\_tracks(hs_i, hs_{i+1})\right]_{i \in \iset{\text{APA}}'} = \window{make\_tracks}{adj}{\text{APA}} \isequence{hs}{\text{APA}} |
| 40 | + |
| 41 | +where the index set :math:`\iset{\text{APA}}'` is :math:`\iset{\text{APA}}` without the last identifier :math:`n` [#flast]_. |
| 42 | +In this example, the identifier of the first :math:`hs` object in the pair is used to identify the tracks collection :math:`ts`. |
| 43 | +But Phlex does not mandate this choice, and a different data category could be specified by the :math:`label` operator for the data products of the output sequence. |
| 44 | + |
| 45 | +Operator Signatures |
| 46 | +^^^^^^^^^^^^^^^^^^^ |
| 47 | + |
| 48 | +One limitation of the above formulation is that index sets of the input and output sequences are not the same. |
| 49 | +To address this infelicity, the function signature of :cpp:`make_tracks` can be adjusted such that the second argument receives an optional type: |
| 50 | + |
| 51 | +.. math:: |
| 52 | + |
| 53 | + make\_tracks': \text{Hits} \times \opt{\text{Hits}} \rightarrow \text{Tracks} |
| 54 | + |
| 55 | +thus permitting symmetry between the input and output data-product sequences: |
| 56 | + |
| 57 | +.. math:: |
| 58 | + |
| 59 | + \isequence{ts}{\text{APA}} &= \left[make\_tracks'(hs_i, hs_{i+1})\right]_{i \in \iset{\text{APA}}'} \boldsymbol{+}\ \left[make\_tracks'(hs_n, ())\right] \\ |
| 60 | + &= \window{make\_tracks'}{adj}{\text{APA}} \isequence{hs}{\text{APA}} |
| 61 | + |
| 62 | +where :math:`\boldsymbol{+}` is the list-concatenation operator, and :math:`()` is the unit element. |
| 63 | +Phlex supports the function signature whose second argument is an optional type :math:`\opt{X}`; the prime following the function name (e.g. :math:`f'`) is a reminder that the second argument is an optional type. |
| 64 | + |
| 65 | +.. table:: |
| 66 | + :widths: 12 88 |
| 67 | + |
| 68 | + +---------------+------------------------------------------------------------------------------------+ |
| 69 | + | **Operator** | **Allowed signature** | |
| 70 | + +===============+====================================================================================+ |
| 71 | + | :math:`f'` | :cpp:`return_type function_name(P1, P2*, Rm...) [quals];` | |
| 72 | + +---------------+------------------------------------------------------------------------------------+ |
| 73 | + | :math:`adj` | :cpp:`bool function_name(<P1 identifier>, <P2 identifier>) [quals];` | |
| 74 | + +---------------+------------------------------------------------------------------------------------+ |
| 75 | + | :math:`label` | *Name of data-set category of output data products* | |
| 76 | + +---------------+------------------------------------------------------------------------------------+ |
| 77 | + |
| 78 | +The :cpp:`return_type` must model the created data-product type described in :numref:`ch_conceptual_design/algorithms:Return Types`. |
| 79 | +The algorithm :math:`f'` may also create multiple data products by returning a :cpp:`std::tuple<T1, ..., Tn>` where each of the types :cpp:`T1, ..., Tn` models a created data-product type. |
| 80 | + |
| 81 | +The second argument :cpp:`P2*` indicates that an optional type is passed to the algorithm. |
| 82 | +It is permitted to use resources (i.e. :cpp:`Rm...`) in the function :math:`f'`. |
| 83 | +The data-product set identifers of :cpp:`P1` and :cpp:`P2` are used to determine whether two data-products reside in adjacent data-product sets. |
| 84 | + |
| 85 | +Registration Interface |
| 86 | +^^^^^^^^^^^^^^^^^^^^^^ |
| 87 | + |
| 88 | +The :math:`\textit{window(make\_tracks)}` node in :numref:`workflow` would be represented in C++ as: |
| 89 | + |
| 90 | +.. code:: c++ |
| 91 | + |
| 92 | + class hits { ... }; |
| 93 | + class tracks { ... }; |
| 94 | + tracks make_tracks(tracks const& ts, tracks const* next_ts) { ... } |
| 95 | + bool are_adjacent(phlex::id const& left, phlex::id const& right) { ... } |
| 96 | + |
| 97 | + PHLEX_REGISTER_ALGORITHMS(config) |
| 98 | + { |
| 99 | + products("GoodTracks") = |
| 100 | + window( |
| 101 | + "track_maker", // <= Node name for framework |
| 102 | + make_tracks, // <= Window algorithm (f') |
| 103 | + are_adjacent // <= Adjacency criterion |
| 104 | + "APA", // <= Output data-product category |
| 105 | + concurrency::unlimited // <= Allowed concurrency |
| 106 | + ) |
| 107 | + .sequence("GoodHits"_in("APA")); |
| 108 | + } |
| 109 | + |
| 110 | +Note that the second input parameter for :cpp:`make_tracks` is an optional type. |
| 111 | +The type :cpp:`phlex::id` is a putative type that enables the comparison of data-product set identifiers for establishing adjacency. |
| 112 | + |
| 113 | +.. rubric:: Footnotes |
| 114 | + |
| 115 | +.. [#flast] The expression :math:`f(hs_n, hs_{n+1})` is ill-formed as there are only :math:`n` elements in the set :math:`\iset{\text{APA}}`. |
0 commit comments