Commit 0b3f17c8 authored by bes0030's avatar bes0030
Browse files

TMP: Solved many minor problems. NOT WORKING YET

parent b25cd750
......@@ -22,7 +22,8 @@ module connection_m
!> Represents a connection between two neurons.
type, extends(abstract_base_t) :: connection_t
private
!TODO properties are public because of problems with reading from binary
!file - solve in a better way
class(neuron_t), pointer :: input_neuron !< Pointer to an input neuron
class(neuron_t), pointer :: output_neuron !< Pointer to an output neuron
......@@ -225,10 +226,10 @@ module connection_m
!-------------------!
!> Getter for the private 'input_neuron' component
!! @return Pointer to the input neuron (type neuron_t, pointer)
!! @return Pointer to the input neuron (type class(*), pointer)
function get_input_neuron_impl(this) result (input_neuron)
class(connection_t), target, intent(in) :: this
class(neuron_t), pointer :: input_neuron
class(*), pointer :: input_neuron
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
......@@ -240,10 +241,10 @@ module connection_m
end function get_input_neuron_impl
!> Getter for the private 'output_neuron' component
!! @return Pointer to the output neuron (type neuron_t, pointer)
!! @return Pointer to the output neuron (type class(*), pointer)
function get_output_neuron_impl(this) result (output_neuron)
class(connection_t), target, intent(in) :: this
class(neuron_t), pointer :: output_neuron
class(*), pointer :: output_neuron
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
......
......@@ -10,7 +10,7 @@ module net_m
use time_measurement_m
use neuron_m
use connection_m
use container_m
!use container_m
implicit none
......@@ -28,7 +28,7 @@ module net_m
integer(kind=integer_4neuro) :: num_of_neurons !< Number of neurons in the net
character(:), allocatable :: training_method !< Used training method
class(neuron_t), allocatable :: neuron_arr(:) !< Array containing all neurons
class(*), allocatable :: neuron_arr(:) !< Array containing all neurons
integer(kind=integer_4neuro), allocatable :: input_neuron_arr(:) !< Array of input neuron indices
integer(kind=integer_4neuro), allocatable :: output_neuron_arr(:) !< Array of output neuron indices
class(connection_t), allocatable :: connection_arr(:) !< Array of all connections
......@@ -171,16 +171,23 @@ contains
SIZE(this%input_neuron_arr), &
SIZE(this%output_neuron_arr), &
SIZE(this%connection_arr)
write(unit, iostat=iostat, iomsg=iomsg) (this%neuron_arr(i)%get_id(), &
this%neuron_arr(i)%get_potential(), &
this%neuron_arr(i)%get_state(), &
i=1,SIZE(this%neuron_arr)), &
this%input_neuron_arr, &
this%output_neuron_arr, &
(this%connection_arr(i)%get_input_neuron(), &
this%connection_arr(i)%get_output_neuron(), &
this%connection_arr(i)%get_weight(), &
i=1,SIZE(this%connection_arr))
select type(tmp => this%neuron_arr)
type is(neuron_t)
select type(tmp2 => this%connection_arr)
type is(connection_t)
write(unit, iostat=iostat, iomsg=iomsg) (tmp(i)%get_id(), &
tmp(i)%get_potential(), &
tmp(i)%get_state(), &
i=1,SIZE(this%neuron_arr)), &
this%input_neuron_arr, &
this%output_neuron_arr, &
(tmp2(i)%get_input_neuron(), &
tmp2(i)%get_output_neuron(), &
tmp2(i)%get_weight(), &
i=1,SIZE(this%connection_arr))
end select
end select
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'write_net_sample')
#endif
......@@ -202,23 +209,31 @@ contains
read(unit, iostat=iostat, iomsg=iomsg) s1, s2, s3, s4
! So we do the allocation
allocate(this%neuron_arr(s1), &
select type(tmp => this%neuron_arr)
type is(neuron_t)
allocate(tmp(s1), &
this%input_neuron_arr(s2), &
this%output_neuron_arr(s3), &
this%connection_arr(s4))
end select
! And then finally the reading.
read(unit, iostat=iostat, iomsg=iomsg) (this%neuron_arr(i)%id, &
this%neuron_arr(i)%potential, &
this%neuron_arr(i)%state, &
i=1, SIZE(this%neuron_arr)), &
this%input_neuron_arr, &
this%output_neuron_arr, &
(this%connection_array(i)%input_neuron, &
this%connection_array(i)%output_neuron, &
this%connection_array(i)%weight, &
i=1, SIZE(this%connection_array))
select type(tmp => this%neuron_arr)
type is(neuron_t)
select type(tmp2 => this%connection_arr)
type is(connection_t)
read(unit, iostat=iostat, iomsg=iomsg) (tmp(i)%id, &
tmp(i)%potential, &
tmp(i)%state, &
i=1, SIZE(this%neuron_arr)), &
this%input_neuron_arr, &
this%output_neuron_arr, &
(tmp2(i)%input_neuron, &
tmp2(i)%output_neuron, &
tmp2(i)%weight, &
i=1, SIZE(this%connection_arr))
end select
end select
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'read_net_sample')
#endif
......
......@@ -22,7 +22,7 @@ module neuron_m
!> Abstract class representing a general neuron
type, abstract, extends(abstract_base_t) :: neuron_t
private
!TODO properties are public because of problems with reading from binary file - find another way
real(kind=real_4neuro) :: potential !< Neuron inner potential
real(kind=real_4neuro) :: state !< State of the neuron (0/1 for binary n. etc.)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment