workflow SOMFlow
  template: define-unit -> define-unit ->
            loop(characterise -> build-model -> define-unit ->
                 characterise -> characterise -> characterise ->
                 characterise -> contextualise -> define-unit ->
                 contextualise -> visualise -> visualise -> abstract ->
                 characterise -> assess ->
                 generate-knowledge (specify) ->
                 define-unit -> define-unit) ->
            generate-knowledge
  description: "Assumed composite workflow enabled by SOMFlow for guided
    exploratory cluster analysis of time-series collections. Analysts
    iteratively inspect topology-preserving cluster maps, assess quality
    and metadata relations, adapt analysis settings, partition data into
    subsets, and reflect on branching analytical provenance."

# ============================================================================
# INPUT
# ============================================================================

artifact D_time_series : entities
  origin: given
  internal structure: sequence
  embedment: set
  features:
    - id: primary_series
      value structure: vector
      value type: numeric
      description: "Numeric sequence representing the primary measurement
        profile of each data item"
    - id: metadata_attributes
      value structure: vector
      value type: categorical
      description: "Descriptive categorical attributes associated with each
        time-series item"
  description: "Collection of time-series items with associated metadata"

artifact S_exploration_configuration : specification
  origin: given
  representation form: "preprocessing, clustering, partitioning, layout,
    and display settings"
  description: "Initial settings for data transformation, feature
    weighting, similarity calculation, cluster-map configuration,
    cell and provenance layouts, metadata overlays, recommendation
    thresholds, and partitioning strategy"

# ============================================================================
# INITIALISE ANALYTICAL FOCUS AND PROVENANCE
# ============================================================================

transform T_initialise_analysis_subset :
  intent: define-unit
  manner: "initialise analysis collection"
  input: D_time_series
  output: D_current_subset
  actor: machine
  description: "Create the initial current subset containing the entire
    time-series collection for exploratory analysis"

artifact D_current_subset : entities
  internal structure: sequence
  embedment: set
  description: "Current collection of time-series items selected for
    cluster-map analysis"

transform T_initialise_provenance :
  intent: define-unit
  manner: "create analytical provenance structure"
  input: D_current_subset
  output: D_analysis_graph, D_analysis_states
  actor: machine
  description: "Create a provenance graph and its initial analysis state
    for recording cluster-map results, partitions, and their
    relationships"

artifact D_analysis_graph : entities
  internal structure: formation
  description: "Single analytical provenance graph containing analysis
    states and links representing subset-selection and partitioning
    relationships"

artifact D_analysis_states : entities
  internal structure: elementary
  embedment: relational structure
  description: "Analysis-state nodes contained in the provenance graph,
    each representing a recorded cluster-map result and its associated
    subset"

# ============================================================================
# GUIDED EXPLORATORY CLUSTER ANALYSIS
# ============================================================================

loop L_guided_cluster_exploration:
  purpose: "Iteratively analyse cluster-map results, adapt computations,
    create finer-grained data partitions, and preserve an overview of
    alternative analytical branches"
  until: "Relevant structures, metadata relations, data-quality issues,
    and useful data partitions have been sufficiently explored and
    documented"
  body:

    # ========================================================================
    # PREPARE CURRENT DATA SUBSET
    # ========================================================================

    transform T_prepare_series_representation :
      intent: characterise
      manner: "preprocess and weight time-series profiles"
      input: D_current_subset, S_exploration_configuration
      output: F_series_representation
      actor: machine
      description: "Transform, align, and weight time-series profiles
        according to the current analysis configuration"

    artifact F_series_representation : feature(D_current_subset)
      value structure: vector
      value type: numeric
      description: "Preprocessed and weighted numeric representation of
        each time-series item for similarity-based analysis"

    # ========================================================================
    # BUILD AND CHARACTERISE CURRENT CLUSTER MAP
    # ========================================================================

    transform T_build_cluster_map :
      intent: build-model
      manner: "fit topology-preserving clustering model"
      input: F_series_representation, S_exploration_configuration
      output: M_cluster_map
      actor: machine
      description: "Construct a two-dimensional prototype-based clustering
        model for the current time-series subset"

    artifact M_cluster_map : model(F_series_representation,
        S_exploration_configuration)
      model type: "topology-preserving clustering model"
      representation form: "two-dimensional grid of prototype profiles"
      description: "Model representing the current time-series subset by
        a two-dimensional arrangement of representative profiles"

    transform T_define_map_cells :
      intent: define-unit
      manner: "derive prototype-cell units"
      input: M_cluster_map
      output: D_map_cells
      actor: machine
      description: "Create cluster-map cells as units representing local
        regions of the learned profile space"

    artifact D_map_cells : entities
      internal structure: elementary
      embedment: space
      description: "Cells of the two-dimensional cluster map, each
        representing a prototype profile and its associated data items"

    transform T_characterise_map_cells :
      intent: characterise
      manner: "profile prototype cells"
      input: D_map_cells, M_cluster_map, F_series_representation
      output: F_cell_profile, F_cell_density, F_cell_variation
      actor: machine
      description: "Compute representative profiles, membership counts,
        and within-cell variation for cluster-map cells"

    artifact F_cell_profile : feature(D_map_cells)
      value structure: vector
      value type: numeric
      description: "Representative time-series profile for each
        cluster-map cell"

    artifact F_cell_density : feature(D_map_cells)
      value structure: atomic
      value type: numeric
      description: "Number or relative density of time-series items
        associated with each cluster-map cell"

    artifact F_cell_variation : feature(D_map_cells)
      value structure: atomic
      value type: numeric
      description: "Within-cell profile variation indicating local
        aggregation precision"

    transform T_assign_items_to_cells :
      intent: characterise
      manner: "assign items to prototype cells"
      input: D_current_subset, F_series_representation, M_cluster_map
      output: F_item_cell_membership
      actor: machine
      description: "Associate each time-series item with its best-matching
        cluster-map cell"

    artifact F_item_cell_membership : feature(D_current_subset)
      value structure: atomic
      value type: reference
      description: "Reference to the cluster-map cell associated with each
        time-series item"

    transform T_characterise_cell_guidance :
      intent: characterise
      manner: "compute topology, quality, and metadata-relation features"
      input: D_map_cells, D_current_subset, F_cell_profile,
             F_cell_density, F_cell_variation, F_item_cell_membership
      output: F_cell_topology, F_cell_quality, F_metadata_association
      actor: machine
      description: "Compute cell-neighbourhood relations, separation
        indicators, and associations between cell membership and
        metadata attributes"

    artifact F_cell_topology : feature(D_map_cells)
      value structure: relational configuration
      representation form: "neighbourhood relations between map cells"
      description: "Similarity and neighbourhood relationships among
        cluster-map cells"

    artifact F_cell_quality : feature(D_map_cells)
      value structure: vector
      value type: numeric
      description: "Cell-level indicators of separation from neighbouring
        cells and potential cluster boundaries"

    artifact F_metadata_association : feature(D_map_cells)
      value structure: vector
      value type: numeric
      description: "Strength of association between cell membership and
        available metadata attributes"

    transform T_compute_partition_cues :
      intent: characterise
      manner: "rank candidate refinement and partitioning actions"
      input: D_map_cells, F_cell_topology, F_cell_quality,
             F_metadata_association
      output: F_partition_cues
      actor: machine
      description: "Derive ranked recommendations for refining imprecise
        regions, splitting by metadata relations, or partitioning by
        cell-group structure"

    artifact F_partition_cues : feature(D_map_cells)
      value structure: list
      value type: categorical
      description: "Ranked candidate actions for refining or partitioning
        the current data subset"

    # ========================================================================
    # CONTEXTUALISE CELLS AND RECORD CURRENT ANALYSIS STATE
    # ========================================================================

    transform T_layout_map_cells :
      intent: contextualise
      manner: "grid-based or topology-driven cell layout"
      input: D_map_cells, F_cell_topology, S_exploration_configuration
      output: D_cell_layout_space, A_map_cell_layout
      actor: machine
      description: "Position map cells in a two-dimensional display space
        using either native grid coordinates or a topology-driven layout
        based on inter-cell relations"

    artifact D_cell_layout_space : entities
      internal structure: elementary
      features:
        - id: dimensions
          value structure: atomic
          value type: numeric
          description: "Number of display dimensions"
      description: "Computed two-dimensional display space for the
        cluster-map overview"

    artifact A_map_cell_layout : arrangement(D_map_cells)
      context: D_cell_layout_space
      principle: "native grid position or topology-driven layout based on
        cell neighbourhood relations"
      description: "Placement of map cells in either their default grid
        positions or a rearranged similarity-oriented layout"

    transform T_register_analysis_state :
      intent: define-unit
      manner: "extend analytical provenance graph"
      input: D_analysis_graph, D_analysis_states, D_current_subset,
             M_cluster_map, D_map_cells, F_item_cell_membership
      output: D_analysis_graph_r, D_analysis_states_r
      actor: machine
      description: "Add the current cluster-map analysis state and its
        relationship to the analysed subset to the provenance graph"

    artifact D_analysis_graph_r : entities
      internal structure: formation
      description: "Updated provenance graph containing the current
        cluster-map analysis state and its connections to preceding
        analysis states"

    artifact D_analysis_states_r : entities
      internal structure: elementary
      embedment: relational structure
      description: "Updated collection of provenance-state nodes,
        including the current cluster-map analysis state"

    assign:
      D_analysis_graph := D_analysis_graph_r
      D_analysis_states := D_analysis_states_r

    transform T_layout_analysis_graph :
      intent: contextualise
      manner: "force-directed analytical provenance layout"
      input: D_analysis_graph, D_analysis_states,
             S_exploration_configuration
      output: D_analysis_flow_layout_space, A_analysis_state_layout
      actor: machine
      description: "Position provenance-state nodes in a two-dimensional
        flow layout that exposes parent-child analysis relationships and
        supports comparison of alternative branches"

    artifact D_analysis_flow_layout_space : entities
      internal structure: elementary
      features:
        - id: dimensions
          value structure: atomic
          value type: numeric
          description: "Number of display dimensions"
      description: "Computed two-dimensional display space for the
        analytical provenance view"

    artifact A_analysis_state_layout : arrangement(D_analysis_states)
      context: D_analysis_flow_layout_space
      principle: "force-directed placement based on provenance links"
      description: "Placement of recorded analysis states to reveal
        derivation relationships and branching structure"

    # ========================================================================
    # VISUAL ANALYSIS OF CURRENT RESULT AND ANALYTICAL HISTORY
    # ========================================================================

    transform T_visualise_cluster_map :
      intent: visualise
      manner: "interactive cluster-map overview"
      input: D_map_cells, D_current_subset, A_map_cell_layout,
             F_cell_profile, F_cell_density, F_cell_variation,
             F_cell_topology, F_cell_quality, F_metadata_association,
             F_partition_cues, F_item_cell_membership,
             S_exploration_configuration
      output: V_cluster_map
      actor: machine
      description: "Display representative profiles, cell density,
        topology, quality overlays, metadata associations, and guidance
        cues for the current cluster map"

    artifact V_cluster_map : visualisation(D_map_cells, D_current_subset,
        A_map_cell_layout, F_cell_profile, F_cell_density,
        F_cell_variation, F_cell_topology, F_cell_quality,
        F_metadata_association, F_partition_cues,
        F_item_cell_membership)
      layout: "two-dimensional grid or topology-driven cluster-map layout"
      form: "profile glyphs, cell overlays, borders, metadata marks,
        recommendation cues, and linked item displays"
      encoding: "cell position from A_map_cell_layout; profile marks from
        F_cell_profile; cell size or colour from F_cell_density;
        variation overlay from F_cell_variation; separation overlay from
        F_cell_quality; metadata colouring from F_metadata_association;
        suggested actions from F_partition_cues"
      description: "Interactive display for inspecting cluster-map
        structure, local quality, metadata relationships, and candidate
        refinement actions"

    transform T_visualise_analysis_provenance :
      intent: visualise
      manner: "interactive analytical provenance graph"
      input: D_analysis_graph, D_analysis_states, A_analysis_state_layout,
             F_item_cell_membership, F_metadata_association
      output: V_analysis_flow
      actor: machine
      description: "Display the branching history of cluster-map analyses
        and data partitions to support comparison, navigation, and
        reflection on prior analytical decisions"

    artifact V_analysis_flow : visualisation(D_analysis_graph,
        D_analysis_states, A_analysis_state_layout,
        F_item_cell_membership, F_metadata_association)
      layout: "force-directed analytical flow graph"
      form: "cluster-map nodes, partition links, annotations, and linked
        highlights"
      encoding: "state-node position from A_analysis_state_layout; graph
        nodes represent recorded analysis-state snapshots; links represent
        subset derivation and partitioning; link prominence represents
        relative data flow; shared-item highlighting derives from
        F_item_cell_membership"
      description: "Interactive provenance view showing the analytical
        branching structure, preserved analysis snapshots, and
        relationships among cluster-map results"

    transform T_interpret_cluster_patterns :
      intent: abstract
      manner: "perception-and-interpretation"
      input: V_cluster_map, V_analysis_flow, F_cell_profile,
             F_cell_quality, F_metadata_association
      output: P_cluster_patterns
      actor: human
      description: "Identify meaningful profile groups, metadata-related
        structures, heterogeneous regions, data-quality issues, and
        promising branches for further exploration"

    artifact P_cluster_patterns : pattern(D_map_cells, F_cell_profile,
        F_metadata_association)
      representation form: "profile-group descriptions and relation
        annotations"
      description: "Interpreted cluster-map structures, profile
        characteristics, metadata relations, and candidate subsets of
        analytical interest"

    transform T_annotate_current_result :
      intent: characterise
      manner: "manual annotation of cells and items"
      input: D_current_subset, D_map_cells, V_cluster_map,
             P_cluster_patterns
      output: F_manual_annotations, F_cell_annotations
      actor: human
      description: "Assign analyst-defined labels to selected cells or
        time-series items for documenting interpretations, data issues,
        or analytical relevance"

    artifact F_manual_annotations : feature(D_current_subset)
      value structure: list
      value type: categorical
      description: "Analyst-defined labels marking time-series items as
        relevant, uninteresting, erroneous, or otherwise notable"

    artifact F_cell_annotations : feature(D_map_cells)
      value structure: list
      value type: categorical
      description: "Analyst-defined labels marking cluster-map cells as
        noisy, relevant, uninteresting, or otherwise notable"

    transform T_assess_current_analysis :
      intent: assess
      manner: "evaluate cluster-map adequacy and exploration value"
      input: V_cluster_map, V_analysis_flow, P_cluster_patterns,
             F_cell_quality, F_partition_cues, F_manual_annotations,
             F_cell_annotations
      output: K_analysis_assessment
      actor: human
      description: "Assess whether the current result adequately reveals
        relevant structures and whether further computation adaptation,
        data partitioning, or provenance exploration is needed"

    artifact K_analysis_assessment : knowledge(P_cluster_patterns,
        D_map_cells)
      representation form: "quality judgment"
      description: "Assessment of cluster-map quality, metadata relevance,
        usefulness of guidance, and need for further exploration"

    if K_analysis_assessment indicates further exploration needed:
      then:

        transform T_specify_next_action :
          intent: generate-knowledge
          manner: "select refinement and partitioning strategy"
          input: K_analysis_assessment, P_cluster_patterns,
                 V_cluster_map, V_analysis_flow,
                 S_exploration_configuration
          output: S_exploration_configuration_r
          actor: human
          description: "Specify updated preprocessing, feature weighting,
            cluster-map configuration, layout, metadata focus, or
            partitioning action for the next analysis branch"

        artifact S_exploration_configuration_r : specification
          representation form: "preprocessing, clustering, partitioning,
            layout, and display settings"
          description: "Updated settings defining the next computation,
            layout, partitioning, and visual exploration action"

        transform T_define_next_subset :
          intent: define-unit
          manner: "select or partition time-series subset"
          input: D_current_subset, D_map_cells, F_item_cell_membership,
                 F_cell_quality, F_metadata_association,
                 F_partition_cues, F_manual_annotations,
                 F_cell_annotations, S_exploration_configuration_r
          output: D_next_subset
          actor: hybrid
          description: "Create the next analysis subset by selecting map
            cells, cluster regions, metadata-defined groups, labelled
            items, or items requiring finer-grained refinement"

        artifact D_next_subset : entities
          internal structure: sequence
          embedment: set
          description: "Selected or partitioned subset of time-series
            items for the next cluster-map analysis"

        transform T_extend_partition_provenance :
          intent: define-unit
          manner: "record subset derivation in provenance graph"
          input: D_analysis_graph, D_analysis_states, D_current_subset,
                 D_next_subset, P_cluster_patterns,
                 F_manual_annotations, F_cell_annotations,
                 S_exploration_configuration_r
          output: D_analysis_graph_next, D_analysis_states_next
          actor: machine
          description: "Add the selected partitioning action and its
            parent-child subset relationship to the provenance graph"

        artifact D_analysis_graph_next : entities
          internal structure: formation
          description: "Updated provenance graph recording the selected
            next branch and its derivation from the current analysis
            state"

        artifact D_analysis_states_next : entities
          internal structure: elementary
          embedment: relational structure
          description: "Updated provenance-state collection recording the
            newly created analysis branch"

        assign:
          S_exploration_configuration :=
            S_exploration_configuration_r
          D_current_subset := D_next_subset
          D_analysis_graph := D_analysis_graph_next
          D_analysis_states := D_analysis_states_next

      else:
        exit loop L_guided_cluster_exploration

end loop L_guided_cluster_exploration

# ============================================================================
# KNOWLEDGE SYNTHESIS
# ============================================================================

transform T_synthesise_cluster_findings :
  intent: generate-knowledge
  manner: "formulate statements about profile groups and metadata
    relations"
  input: P_cluster_patterns, K_analysis_assessment, V_cluster_map,
         V_analysis_flow, F_manual_annotations, F_cell_annotations
  output: K_cluster_findings
  actor: human
  description: "Document findings about meaningful time-series profile
    groups, metadata relations, data-quality issues, and the analytical
    decisions represented in the provenance graph"

artifact K_cluster_findings : knowledge(P_cluster_patterns,
    D_analysis_graph)
  representation form: "statements, explanations, and annotated
    analytical provenance"
  description: "Documented findings about discovered profile structures,
    relevant metadata relations, selected data partitions, and the
    reasoning underlying the exploratory analysis"