Skip to content

Stateful encoding of hypervectors #10

@cvigilv

Description

@cvigilv

As discussed in person, an interesting idea for things to eventually add to the package is the idea of having some kind of way of maintaining a history on how hypervectors are constructed. The following snippet enables the creation of Memory structures, which have an internal structure that contains information on how a given hypervector was constructed.

I thinks this could be added as a new data structure once we finish the first pass through of the package. LMKWYT

abstract type AbstractMemory end
struct Memory{T <: AbstractHDV} <: AbstractMemory
   v::T
   values::Tuple{Vararg{Union{T,AbstractMemory}}}
   fun::Function
end

function Memory(fun::Function, hvs::Union{AbstractHDV,AbstractMemory}...)
   @assert length(unique(typeof.(hvs))) == 1
   Memory{typeof(collect(first(hvs)))}(fun(hvs...), hvs, fun)
end
Memory(hv::AbstractHDV) = Memory(hv, Tuple([hdv]), identity)

Base.show(io::IO, m::Memory) = print(io, "$(typeof(m.v))($(m.fun); $(length(m.values))x$(length(m.v)))")
Base.collect(m::Memory) = m.v

bundle(hvs::Union{AbstractMemory,AbstractHDV}...) = Memory(bundle(collect.(hvs)...), hvs, bundle)
bind(hvs::Union{AbstractHDV,AbstractMemory}...) = Memory(bind(collect.(hvs)...), hvs, bind)
shift(hv::Memory, i) = Memory(shift(collect.(hvs), i), hvs, x -> shift(x, i))

end

I think we can improve this a lot, but as a first prototype it gets the job done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions