### Install HyperdimensionalComputing.jl in Package Mode Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/README.md Install the package by entering Julia's package mode (pressing ']') and then adding the repository URL. ```julia ]add https://github.com/MichielStock/HyperdimensionalComputing.jl#main ``` -------------------------------- ### Install HyperdimensionalComputing.jl using Pkg.jl Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/README.md Install the package using the Pkg.jl manager by providing the repository URL. ```julia using Pkg; Pkg.add(url = "https://github.com/MichielStock/HyperdimensionalComputing.jl") ``` -------------------------------- ### Associative Property Example 2 Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md Another demonstration of associative properties, showing that USTATES * DOL * MEXICO is approximately equal to KRO (Swedish Krona). ```julia USTATES * DOL * MEXICO ≈ KRO ``` -------------------------------- ### Associative Property Example 3 Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md A further example of associative properties, indicating that USTATES * DOL * MEXICO is approximately equal to DOL (US Dollar). ```julia USTATES * DOL * MEXICO ≈ DOL ``` -------------------------------- ### Associative Property Example 1 Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md Illustrates an associative property where multiplying USTATES by DOL and then by MEXICO is approximately equal to multiplying MEXICO by PES. ```julia USTATES * DOL * MEXICO ≈ PES ``` -------------------------------- ### Calculate Similarity Between Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/README.md Shows how to compute the similarity between two hypervectors using the 'similarity' function. The default behavior uses the best metric for the hypervector type. Examples include comparing two distinct hypervectors and comparing a hypervector with a combined one. ```julia julia> a = GradedBipolarHV(10); julia> b = GradedBipolarHV(10); julia> c = a + b; julia> similarity(a, b) 0.7857595020921353 julia> similarity(a, c) 0.9241024788902716 julia> similarity(b, c) 0.9295606930584789 ``` -------------------------------- ### Initialize Animal and Sound Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Create bipolar hypervectors for different animals and their corresponding sounds. These will be used to build an associative memory. ```julia dog_hv = BipolarHDV() cat_hv = BipolarHDV() cow_hv = BipolarHDV() animals = [dog_hv, cat_hv, cow_hv] ``` ```julia bark_hv = BipolarHDV() meow_hv = BipolarHDV() moo_hv = BipolarHDV() sounds = [bark_hv, meow_hv, moo_hv] ``` -------------------------------- ### Initialize Character to Hypervector Mapping Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Create a dictionary mapping each character of the alphabet (and space) to a unique bipolar hypervector. This is the first step in encoding text sequences. ```julia char2hv = Dict(c => BipolarHDV() for c in 'a':'z') char2hv[' '] = BipolarHDV() ``` -------------------------------- ### Load Handcalcs Package Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Loads the Handcalcs package for documentation generation. This is typically hidden in final documentation. ```julia using Handcalcs #hide ``` -------------------------------- ### Create Binary, Bipolar, and Ternary Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/README.md Demonstrates the creation of different types of hypervectors: BinaryHV (default size 10,000), BipolarHV with a specified size, and TernaryHV from an existing vector. ```julia using HyperdimensionalComputing julia> x = BinaryHV() # default length is 10,000 10000-element BinaryHV: 1 0 0 0 0 1 1 0 ⋮ 1 0 1 0 1 0 0 0 julia> y = BipolarHV(6) # different size 6-element BipolarHV: 1 -1 1 1 -1 1 julia> z = TernaryHV([1, 1, -1, 0, 0, 0, 1, 1, -1, 0]) # From a vector 10-element TernaryHV: 1 1 -1 0 0 0 1 1 -1 0 ``` -------------------------------- ### Load HyperdimensionalComputing Package Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Loads the HyperdimensionalComputing package. This is a prerequisite for using HDC functionalities. ```julia using HyperdimensionalComputing ρ(hv::AbstractHDV, n::Int=1) = Π(hv,n) #hide ``` -------------------------------- ### Create Associative Memory for Animal Sounds Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Combine animal and sound hypervectors using binding and bundling to create an associative memory. This allows for querying relationships between entities. ```julia memory = (dog_hv * bark_hv) + (cat_hv * meow_hv) + (cow_hv * moo_hv); nothing #hide ``` -------------------------------- ### Permutation Dissimilarity (using @handcalcs) Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Demonstrates the dissimilarity between a hypervector and its permuted version (h₁ != ρ(h₁)) using '@handcalcs'. This is typically hidden. ```julia @handcalcs h₁ != ρ(h₁) # hide ``` -------------------------------- ### Find Equivalent of Dollar in Mexico Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md Demonstrates finding the hypervector corresponding to Mexico's peso by multiplying the dollar hypervector with the USTATES-MEXICO bundle. ```julia DOL * F_UM ≈ PES ``` -------------------------------- ### Bundle, Bind, and Shift Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/README.md Illustrates hypervector operations: bundling (creating a similar vector from multiple vectors), binding (creating a dissimilar vector), and shifting (cyclically shifting elements). Overloaded operators '+' for bundle and '*' for bind are shown, along with 'ρ' as an alias for 'shift'. ```julia julia> x, y, z = GradedHV(10), GradedHV(10), GradedHV(10); julia> bundle([x,y,z]) 10-element GradedHV{Float64}: 0.24160752324192117 0.0004620105852614061 0.21122703146393468 0.8806160209097325 0.748086047467331 0.29234791431258145 0.2804922831134219 0.18556141274368268 0.08208462507331278 0.9015873952761569 julia> x + y + z 10-element GradedHV{Float64}: 0.24160752324192117 0.0004620105852614061 0.21122703146393468 0.8806160209097325 0.748086047467331 0.29234791431258145 0.2804922831134219 0.18556141274368268 0.08208462507331278 0.9015873952761569 julia> bind([x, y, z]) 10-element GradedHV{Float64}: 0.5061620120454368 0.26070792597812487 0.513025014409134 0.4717013369896599 0.49961155414024105 0.46309236900588013 0.5006006610486007 0.533210817253628 0.529186380757248 0.46622954535393824 julia> x * y * z 10-element GradedHV{Float64}: 0.5061620120454368 0.26070792597812487 0.513025014409134 0.4717013369896599 0.49961155414024105 0.46309236900588013 0.5006006610486007 0.533210817253628 0.529186380757248 0.46622954535393824 julia> shift(x, 2) 10-element GradedHV{Float64}: 0.6572388961520694 0.38592896770130286 0.5732316268033676 0.1280407117618328 0.13125571831454053 0.40139428175287556 0.5286213065298765 0.1038774285737532 0.43575817327464744 0.32479919832749704 julia> ρ(x, 2) 10-element GradedHV{Float64}: 0.6572388961520694 0.38592896770130286 0.5732316268033676 0.1280407117618328 0.13125571831454053 0.40139428175287556 0.5286213065298765 0.1038774285737532 0.43575817327464744 0.32479919832749704 julia> shift!(x, 2) 10-element Vector{Float64}: 0.6572388961520694 0.38592896770130286 0.5732316268033676 0.1280407117618328 0.13125571831454053 0.40139428175287556 0.5286213065298765 0.1038774285737532 0.43575817327464744 0.32479919832749704 julia> x 10-element GradedHV{Float64}: 0.6572388961520694 0.38592896770130286 0.5732316268033676 0.1280407117618328 0.13125571831454053 0.40139428175287556 0.5286213065298765 0.1038774285737532 0.43575817327464744 0.32479919832749704 ``` -------------------------------- ### Permute Hypervector (using @handcalcs) Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Demonstrates the permutation operation on a single hypervector using the '@handcalcs' macro for symbolic representation. This is typically hidden. ```julia @handcalcs h₁ # hide ``` -------------------------------- ### Query Animal from Sound in Associative Memory Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Determine which animal corresponds to a given sound (e.g., "moo") by querying the associative memory. This demonstrates reverse lookup capabilities. ```julia findmax(hv -> similarity(memory * moo_hv, hv), animals) ``` -------------------------------- ### Create Multiple Bipolar Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Initializes three bipolar hypervectors of 8 dimensions each for subsequent operations. ```julia h₁ = BipolarHDV(8) h₂ = BipolarHDV(8) h₃ = BipolarHDV(8); nothing #hide ``` -------------------------------- ### Compare Bundles of Country Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md Compares different bundle combinations of Sweden, USA, and Mexico hypervectors to explore associative relationships. ```julia F_UM = USTATES * MEXICO F_SU = SWEDEN * USTATES F_SM = SWEDEN * MEXICO F_SU * F_UM ≈ F_SM ``` -------------------------------- ### Query Animal Sound from Associative Memory Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Search the associative memory for the sound associated with a specific animal (e.g., dog) by comparing the bound hypervector with the sound hypervectors. ```julia findmax(hv -> similarity(memory * dog_hv, hv), sounds) ``` -------------------------------- ### Declare Concept Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md Initializes bipolar hypervectors for abstract concepts like COUNTRY, CAPITAL, and MONEY. ```julia COUNTRY = BipolarHDV() CAPITAL = BipolarHDV() MONEY = BipolarHDV() ``` -------------------------------- ### Search for a Subsequence (N-gram) in Encoded Phrases Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Encode a query phrase (e.g., "crazy") using the same n-gram method and then find the most similar hypervector among the encoded phrases. This demonstrates sequence retrieval. ```julia query = ngrams("crazy", char2hv) findmax(h -> similarity(query, h), phrases_hvs) ``` -------------------------------- ### Calculate Similarity Using Broadcasting Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Apply the `similarity` function element-wise between a reference hypervector and a vector of hypervectors using Julia's broadcasting syntax. ```julia similarity.(Ref(h₁), [h₁, h₂, h₃]) ``` -------------------------------- ### Bind Hypervectors using bind Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Combines multiple hypervectors into a single hypervector that is dissimilar to its constituents using the 'bind' function. ```julia bind([h₁, h₂, h₃]) ``` -------------------------------- ### Permutation Dissimilarity with shift amounts Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Compares a hypervector with its permuted versions shifted by different amounts (1, 2, and 3 positions) to show dissimilarity. ```julia h₁ != ρ(h₁, 1) != ρ(h₁, 2) != ρ(h₁, 3) ``` -------------------------------- ### Permute Hypervector (using ρ and @handcalcs) Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Shows the symbolic representation of a permuted hypervector (ρ(h₁)) using the '@handcalcs' macro. This is typically hidden. ```julia @handcalcs ρ(h₁) # hide ``` -------------------------------- ### Define Similarity and Equality for BipolarHDV Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md Defines custom similarity and approximate equality functions for BipolarHDV types, crucial for comparing hypervectors. ```julia using HyperdimensionalComputing using LinearAlgebra #hide HyperdimensionalComputing.similarity(u::T,v::T) where T<:BipolarHDV = dot(u, v) / (norm(u) * norm(v)) #hide HyperdimensionalComputing.isapprox(u::T, v::T) where T<:BipolarHDV = similarity(u, v) > 3/sqrt(length(v)) #hide HyperdimensionalComputing.hash(u::AbstractHDV) = hash(u.v, hash(typeof(v))) HyperdimensionalComputing.isequal(u::T, v::T) where T<:AbstractHDV = hash(u) == hash(v) ``` -------------------------------- ### Create Bipolar Hypervector from AbstractVector Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Creates a bipolar hypervector directly from a provided AbstractVector of random bipolar values. ```julia BipolarHDV(rand([-1,1], 8)) ``` -------------------------------- ### Bundle USTATES and MEXICO Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md Creates a bundle (multiplication) of the USTATES and MEXICO hypervectors to represent their combined associations. ```julia F_UM = USTATES * MEXICO ``` -------------------------------- ### Compare Country Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md Compares the holistic hypervectors for USA and Mexico using the defined approximate equality. ```julia USTATES ≈ MEXICO ``` -------------------------------- ### Bind Hypervectors using '*' operator Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Combines multiple hypervectors using the overloaded '*' operator, resulting in a hypervector dissimilar to its constituents. ```julia h₁ * h₂ * h₃ ``` -------------------------------- ### Create Default Bipolar Hypervector Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Creates a random bipolar hypervector with the default dimensionality of 10,000. ```julia BipolarHDV() ``` -------------------------------- ### Bundle Hypervectors using '+' operator Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Combines multiple hypervectors using the overloaded '+' operator, resulting in a hypervector similar to its constituents. ```julia h₁ + h₂ + h₃ ``` -------------------------------- ### Bundle Hypervectors using aggregate Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Combines multiple hypervectors into a single hypervector that is similar to its constituents using the 'aggregate' function. ```julia aggregate([h₁, h₂, h₃]) ``` -------------------------------- ### Represent Countries with Holistic Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md Creates holistic hypervectors for USA and Mexico by combining concept hypervectors with specific entity hypervectors. ```julia USA = BipolarHDV() MEX = BipolarHDV() WDC = BipolarHDV() MXC = BipolarHDV() DOL = BipolarHDV() PES = BipolarHDV() USTATES = (COUNTRY * USA) + (CAPITAL * WDC) + (MONEY * DOL) MEXICO = (COUNTRY * MEX) + (CAPITAL * MXC) + (MONEY * PES) ``` -------------------------------- ### Create Bipolar Hypervector with Specific Dimensionality Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Creates a random bipolar hypervector with a specified number of dimensions. ```julia BipolarHDV(8) ``` -------------------------------- ### Encode Phrases using N-grams Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Define and apply an n-gram encoding function to convert phrases into hypervectors. This function uses bundling and shifting to capture sequential information. ```julia phrases = [ "the quick brown fox jumps over the lazy dog", "the slick grown box bumps under the hazy fog", "the thick known cox dumps inter the crazy cog", "the brick shown pox lumps enter the glazy jog", "the stick blown sox pumps winter the blazy log" ] ngrams(p, d) = aggregate([d[p[i]] + Π(d[p[i+1]], 1) + Π(d[p[i+2]], 2) for i in 1:length(p)-2]) phrases_hvs = [ngrams(p, char2hv) for p in phrases] ``` -------------------------------- ### Calculate Similarity With a Vector of Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Compare a single hypervector against a vector of hypervectors using the `similarity` function. This is useful for finding the most similar hypervector in a collection. ```julia similarity(h₁, h₁) ``` -------------------------------- ### Permute Hypervector with shift amount Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Applies a permutation (circular shift) to a hypervector by one position using the 'ρ' function. ```julia ρ(h₁, 1) ``` -------------------------------- ### Calculate Similarity Between Two Hypervectors Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/introduction-to-hdc.md Use the `similarity` function to compare two hypervectors. This is a fundamental operation for retrieving information from HDC representations. ```julia similarity(h₁, h₂) ``` -------------------------------- ### Represent Sweden Source: https://github.com/kermit-ugent/hyperdimensionalcomputing.jl/blob/main/docs/src/examples/whats-the-dollar-of-mexico.md Creates a holistic hypervector for Sweden, similar to how USA and Mexico were represented. ```julia SWE = BipolarHDV() STO = BipolarHDV() KRO = BipolarHDV() SWEDEN = (COUNTRY * SWE) + (CAPITAL * STO) + (MONEY * KRO) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.