Ingredient Replacement Example Pipeline Details

The Ingredient Replacement Advisor Example pipeline demonstrates how to extend Formulation Design using a generative workflow to replace dextrose in a yogurt formula while maintaining selected sensory properties.

Virtual Companions and Generative Experiences leverage artificial intelligence (AI) technology. You should ensure prior validation of any output created using these solutions before use in production and especially in business-critical systems. Always follow your organization's best practices and data policies when using it. For more information, see https://www.3ds.com/trust/ai.

This page discusses:

See Also
Configuring to Run an Example Pipeline for Formulation Design
Design Advisor Templates and Example Pipelines

The Ingredient Replacement Advisor Example pipeline runs in the Design Advisor app, and enables formulators to replace one or more sugar sources in a product formula with healthier alternatives, while maintaining sensory quality. It extends the core optimizer advisor workflow with sugar-specific logic for controlling which ingredients are removed, which are introduced, and how the Design of Experiments (DOE) explores the resulting design space.

This document covers the configuration, parameter handling, and calculation logic specific to ingredient replacement. For background on the shared advisor architecture, see Optimizer Example Pipeline Details.

Top-Level Pipeline

The examples use the Design Advisor template. On the top level, the main components are the Advisor Configuration subpipeline, which controls user input, and Advisor Calculation subpipeline, which performs the calculations. Both branches converge at the output anchor, which renders the output:

Pipeline Workflow

The pipeline executes the following stages:

  1. Configure the advisor: Advisor (vc_*) parameters are defined with default values. The component generates a configuration dialog that the user can use to modify the values before the calculation runs. Values are passed using global variables.
  2. Perform the advisor calculation:
    1. Generate the DOE:
      • Select features by means of Pearson correlation.
      • Create discrete levels around the reference formula.
      • Use Latin Hypercube Sampling to generate candidate formulations.
      • Define the distribution for each feature using a historical data set.
    2. Make predictions: Use pre-trained XGBoost models (trained in Machine Learning Workbench) to predict sensory scores and nutritional properties for each candidate.
    3. Rank and filter: Apply hard filters (for example, fat or sugar bounds), and then compute a composite score, which combines minimization, maximization, and deviation-from-target penalties.
  3. Generate output:
    • Combined radar chart compares all shortlisted formulations to the original.
    • Table of original and optimized formulas.
    • Scatter plot of the key trade-off.

Advisor Configuration Subpipeline

The configuration branch builds the ingredient replacement dialog dynamically. A code component defines the list of sugar names as an array (Lactose, Glucose, Fructose, Honey, Agave_Syrup, Maple_Syrup, Maltose, and Dextrose). The array is unmerged into individual rows, and each sugar is rendered with two WebUX Checkbox components, one for Replace and one for Target. Each check box is mapped to a corresponding vc_ parameter:

The Parameters panel shows the check box parameter mapping. The Parameter to Map field binds the check box to a Design Advisor (for example, vc_lactose_replace). Checked Value is 1 and Unchecked Value is 0. This ensures that the Python scripts receive clean integer flags from plp_globals.

Configuration Interface

The configuration dialog presents two sections. The upper section is an ingredient replacement grid listing all eight sugar sources, each with a Replace check box and a Target check box. The lower section contains the standard sensory maintenance toggles.

The Replace and Target columns control the calculation as follows:

  • Replace means “remove this sugar from the formula.” The sugar’s concentration is forced to zero. It is removed from the set of ingredients varied by the DOE. The goal is to eliminate this sugar entirely.
  • Target means “introduce this sugar as an alternative.” The sugar is force-added to the set of varied ingredients, even if it had zero concentration in the original formula. The DOE explores a range of concentrations for it.
  • This two-flag design allows flexible multi-source replacement. For example, a user could replace dextrose and glucose simultaneously (both set to Replace) while introducing maple syrup and honey as alternatives (both set to Target). The DOE would then explore formulations that contain various concentrations of maple syrup and honey with zero dextrose and zero glucose.

