optics

package
v0.0.0-...-16e292c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OPTICS

type OPTICS struct {
	// MinPts is the minimum number of points required to form a cluster
	MinPts int
	// Epsilon is the maximum distance between two points to be considered neighbors
	Epsilon float64
	// Ordering contains the processing order of the points
	Ordering []int
	// ReachDist contains the reachability distance for each point
	ReachDist []float64
	// CoreDist contains the core distance for each point
	CoreDist []float64
}
Example
// Simple dataset: two clusters
data := [][]float64{
	{0, 0}, {0, 1}, {1, 0}, {1, 1}, // cluster 1
	{10, 10}, {10, 11}, {11, 10}, {11, 11}, // cluster 2
}
minPts := 2
epsilon := 2.0
opt := New(minPts, epsilon)
opt.Fit(data)

fmt.Println("Ordering:", opt.Ordering)
fmt.Println("Reachability distances:", opt.ReachDist)
fmt.Println("Core distances:", opt.CoreDist)
Output:

Ordering: [0 1 2 3 4 5 6 7]
Reachability distances: [+Inf 1 1 1 +Inf 1 1 1]
Core distances: [1 1 1 1 1 1 1 1]

func New

func New(minPts int, epsilon float64) *OPTICS

New creates a new OPTICS instance with the specified parameters. minPts: minimum number of points required to form a cluster epsilon: maximum distance between two points to be considered neighbors

func (*OPTICS) Fit

func (o *OPTICS) Fit(data [][]float64)

Fit runs the OPTICS algorithm on the provided data. data: slice of points where each point is represented as a slice of float64 coordinates The algorithm will populate the Ordering, ReachDist, and CoreDist fields.

type OpticsAdapter

type OpticsAdapter struct {
	*OPTICS
	// contains filtered or unexported fields
}

OpticsAdapter wraps the OPTICS algorithm to implement the clustering interfaces

func NewAdapter

func NewAdapter(minPts int, epsilon float64) *OpticsAdapter

NewAdapter creates a new OPTICS adapter that implements the clustering interfaces

func (*OpticsAdapter) ExtractClustersWithThreshold

func (o *OpticsAdapter) ExtractClustersWithThreshold(threshold float64) (*clustering.ClusterResult, error)

ExtractClustersWithThreshold allows extracting clusters with a custom threshold

func (*OpticsAdapter) Fit

func (o *OpticsAdapter) Fit(data clustering.Dataset) error

Fit trains the clustering algorithm on the provided dataset

func (*OpticsAdapter) FitPredict

FitPredict is a convenience method that fits and predicts in one step

func (*OpticsAdapter) GetCoreDistances

func (o *OpticsAdapter) GetCoreDistances() []float64

GetCoreDistances returns core distances (DensityBasedClusterer interface)

func (*OpticsAdapter) GetOrdering

func (o *OpticsAdapter) GetOrdering() []int

GetOrdering returns the ordering of points (DensityBasedClusterer interface)

func (*OpticsAdapter) GetParams

func (o *OpticsAdapter) GetParams() map[string]interface{}

GetParams returns the algorithm parameters

func (*OpticsAdapter) GetReachabilityDistances

func (o *OpticsAdapter) GetReachabilityDistances() []float64

GetReachabilityDistances returns reachability distances (DensityBasedClusterer interface)

func (*OpticsAdapter) Predict

Predict returns cluster assignments for the provided data

func (*OpticsAdapter) SetParams

func (o *OpticsAdapter) SetParams(params map[string]interface{}) error

SetParams sets the algorithm parameters

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL