inverse_design_array_0d Module Function

module function inverse_design_array_0d(this, target, x_init, optimiser, steps) result(x_opt)

Optimise the input so the network output matches a target. Wraps the array_type implementation after converting to 2D array.

Arguments

Type IntentOptional Attributes Name
class(network_type), intent(inout), target :: this

Instance of the network

type(array_type), intent(in) :: target

Target output values

type(array_type), intent(in) :: x_init

Initial input values

class(base_optimiser_type), intent(in), optional :: optimiser

Optimiser for input updates (defaults to network optimiser)

integer, intent(in) :: steps

Number of optimisation iterations

Return Value type(array_type)

Optimised input


Source Code

  module function inverse_design_array_0d( &
       this, target, x_init, optimiser, steps &
  ) result(x_opt)
    !! Optimise the input so the network output matches a target.
    !! Wraps the array_type implementation after converting to 2D array.
    implicit none

    ! Arguments
    class(network_type), intent(inout), target :: this
    !! Instance of the network
    type(array_type), intent(in) :: target
    !! Target output values
    type(array_type), intent(in) :: x_init
    !! Initial input values
    class(base_optimiser_type), optional, intent(in) :: optimiser
    !! Optimiser for input updates (defaults to network optimiser)
    integer, intent(in) :: steps
    !! Number of optimisation iterations
    type(array_type) :: x_opt
    !! Optimised input

    ! Local variables
    type(array_type), pointer :: target_arr(:,:), x_init_arr(:,:), x_opt_arr(:,:)


    !---------------------------------------------------------------------------
    ! Convert real arrays to array_type
    !---------------------------------------------------------------------------
    allocate(target_arr(1,1), x_init_arr(1,1), x_opt_arr(1,1))
    call target_arr(1,1)%allocate(source=target)
    call x_init_arr(1,1)%allocate(source=x_init)

    !---------------------------------------------------------------------------
    ! Delegate to array_type implementation
    !---------------------------------------------------------------------------
    x_opt_arr = this%inverse_design_array_2d( &
         target_arr, x_init_arr, optimiser, steps &
    )
    x_opt = x_opt_arr(1,1)

    call target_arr(1,1)%deallocate()
    call x_init_arr(1,1)%deallocate()
    call x_opt_arr(1,1)%deallocate()
    deallocate(target_arr, x_init_arr, x_opt_arr)

  end function inverse_design_array_0d