The following is an example configuration:

  • Replace Dextrose. Its concentration is forced to zero in all candidate formulations.
  • Target Honey and Maple_Syrup. They are introduced as varied ingredients in the DOE, even if they were absent from the original formula.
  • Maintain Flavor Intensity, Sweetness, and Global Appreciation. The ranking function penalizes candidates that deviate from the original formula’s values for these properties.

Sugar Replacement Parameters

Each sugar source has a paired set of VC parameters — one for replacement and one for targeting. Both are 0/1 flags. The table below lists all sugar parameters and their defaults:

Replace Parameter Target Parameter Default Sugar Source
vc_lactose_replace vc_lactose_target 0 / 0 Lactose
vc_glucose_replace vc_glucose_target 0 / 0 Glucose
vc_fructose_replace vc_fructose_target 0 / 0 Fructose
vc_honey_replace vc_honey_target 0 / 0 Honey
vc_agave_syrup_replace vc_agave_syrup_target 0 / 0 Agave Syrup
vc_maple_syrup_replace vc_maple_syrup_target 0 / 1 Maple Syrup
vc_maltose_replace vc_maltose_syrup_target 0 / 0 Maltose
vc_dextrose_replace vc_dextrose_target 1 / 0 Dextrose

The default configuration replaces Dextrose (vc_dextrose_replace = 1) and aims to replace it with Maple Syrup (vc_maple_syrup_target =1) only.

Sensory Maintenance Parameters

Parameter Default Description
vc_flavor_intensity 1 Maintain flavor intensity
vc_sweetness 1 Maintain sweetness
vc_fruit_intensity 0 Maintain fruit intensity
vc_color_intensity 0 Maintain color intensity
vc_thickness 0 Maintain thickness
vc_nappant 0 Maintain nappant
vc_global_appreciation 1 Maintain global appreciation

Protocol Defaults

The protocol defines defaults for all parameters using Pipeline Pilot expression syntax. The sugar replacement and target defaults are defined as follows:

// REPLACE VARIABLES (Dextrose = 1, all others = 0)
If @vc_lactose_replace Is Not Defined Then
    @vc_lactose_replace := 0;
End if;
If @vc_dextrose_replace Is Not Defined Then
    @vc_dextrose_replace := 1;
End if;

// TARGET VARIABLES (all default to 0)
If @vc_honey_target Is Not Defined Then
    @vc_honey_target := 0;
End if;
If @vc_maple_syrup_target Is Not Defined Then
    @vc_maple_syrup_target := 1;
End if;

Advisor Calculation Subpipeline

The calculation branch executes the full formulation pipeline. It extends the standard optimizer workflow with sugar-specific DOE logic:

The pipeline proceeds through the following stages:

  1. The Data Port and Get Formula components load the reference formula and historical data set.
  2. The Design of Experiment component generates candidate formulations with force-added targets and replaced sugars zeroed.
  3. The Property Prediction (MLWB Models) component runs pre-trained XGBoost models predict sensory and nutritional properties.
  4. The Pareto Front component scores and ranks the best candidates using the composite objective function, maintaining sensory properties at reference values.
  5. Ranked formulas are merged with the original, and Radar Plot and Formulas table output is generated.

Sugar Replacement Logic in the DOE

