Kohonen/two_level_self_organized_map_utilities [ Modules ]

[ Top ] [ Modules ]

NAME

  MODULE two_level_self_organized_map_utilities

PURPOSE

  In this module the two-level SOM is defined 

AUTHOR

 Oscar Garcia-Cabrejo
 NOTES 

MODIFICATION HISTORY


two_level_self_organized_map/assign_input_to_clusters [ Functions ]

[ Top ] [ two_level_self_organized_map ] [ Functions ]

NAME

   assign_input_to_clusters

PURPOSE

    Subroutine to assign input to clusters

SYNOPSIS

!======================================================================================== 
 subroutine assign_input_to_clusters(kohonen_map,input_patterns)
!========================================================================================
 class(two_level_self_organized_map) :: kohonen_map
 type(kohonen_pattern),dimension(:),intent(inout) :: input_patterns

two_level_self_organized_map/calculate_u_matrix [ Functions ]

[ Top ] [ two_level_self_organized_map ] [ Functions ]

NAME

   calculate_u_matrix

PURPOSE

    Subroutine to calculate  the u_matrix

SYNOPSIS

!========================================================================================
 subroutine calculate_u_matrix(kohonen_map)
!========================================================================================
 class(two_level_self_organized_map) :: kohonen_map

two_level_self_organized_map/external_train_map [ Functions ]

[ Top ] [ two_level_self_organized_map ] [ Functions ]

NAME

   external_train_map

PURPOSE

    Subroutine to connect the two_level_self_organizing_map module to R o C

SYNOPSIS

!========================================================================================
 subroutine external_train_map(x,nvar,npat,som_type,nx1,ny1,nepoch1,alpha1,grid_type1,&
            distance_type1,neigh_type1,toroidal1,nx2,nepoch2,alpha2,grid_type2,&
            prot,distortion,u_matrix,coords,number_patterns,&
            node_index) bind(C, name="train_2lsom_")
!========================================================================================
use, intrinsic :: iso_c_binding, only : c_double, c_int, c_char
 real(kind=8),parameter :: version=0.1d0
 character(len=*),parameter :: program_name="2lsom_train"
 integer(c_int), intent(in) :: nvar,npat,som_type,nx1,ny1,nepoch1,toroidal1
 real(c_double),intent(out) :: prot(nx1*ny1,nvar),distortion(nepoch1)
 real(c_double),intent(out) :: u_matrix(2*nx1-1,2*ny1-1),coords(nx1*ny1,3)
 integer(c_int),intent(out) :: number_patterns(nx1,ny1),node_index(npat,3)
 real(c_double),intent(in) :: x(npat,nvar)
 real(c_double),intent(in) :: alpha1,alpha2
 integer(c_int),intent(in) :: grid_type1,distance_type1,neigh_type1
 integer(c_int),intent(in) :: nx2,grid_type2,nepoch2 !,distance_type1,neigh_type2

two_level_self_organized_map/find_best_match_unit [ Functions ]

[ Top ] [ two_level_self_organized_map ] [ Functions ]

NAME

   find_best_match_unit

PURPOSE

    Subroutine to calculate the best match unit  

SYNOPSIS

!========================================================================================
 subroutine find_best_match_unit(kohonen_map,current_prototype,ihit,jhit,khit,dist_hit)
!========================================================================================
   class(two_level_self_organized_map) :: kohonen_map
   type(kohonen_prototype),intent(inout) :: current_prototype
   integer,intent(out) :: ihit,jhit,khit
   real(kind=8),intent(out) :: dist_hit

two_level_self_organized_map/read_som_layer [ Functions ]

[ Top ] [ two_level_self_organized_map ] [ Functions ]

NAME

   read_som_layer

PURPOSE

    Subroutine to read the prototypes of the first/seconf layer of a two level 
    self_organized_map 

SYNOPSIS

!========================================================================================
 subroutine read_som_layer(kohonen_map,som_fl,layer_type)
!========================================================================================
   class(two_level_self_organized_map) :: kohonen_map
   character(len=*) :: som_fl,layer_type

