Class: ClusterTool
- Inherits:
-
Object
- Object
- ClusterTool
- Defined in:
- lib/clustertool.rb
Overview
The main ClusterTool driver.
Class Method Summary collapse
-
.cluster(database, table, columns, algorithm, args) ⇒ Object
Data is retrieved from the database and passed off to the appropriate algorithm.
Class Method Details
.cluster(database, table, columns, algorithm, args) ⇒ Object
Data is retrieved from the database and passed off to the appropriate algorithm.
Example: >> args = { >> :k => 3, >> :cycles => 10, >> } >> ClusterTool.cluster(“test.db”, “TestSimple2D”, [“Field1”, “Field2”], >> :kmeans, args)
> [[[0, 0], [-1, 0], [1, 0], [0, -1], [0, 1]], [[0, 10], [-1, 10], [1,
10], [0, 9], [0, 11]], [[-10, 0], [-11, 0], [-9, 0], [-10, -1], [-10, 1]]]
Example:
>> args = {
>> :epsilon = 1.5, >> :min_points = 2, >> } >> ClusterTool.cluster(“test.db”, “TestSimple1D”, [“Field”], :dbscan, >> args)
> 0], [-1, 0], [1, 0], [0, -1], [0, 1]], 1=>[[0, 10], [-1,
10], [1, 10], [0, 9], [0, 11]], 2=>[[-10, 0], [-11, 0], [-9, 0], [-10, -1], [-10, 1]]
Arguments: database: (String) table: (String) columns: [(String), …] algorithm: :kmeans or :dbscan args: { (Symbol) => (Numeric), … }
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/clustertool.rb', line 38 def self.cluster(database, table, columns, algorithm, args) db = SQLite3::Database.new(database) data = db.execute("select #{columns.join(", ")} from #{table};") case algorithm when :kmeans then return KMeans.cluster(data, args) when :dbscan then return DBSCAN.cluster(data, args) else raise ArgumentError, 'Unknown clustering algorithm' end end |