The DOE Generator script applies a multi-step sugar handling process that runs after the standard correlation-based feature selection. This section describes each step in detail.

  1. Read sugar flags:
    sugar_flags_target = {
        "Lactose":     int(plp_globals["vc_lactose_target"]),
        "Glucose":     int(plp_globals["vc_glucose_target"]),
        "Fructose":    int(plp_globals["vc_fructose_target"]),
        "Honey":       int(plp_globals["vc_honey_target"]),
        "Agave_Syrup": int(plp_globals["vc_agave_syrup_target"]),
        "Maple_Syrup": int(plp_globals["vc_maple_syrup_target"]),
        "Maltose":     int(plp_globals["vc_maltose_syrup_target"]),
        "Dextrose":    int(plp_globals["vc_dextrose_target"]),
    }
    
    sugar_flags_replace = {
        "Lactose":     int(plp_globals["vc_lactose_replace"]),
        "Glucose":     int(plp_globals["vc_glucose_replace"]),
        ...  # Same pattern for all eight sugars
    }
    
  2. Force-add sugar targets: Sugars flagged as targets are added to the list of varied ingredients, regardless of whether they were selected by correlation analysis. This ensures that the DOE explores their concentration range even if they have zero concentration in the reference formula and no correlation with existing targets.
    for sugar, flag in sugar_flags_target.items():
        if flag != 0 and sugar in composite_features
                     and sugar not in selected_ingredients:
            selected_ingredients.append(sugar)
    
  3. Remove replaced sugars: Sugars flagged for replacement are removed from the varied ingredient set. They are forced to zero concentration in the non-varied ingredients step.
    for sugar, flag in sugar_flags_replace.items():
        if flag != 0:
            if sugar in selected_ingredients:
                selected_ingredients.remove(sugar)
    
  4. Filter zero-concentration sugars: Sugars that have zero concentration in the reference formula and are not flagged as targets are excluded from the design space. This prevents the DOE from introducing sugars that were never part of the formula unless the user explicitly requests it by means of the Target check box.
    for sugar in selected_ingredients:
        if sugar in all_sugar_names:
            ref_val = reference_values.get(sugar, 0)
            is_target = sugar_flags_target.get(sugar, 0) != 0
            if (ref_val == 0 or pd.isna(ref_val)) and not is_target:
                sugars_to_remove.append(sugar)
    
  5. Specify non-varied sugar concentrations: When building the non-varied ingredients dictionary, replaced sugars are explicitly specified as zero. Non-target sugars that were absent from the reference formula are also specified as zero:
    for ingredient in composite_features:
        if ingredient not in selected_ingredients:
            if ingredient in sugar_flags_replace
                     and sugar_flags_replace[ingredient] != 0:
                non_varied_ingredients[ingredient] = 0.0
            elif ingredient == 'Aroma' and _force_aroma_zero:
                non_varied_ingredients[ingredient] = 0.0
            elif ingredient in all_sugar_names
                     and reference_values[ingredient] == 0:
                non_varied_ingredients[ingredient] = 0.0
            else:
                non_varied_ingredients[ingredient] = reference_values[ingredient]
    

The following summarizes the decision logic based on the input flags:

Condition Result
Sugar is flagged as a target (target = 1) Sugar is force-added to the varied ingredient specified in the DOE, even if absent from the reference formula.
Sugar flagged for replacement (replace = 1) Sugar is removed from the varied set and fixed at zero concentration.
Sugar has a non-zero concentration in reference, and is not flagged Sugar is varied normally (picked up by correlation analysis).
Sugar has zero concentration in the reference, and is not a target Sugar stays at zero and is excluded from the design space.
Sugar is flagged as both a replacement and target Sugar replacement takes priority. Concentration is forced to zero.

Advisor Calculation Scripts

The Advisor Calculation subpipeline contains three Python scripts executed in sequence. The scripts are shared with the other optimizer advisors but include additional logic for sugar handling:

Script Purpose Key Outputs
DOE Generator Generate candidate formulations by means of Latin Hypercube Sampling. Apply sugar replacement and targeting logic to control which sugars are varied, zeroed, or introduced. DataFrame of candidate formulations with adjusted sugar compositions.
Formulation Ranking Score and rank candidates using a composite objective. Maintain sensory properties at reference values. Drop non-relevant sugar columns from the output. Top eight ranked formulations with composite scores and predicted properties.
Radar Plot Visualize sensory property profiles by overlaying all candidates against the original formula on a single radar chart. Base64-encoded PNG image for the Advisor output.

DOE Generator: Sugar-Specific Extensions

