### Bundle Hypervectors using `bundle` function Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc This example demonstrates bundling multiple hypervectors (h₁, h₂, h₃) into a single hypervector using the `bundle` function. Bundling combines hypervectors such that the resulting vector is similar to its constituents. ```julia bundle([h₁, h₂, h₃]) ``` -------------------------------- ### Create Specific Instance Hypervectors in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This code defines hypervectors for specific instances like countries (USA, Mexico), their capitals (Washington DC, Mexico City), and currencies (Dollar, Peso). These are concrete examples that will be linked to the abstract concepts. The output displays the generated hypervectors. ```julia USA = BipolarHV(:usa) MEX = BipolarHV(:mexico) WDC = BipolarHV(:wdc) # Washington DC MXC = BipolarHV(:mxc) # Mexico City DOL = BipolarHV(:dollar) PES = BipolarHV(:peso) USA, MEX, WDC, MXC, DOL, PES ``` -------------------------------- ### Create Level Encoder/Decoder with HyperdimensionalComputing.convertlevel Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api A utility function to create both the encoder and decoder for level encoding in a single step. It abstracts the process described in encodelevel and decodelevel functions, simplifying the setup for level-based hyperdimensional representations. ```julia convertlevel(hvlevels, numvals..., kwargs...) ``` -------------------------------- ### Create Bipolar Hypervector from a Seed Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc Demonstrates creating a bipolar hypervector using an arbitrary Julia object (like a symbol) as a seed. The package uses this seed to deterministically generate the hypervector, ensuring reproducibility. ```julia BipolarHV(:foo) ``` -------------------------------- ### Encode Key-Value Pairs as Hypervectors using Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc Illustrates encoding key-value pairs into a single hypervector using bundling and binding operations in HyperdimensionalComputing.jl. This demonstrates creating an associative memory where keys (e.g., animals) are mapped to values (e.g., sounds). ```julia H_dog = TernaryHV(:dog) H_cat = TernaryHV(:cat) H_cow = TernaryHV(:cow) H_animals = [H_dog, H_cat, H_cow] H_bark = TernaryHV(:bark) H_meow = TernaryHV(:meow) H_moo = TernaryHV(:moo) H_sounds = [H_bark, H_meow, H_moo] memory = (H_dog * H_bark) + (H_cat * H_meow) + (H_cow * H_moo) ``` ```julia memory == hashtable(H_animals, H_sounds) ``` ```julia nearest_neighbor(H_dog * memory, H_sounds) ``` ```julia nearest_neighbor(H_moo * memory, H_animals) ``` -------------------------------- ### Create Bipolar Hypervector from a Vector Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc Shows how to initialize a bipolar hypervector directly from a Julia `Vector` of integers (typically -1 and 1). This method allows for precise control over the hypervector's initial state. ```julia BipolarHV(rand((-1, 1), 8)) ``` -------------------------------- ### Import HyperdimensionalComputing.jl Library Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This code snippet imports the necessary HyperdimensionalComputing.jl library to begin working with hyperdimensional computing concepts in Julia. No specific inputs or outputs are generated, but it's a prerequisite for all subsequent operations. ```julia using HyperdimensionalComputing ``` -------------------------------- ### Create Default Bipolar Hypervector Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc Demonstrates the creation of a default bipolar hypervector using the BipolarHV() function. By default, it generates a hypervector with 10,000 dimensions. The output shows the dimensionality and the count of +1 and -1 elements. ```julia BipolarHV() ``` -------------------------------- ### Create Bipolar Hypervector with Specific Dimensions Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc Illustrates how to create a bipolar hypervector with a specified number of dimensions. The `D` keyword argument allows you to set the desired dimensionality, overriding the default. ```julia BipolarHV(; D = 8) ``` -------------------------------- ### Create Multiple Bipolar Hypervectors Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc This code snippet initializes three bipolar hypervectors (h₁, h₂, h₃) with 8 dimensions each. These are typically used for demonstrating HDC operations like bundling and binding. ```julia h₁ = BipolarHV(; D = 8) h₂ = BipolarHV(; D = 8) h₃ = BipolarHV(; D = 8); ``` -------------------------------- ### Bundle Hypervectors using `+` operator Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc Shows an alternative way to bundle hypervectors (h₁, h₂, h₃) using the overloaded `+` operator. This operation results in a hypervector that is similar to all the input hypervectors, often followed by a normalization step (like `sign` for bipolar hypervectors). ```julia h₁ + h₂ + h₃ ``` -------------------------------- ### Bind Hypervectors using `*` operator Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc Demonstrates binding hypervectors (h₁, h₂, h₃) using the overloaded `*` operator. Similar to the `bind` function, this operation produces a hypervector that is quasi-orthogonal to the input hypervectors. ```julia h₁ * h₂ * h₃ ``` -------------------------------- ### Query Corresponding Currency using Country and Currency in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This code demonstrates querying for corresponding elements. It checks if binding the USA's composite hypervector with the dollar hypervector is approximately equal to binding Mexico's composite hypervector with the peso hypervector. This tests the relationship between currencies across countries. The output is a boolean value. ```julia USTATES * DOL ≈ MEXICO * PES ``` -------------------------------- ### Bind Hypervectors using `bind` function Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc This snippet illustrates binding multiple hypervectors (h₁, h₂, h₃) into a single hypervector using the `bind` function. Binding creates a hypervector that is dissimilar (quasi-orthogonal) to its constituents. ```julia bind([h₁, h₂, h₃]) ``` -------------------------------- ### Calculate Similarity Between Hypervectors in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc Shows how to use the `similarity` function (and its synonym `δ`) in HyperdimensionalComputing.jl to compare hypervectors. It handles comparisons between two hypervectors, a hypervector and a list of hypervectors, or creating a similarity function for repeated use. ```julia similarity(h₁, h₂) ``` ```julia similarity(h₁, h₁) ``` ```julia similarity.(Ref(h₁), [h₁, h₂, h₃]) ``` ```julia f = δ(h₁) f.([h₁, h₂, h₃]) ``` -------------------------------- ### Encode Phrases using N-grams in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc This snippet demonstrates encoding a list of phrases into hypervectors using the `ngrams` encoder in Julia. It utilizes `BinaryHV` for character encoding and a sliding window of 3 characters for n-gram generation. The output is a vector of hypervectors representing each phrase. ```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", ]; encode(p::String) = map(c -> BinaryHV(c), collect(p)) |> ngrams H_phrases = map(encode, phrases) ``` -------------------------------- ### Permute Hypervector using Circular Shift in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc Demonstrates the permutation operation (circular shifting) on a hypervector in HyperdimensionalComputing.jl. This operation creates a variant of a hypervector that is dissimilar to the original, useful for creating quasi-orthogonal representations. ```julia h₄ = TernaryHV(collect(0:9)) ρ(h₄).v ``` ```julia ρ(h₁, 1) ``` -------------------------------- ### Build Composite Country Hypervectors in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This snippet constructs composite hypervectors for the USA and Mexico by binding abstract concepts (COUNTRY, CAPITAL, MONEY) to their specific instances (USA, WDC, DOL for USA; MEX, MXC, PES for Mexico) and then summing them. This creates a single hypervector representing each country holistically. The output shows the resulting composite hypervectors. ```julia USTATES = (COUNTRY * USA) + (CAPITAL * WDC) + (MONEY * DOL) MEXICO = (COUNTRY * MEX) + (CAPITAL * MXC) + (MONEY * PES) USTATES, MEXICO ``` -------------------------------- ### Create Query Hypervector for N-gram Search in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc This code prepares a query hypervector for searching within encoded phrases. It converts the search term 'crazy' into a hypervector using the same character-to-`BinaryHV` mapping and `ngrams` encoder as used for phrase encoding. ```julia query = map(c -> BinaryHV(c), collect("crazy")) |> ngrams ``` -------------------------------- ### Create Abstract Concept Hypervectors in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This snippet defines hypervectors for abstract concepts such as COUNTRY, CAPITAL, and MONEY using the BipolarHV function. These represent general categories that will be associated with specific instances later. The output shows the structure of these hypervectors. ```julia COUNTRY = BipolarHV(:country) CAPITAL = BipolarHV(:capital) MONEY = BipolarHV(:money) COUNTRY, CAPITAL, MONEY ``` -------------------------------- ### Check Hypervector Similarity with Base.isapprox Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Measures the similarity between two hypervectors (AbstractHV) using Hamming distance. It can optionally use bootstrapping to construct a null distribution for more robust similarity assessment. Parameters include atol for the number of matches beyond chance and ptol for the probability threshold. ```julia Base.isapprox(u::AbstractHV, v::AbstractHV, atol=length(u)/100, ptol=0.01) ``` -------------------------------- ### Bundle Sequence Encoding with HyperdimensionalComputing.bundlesequence Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Encodes a sequence of hypervectors using a bundling-based method. Similar to bindsequence, the first hypervector is not permuted, and subsequent hypervectors are permuted. This method uses the mathematical notation ⊕i=1mΠ(Vi,i−1) and is a bundling variant of bindsequence. ```julia bundlesequence(vs::AbstractVector{<:AbstractHV}) ``` -------------------------------- ### Verify Relationship Hypervector Composition in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This code verifies that the relationship hypervector (F_UM) created by binding USA and Mexico is approximately equal to the sum of the bindings of their respective components (USA*MEX, WDC*MXC, DOL*PES). This demonstrates the composability of hypervector operations. The output is a boolean value. ```julia F_UM ≈ (USA * MEX) + (WDC * MXC) + (DOL * PES) ``` -------------------------------- ### Base.isapprox - Hypervector Similarity Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Measures the similarity between two hypervectors using the Hamming distance. It determines if the hypervectors have more elements in common than expected by chance, employing a bootstrap method to construct a null distribution. Parameters like `ptol` (threshold for chance matches) and `N_bootstrap` (number of bootstrap samples) can be specified. ```APIDOC ## Base.isapprox ### Description Measures when two hypervectors are similar (have more elements in common than expected by chance) using the Hamming distance. Uses a bootstrap to construct a null distribution. ### Method `Base.isapprox(u::AbstractHV, v::AbstractHV, atol=length(u)/100, ptol=0.01)` ### Parameters #### Path Parameters None #### Query Parameters * `u` (AbstractHV) - The first hypervector. * `v` (AbstractHV) - The second hypervector. * `atol` (Float64) - Optional. Threshold for number of matches more than due to chance needed for being assumed similar. Defaults to `length(u)/100`. * `ptol` (Float64) - Optional. Threshold for seeing that many matches due to chance. Defaults to `0.01`. ### Request Example ```json { "u": "hypervector_u_representation", "v": "hypervector_v_representation" } ``` ### Response #### Success Response (200) - **is_approx** (Boolean) - True if hypervectors are considered similar, false otherwise. #### Response Example ```json { "is_approx": true } ``` ``` -------------------------------- ### Add Sweden's Composite Hypervector in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This snippet introduces Sweden by creating its composite hypervector, similar to how the USA and Mexico were represented. It binds the abstract concepts of COUNTRY, CAPITAL, and MONEY to their specific instances (SWE, STO, SEK). The output describes the newly created hypervector for Sweden. ```julia SWE = BipolarHV(:sweden) STO = BipolarHV(:stockholm) SEK = BipolarHV(:krona) SWEDEN = (COUNTRY * SWE) + (CAPITAL * STO) + (MONEY * SEK) ``` -------------------------------- ### Query Corresponding Currency using USA, Currency, and Mexico in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This snippet further refines the query for corresponding currencies. It checks if binding the USA's composite hypervector with the dollar, and then with Mexico's composite hypervector, results in a vector approximately equal to the peso hypervector. This demonstrates a more complex retrieval path. The output is a boolean value. ```julia USTATES * DOL * MEXICO ≈ PES ``` -------------------------------- ### Compare Composite Country Hypervectors in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This code compares the composite hypervectors for the United States and Mexico using the approximate equality operator (`≈`). It demonstrates that these distinct composite hypervectors are not approximately equal, reflecting their different underlying specific instances. The output is a boolean value. ```julia USTATES ≈ MEXICO ``` -------------------------------- ### Create Multiple Relationship Hypervectors in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This code generates relationship hypervectors between different country pairs: USA-Mexico (F_UM), Sweden-USA (F_SU), and Sweden-Mexico (F_SM). These vectors capture the associations between the respective countries. The output describes the generated hypervectors. ```julia F_UM = USTATES * MEXICO F_SU = SWEDEN * USTATES F_SM = SWEDEN * MEXICO ``` -------------------------------- ### Query Currency of Mexico using USA-Mexico Relationship in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This code answers the question "What in Mexico corresponds to the United States' dollar?" by unbinding the dollar hypervector from the USA-Mexico relationship hypervector. The result is expected to be approximately equal to the peso hypervector, demonstrating concept retrieval. The output is a boolean value. ```julia DOL * F_UM ≈ PES ``` -------------------------------- ### hashtable Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Creates a hash table from key-value hypervector pairs. Keys and values must have the same length for encoding. ```APIDOC ## hashtable ### Description Hash table from keys-values hypervector pairs. Keys and values must be the same length in order to encode as a hypervector. ### Method `hashtable(keys::T, values::T) where {T <: AbstractVector{<:AbstractHV}}` ### Parameters #### Arguments - **keys** (AbstractVector{<:AbstractHV}) - Required - Keys hypervectors. - **values** (AbstractVector{<:AbstractHV}) - Required - Values hypervectors. ### Example ```julia ks = [BinaryHV(10) for _ in 1:5] vs = [BinaryHV(10) for _ in 1:5] hashtable(ks, vs) ``` ### Mathematical Notation ⊕i=1mKi⊗Vi where `K` and `V` are the key and value hypervector collections, `m` is the size of the hypervector collection, `i` is the position of the entry in the collection, and `⊗` and `⊕` are the binding and bundling operations. ### References - Torchhd documentation ``` -------------------------------- ### Perform Nearest Neighbor Search with N-grams in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/introduction-to-hdc This snippet performs a nearest neighbor search to find the phrase most similar to the query 'crazy' among the encoded phrases. It uses the `nearest_neighbor` function, returning the similarity score, the index of the closest phrase, and the hypervector of that phrase. ```julia nearest_neighbor(query, H_phrases) ``` -------------------------------- ### Bundle hypervectors using multiset in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api The multiset function creates a hypervector representing the multiset of input hypervectors, bundling them together. It takes a vector of hypervectors and returns a single hypervector. This is useful for representing collections where order does not matter, as opposed to sequential encoding. ```julia function multiset(vs::AbstractVector{<:T})::T where {T <: AbstractHV} # ... implementation ... end ``` -------------------------------- ### Bind Sequence Encoding with HyperdimensionalComputing.bindsequence Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Encodes a sequence of hypervectors using a binding-based method. The first hypervector is not permuted, while subsequent hypervectors are permuted based on their position in the sequence. This function is based on the mathematical notation ⊗i=1mΠ(Vi,i−1). ```julia bindsequence(vs::AbstractVector{<:AbstractHV}) ``` -------------------------------- ### Creating Hash Table Encoding from Hypervector Pairs in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Encodes key-value pairs of hypervectors into a single hypervector using a hash table strategy. Both keys and values must be provided as vectors of hypervectors of the same length. The encoding employs binding and bundling operations. ```julia function hashtable(keys::T, values::T) where {T <: AbstractVector{<:AbstractHV}} end ``` -------------------------------- ### HyperdimensionalComputing.bindsequence Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Encodes a sequence of hypervectors using a binding-based approach. The first hypervector is not permuted, while subsequent hypervectors are permuted sequentially. This method is based on the mathematical notation ⊗i=1mΠ(Vi,i−1). ```APIDOC ## HyperdimensionalComputing.bindsequence ### Description Binding-based sequence encoding. The first value is not permuted, the last value is permuted n-1 times. This encoding is based on the mathematical notation ⊗i=1mΠ(Vi,i−1). ### Method `bindsequence(vs::AbstractVector{<:AbstractHV})` ### Parameters #### Path Parameters None #### Query Parameters * `vs` (AbstractVector{<:AbstractHV}) - A sequence of hypervectors to be encoded. ### Request Example ```json { "vs": [ "hypervector_1_representation", "hypervector_2_representation", "..." ] } ``` ### Response #### Success Response (200) - **bound_sequence** (AbstractHV) - The resulting bound sequence hypervector. #### Response Example ```json { "bound_sequence": "encoded_hypervector_representation" } ``` ### See also * `bundlesequence` ``` -------------------------------- ### Infer Indirect Relationship via Transitivity in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This snippet demonstrates the transitivity property of hypervector operations by checking if the relationship between Sweden and Mexico (F_SM) can be inferred by combining the Sweden-USA relationship (F_SU) and the USA-Mexico relationship (F_UM). The output is a boolean value. ```julia F_SU * F_UM ≈ F_SM ``` -------------------------------- ### HyperdimensionalComputing.bundlesequence Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Encodes a sequence of hypervectors using a bundling-based approach. Similar to bindsequence, the first hypervector is not permuted, while subsequent hypervectors are permuted sequentially. This method is based on the mathematical notation ⊕i=1mΠ(Vi,i−1). ```APIDOC ## HyperdimensionalComputing.bundlesequence ### Description Bundling-based sequence encoding. The first value is not permuted, the last value is permuted n-1 times. This encoding is based on the mathematical notation ⊕i=1mΠ(Vi,i−1). ### Method `bundlesequence(vs::AbstractVector{<:AbstractHV})` ### Parameters #### Path Parameters None #### Query Parameters * `vs` (AbstractVector{<:AbstractHV}) - A sequence of hypervectors to be encoded. ### Request Example ```json { "vs": [ "hypervector_1_representation", "hypervector_2_representation", "..." ] } ``` ### Response #### Success Response (200) - **bundled_sequence** (AbstractHV) - The resulting bundled sequence hypervector. #### Response Example ```json { "bundled_sequence": "encoded_hypervector_representation" } ``` ### See also * `bindsequence` ``` -------------------------------- ### Create Relationship Hypervector between USA and Mexico in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/examples/whats-the-dollar-of-mexico This snippet creates a hypervector (F_UM) that encodes the relationship between the USA and Mexico by binding their composite hypervectors. This operation captures similarities and differences between the bundled concepts. The output is a description of the resulting hypervector. ```julia F_UM = USTATES * MEXICO ``` -------------------------------- ### graph Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Creates a graph representation from source-target hypervector pairs. Supports both directed and undirected graphs. ```APIDOC ## graph ### Description Graph for `source`-`target` pairs. Can be directed or undirected. ### Method `graph(source::T, target::T, directed::Bool = false)` ### Parameters #### Arguments - **source** (T) - Required - Source node hypervectors. - **target** (T) - Required - Target node hypervectors. - **directed** (Bool) - Optional - Whether the graph is directed or not. Defaults to `false`. ### Mathematical Notation _Undirected graphs_ ⊗i=1mSi⊗Ti _Directed graphs_ ⊗i=1mSi⊗Π(Ti) where `K` and `V` are the key and value hypervector collections, `m` is the size of the hypervector collection, `i` is the position of the entry in the collection, and `⊗`, `⊕` and `Π` are the binding, bundling and shift operations. ### See Also - `hashtable`: Hash table encoding, underlying encoding strategy of this encoder. ### References - Torchhd documentation ``` -------------------------------- ### HyperdimensionalComputing.convertlevel Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Creates the encoder and decoder for level encoding in a single step. This function serves as a convenience wrapper for `encodelevel` and `decodelevel`. ```APIDOC ## HyperdimensionalComputing.convertlevel ### Description Creates the `encoder` and `decoder` for a level encoding in one step. See `encodelevel` and `decodelevel` for their respective documentations. ### Method `convertlevel(hvlevels, numvals..., kwargs...) ### Parameters #### Path Parameters None #### Query Parameters * `hvlevels` - Hypervector levels for encoding. * `numvals...` - Number of values for the encoding. * `kwargs...` - Additional keyword arguments for encoder/decoder. ### Request Example ```json { "hvlevels": "level_definition", "numvals": [10, 5], "other_param": "value" } ``` ### Response #### Success Response (200) - **encoder** (Object) - The created encoder. - **decoder** (Object) - The created decoder. #### Response Example ```json { "encoder": { /* encoder details */ }, "decoder": { /* decoder details */ } } ``` ``` -------------------------------- ### Cross Product of Hypervector Sets with HyperdimensionalComputing.crossproduct Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Computes the cross product between two sets of hypervectors. It generates all pairwise combinations of hypervectors from the two input sets and binds them. The operation follows the formula (⊕i=1mUi)⊗(⊕i=1nVi). ```julia crossproduct(U::T, V::T) where {T <: AbstractVector{<:AbstractHV}} ``` -------------------------------- ### Converting Graded Numbers to Bipolar Format in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Maps a graded number within the [0, 1] interval to the [-1, 1] interval, which is a common requirement for bipolar hypervector representations. This is a straightforward numerical conversion function. ```julia function grad2bipol(x::Number) end ``` -------------------------------- ### Creating Graph Representations from Hypervectors in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Generates a graph representation from source and target hypervectors. It supports both directed and undirected graphs. The function takes source hypervectors, target hypervectors, and an optional boolean to specify directionality. Internally, it uses binding and bundling operations. ```julia function graph(source::T, target::T, directed::Bool = false) where T <: AbstractVector{<:AbstractHV} end ``` -------------------------------- ### Create n-gram statistics hypervector using ngrams in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api The ngrams function generates a hypervector that captures the n-gram statistics of an input sequence of hypervectors. It takes a vector of hypervectors and an integer n (defaulting to 3) for the n-gram size. This is useful for analyzing sequential data. ```julia function ngrams(vs::AbstractVector{<:AbstractHV}, n::Int = 3) # ... implementation ... end ``` -------------------------------- ### Bind multiple hypervectors using multibind in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api The multibind function binds all input hypervectors together into a single hypervector. It takes a vector of hypervectors as input and returns a single hypervector representing the bound collection. This operation is a core component of hyperdimensional computing for combining information. ```julia function multibind(vs::AbstractVector{<:AbstractHV}) # ... implementation ... end ``` -------------------------------- ### level Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Creates a set of level-correlated hypervectors where the first and last hypervectors are quasi-orthogonal. ```APIDOC ## level ### Description Creates a set of level correlated hypervectors, where the first and last hypervectors are quasi-orthogonal. ### Method Overload 1 `level(v::HV, n::Int) where {HV <: AbstractHV}` ### Parameters #### Arguments - **v** (HV) - Required - Base hypervector. - **n** (Int) - Required - Number of levels. ### Method Overload 2 `level(HV::Type{<:AbstractHV}, n::Int; D::Int = 10_000)` ### Parameters #### Arguments - **HV** (Type{<:AbstractHV}) - Required - The type of hypervector to create. - **n** (Int) - Required - Number of levels. - **D** (Int) - Optional - The dimension of the hypervectors. Defaults to 10,000. ``` -------------------------------- ### Convert Bipolar to Graded Representation with HyperdimensionalComputing.bipol2grad Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Maps a bipolar number, typically in the range [-1, 1], to the [0, 1] interval. This is useful for converting hypervector representations or other bipolar numerical data into a graded scale. ```julia bipol2grad(x::Number) ``` -------------------------------- ### Generating Level Correlated Hypervectors in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Creates a set of level-correlated hypervectors where adjacent hypervectors are quasi-orthogonal. This can be done by providing a base hypervector and the desired number of levels, or by providing a vector of items to be encoded into levels. It's useful for creating ordered sets of hypervectors. ```julia level(v::HV, n::Int) where {HV <: AbstractHV} level(HV::Type{<:AbstractHV}, n::Int; D::Int = 10000) ``` -------------------------------- ### grad2bipol Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Maps a graded number from the [0, 1] interval to the [-1, 1] interval. ```APIDOC ## grad2bipol ### Description Maps a graded number in [0, 1] to the [-1, 1] interval. ### Method `grad2bipol(x::Number)` ### Parameters #### Arguments - **x** (Number) - Required - The graded number in the [0, 1] interval. ### Response Example ```julia grad2bipol(0.5) # returns 0.0 grad2bipol(1.0) # returns 1.0 grad2bipol(0.0) # returns -1.0 ``` ``` -------------------------------- ### HyperdimensionalComputing.bipol2grad Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Converts a bipolar number from the interval [-1, 1] to the interval [0, 1]. This is a simple mapping function. ```APIDOC ## HyperdimensionalComputing.bipol2grad ### Description Maps a bipolar number in [-1, 1] to the [0, 1] interval. ### Method `bipol2grad(x::Number)` ### Parameters #### Path Parameters None #### Query Parameters * `x` (Number) - The bipolar number to convert. ### Request Example ```json { "x": -0.5 } ``` ### Response #### Success Response (200) - **grad_value** (Float64) - The converted value in the [0, 1] interval. #### Response Example ```json { "grad_value": 0.25 } ``` ``` -------------------------------- ### HyperdimensionalComputing.crossproduct Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Computes the cross product between two sets of hypervectors. This operation involves creating a multiset from both input hypervector sets and then binding them together to generate all cross products. The formula is (⊕i=1mUi)⊗(⊕i=1nVi). ```APIDOC ## HyperdimensionalComputing.crossproduct ### Description Cross product between two sets of hypervectors. This encoding strategy first creates a multiset from both input hypervector sets, which are then bound together to generate all cross products, i.e. U₁ × V₁ + U₁ × V₂ + ... + U₁ × Vₘ + ... + Uₙ × Vₘ. This encoding is based on the formula (⊕i=1mUi)⊗(⊕i=1nVi). ### Method `crossproduct(U::T, V::T) where {T <: AbstractVector{<:AbstractHV}}` ### Parameters #### Path Parameters None #### Query Parameters * `U` (AbstractVector{<:AbstractHV}) - The first set of hypervectors. * `V` (AbstractVector{<:AbstractHV}) - The second set of hypervectors. ### Request Example ```json { "U": [ "hypervector_u1_representation", "hypervector_u2_representation" ], "V": [ "hypervector_v1_representation", "hypervector_v2_representation" ] } ``` ### Response #### Success Response (200) - **cross_product_hv** (AbstractHV) - The resulting hypervector from the cross product operation. #### Response Example ```json { "cross_product_hv": "resultant_hypervector_representation" } ``` ``` -------------------------------- ### decodelevel Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Generates a decoding function for numerical values based on a provided vector of hypervectors representing levels. The returned function maps a hypervector to its corresponding numerical value through similarity matching. ```APIDOC ## decodelevel ### Description Generate a decoding function based on `level`, for decoding numerical values. It returns a function that gives the numerical value for a given hypervector, based on similarity matching. ### Method `decodelevel(hvlevels::AbstractVector{<:AbstractHV}, numvalues)` ### Parameters #### Arguments - **hvlevels** (AbstractVector{<:AbstractHV}) - Required - Vector of hypervectors representing the level encoding. - **numvalues** - Required - The range or vector with the corresponding numerical values. ### Request Example ```julia numvalues = range(0, 2pi, 100) hvlevels = level(BipolarHV(), 100) decoder = decodelevel(hvlevels, numvalues) decoder(hvlevels[17]) # value that closely matches the corresponding HV ``` ``` -------------------------------- ### Find nearest neighbor in a collection using Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api The nearest_neighbor function identifies the hypervector in a given collection that is most similar to a query hypervector. It can return the most similar element, its index, and the vector itself, or the k-closest neighbors if k is specified. This is crucial for retrieval and classification tasks. ```julia function nearest_neighbor(u::AbstractHV, collection[, k::Int]; kwargs...) # ... implementation ... end ``` -------------------------------- ### Encoding Numerical Range with Level Encoding in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api An overloaded version of `encodelevel` that accepts lower and upper bounds for an interval to be encoded into a hypervector. It utilizes the same underlying logic as the primary `encodelevel` function but specifically targets a continuous range. ```julia function encodelevel(hvlevels::AbstractVector{<:AbstractHV}, a::Number, b::Number; testbound=false) end ``` -------------------------------- ### Decoding Numerical Values with Level Encoding in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Generates a decoding function for numerical values based on a provided vector of hypervectors representing levels. This function returns a new function that takes a hypervector and returns the corresponding numerical value by matching similarity. It requires a vector of hypervectors and the range or vector of numerical values to be decoded. ```julia function decodelevel(hvlevels::AbstractVector{<:AbstractHV}, numvalues) end ``` -------------------------------- ### Alias for Similarity Calculation Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api The `δ` function is an alias for the `similarity` function in the HyperdimensionalComputing package. It provides an alternative way to compute the similarity matrix for hypervectors. ```Julia δ(u::AbstractHV, v::AbstractHV; [method]) δ(u::AbstractHV; [method]) δ(hvs::AbstractVector{<:AbstractHV}; [method]) ``` -------------------------------- ### Compute Similarity Matrix for Hypervectors Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Calculates the similarity matrix for a collection of hypervectors using specified similarity metrics. This function is essential for comparing and analyzing relationships between hypervectors within a dataset. ```Julia similarity(hvs::AbstractVector{<:AbstractHV}; [method]) ``` -------------------------------- ### Encoding Numerical Values with Level Encoding in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Generates an encoding function for numerical values based on a provided vector of hypervectors representing levels. This function returns a new function that takes a numerical input and returns the hypervector that best represents it. It accepts a vector of hypervectors, the numerical range or vector, and an optional boolean to test bounds. ```julia function encodelevel(hvlevels::AbstractVector{<:AbstractHV}, numvalues; testbound=false) end ``` -------------------------------- ### encodelevel Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Generates an encoding function for numerical values. The function maps a given numerical input to its corresponding hypervector representation based on a provided set of level hypervectors. ```APIDOC ## encodelevel ### Description Generate an encoding function based on `level`, for encoding numerical values. It returns a function that gives the corresponding hypervector for a given numerical input. ### Method `encodelevel(hvlevels::AbstractVector{<:AbstractHV}, numvalues; testbound=false)` ### Parameters #### Arguments - **hvlevels** (AbstractVector{<:AbstractHV}) - Required - Vector of hypervectors representing the level encoding. - **numvalues** - Required - The range or vector with the corresponding numerical values. - **testbound** (Bool) - Optional - Check whether the provided value is in bounds. Defaults to `false`. ### Request Example ```julia numvalues = range(0, 2pi, 100) hvlevels = level(BipolarHV(), 100) encoder = encodelevel(hvlevels, numvalues) encoder(pi/3) # hypervector that best represents this numerical value ``` ### Method Overload `encodelevel(hvlevels::AbstractVector{<:AbstractHV}, a::Number, b::Number; testbound=false)` ### Description Overload See `encodelevel`, same but provide lower (`a`) and upper (`b`) limit of the interval to be encoded. ``` -------------------------------- ### Compute similarity between two hypervectors in Julia Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api The similarity function computes the similarity between two hypervectors using a specified method (e.g., cosine, Jaccard, Hamming). It can also create a closure that computes similarity against a fixed hypervector. This is fundamental for comparing hyperdimensional representations. ```julia function similarity(u::AbstractHV; [method]) # ... implementation ... end ``` ```julia function similarity(u::AbstractVector, v::AbstractVector; method::Symbol) # ... implementation ... end ``` -------------------------------- ### Binary Hypervector Type Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Defines the `BinaryHV` type, representing hypervectors with boolean elements. This type is based on the Binary Splatter Code (BSC) vector symbolic architecture. ```Julia BinaryHV ``` -------------------------------- ### Ternary Hypervector Type Source: https://michielstock.github.io/HyperdimensionalComputing.jl/dev/api Defines the `TernaryHV` type, representing hypervectors with elements in `(-1, 1)`. This type is based on the Multiply-Add-Permute (MAP) vector symbolic architecture. ```Julia TernaryHV ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.