workflow somflow-guided-cluster-exploration
  template: loop(build-model -> define-unit (assign cells) ->
                 contextualise (grid layout) ->
                 characterise (cell measures) ->
                 visualise (SOM view) ->
                 characterise (annotate) ->
                 abstract (interpret) ->
                 define-unit (record run) ->
                 visualise (provenance flow) ->
                 abstract (reflect) ->
                 assess ->
                 generate-knowledge (strategy) ->
                 define-unit (partition/retain)) ->
            generate-knowledge (synthesise)
  description: "Assumed composite workflow (synthesised from the exploratory
    analysis usage scenario) for guided iterative cluster exploration with
    self-organizing maps; a map is trained on the current data subset, cells
    are analysed for quality, interestingness, and partitioning
    recommendations, the analyst adapts computations or partitions the data
    while retaining every analysis step in a branching analytic-provenance
    graph that is continuously visualised and used for reflection and
    comparison across the exploration"

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

artifact D_utterances : entities
  origin: given
  internal structure: elementary
  embedment: set
  features:
    - id: f_pitch_contour
      value structure: vector
      value type: numeric
      description: "Time series values representing the item's temporal
        profile (e.g., pitch contour over time)"
    - id: f_metadata
      value structure: vector
      value type: categorical
      description: "Associated categorical metadata attributes (e.g.,
        speaker characteristics, utterance type, repetition)"
  description: "Collection of time series items with associated categorical
    metadata, forming the dataset to be explored; also serves as the current
    working subset for the drill-down loop"

artifact S_analysis_strategy : specification
  origin: given
  representation form: "configuration schema"
  description: "Initial choices for data preprocessing, distance metric,
    self-organizing map parameters, and criteria for partitioning the
    current data subset"

artifact D_som_runs : entities
  origin: given
  internal structure: elementary
  embedment: relational structure
  description: "Initially empty collection of retained SOM analysis runs, to
    be populated with the initial SOM and all subsequently created,
    retrained, filtered, or partitioned SOMs; a cluster may correspond to a
    single cell or a set of similar neighbouring cells"

artifact F_run_lineage : feature(D_som_runs)
  origin: given
  value structure: relational configuration
  representation form: "directed parent-child analysis flow graph"
  description: "Initially empty parent-child relations between SOM runs,
    indicating retraining, filtering, splitting, or selection-based
    partitioning operations"

# ============================================================================
# DRILL-DOWN EXPLORATION LOOP
# ============================================================================