two_level_self_organized_map_utilities/calculate_cluster_measures [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   calculate_cluster_measures

PURPOSE

   Subroutine to calculate some clustering statistics of a two-level self_organized_map 

SYNOPSIS

!========================================================================================
  subroutine calculate_cluster_measures(kohonen_map,results)
!========================================================================================
  class(two_level_self_organized_map) :: kohonen_map
  real(kind=8),dimension(:,:,:) :: results

two_level_self_organized_map_utilities/calculate_coordinates [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   calculate_coordinates

PURPOSE

    Subroutine to calculate the coordinates of the units inside a kohonen layer 

SYNOPSIS

!========================================================================================
  subroutine calculate_coordinates(current_index,ix,iy,iz,nx,ny,nz,coordinates,node_type)
!========================================================================================
  integer,intent(inout) :: current_index,ix,iy,iz,nx,ny,nz
  real(kind=8),dimension(:,:),intent(out) :: coordinates
  character(len=*),intent(in) :: node_type

two_level_self_organized_map_utilities/calculate_distance_between_prototypes [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   calculate_distance_between_prototypes

PURPOSE

    Subroutine to calculate distance between prototypes

SYNOPSIS

!========================================================================================
 subroutine calculate_distance_between_prototypes(kohonen_map)
!========================================================================================
  class(two_level_self_organized_map) :: kohonen_map

two_level_self_organized_map_utilities/calculate_distance_matrix [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   calculate_distance_matrix

PURPOSE

    Subroutine to calculate the distance between the units inside a kohonen layer 

SYNOPSIS

!========================================================================================
  subroutine calculate_distance_matrix(coordinates,distance_matrix,grid_type,toroidal)
!========================================================================================
  real(kind=8),dimension(:,:),intent(inout) :: coordinates,distance_matrix
  character(len=*) :: grid_type
  logical :: toroidal

two_level_self_organized_map_utilities/calculate_sum2_clusters_grid [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   calculate_sum2_clusters_grid

PURPOSE

   Subroutine to calculate some clustering statistics of a two-level self_organized_map 

SYNOPSIS

!========================================================================================
  subroutine calculate_sum2_clusters_grid(kohonen_map,results)
!========================================================================================
  class(two_level_self_organized_map) :: kohonen_map
  real(kind=8),dimension(:),optional :: results

two_level_self_organized_map_utilities/create [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   create

PURPOSE

   Constructor of a two_level self_organized_map 

SYNOPSIS

!========================================================================================
 subroutine create_2lsom(kohonen_map,training_parameters)
!========================================================================================
   class(two_level_self_organized_map) :: kohonen_map
   type(kohonen_layer_parameters),dimension(:) :: training_parameters

two_level_self_organized_map_utilities/destroy [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   destroy

PURPOSE

   Destructor of a two_level self_organized_map 

SYNOPSIS

!========================================================================================
 subroutine destroy_2lsom(kohonen_map)
!========================================================================================
   class(two_level_self_organized_map) :: kohonen_map

two_level_self_organized_map_utilities/evaluate_2lsom [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   evaluate_2lsom

PURPOSE

   Subroutine to calculate some clustering statistics of a two-level self_organized_map 

SYNOPSIS

!========================================================================================  
  subroutine evaluate_2lsom(kohonen_map,input_data,results)
!========================================================================================
   class(two_level_self_organized_map) :: kohonen_map
   type(kohonen_pattern),dimension(:),intent(inout) :: input_data
   real(kind=8),dimension(:),optional :: results

two_level_self_organized_map_utilities/get_cluster_samples [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   get_cluster_samples

PURPOSE

   Accessor to cluster results obtained using a two-level self_organized_map 

SYNOPSIS

!======================================================================================== 
  subroutine get_cluster_samples(kohonen_map,clusters)
!========================================================================================
  class(two_level_self_organized_map) :: kohonen_map
  integer,dimension(:),intent(inout) :: clusters

two_level_self_organized_map_utilities/index2position [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   index2position

PURPOSE

    Subroutine to calculate the position ix,iy,iz inside a rectangular grid from index

SYNOPSIS

!========================================================================================
  subroutine index2position(index_,nx,ny,nz,cx,cy,cz)
!========================================================================================
  integer,intent(inout) :: index_,nx,ny,nz
  integer,intent(inout) :: cx,cy,cz

two_level_self_organized_map_utilities/position2index [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   position2index

PURPOSE

    Function to calculate the index inside a rectangular grid from position ix,iy,iz

SYNOPSIS

!========================================================================================
  function position2index(ix,iy,iz,nx,ny) result(index_)
!========================================================================================
    integer,intent(inout) :: ix,iy,iz,nx,ny
    integer ::index_

two_level_self_organized_map_utilities/predict_2lsom [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   predict_2lsom

PURPOSE

   Subroutine to make a prediction from a trained two_level self_organized_map 

SYNOPSIS

!========================================================================================
 subroutine predict_2lsom(kohonen_map,input_data,map_output)
!========================================================================================
   class(two_level_self_organized_map) :: kohonen_map
   type(kohonen_pattern),dimension(:),intent(inout) :: input_data
   integer,dimension(:,:),intent(out) :: map_output

two_level_self_organized_map_utilities/print_2lsom [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   print_2lsom

PURPOSE

   Subroutine to print the layers of a two_level self_organized_map 

SYNOPSIS

!========================================================================================
  subroutine print_2lsom(kohonen_map,unit_)
!========================================================================================
    class(two_level_self_organized_map) :: kohonen_map
    integer,optional :: unit_

two_level_self_organized_map_utilities/query_som [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   query_som

PURPOSE

   Function to find the input samples associated with specific vector 

SYNOPSIS

!========================================================================================
 subroutine query_2lsom(kohonen_map,input_pattern,sample_index) !,output_patterns)
!========================================================================================
   class(two_level_self_organized_map) :: kohonen_map
   real(kind=8),dimension(:,:),intent(inout) :: input_pattern
   integer,allocatable :: sample_index(:)

two_level_self_organized_map_utilities/set_cluster_layer [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   set_cluster_layer

PURPOSE

   Subroutine to initialize the cluster layer of a Two Level Self-Organizing Map

SYNOPSIS

!========================================================================================  
 subroutine set_cluster_layer(kohonen_map,seed)
!========================================================================================  
 class(two_level_self_organized_map) :: kohonen_map
 integer :: seed
!
 integer :: ix,number_clusters,ierr
 real(kind=8),allocatable :: input(:,:)

two_level_self_organized_map_utilities/set_parameters [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   set_parameters

PURPOSE

   Subroutine to set parameters

SYNOPSIS

!========================================================================================  
 subroutine set_parameters(kohonen_map,training_parameters)
!========================================================================================  
 class(two_level_self_organized_map) :: kohonen_map
 type(kohonen_layer_parameters),dimension(2) :: training_parameters

two_level_self_organized_map_utilities/train_2lsom [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   train_2lsom

PURPOSE

   Subroutine to train a two_level self_organized_map 

SYNOPSIS

!========================================================================================
 subroutine train_2lsom(kohonen_map,input_data)
!========================================================================================
   class(two_level_self_organized_map) :: kohonen_map
   type(kohonen_pattern),dimension(:),intent(inout) :: input_data

two_level_self_organized_map_utilities/train_cluster_layer [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   train_cluster_layer

PURPOSE

   Subroutine to train the cluster layer of a two_level self_organized_map 

SYNOPSIS

!========================================================================================
  subroutine train_cluster_layer(kohonen_map)
!========================================================================================
   class(two_level_self_organized_map) :: kohonen_map

two_level_self_organized_map_utilities/train_grid_layer [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   train_grid_layer

PURPOSE

   Subroutine to train the grid layer of a two_level self_organized_map 

SYNOPSIS

!========================================================================================
  subroutine train_grid_layer(kohonen_map,input_data)
!========================================================================================
   class(two_level_self_organized_map) :: kohonen_map
   type(kohonen_pattern),dimension(:),intent(inout) :: input_data

two_level_self_organized_map_utilities/two_level_self_organized_map [ Classes ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Classes ]

NAME

   two_level_self_organized_map

PURPOSE

   Class to represent a two level self_organized_map

ATTRIBUTES

    type(kohonen_prototype),allocatable :: grid(:,:,:),cluster_layer(:)
    real(kind=8),allocatable :: coordinates(:,:)
    integer,allocatable :: number_patterns(:,:,:),cells_index(:,:)
    integer,allocatable :: cluster_number_patterns(:),cluster_cells_index(:,:)
    integer,allocatable :: grid_cluster(:,:,:),cluster_samples(:)
    real(kind=8),allocatable :: u_matrix(:,:,:),distance(:,:),cells_distances(:,:)
    integer,allocatable :: number_cluster_samples(:),index_cluster_samples(:,:)
    type(kohonen_layer_parameters),dimension(2) :: parameters
    type(factory_distance) :: factory
    class(distance_base),allocatable :: distance_function
    integer :: number_variables,number_variables1,number_variables2,number_clusters
    integer :: number_nodes
  contains

METHODS

    procedure,public :: create => create_2lsom
    procedure,public :: destroy => destroy_2lsom
    procedure,public :: train => train_2lsom
    procedure,public :: predict => predict_2lsom
    procedure,public :: train_grid_layer
    procedure,public :: train_cluster_layer
    procedure,public :: print => print_2lsom
    procedure,public :: query => query_2lsom
    procedure,public :: set_cluster_layer
    procedure,public :: set_parameters
!    procedure,public :: read => read_som
    procedure,private :: query_2lsom
    procedure,public :: read_som_layer
    procedure,private :: calculate_u_matrix
    procedure,private :: find_best_match_unit
    procedure,private :: update_weights
    procedure,private :: calculate_distance_between_prototypes
    procedure,private :: assign_input_to_clusters
    !procedure,public :: get_count => get_count_2lsom
    !procedure,public :: get_index => get_index_som
    !procedure,public :: get_u_matrix => get_u_matrix_som
    procedure,public :: calculate_sum2_clusters_samples => evaluate_2lsom
    procedure,public :: get_cluster_samples
    procedure,public :: calculate_sum2_clusters_grid
    procedure,nopass,private :: calculate_distance_matrix
    procedure,nopass,private :: calculate_coordinates
!    
    procedure,nopass,public :: external_train_map
!    procedure,nopass,public :: external_predict_map    

two_level_self_organized_map_utilities/update_weights [ Functions ]

[ Top ] [ two_level_self_organized_map_utilities ] [ Functions ]

NAME

   update_weights

PURPOSE

    Subroutine to update the weights   

SYNOPSIS

!========================================================================================
 subroutine update_weights(kohonen_map,current_values,ihit,jhit,khit,&
            maximum_radius,iteration) 
!========================================================================================
  class(two_level_self_organized_map) :: kohonen_map
  real(kind=8),dimension(:,:),intent(inout) :: current_values
  integer,intent(inout) :: ihit,jhit,khit,iteration
  real(kind=8),intent(inout) :: maximum_radius