Main Content

getInitializationData

View optimizer member data at initialization

Since R2025a

    Description

    initdata = getInitializationData(obj) returns an initializationData object representing the data of optimizer members at initialization.

    example

    Examples

    collapse all

    Create a dipole antenna resonating at 75 MHz and calculate its maximum directivity.

    Choose its length and width as design variables. Provide lower and upper bounds of length and width.

    referenceAnt = design(dipole,75e6);
    InitialDirectivity = max(max(pattern(referenceAnt,75e6)))
    InitialDirectivity = 
    2.1002
    
    Bounds = [3 0.11; 7 0.13];

    Use the SADEA optimizer to optimize this dipole antenna for its directivity. Specify an evaluation function for optimization using the CustomEvaluationFunction property of the OptimizerSADEA object. The evaluation function used in this example is defined at the end of this example.

    s = OptimizerSADEA(Bounds);
    s.CustomEvaluationFunction = @customEvaluationOnlyObjective;

    Run the optimization for 100 iterations.

    figure
    s.optimizeWithPlots(100);

    Figure contains 2 axes objects. Axes object 1 with title Population Diversity Plot, xlabel Number of Iterations, ylabel Population Diversity contains an object of type line. Axes object 2 with title Convergence Trend Plot, xlabel Number of Iterations, ylabel Fitness contains an object of type line.

    View the best member data.

    bestDesign = s.getBestMemberData
    bestDesign = 
      bestMemberData with properties:
    
                 member: [4.7998 0.1101]
           performances: -4.7895
                fitness: -4.7895
        bestIterationId: 50
    
    
    bestdesignValues = bestDesign.member
    bestdesignValues = 1×2
    
        4.7998    0.1101
    
    

    Update the reference antenna with best design values from the optimizer. Calculate directivity of the optimized design.

    Observe an increase in directivity value after optimization.

    referenceAnt.Length = bestdesignValues(1);
    referenceAnt.Width = bestdesignValues(2);
    postOptimizationDirectivity = max(max(pattern(referenceAnt,75e6)))
    postOptimizationDirectivity = 
    4.7895
    

    View the surrogate model data used for prediction.

    InitialData = s.getInitializationData
    InitialData = 
      initializationData with properties:
    
             members: [30×2 double]
        performances: [30×1 double]
             fitness: [30×1 double]
    
    

    View the data for all iterations.

    iterData = s.getIterationData
    iterData = 
      iterationData with properties:
    
             members: [68×2 double]
        performances: [68×1 double]
             fitness: [68×1 double]
    
    

    Check if the algorithm has converged.

    ConvergenceFlag = s.isConverged
    ConvergenceFlag = logical
       1
    
    

    Check how many times the evaluation function is computed.

    NumEvaluations = s.getNumberOfEvaluations
    NumEvaluations = 
    98
    

    Plot the convergence trend.

    s.showConvergenceTrend

    Figure contains an axes object. The axes object with title Convergence Trend Plot, xlabel Number of Iterations, ylabel Fitness contains an object of type line.

    Following code defines the evaluation function used in this example.

    function fitness = customEvaluationOnlyObjective(designVariables)
        fitness = [];
        try
            % Create geometry
            ant = design(dipole,75e6);
            ant.Length = designVariables(1);
            ant.Width = designVariables(2);
        catch
            % Handle errors during geometry creation.
            % High penalty value is used to handle errors.
            fitness = 1e6;
        end
        
        if isempty(fitness)
            try
                % Calculate directivity
                % Optimizer always minimizes the objective hence reverse the sign to maximize gain.
                objective = max(max(pattern(ant,75e6)));
                objective = -objective; 
            catch
                % Handle errors during gain computation.
                % High penalty value is used to handle errors.
                objective = 1e6;
            end
            % As there are no constraints, fitness equals objective.
            fitness = objective;
        end
    end

    Input Arguments

    collapse all

    Optimizer, specified as an OptimizerSADEA or OptimizerTRSADEA object. The function returns data for members of the optimizer object specified in obj.

    Example: OptimizerSADEA

    Output Arguments

    collapse all

    Optimizer member data at initialization, returned as an initializationData object with these properties:

    • members – Initial design variable values

    • performances – Vector of objective and constraints, with first element as objective and the rest as constraints

    • fitness – Summation of objective and weighted constraint values at initialization

    Version History

    Introduced in R2025a