mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-04-30 03:50:39 +00:00
⬆️ version bump to v4.5
- Update obioptions.Version from "Release 4.4.29" to "/v/ Release v5" - Update version.txt from 4.29 → .30 (automated by Makefile)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
# `obidist` Package: Efficient Symmetric Distance/Similarity Matrix Management
|
||||
|
||||
The `*DistMatrix` type provides a memory-efficient, symmetric matrix implementation for distance or similarity data.
|
||||
|
||||
- **Storage Strategy**: Only the upper triangle (i < j) is stored, reducing memory usage from *O(n²)* to *n(n−1)/2*.
|
||||
- **Diagonal Handling**: Diagonal entries are fixed (0.0 for distances, 1.0 for similarities); assignments to diagonal indices are silently ignored.
|
||||
- **Symmetry Guarantee**: `Get(i, j)` and `Set(i, j, v)` automatically handle both (i,j) and (j,i), ensuring consistency.
|
||||
|
||||
## Constructors
|
||||
|
||||
| Function | Description |
|
||||
|---------|-------------|
|
||||
| `NewDistMatrix(n)` / `WithLabels(labels)` | Creates *n×n* distance matrix (diag = 0). |
|
||||
| `NewSimilarityMatrix(n)` / `WithLabels(labels)` | Creates *n×n* similarity matrix (diag = 1). |
|
||||
|
||||
## Core Operations
|
||||
|
||||
- `Get(i, j)` / `Set(i, j, v)`: Access/update symmetric entries.
|
||||
- `Size() int`, `GetLabel(i)` / `SetLabel(i, label)`: Query/mutate element labels.
|
||||
- `Labels() []string`, `GetRow(i)` / `GetColumn(j)`: Retrieve full rows/columns (as copies).
|
||||
|
||||
## Analysis Helpers
|
||||
|
||||
- `MinDistance()`, `MaxDistance()` → `(value, i, j)` of the extremal off-diagonal entry.
|
||||
- `Copy() *DistMatrix`: Deep copy for immutability-safe operations.
|
||||
- `ToFullMatrix()` → `[][]float64`: Converts to dense representation (use sparingly).
|
||||
|
||||
Designed for clustering, phylogenetics, or any domain requiring fast symmetric matrix access with minimal footprint.
|
||||
@@ -0,0 +1,28 @@
|
||||
# `obidist` Package: Semantic Feature Overview
|
||||
|
||||
The `obidist` Go package provides two core data structures for managing **distance** and **similarity matrices**, with built-in guarantees suitable for scientific computing (e.g., clustering, phylogenetics). Key features include:
|
||||
|
||||
- **`DistMatrix`**: A symmetric `n×n` matrix representing pairwise distances, where:
|
||||
- Diagonal entries are *always* `0.0` (self-distance).
|
||||
- Off-diagonals obey symmetry: `dist(i, j) == dist(j, i)`.
|
||||
- Automatic enforcement via dedicated `Set()`/`Get()` methods.
|
||||
|
||||
- **`SimilarityMatrix`**: A symmetric matrix where:
|
||||
- Diagonal entries are *always* `1.0`.
|
||||
- Off-diagonals represent similarity scores (e.g., between `0` and `1`, though not enforced).
|
||||
- Symmetry is similarly guaranteed.
|
||||
|
||||
Both matrix types support:
|
||||
- **Optional labels**: Associate human-readable identifiers (e.g., sample names) with rows/columns.
|
||||
- **Safe bounds checking**: Panics on out-of-range access (tested via `defer/recover`).
|
||||
- **Deep copy support**: Ensures isolation between original and copied instances.
|
||||
- **Utility methods**:
|
||||
- `MinDistance()` / `MaxDistance()`: Return extremal values and their indices.
|
||||
- `GetRow(i)`: Retrieve a full row as a slice (symmetric copy).
|
||||
- `ToFullMatrix()`: Export the matrix as an immutable 2D slice.
|
||||
|
||||
Edge cases are rigorously handled:
|
||||
- Empty (`n=0`) and singleton (`n=1`) matrices return `(0.0, -1, -1)` for min/max.
|
||||
- Label mutations do not affect internal state via defensive copying.
|
||||
|
||||
All behaviors are validated through comprehensive unit tests, emphasizing correctness and robustness.
|
||||
Reference in New Issue
Block a user