Replies: 19 comments 1 reply
-
Beta Was this translation helpful? Give feedback.
-
|
Norm vs Seminorm 🔹 NormA norm ∥⋅∥\|\cdot\|∥⋅∥ on a vector space satisfies:
✅ Induces a true metric d(x,y)=∥x−y∥d(x, y) = \|x - y\|d(x,y)=∥x−y∥ 🔹 SeminormA seminorm ppp satisfies:
🚫 Does not require that p(x)=0⇒x=0p(x) = 0 \Rightarrow x = 0p(x)=0⇒x=0; can assign 0 to non-zero vectors. 🔁 Key Differences
Property | Norm | Seminorm
-- | -- | --
Separates points | Yes | No (can have x≠yx \ne yx=y with 0 “length”)
Induced metric type | Metric | Pseudometric
Kernel (set where value = 0) | Only {0}\{0\}{0} | Possibly a whole subspace
Topology | Hausdorff | Not Hausdorff unless kernel is factored out
Common usage | Distance geometry, Banach spaces | Quotients, function spaces like LpL^pLp
|
Beta Was this translation helpful? Give feedback.
-
|
Cosine similarity falls into a distinct category: it is not a norm, not a seminorm, and not a metric — but it is a bounded similarity function based on the angle between vectors. 🔹 Cosine Similarity DefinitionGiven vectors x,y∈Rn∖{0}x, y \in \mathbb{R}^n \setminus \{0\}x,y∈Rn∖{0}, the cosine similarity is defined as: cos_sim(x,y)=x⋅y∥x∥ ∥y∥\text{cos\_sim}(x, y) = \frac{x \cdot y}{\|x\| \, \|y\|}cos_sim(x,y)=∥x∥∥y∥x⋅yWhere:
🔸 Key Properties
Property | Cosine Similarity
-- | --
Range | [−1,1][-1, 1][−1,1], or [0,1][0,1][0,1] if x,y≥0x, y \ge 0x,y≥0
Symmetric | Yes (cos_sim(x,y)=cos_sim(y,x)\text{cos\_sim}(x, y) = \text{cos\_sim}(y, x)cos_sim(x,y)=cos_sim(y,x))
Identity of indiscernibles | No: cos_sim(x,y)=1\text{cos\_sim}(x, y) = 1cos_sim(x,y)=1 ⇏ x=yx = yx=y
Triangle inequality | No
Homogeneity | No (not linear/scaling invariant as a function of a single input)
Unit-free | Yes — it compares direction, not magnitude
🔸 Geometric MeaningCosine similarity captures the angle between vectors. Two vectors are:
Hence, it is a directional similarity, insensitive to scale. 🔸 Related Metric (Optional)You can derive a distance-like function called cosine distance: cos_dist(x,y)=1−cos_sim(x,y)\text{cos\_dist}(x, y) = 1 - \text{cos\_sim}(x, y)cos_dist(x,y)=1−cos_sim(x,y)But this is not a true metric — it fails the triangle inequality unless restricted to certain domains (e.g. unit sphere in positive orthant). ✅ SummaryCosine similarity is:
Would you like a comparison of cosine similarity to Euclidean distance or to other similarity/distance functions in a table? |
Beta Was this translation helpful? Give feedback.
-
|
Here’s a concise explanation of how norms and seminorms relate to metrics and pseudometrics in mathematics and metric theory: 🔹 From Norms to MetricsA norm ∥⋅∥\|\cdot\| on a vector space XX directly induces a metric: d(x,y)=∥x−y∥d(x, y) = \|x - y\|This dd satisfies all metric axioms:
✅ Therefore, every norm induces a metric, and a normed space is also a metric space. 🔹 From Seminorms to PseudometricsA seminorm p(⋅)p(\cdot) also defines a distance-like function: dp(x,y)=p(x−y)d_p(x, y) = p(x - y)This function is a pseudometric because it satisfies:
✅ So, every seminorm induces a pseudometric, not a true metric. 🔁 Summary Table
✅ Final Insight
Let me know if you want a diagram or visual example of this relationship. |
Beta Was this translation helpful? Give feedback.
-
|
Here’s a direct breakdown of what induces a seminorm and what induces a norm, organized by source structure, the induction mechanism, and the required condition. 🔹 What Induces a Seminorm
|
Beta Was this translation helpful? Give feedback.
-
|
An inner product can be induced or constructed from a variety of underlying structures, especially in the context of functional analysis, geometry, and kernel theory. Unlike norms or metrics, inner products require a richer structure: they define not only length but also angles and orthogonality. Here's a breakdown of what can induce or define an inner product: 🔹 What Can Induce an Inner Product?
🔁 Summary of Induction Paths🔸 Example: From Norm to Inner ProductIf ∥⋅∥\|\cdot\| satisfies the parallelogram identity, define: ⟨x,y⟩=14(∥x+y∥2−∥x−y∥2)\langle x, y \rangle = \frac{1}{4}\left( \|x + y\|^2 - \|x - y\|^2 \right)This reconstructs the inner product from the norm. If the norm doesn't satisfy this law, it cannot come from an inner product. ✅ Final InsightAn inner product can be induced by:
|
Beta Was this translation helpful? Give feedback.
-
|
Here is a clear and complete list of axioms for each structure you asked about, aligned side-by-side for comparison: ✅ Axioms by Mathematical Structure
🧠 Key Distinctions
|
Beta Was this translation helpful? Give feedback.
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
1. Kernel Function: A positive-definite kernel (often just “kernel” in RKHS theory) is a symmetric bivariate function satisfying a positive semidefiniteness condition. Formally, (K: X\times X \to \mathbb{R}) (or ℂ) is a kernel if:
2. Inner Product: An inner product on a vector space (V) (over ℝ or ℂ) is a binary operation (\langle \cdot,\cdot\rangle: V\times V\to \mathbb{F}) (with ℝ or ℂ as the field) satisfying the following axioms ([NotesFromAnton10thEdCh6.pages](https://www.math.ucdavis.edu/~cooperjacob/NotesFromAnton10thEdCh6.pdf#:~:text=1,positivity%20axiom)):
3. Degenerate Inner Product: If the positive-definiteness requirement is dropped, one obtains a degenerate inner product – a sesquilinear form that is symmetric (or Hermitian) and positive semidefinite but not strictly definite. Formally, it satisfies the linearity and symmetry axioms of an inner product, except that now (\langle v,v\rangle = 0) is allowed for some nonzero vectors (v) ([Inner product space - Wikipedia](https://en.wikipedia.org/wiki/Inner_product_space#:~:text=If%20Image%3A%20,x%3A%5C%7Cx%5C%7C%3D0)). In particular:
4. Norm: A norm on a vector space (V) is a function (||\cdot||: V\to [0,\infty)) assigning lengths to vectors, subject to these axioms ([Norm (mathematics) - Wikipedia, the free encyclopedia](https://chibum.files.wordpress.com/2013/09/ch11_supple_norm.pdf#:
5. Seminorm: A seminorm is a generalized norm that drops the definiteness requirement. Formally, (p: V\to [0,\infty)) is a seminorm if for all scalars (\alpha) and vectors
The only difference from a norm is that one may have 6. Metric: A metric (distance function) on a set
These are the familiar metric space axioms from topology and analysis ([Definition:Metric Space - ProofWiki](https://proofwiki.org/wiki/Definition:Metric_Space#:~:text=,%3D%200)). Intuitively, a metric assigns a nonnegative, symmetric distance between any two points, zero only when the points coincide, and distances obey the triangle inequality. Note: Some authors do not list the 7. Pseudometric: A pseudometric on
Unlike a true metric, it is possible that 8. Bounded Similarity Function: A similarity function (or similarity measure) is an informal dual of a distance: it assigns a high value when two objects are “similar.” In practice, one often assumes the function is bounded (e.g. range in
These three conditions are widely assumed in applications to ensure |
Beta Was this translation helpful? Give feedback.
-
# swarmauri_core/innerproducts/IInnerProduct.py
from abc import ABC, abstractmethod
from typing import Union
from swarmauri_core.vectors.IVector import IVector
class IInnerProduct(ABC):
"""
Abstract class for an inner product.
Enforces a strict structure with only abstract methods.
"""
@abstractmethod
def compute(self, u: IVector, v: IVector) -> Union[float, complex]:
"""
Compute the inner product ⟨u, v⟩.
"""
pass
@abstractmethod
def check_conjugate_symmetry(self, u: IVector, v: IVector) -> bool:
"""
Checks conjugate symmetry: ⟨u, v⟩ = conjugate(⟨v, u⟩).
"""
pass
@abstractmethod
def check_linearity_first_argument(self, u: IVector, v: IVector, w: IVector, alpha: complex) -> bool:
"""
Checks linearity in the first argument:
⟨αu + v, w⟩ = α⟨u, w⟩ + ⟨v, w⟩.
"""
pass
@abstractmethod
def check_positivity(self, v: IVector) -> bool:
"""
Checks positivity: ⟨v, v⟩ ≥ 0 and ⟨v, v⟩ = 0 iff v = 0.
"""
pass
@abstractmethod
def check_all_axioms(self, u: IVector, v: IVector, w: IVector, alpha: complex) -> bool:
"""
Checks all axioms for a given set of vectors and a scalar.
Returns True if all checks pass.
"""
pass |
Beta Was this translation helpful? Give feedback.
-
# swarmauri_core/norms/INorm.py
from abc import ABC, abstractmethod
from swarmauri.vectors.IVector import IVector
class INorm(ABC):
"""
Abstract base class for a norm.
A norm ∥⋅∥ satisfies the following axioms:
1. Non-negativity: ∥x∥ ≥ 0 and ∥x∥ = 0 ⟺ x = 0
2. Absolute scalability: ∥αx∥ = |α| ⋅ ∥x∥
3. Triangle inequality: ∥x + y∥ ≤ ∥x∥ + ∥y∥
"""
@abstractmethod
def compute(self, x: IVector) -> float:
"""
Compute the norm of a vector x.
:param x: The vector for which to compute the norm.
:return: The norm of x.
"""
pass
@abstractmethod
def verify_non_negativity(self, x: IVector):
"""
Verify non-negativity: ∥x∥ ≥ 0 and ∥x∥ = 0 ⟺ x = 0
:param x: The vector to verify.
"""
pass
@abstractmethod
def verify_absolute_scalability(self, alpha: float, x: IVector):
"""
Verify absolute scalability: ∥αx∥ = |α| ⋅ ∥x∥
:param alpha: The scalar multiplier.
:param x: The vector to verify.
"""
pass
@abstractmethod
def verify_triangle_inequality(self, x: IVector, y: IVector):
"""
Verify triangle inequality: ∥x + y∥ ≤ ∥x∥ + ∥y∥
:param x: The first vector (an instance of IVector).
:param y: The second vector (an instance of IVector).
"""
pass
@abstractmethod
def verify_definiteness(self, x: IVector):
"""
Verify definiteness: ∥x∥ = 0 ⟺ x is the zero vector.
:param x: The vector to verify.
"""
pass
``` |
Beta Was this translation helpful? Give feedback.
-
# swarmauri_core/norms/IUseInnerProduct
from abc import ABC, abstractmethod
from swarmauri.vectors.IVector import IVector
class IUseInnerProduct(ABC):
"""
Abstract base class for norms using inner products, defining inner-product-specific methods.
"""
@abstractmethod
def angle_between_vectors(self, x: IVector, y: IVector) -> float:
"""
Compute the angle between two vectors.
"""
pass
@abstractmethod
def verify_orthogonality(self, x: IVector, y: IVector) -> bool:
"""
Verify if two vectors are orthogonal.
"""
pass
@abstractmethod
def project(self, x: IVector, y: IVector) -> IVector:
"""
Compute the projection of vector x onto vector y.
"""
pass
@abstractmethod
def verify_parallelogram_law(self, x: IVector, y: IVector):
"""
Verify the parallelogram law.
"""
pass |
Beta Was this translation helpful? Give feedback.
-
# swarmauri_core/norms/INorm.py
from abc import ABC, abstractmethod
from swarmauri.vectors.IVector import IVector
class ISeminorm(ABC):
"""
Abstract base class for a norm.
A norm ∥⋅∥ satisfies the following axioms:
1. Non-negativity: ∥x∥ ≥ 0 and ∥x∥ = 0 ⟺ x = 0
2. Absolute scalability: ∥αx∥ = |α| ⋅ ∥x∥
3. Triangle inequality: ∥x + y∥ ≤ ∥x∥ + ∥y∥
"""
@abstractmethod
def compute(self, x: IVector) -> float:
"""
Compute the norm of a vector x.
:param x: The vector for which to compute the norm.
:return: The norm of x.
"""
pass
@abstractmethod
def verify_non_negativity(self, x: IVector):
"""
Verify non-negativity: ∥x∥ ≥ 0 and ∥x∥ = 0 ⟺ x = 0
:param x: The vector to verify.
"""
pass
@abstractmethod
def verify_absolute_scalability(self, alpha: float, x: IVector):
"""
Verify absolute scalability: ∥αx∥ = |α| ⋅ ∥x∥
:param alpha: The scalar multiplier.
:param x: The vector to verify.
"""
pass
@abstractmethod
def verify_triangle_inequality(self, x: IVector, y: IVector):
"""
Verify triangle inequality: ∥x + y∥ ≤ ∥x∥ + ∥y∥
:param x: The first vector (an instance of IVector).
:param y: The second vector (an instance of IVector).
"""
pass
|
Beta Was this translation helpful? Give feedback.
-
# swarmauri_core/metrics/IMetric.py
from abc import ABC, abstractmethod
from typing import List
from swarmauri_core.vectors.IVector import IVector
class IMetric(ABC):
"""
Interface for computing distances and similarities between high-dimensional data vectors. This interface
abstracts the method for calculating the distance and similarity, allowing for the implementation of various
distance metrics such as Euclidean, Manhattan, Cosine similarity, etc.
"""
@abstractmethod
def distance(self, vector_a: IVector, vector_b: IVector) -> float:
"""
Computes the distance between two vectors.
Args:
vector_a (IVector): The first vector in the comparison.
vector_b (IVector): The second vector in the comparison.
Returns:
float: The computed distance between vector_a and vector_b.
"""
pass
@abstractmethod
def distances(self, vector_a: IVector, vectors_b: List[IVector]) -> List[float]:
"""
Computes distances from one vector to a list of vectors.
Args:
vector_a (IVector): The reference vector.
vectors_b (List[IVector]): A list of vectors to compute distances to.
Returns:
List[float]: A list of distances.
"""
pass
@abstractmethod
def check_triangle_inequality(self, vector_a: IVector, vector_b: IVector, vector_c: IVector) -> bool:
"""
Validates the triangle inequality property for three vectors.
Args:
vector_a (IVector): The first vector.
vector_b (IVector): The second vector.
vector_c (IVector): The third vector.
Returns:
bool: True if the triangle inequality holds, False otherwise.
"""
pass
@abstractmethod
def check_non_negativity(self, vector_a: IVector, vector_b: IVector) -> bool:
"""
Validates the non-negativity property of the metric.
Args:
vector_a (IVector): The first vector.
vector_b (IVector): The second vector.
Returns:
bool: True if the non-negativity property holds, False otherwise.
"""
pass
@abstractmethod
def check_identity_of_indiscernibles(self, vector_a: IVector, vector_b: IVector) -> bool:
"""
Validates the identity of indiscernibles property of the metric.
Args:
vector_a (IVector): The first vector.
vector_b (IVector): The second vector.
Returns:
bool: True if the identity of indiscernibles property holds, False otherwise.
"""
pass
@abstractmethod
def check_symmetry(self, vector_a: IVector, vector_b: IVector) -> bool:
"""
Validates the symmetry property of the metric.
Args:
vector_a (IVector): The first vector.
vector_b (IVector): The second vector.
Returns:
bool: True if the symmetry property holds, False otherwise.
"""
pass
@abstractmethod
def check_positivity(self, vector_a: IVector, vector_b: IVector) -> bool:
"""
Validates the positivity (separation) property of the metric.
Args:
vector_a (IVector): The first vector.
vector_b (IVector): The second vector.
Returns:
bool: True if the positivity property holds, False otherwise.
"""
pass |
Beta Was this translation helpful? Give feedback.
-
# swarmauri_core/vectors/IVector.py
from abc import ABC, abstractmethod
class IVector(ABC):
"""
Interface for a high-dimensional data vector. This interface defines the
basic structure and operations for interacting with vectors in various applications,
such as machine learning, information retrieval, and similarity search.
"""
@abstractmethod
def check_closure_addition(self, other: "IVector") -> bool:
"""
Checks if the result of vector addition is a valid vector.
"""
pass
@abstractmethod
def check_closure_scalar_multiplication(self, scalar: float) -> bool:
"""
Checks if the result of scalar multiplication is a valid vector.
"""
pass
@abstractmethod
def check_additive_identity(self) -> bool:
"""
Checks if adding the zero vector to this vector returns the original vector.
"""
pass
@abstractmethod
def check_additive_inverse(self) -> bool:
"""
Checks if adding the additive inverse of this vector results in the zero vector.
"""
pass
@abstractmethod
def check_commutativity_addition(self, other: "IVector") -> bool:
"""
Checks if vector addition is commutative.
"""
pass
@abstractmethod
def check_distributivity_scalar_vector(self, scalar: float, other: "IVector") -> bool:
"""
Checks if scalar multiplication distributes over vector addition.
"""
pass
@abstractmethod
def check_distributivity_scalar_scalar(self, scalar1: float, scalar2: float) -> bool:
"""
Checks if scalar multiplication distributes over scalar addition.
"""
pass
@abstractmethod
def check_compatibility_scalar_multiplication(self, scalar1: float, scalar2: float) -> bool:
"""
Checks if scalar multiplication is compatible with field multiplication.
"""
pass
@abstractmethod
def check_scalar_multiplication_identity(self) -> bool:
"""
Checks if scalar multiplication by 1 returns the original vector.
"""
pass
@abstractmethod
def check_all_axioms(self, other: "IVector", scalar1: float, scalar2: float) -> bool:
"""
Verifies if the vector satisfies all vector space axioms.
"""
pass
|
Beta Was this translation helpful? Give feedback.
-
# swarmauri_base/vectors/VectorBase.py
from abc import ABC
from typing import Union, Callable, List, Tuple, Dict, Any, Optional, Literal
import numpy as np
from pydantic import BaseModel, Field
from swarmauri_core.vectors.IVector import IVector
from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
VectorValue = Union[
float, # Real numbers
int, # Integers
complex, # Complex numbers
Callable[[float], float], # Functions (e.g., continuous representations)
np.ndarray, # NumPy arrays
List[float], # Lists of floats
List[int], # Lists of integers
Tuple[float, ...], # Tuples of floats
Dict[Any, float], # Sparse representations
str, # Optional: for categorical vectors
]
class VectorBase(ComponentBase, BaseModel):
value: VectorValue
domain: Optional[Tuple[float, float]] = None
num_samples: int = 100
resource: Optional[str] = Field(default=ResourceTypes.VECTOR.value, frozen=True)
type: Literal['VectorBase'] = 'VectorBase'
def __init__(self, **kwargs):
"""
Custom initialization to process `value` into the internal representation
while leveraging Pydantic for validation and management of attributes.
"""
# Extract `value` from kwargs for special processing
value = kwargs.get('value')
domain = kwargs.get('domain', None)
num_samples = kwargs.get('num_samples', 100)
# Process the value using `_process_value` to ensure a consistent format
processed_value = self._process_value(value, domain, num_samples)
kwargs['value'] = processed_value # Update kwargs with processed value
# Call the parent __init__ to handle validation and other attributes
super().__init__(**kwargs)
def _process_value(self, value: VectorValue, domain: Optional[Tuple[float, float]], num_samples: int) -> np.ndarray:
"""
Processes the input value into a consistent internal NumPy array format.
Args:
value (VectorValue): The input value to process.
domain (Optional[Tuple[float, float]]): Domain for callable values.
num_samples (int): Number of samples for callable values.
Returns:
np.ndarray: The processed vector in NumPy array format.
"""
# Handle numbers
if isinstance(value, (int, float, complex)):
return np.array([value], dtype=np.float64)
# Handle lists, tuples, or NumPy arrays
if isinstance(value, (list, tuple, np.ndarray)):
return np.array(value, dtype=np.float64)
# Handle functions
if callable(value):
if not domain:
raise ValueError("A domain must be specified when the value is a function.")
start, end = domain
sample_points = np.linspace(start, end, num_samples)
return np.array([value(x) for x in sample_points], dtype=np.float64)
# Handle sparse representations
if isinstance(value, dict):
max_index = max(value.keys())
sparse_array = np.zeros(max_index + 1, dtype=np.float64)
for key, val in value.items():
sparse_array[key] = val
return sparse_array
# Handle unsupported types
raise TypeError(f"Unsupported value type: {type(value)}")
def to_numpy(self) -> np.ndarray:
"""
Converts the vector into a numpy array.
Returns:
np.ndarray: The numpy array representation of the vector.
"""
return self.value
@property
def shape(self):
return self.value.shape
def __len__(self):
return len(self.value)
def __add__(self, other: "VectorBase") -> "VectorBase":
if not isinstance(other, VectorBase):
raise TypeError("Can only add another VectorBase instance.")
if len(self) != len(other):
raise ValueError("Vectors must have the same length.")
return VectorBase(value=(self.value + other.value))
def __neg__(self) -> "VectorBase":
return VectorBase(value=(-self.value))
def __sub__(self, other: "VectorBase") -> "VectorBase":
return self + (-other)
def __mul__(self, scalar: float) -> "VectorBase":
return VectorBase(value=(self.value * scalar))
def __rmul__(self, scalar: float) -> "VectorBase":
return self * scalar
def __eq__(self, other: "VectorBase") -> bool:
if not isinstance(other, VectorBase):
return False
return np.array_equal(self.value, other.value)
@property
def zero(self) -> "VectorBase":
return VectorBase(value=[0.0] * len(self))
# Axiom checks (unchanged)
def check_closure_addition(self, other: "VectorBase") -> bool:
try:
result = self + other
return isinstance(result, VectorBase)
except Exception:
return False
def check_closure_scalar_multiplication(self, scalar: float) -> bool:
try:
result = scalar * self
return isinstance(result, VectorBase)
except Exception:
return False
def check_additive_identity(self) -> bool:
return self + self.zero == self
def check_additive_inverse(self) -> bool:
return self + (-self) == self.zero
def check_commutativity_addition(self, other: "VectorBase") -> bool:
return self + other == other + self
def check_distributivity_scalar_vector(self, scalar: float, other: "VectorBase") -> bool:
return scalar * (self + other) == scalar * self + scalar * other
def check_distributivity_scalar_scalar(self, scalar1: float, scalar2: float) -> bool:
return (scalar1 + scalar2) * self == scalar1 * self + scalar2 * self
def check_compatibility_scalar_multiplication(self, scalar1: float, scalar2: float) -> bool:
return (scalar1 * scalar2) * self == scalar1 * (scalar2 * self)
def check_scalar_multiplication_identity(self) -> bool:
return 1 * self == self
def check_all_axioms(self, other: "VectorBase", scalar1: float, scalar2: float) -> bool:
return (
self.check_closure_addition(other) and
self.check_closure_scalar_multiplication(scalar1) and
self.check_additive_identity() and
self.check_additive_inverse() and
self.check_commutativity_addition(other) and
self.check_distributivity_scalar_vector(scalar1, other) and
self.check_distributivity_scalar_scalar(scalar1, scalar2) and
self.check_compatibility_scalar_multiplication(scalar1, scalar2) and
self.check_scalar_multiplication_identity()
) |
Beta Was this translation helpful? Give feedback.
-
|
Missing resource_kind: Psuedometrics |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
For the purpose of discussion distinguishing characteristics for Distance and Similarity resources
Beta Was this translation helpful? Give feedback.
All reactions