Contenuto principale

connect

Create connections between pipeline components

Since R2026a

    Description

    newPipeline = connect(pipeline,connections) connects the components, pipelines, and ports in pipeline as indicated by the directed edges in connections. All the connections must be valid, or none are made.

    connect guarantees that the resulting pipeline newPipeline has no cycles or duplicate edges. However, the function does not guarantee that the pipeline can be executed after the connections are made.

    example

    Examples

    collapse all

    Create a pipeline with components for data preprocessing. First, connect the normalizer and oneHotEncoder components in parallel to create pipeline. Then, combine removeMissing, pipeline, and pcaTransformer in series to create preprocessingPipeline. View the data preprocessing pipeline.

    removeMissing = observationRemoverComponent;
    normalizer = normalizerComponent;
    oneHotEncoder = oneHotEncoderComponent; 
    pcaTransformer = pcaComponent;
    
    pipeline = parallel(normalizer,oneHotEncoder);
    
    preprocessingPipeline = series(removeMissing,pipeline,pcaTransformer);
    view(preprocessingPipeline)

    View of the pipeline

    Remove the oneHotEncoder component from the pipeline.

    preprocessingPipeline = remove(preprocessingPipeline,"OneHotEncoder");
    view(preprocessingPipeline)

    Pipeline after removing the OneHotEncoder component

    Next, remove the normalizer component from the pipeline.

    preprocessingPipeline = remove(preprocessingPipeline,"Normalizer");
    view(preprocessingPipeline)

    Pipeline after removing the Normalizer component

    The remaining two components are not connected.

    Connect the components and view the pipeline. The number of outputs in removeMissing is not equivalent to the number of inputs in pcaTransformer. So, you must specify the input and output ports to connect. To see the names of the inputs and outputs of a component, index into the component, for example, preprocessingPipeline.Components.ObservationRemover.

    preprocessingPipeline = connect(preprocessingPipeline, ...
        ["ObservationRemover/DataOut1","PCA/DataIn"]);
    view(preprocessingPipeline)

    Pipeline after connecting components

    Create a pipeline object.

    pipeline = LearningPipeline
    pipeline = 
    
      LearningPipeline with properties:
    
                 Name: "defaultName"
               Inputs: [0×0 string]
            InputTags: []
              Outputs: [0×0 string]
           OutputTags: []
    
           Components: struct with 0 entries
          Connections: [0×2 table]
    
        HasLearnables: false
    
    
    Show summary of the components

    Create a component to remove missing values and another to perform multiclass classification. Add the components to the pipeline, and then view the pipeline.

    removeMissing = observationRemoverComponent;
    ecoc = classificationECOCComponent;
    newPipeline = add(pipeline,removeMissing,ecoc);
    
    view(newPipeline)

    View of the new pipeline

    The pipeline does not have the same number of ports as the inputs and outputs of the removeMissing and ecoc components.

    Add corresponding ports to the pipeline. View the pipeline.

    newPipeline.Inputs = ["XIn","YIn"];
    newPipeline.Outputs = ["Predictions","Scores","Loss"]
    view(newPipeline)
    newPipeline = 
    
      LearningPipeline with properties:
    
                 Name: "defaultName"
               Inputs: ["XIn"    "YIn"]
            InputTags: [0 0]
              Outputs: ["Predictions"    "Scores"    "Loss"]
           OutputTags: [0 0 0]
    
           Components: struct with 2 entries
          Connections: [0×2 table]
    
        HasLearnables: true
           HasLearned: false
    
    
    Show summary of the components

    Pipeline with ports added

    The software does not automatically connect components or ports.

    Connect the two components and the new ports. View the final pipeline.

    finalPipeline = connect(newPipeline, ...
        ["XIn","ObservationRemover/DataIn1", ...
        "YIn","ObservationRemover/DataIn2"]);
    finalPipeline = connect(finalPipeline, ...
        ["ObservationRemover/DataOut1","ClassificationECOC/Predictors", ...
        "ObservationRemover/DataOut2","ClassificationECOC/Response"]);
    finalPipeline = connect(finalPipeline, ...
        ["ClassificationECOC/Predictions","Predictions", ...
        "ClassificationECOC/Scores","Scores", ...
        "ClassificationECOC/Loss","Loss"]);
    view(finalPipeline)

    Final pipeline with connected components and ports

    Input Arguments

    collapse all

    Existing pipeline, specified as a LearningPipeline object.

    Names of the ports to connect, specified as a string array or cell array of character vectors, indicating ordered pairs of sources and destinations, or a table with two columns (Source and Destination). The format of connections must be the same as the format of the Connections property of the pipeline. You can find the name of a component in a pipeline by using the describe object function (for example, describe(pipeline)). describe also displays the component input and output port names.

    Data Types: string | cell | table

    Output Arguments

    collapse all

    Pipeline with new connections, returned as a LearningPipeline object.

    More About

    collapse all

    Version History

    Introduced in R2026a