The DOE generator extends the base optimizer version with the sugar replacement logic described in the steps in the previous section. The following are the differences from the standard optimizer DOE:

  • The targets_min list does not include a minimization target. The objective is replacement, not reduction.
  • Sugar target flags can inject new ingredients into the design space that have zero concentration in the reference formula.
  • Sugar replacement flags remove ingredients from the design space and force their concentration to zero.
  • An additional zero-concentration filter prevents accidental introduction of sugars not requested by the user.

Formulation Ranking: Column Cleanup

After prediction, the following script scores and ranks the candidate formulations. The core function get_best_formulations accepts three objective dictionaries and an optional filter dictionary:

def get_best_formulations(
    exp_df,
    targets_to_min=None,      # {column: weight}
    targets_to_max=None,      # {column: weight}
    targets_to_maintain=None,  # {column: (weight, target_value)}
    filters=None,             # {column: {upper:, lower:}}
    n_formulas=8,
):

The composite score is calculated as:

Score = Σ(maximize_weights × values) − Σ(minimize_weights × values) − Σ(maintain_weights × |value − target|)

After ranking, the output table is cleaned to show only relevant sugar columns. Sugars that are not flagged and have zero concentration are dropped from the output DataFrame to reduce clutter:

# Keep only sugars that are flagged (replace or target)
# Drop all others from the output table
sugars_to_drop = [
    s for s, flag in sugar_flags_replace.items()
    if flag == 0 and s in target_for_ref.columns
]
target_for_ref = target_for_ref.drop(columns=sugars_to_drop)

This ensures the Formulas tab in the output shows the replaced sugar (at zero) and the target sugars (at their optimized concentrations), without displaying seven additional zero-valued columns for sugars that were never involved.

Radar Plot: Sensory Focus

The radar plot for the ingredient replacement advisor shows only the maintained sensory properties. It does not include a nutritional minimization axis. The axes are determined entirely by the sensory maintenance flags.

Example: Replace Dextrose with Honey and Maple Syrup

This section describes a complete ingredient replacement scenario using the default configuration. In this example, the formulator wants to remove dextrose from a yogurt formula and explore honey and maple syrup as healthier alternatives, while maintaining flavor intensity, sweetness, and global appreciation.

The user runs the advisor and specifies the following:

  • Replace dextrose
  • Target honey and maple syrup
  • Maintain flavor intensity, sweetness, and global appreciation
  1. The pipeline specifies vc_dextrose_replace = 1, vc_honey_target = 1, vc_maple_syrup_target = 1. All sensory flags are specified as 1 for the three enabled properties.
  2. The DOE Generator component reads the flags. It removes Dextrose from the varied ingredients and specifies it as zero. It force-adds Honey and Maple_Syrup to the varied set.
  3. Other sugars (Lactose, Glucose, Fructose, Agave_Syrup, Maltose) are handled by the zero-concentration filter. If they are present in the reference formula, they are varied normally. If absent, they stay at zero.
  4. Around 100 candidate formulations with varied Honey and Maple_Syrup concentrations (plus any other correlated ingredients), zero Dextrose, and unchanged values for everything else are generated using Latin Hypercube Sampling.
  5. XGBoost models predict Flavor_intensity_XGB, sweetness_XGB, and Global Appreciation_XGB for each candidate.
  6. The ranking script scores candidates by penalizing deviation from the reference sensory values (weight = 0.3 each). The top eight formulations are returned.
  7. The output table drops all non-relevant sugar columns, showing only Dextrose (at zero), Honey, and Maple_Syrup alongside the standard ingredient and property columns.

    The radar plot shows three sensory axes, Flavor Intensity, Sweetness, and Global Appreciation. The original formula is plotted in bold red. The eight replacement candidates are shown as dashed colored lines:

In this example, several candidates achieve comparable or improved sensory scores relative to the original formula, indicating that dextrose can be replaced without significant sensory loss.

The Formulas tab shows the original formula (with dextrose present) and the eight suggested formulas (with Dextrose at zero, and Maple_Syrup and Honey at optimized concentrations):