Julia: repetition memory experience – Exchange Stack code review

I just started learning Julia.

Here is an implementation of experience playback memory to use in a reinforcement learning algorithm. It is quite simple, essentially a ring buffer with the following requirements:

  • It is used to store 1D arrays of numbers, typically Float32 or Float64. All stored arrays are the same size.
  • It has a maximum capacity, after which the new entries overwrite the old ones.
  • It has a sample function to recover a given number of entries


import Base.length

Structure memory {T <: Real}
max_size :: UInt32
experiences :: Vector {Vector {T}}

Memory {T} (max size) Where {T <: Real} = Memory {T} (max size, Vector {Vector {T}} ())

length (memory :: Memory) = length (memory.experiences)

remember function! (memory :: memory, experience)
size = length (memory)
if size == memoria.max_size
memory.experiences[1 + size % memory.max_size] = experience
Push! (memory, experiences, experience)

function sample (memory :: Memory {T}, count :: Integer) where {T <: Real}
size = length (memory)
@assert count <= size
he came back [memory.experiences[1 + rand(UInt32) % size] for i in 1: account]finish