loop L_drilldown:
  purpose: "Iteratively train, analyse, and refine self-organizing maps on
    successive data subsets, retaining every analysis step in a branching
    provenance graph, adapting computations or partitioning data to
    progressively explore clusters and their relations to metadata"
  until: "Clusters and metadata relations are sufficiently understood across
    the retained analysis graph, and no further adaptation or partitioning
    is warranted"
  body:

    # ========================================================================
    # Analyze: train map and compute cell-level views
    # ========================================================================

    transform T_train_som :
      intent: build-model
      manner: "train self-organizing map providing joint vector
        quantization and topology-preserving two-dimensional embedding"
      input: D_utterances, S_analysis_strategy
      output: M_som
      actor: machine
      description: "Train a self-organizing map on the current data subset
        according to the current preprocessing, metric, and parameter
        configuration"

    artifact M_som : model(D_utterances, S_analysis_strategy)
      model type: "clustering and dimensionality-reduction model"
      representation form: "grid of prototype vectors with topological
        neighborhood structure (self-organizing map)"
      description: "Trained model partitioning the current data subset into
        topologically ordered prototype cells"

    transform T_assign_cells :
      intent: define-unit
      manner: "assign items to best-matching grid cells"
      input: D_utterances, M_som
      output: D_cells, F_cell_assignment
      actor: machine
      description: "Define grid cells as analysis units and assign each
        item to its best-matching cell"

    artifact D_cells : entities
      internal structure: group/cluster
      embedment: relational structure
      features:
        - id: f_cell_size
          value structure: atomic
          value type: numeric
          description: "Number of items assigned to the cell"
      description: "Grid cells of the self-organizing map, each an
        unordered group of similar items; cells are related through the
        map's neighborhood topology"

    artifact F_cell_assignment : feature(D_utterances)
      value structure: atomic
      value type: categorical
      description: "Best-matching cell identifier for each item"

    transform T_grid_layout :
      intent: contextualise
      manner: "position cells according to the map's topology-preserving
        embedding"
      input: D_cells, M_som
      output: D_grid_space, A_cell_layout
      actor: machine
      description: "Place grid cells within a two-dimensional reference
        space derived from the trained map's topology"

    artifact D_grid_space : entities
      internal structure: elementary
      features:
        - id: f_dimensions
          value structure: atomic
          value type: numeric
          description: "Number of spatial dimensions (2)"
      description: "Two-dimensional grid space serving as reference frame
        for cell positions"

    artifact A_cell_layout : arrangement(D_cells)
      context: D_grid_space
      principle: "topology-preserving grid placement from self-organizing
        map training"
      description: "Positions of grid cells reflecting their
        similarity-based neighborhood topology"

    transform T_compute_cell_measures :
      intent: characterise
      manner: "compute quality, interestingness, similarity, and
        partitioning recommendations"
      input: D_cells, F_cell_assignment, D_utterances, M_som
      output: F_cell_quality, F_cell_interestingness,
        F_partition_recommendations
      actor: machine
      description: "Compute per-cell quantization error from assigned
        items and SOM prototypes, metadata-interestingness scores,
        similar-neighbour candidates, and derived refinement and
        partitioning action recommendations"

    artifact F_cell_quality : feature(D_cells)
      value structure: atomic
      value type: numeric
      description: "Quantization error per cell, indicating how precisely
        the prototype represents its assigned items"

    artifact F_cell_interestingness : feature(D_cells)
      value structure: vector
      value type: numeric
      description: "Per-metadata-attribute interestingness scores per cell,
        indicating potential relations between cell content and metadata"

    artifact F_partition_recommendations : feature(D_cells)
      value structure: vector
      value type: {numeric, categorical}
      description: "Per-cell and map-level recommendation scores and action
        categories for refinement, similar-cell selection, metadata splits,
        and cluster-based splits"

    transform T_visualise_som :
      intent: visualise
      manner: "SOM grid view with prototype and item time series, topology
        overlays, metadata colouring, and ranked recommendation cues"
      input: A_cell_layout, D_cells, D_utterances, M_som, F_cell_assignment,
        F_cell_quality, F_cell_interestingness, F_partition_recommendations
      output: V_som
      actor: machine
      description: "Render SOM cells with prototype and assigned-item time
        series, topology and quality overlays, metadata colouring, and
        ranked recommendations for further analysis"

    artifact V_som : visualisation(A_cell_layout, D_cells, D_utterances,
        M_som, F_cell_assignment, F_cell_quality, F_cell_interestingness,
        F_partition_recommendations)
      layout: "two-dimensional SOM grid"
      form: "cell glyphs with prototype and item line charts, quality or
        metadata overlays, and recommendation thumbnails"
      encoding: "cell position from A_cell_layout; prototype line and
        training history from M_som; assigned item traces and bandwidth
        from D_utterances and F_cell_assignment; cell shading from
        F_cell_quality or metadata colouring; density from f_cell_size;
        ranked thumbnails from F_cell_interestingness; partitioning cues
        from F_partition_recommendations"
      description: "Interactive SOM view supporting inspection of cluster
        structure, prototype quality, metadata relations, and recommended
        next actions"

    # ========================================================================
    # Adapt (data enrichment): manual annotation
    # ========================================================================

    transform T_annotate_cells :
      intent: characterise
      manner: "interactive assignment of user-defined metadata labels"
      input: D_cells, F_cell_assignment, V_som
      output: F_user_annotations
      actor: human
      description: "Assign analyst-defined labels, such as interesting,
        uninteresting, or measurement-error, to cells or their member items"

    artifact F_user_annotations : feature(D_utterances)
      value structure: atomic
      value type: categorical
      description: "User-defined item annotations propagated from selected
        SOM cells, available for later filtering and recommendation
        computation"

    transform T_interpret :
      intent: abstract
      manner: "perception and interpretation of cell topology, quality
        overlays, metadata colouring, and user annotations"
      input: V_som, F_user_annotations
      output: P_patterns
      actor: human
      description: "Identify salient regions, candidate groupings, and
        apparent relations between map structure and metadata attributes"

    artifact P_patterns : pattern(D_cells, F_cell_interestingness)
      representation form: "categorized patterns with descriptions"
      description: "Identified salient map regions, candidate groupings,
        and apparent relations between cluster structure and metadata
        attributes"

    # ========================================================================
    # Reflect: retain the current run and compare against the provenance graph
    # ========================================================================

    transform T_record_analysis_step :
      intent: define-unit
      manner: "retain current SOM result as a provenance-graph node"
      input: D_som_runs, F_run_lineage, M_som, D_utterances,
        S_analysis_strategy
      output: D_som_runs_r, F_run_lineage_r
      actor: machine
      description: "Add the current SOM analysis result and its relation to
        predecessor runs to the retained analytic-provenance graph"

    artifact D_som_runs_r : entities
      internal structure: elementary
      embedment: relational structure
      description: "Updated collection of retained SOM analysis runs"

    artifact F_run_lineage_r : feature(D_som_runs_r)
      value structure: relational configuration
      representation form: "directed parent-child analysis flow graph"
      description: "Updated provenance relations between retained SOM runs"

    assign:
      D_som_runs := D_som_runs_r
      F_run_lineage := F_run_lineage_r

    transform T_visualise_flow :
      intent: visualise
      manner: "analytic-provenance flow graph with embedded SOM views"
      input: D_som_runs, F_run_lineage
      output: V_som_flow
      actor: machine
      description: "Display retained SOM analyses as graph nodes connected
        by data-flow and partitioning relationships, supporting
        navigation, comparison, annotation, and provenance inspection"

    artifact V_som_flow : visualisation(D_som_runs, F_run_lineage)
      layout: "directed flow graph"
      form: "graph nodes containing SOM thumbnails and directed links"
      encoding: "nodes represent retained SOM runs; links represent
        data-flow relations from F_run_lineage; link width represents the
        number of transferred items; linked colour overlays and
        annotations support comparison across runs"
      description: "Analytic-provenance graph showing the evolution and
        branching structure of SOM-based cluster exploration"

    transform T_reflect :
      intent: abstract
      manner: "compare retained SOM results and analysis branches via
        linked overlays and annotations"
      input: V_som_flow, D_som_runs, F_run_lineage, P_patterns
      output: P_overall_relations
      actor: human
      description: "Compare the current and earlier SOM analyses, branches,
        and data partitions to identify verified relations between cluster
        structure and metadata, informing ongoing exploration"

    artifact P_overall_relations : pattern(D_som_runs, P_patterns)
      representation form: "categorized patterns with descriptions"
      description: "Relations between cluster structure and metadata
        attributes verified by comparison across the retained analysis
        graph"

    # ========================================================================
    # Assess: decide whether to adapt, partition, or stop
    # ========================================================================

    transform T_assess :
      intent: assess
      manner: "judge whether current and accumulated analyses adequately
        reveal relevant structure, guided by quality, interestingness, and
        reflection"
      input: V_som, P_patterns, F_cell_quality, F_cell_interestingness,
        P_overall_relations
      output: K_assessment
      actor: human
      description: "Evaluate whether the current and accumulated SOM
        analyses adequately represent the data and relations of interest,
        or whether further adaptation or partitioning is warranted"

    artifact K_assessment : knowledge(D_cells, M_som, D_som_runs)
      representation form: "quality judgment"
      description: "Assessment of map, partition, and accumulated analysis
        adequacy, and whether further adaptation or partitioning is needed"

    if K_assessment indicates further analysis needed:
      then:

        # ====================================================================
        # Adapt: decide computation or partitioning strategy
        # ====================================================================

        transform T_decide_strategy :
          intent: generate-knowledge
          manner: "decide whether to adapt data preprocessing, metric, or
            parameters, or to define partitioning criteria, guided by
            identified patterns and partitioning recommendations"
          input: K_assessment, P_patterns, F_partition_recommendations,
            S_analysis_strategy
          output: S_analysis_strategy_r
          actor: human
          description: "Formulate updated analysis strategy: adjust
            preprocessing, metric, or self-organizing map parameters,
            and/or specify criteria for the next data partition, optionally
            guided by machine-derived recommendations"

        artifact S_analysis_strategy_r : specification
          representation form: "configuration schema"
          description: "Updated configuration of preprocessing, metric,
            parameters, and partition criteria for the next analysis step"

        assign:
          S_analysis_strategy := S_analysis_strategy_r

        # ====================================================================
        # Partition: define the next data subset
        # ====================================================================

        transform T_define_next :
          intent: define-unit
          manner: "retain the current subset for recomputation, or
            partition it into a subset of interest based on cell, cluster,
            metadata, or annotation criteria"
          input: D_utterances, D_cells, F_cell_assignment,
            F_user_annotations, S_analysis_strategy
          output: D_next
          actor: hybrid
          description: "Define the data subset to analyse in the next
            step, either by retaining the current subset under revised
            preprocessing or by selecting a subset based on cell, cluster,
            metadata, or noise-annotation criteria"

        artifact D_next : entities
          internal structure: elementary
          embedment: set
          features:
            - id: f_pitch_contour
              value structure: vector
              value type: numeric
              description: "Time series profile retained for each selected
                item"
            - id: f_metadata
              value structure: vector
              value type: categorical
              description: "Associated metadata retained for each selected
                item"
          description: "Selected or retained subset of the current data,
            preserving time series and metadata for the next SOM analysis"

        assign:
          D_utterances := D_next
      else:
        exit loop L_drilldown

end loop L_drilldown

# ============================================================================
# SYNTHESISE FINDINGS
# ============================================================================

transform T_synthesise :
  intent: generate-knowledge
  manner: "formulate statements summarising discovered groupings and
    metadata relations across retained analysis branches"
  input: P_overall_relations, K_assessment, D_som_runs, F_run_lineage
  output: K_findings
  actor: human
  description: "Synthesise findings about the data's cluster structure, its
    relations to metadata attributes, and data quality issues uncovered
    across the retained SOM analysis graph"

artifact K_findings : knowledge(P_overall_relations, K_assessment,
    D_som_runs, F_run_lineage)
  representation form: "statements and explanations"
  description: "Documented findings about discovered clusters, their
    relations to metadata attributes, and data quality issues identified
    through iterative, retained SOM-based exploration"