self_organizing_map Derived Type

type, public, extends(kohonen_map_base) :: self_organizing_map

Class to represent a self_organizing_map


Inherits

type~~self_organizing_map~~InheritsGraph type~self_organizing_map self_organizing_map type~distance_base distance_base type~self_organizing_map->type~distance_base distance_function type~factory_distance factory_distance type~self_organizing_map->type~factory_distance factory type~kohonen_layer_parameters kohonen_layer_parameters type~self_organizing_map->type~kohonen_layer_parameters parameters type~kohonen_map_base kohonen_map_base type~self_organizing_map->type~kohonen_map_base type~kohonen_prototype kohonen_prototype type~self_organizing_map->type~kohonen_prototype grid type~rkiss05_generator rkiss05_generator type~self_organizing_map->type~rkiss05_generator rnumber_grator type~random_generator_base random_generator_base type~rkiss05_generator->type~random_generator_base

Type-Bound Procedures

procedure, public :: create => create_som

  • public subroutine create_som(kohonen_map, training_parameters)

    Constructor for self_organizing_map

    Arguments

    Type IntentOptional Attributes Name
    class(self_organizing_map) :: kohonen_map

    A self_organizing_map object

    type(kohonen_layer_parameters), dimension(:) :: training_parameters

    A kohonen_layer_parameters object

procedure, public :: destroy => destroy_som

  • public subroutine destroy_som(kohonen_map)

    Destructor for self_organizing_map

    Arguments

    Type IntentOptional Attributes Name
    class(self_organizing_map) :: kohonen_map

    A self_organizing_map object

procedure, public :: train => train_som_data

  • public subroutine train_som_data(kohonen_map, input_data)

    Training function for self_organizing_map

    Arguments

    Type IntentOptional Attributes Name
    class(self_organizing_map) :: kohonen_map

    A self_organizing_map object

    type(kohonen_pattern), intent(inout), dimension(:) :: input_data

    A kohonen_pattern array with the input data

procedure, public :: predict => predict_som

  • public subroutine predict_som(kohonen_map, input_data, map_output)

    Function for Prediction of a self_organizing_map

    Arguments

    Type IntentOptional Attributes Name
    class(self_organizing_map) :: kohonen_map

    A self_organizing_map object

    type(kohonen_pattern), intent(inout), dimension(:) :: input_data

    A kohonen_pattern array with the input data

    integer, intent(out), dimension(:,:) :: map_output

    An integer array with the map output

procedure, public :: print => print_som

  • public subroutine print_som(kohonen_map, unit_)

    Print function for self_organizing_map

    Arguments

    Type IntentOptional Attributes Name
    class(self_organizing_map) :: kohonen_map
    integer, intent(inout), optional :: unit_

procedure, public :: read => read_som

  • public subroutine read_som(kohonen_map, som_fl)

    Subroutine to read the prototypes to define a self_organizing_map

    Arguments

    Type IntentOptional Attributes Name
    class(self_organizing_map) :: kohonen_map

    A self_organizing_map object

    character(len=*) :: som_fl

    A character variable with the name of the file

procedure, public :: get_count => get_count_som

  • public subroutine get_count_som(kohonen_map, count_)

    Function to get count matrix for self_organizing_map

    Arguments

    Type IntentOptional Attributes Name
    class(self_organizing_map) :: kohonen_map
    integer, intent(inout), dimension(:,:,:) :: count_

procedure, public :: query => query_som

  • public subroutine query_som(kohonen_map, input_pattern, sample_index)

    Function to find the input samples associated with specific vector

    Arguments

    Type IntentOptional Attributes Name
    class(self_organizing_map) :: kohonen_map
    real(kind=wp), intent(inout), dimension(:,:) :: input_pattern
    integer, allocatable :: sample_index(:)

procedure, public :: get_prototypes

  • public subroutine get_prototypes(kohonen_map, prototypes)

    Subroutine to get SOM prototypes

    Arguments

    Type IntentOptional Attributes Name
    class(self_organizing_map) :: kohonen_map

    A self_organizing_map object

    real(kind=wp), intent(out), dimension(:,:) :: prototypes

    A real array to return the values of the SOM prototypes

procedure, public :: get_u_matrix => get_u_matrix_som

  • public subroutine get_u_matrix_som(kohonen_map, u_matrix)

    Subroutine to get the u_matrix from a SOM

    Arguments

    Type IntentOptional Attributes Name
    class(self_organizing_map) :: kohonen_map

    A self_organizing_map object

    real(kind=wp), intent(out), dimension(:,:,:) :: u_matrix

    A real array to return the u_matrix

procedure, public, nopass :: external_train_map

  • public subroutine external_train_map(x, nvar, npat, nx, ny, nepoch, alpha, grid_type, distance_type, neigh_type, toroidal, prot, distortion, u_matrix, coords, number_patterns, node_index) bind(C, name="train_som")

    Subroutine to connect the self_organizing_map module to R o C Import section

    Arguments

    Type IntentOptional Attributes Name
    real(kind=c_double), intent(in) :: x(npat,nvar)

    Real array with the input patterns

    integer(kind=c_int), intent(in) :: nvar

    Integer variables to indicate the number of variables and patterns

    integer(kind=c_int), intent(in) :: npat

    Integer variables to indicate the number of variables and patterns

    integer(kind=c_int), intent(in) :: nx

    Integer variables to indicate the number of nodes of the SOM

    integer(kind=c_int), intent(in) :: ny

    Integer variables to indicate the number of nodes of the SOM

    integer(kind=c_int), intent(in) :: nepoch

    Integer variables to indicate the number of epochs for training

    real(kind=c_double), intent(in) :: alpha

    Real value with the initial learning rate

    integer(kind=c_int), intent(in) :: grid_type

    Integer variable to indicate the type of grid

    integer(kind=c_int), intent(in) :: distance_type

    Integer variable to indicate the distance type

    integer(kind=c_int), intent(in) :: neigh_type

    Integer variable to indicate the neighborhood type

    integer(kind=c_int), intent(in) :: toroidal

    Integer variable to indicate if a toroidal grid is used

    real(kind=c_double), intent(out) :: prot(nx*ny,nvar)

    Real array for the prototypes

    real(kind=c_double), intent(out) :: distortion(nepoch)

    Real array for the distortion measure (error during training)

    real(kind=c_double), intent(out) :: u_matrix(2*nx-1,2*ny-1)

    Real array for the u_matrix

    real(kind=c_double), intent(out) :: coords(nx*ny,3)

    Real array for the grid coordinates of the SOM

    integer(kind=c_int), intent(out) :: number_patterns(nx,ny)

    Integer array with the number of hits for each neuron

    integer(kind=c_int), intent(out) :: node_index(npat,3)

    Integer array with the index node for all the neurons of the SOM

procedure, public, nopass :: external_predict_map

  • public subroutine external_predict_map(prot, nx, ny, new_pat, npat, nvar, node_index) bind(C, name="predict_som")

    Subroutine to connect this module to R

    Arguments

    Type IntentOptional Attributes Name
    real(kind=c_double), intent(in) :: prot(nx*ny,nvar)
    integer(kind=c_int), intent(in) :: nx
    integer(kind=c_int), intent(in) :: ny
    real(kind=c_double), intent(in) :: new_pat(npat,nvar)
    integer(kind=c_int), intent(in) :: npat
    integer(kind=c_int), intent(in) :: nvar
    integer(kind=c_int), intent(out) :: node_index(npat,3)

Source Code

type,extends(kohonen_map_base) :: self_organizing_map
!!   Class to represent a self_organizing_map
    private
        character(len=NUMCHAR) :: class_name='self_organizing_map';
        type(kohonen_prototype),allocatable :: grid(:,:,:)
        integer,allocatable :: number_patterns(:,:,:),cells_index(:,:)
        real(kind=wp),allocatable :: u_matrix(:,:,:),distance(:,:)
        real(kind=wp),allocatable :: cells_distances(:,:),coordinates(:,:)
        type(kohonen_layer_parameters) :: parameters
        type(factory_distance) :: factory
        class(distance_base),allocatable :: distance_function
        real(kind=wp),allocatable :: distortion(:)
        type(rkiss05_generator) :: rnumber_grator
        integer :: seed  
        integer,allocatable :: grid_pattern_index(:,:,:),list_node_grid(:,:,:,:)
    contains
        procedure,public :: create => create_som
        procedure,public :: destroy => destroy_som
        procedure,private :: create_random_sample
        procedure,private :: train_som_data
        procedure,public :: train => train_som_data 
        procedure,public :: predict => predict_som
        procedure,public :: print => print_som
        procedure,public :: read => read_som
        procedure,public :: get_count => get_count_som
        procedure,public :: query => query_som
        procedure,public :: get_prototypes
        !procedure,public :: get_index => get_index_som
        procedure,public :: get_u_matrix => get_u_matrix_som
        procedure,private :: find_best_match_unit
        procedure,private :: update_weights
        !procedure,private :: update_weights1
        procedure,private :: find_bmu_grid
        procedure,private :: calculate_u_matrix
        procedure,private :: calculate_u_matrix_hexagonal
        procedure,private :: calculate_u_matrix_rectangular
        procedure,private :: calculate_sigma
        procedure,nopass,private :: position2index
        procedure,nopass,private :: index2position
        procedure,nopass,private :: calculate_distance_matrix
        procedure,nopass,private :: calculate_coordinates
        procedure,private :: calculate_distance_between_prototypes
        procedure,nopass,public :: external_train_map
        procedure,nopass,public :: external_predict_map
!
end type self_organizing_map