1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-25 13:48:49 +08:00

clustering: creates the package and implements DBSCAN

Verified against scikit-learn's implementation (gen_test.py)
This commit is contained in:
Richard Townsend 2015-09-19 11:26:23 +01:00
parent 6ed783530a
commit 986cd230f9
9 changed files with 2131 additions and 0 deletions

69
base/conversion.go Normal file
View File

@ -0,0 +1,69 @@
package base
import (
"fmt"
"github.com/gonum/matrix/mat64"
)
func checkAllAttributesAreFloat(attrs []Attribute) error {
// Check that all the attributes are float
for _, a := range attrs {
if _, ok := a.(*FloatAttribute); !ok {
fmt.Errorf("All []Attributes to this method must be FloatAttributes")
}
}
return nil
}
// ConvertRowToMat64 takes a list of Attributes, a FixedDataGrid
// and a row number, and returns the float values of that row
// in a mat64.Dense format.
func ConvertRowToMat64(attrs []Attribute, f FixedDataGrid, r int) (*mat64.Dense, error) {
err := checkAllAttributesAreFloat(attrs)
if err != nil {
return nil, err
}
// Allocate the return value
ret := mat64.NewDense(1, len(attrs), nil)
// Resolve all the attributes
attrSpecs := ResolveAttributes(f, attrs)
// Get the results
for i, a := range attrSpecs {
ret.Set(0, i, UnpackBytesToFloat(f.Get(a, r)))
}
// Return the result
return ret, nil
}
// ConvertAllRowsToMat64 takes a list of Attributes and returns a vector
// of all rows in a mat64.Dense format.
func ConvertAllRowsToMat64(attrs []Attribute, f FixedDataGrid) ([]*mat64.Dense, error) {
// Check for floats
err := checkAllAttributesAreFloat(attrs)
if err != nil {
return nil, err
}
// Return value
_, rows := f.Size()
ret := make([]*mat64.Dense, rows)
// Resolve all attributes
attrSpecs := ResolveAttributes(f, attrs)
// Set the values in each return value
for i := 0; i < rows; i++ {
cur := mat64.NewDense(1, len(attrs), nil)
for j, a := range attrSpecs {
cur.Set(0, j, UnpackBytesToFloat(f.Get(a, i)))
}
ret[i] = cur
}
return ret, nil
}

View File

@ -0,0 +1,82 @@
package clustering
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestClusterEquality(t *testing.T) {
Convey("Should be able to determine if two cluster maps represent the same thing...", t, func() {
Convey("When everything's exactly the same...", func() {
m1 := ClusterMap(make(map[int][]int))
m1[0] = []int{1, 2, 3}
m1[1] = []int{4, 5}
m2 := ClusterMap(make(map[int][]int))
m2[0] = []int{1, 2, 3}
m2[1] = []int{4, 5}
ret, err := m1.Equals(m2)
So(err, ShouldBeNil)
So(ret, ShouldBeTrue)
})
Convey("With re-labelled clusters...", func() {
m1 := ClusterMap(make(map[int][]int))
m1[1] = []int{1, 2, 3}
m1[0] = []int{4, 5}
m2 := ClusterMap(make(map[int][]int))
m2[1] = []int{1, 2, 3}
m2[0] = []int{4, 5}
ret, err := m1.Equals(m2)
So(err, ShouldBeNil)
So(ret, ShouldBeTrue)
})
Convey("With missing clusters...", func() {
m1 := ClusterMap(make(map[int][]int))
m1[1] = []int{1, 2, 3}
m2 := ClusterMap(make(map[int][]int))
m2[1] = []int{1, 2, 3}
m2[0] = []int{4, 5}
_, err := m1.Equals(m2)
So(err, ShouldNotBeNil)
})
Convey("With missing points...", func() {
m1 := ClusterMap(make(map[int][]int))
m1[1] = []int{1, 3}
m1[0] = []int{4, 5}
m2 := ClusterMap(make(map[int][]int))
m2[1] = []int{1, 2, 3}
m2[0] = []int{4, 5}
_, err := m1.Equals(m2)
So(err, ShouldNotBeNil)
})
Convey("With invalid maps...", func() {
m1 := ClusterMap(make(map[int][]int))
m1[0] = []int{1, 2, 3}
m1[1] = []int{4, 4, 5}
m2 := ClusterMap(make(map[int][]int))
m2[0] = []int{1, 2, 3}
m2[1] = []int{4, 5}
_, err := m1.Equals(m2)
So(err, ShouldNotBeNil)
})
})
}

107
clustering/clustering.go Normal file
View File

@ -0,0 +1,107 @@
/* This package implements clustering algorithms */
package clustering
import (
"fmt"
"github.com/sjwhitworth/golearn/base"
"github.com/sjwhitworth/golearn/metrics/pairwise"
)
// ClusterParameters takes a number of variables common to all clustering
// algorithms.
type ClusterParameters struct {
// Attributes represents the set of Attributes which
// can be used for clustering
Attributes []base.Attribute
// Metric is used to compute pairwise distance
Metric pairwise.PairwiseDistanceFunc
}
// ClusterMap contains the cluster identifier as a key, followed by a vector of point
// indices that cluster contains.
type ClusterMap map[int][]int
// Invert returns an alternative form of cluster map where the key represents the point
// index and the value represents the cluster index it's assigned to
func (ref ClusterMap) Invert() (map[int]int, error) {
ret := make(map[int]int)
for c := range ref {
for _, p := range ref[c] {
if _, ok := ret[p]; ok {
return nil, fmt.Errorf("Not a valid cluster map (points appear in more than one cluster)")
} else {
ret[p] = c
}
}
}
return ret, nil
}
// Equals checks whether a bijection exists between two ClusterMaps (i.e. the clusters in one can
// be re-labelled to become the clusters of another)
func (ref ClusterMap) Equals(other ClusterMap) (bool, error) {
if len(ref) != len(other) {
return false, fmt.Errorf("ref and other do not contain the same number of clusters (%d and %d)", len(ref), len(other))
}
refInv, err := ref.Invert()
if err != nil {
return false, fmt.Errorf("ref: %s", err)
}
otherInv, err := other.Invert()
if err != nil {
return false, fmt.Errorf("other: %s", err)
}
clusterIdMap := make(map[int]int)
// Range through each point index
for p := range refInv {
c1 := refInv[p] // Get the cluster index of this point
if c2, ok := otherInv[p]; ok { // Check if the other map has this point
// if so, c2 is the point's cluster in the other map
if c3, ok := clusterIdMap[c2]; ok { // what's our correspondance with c2?
if c1 != c3 {
// if c1 is not what we've currently got, error out
return false, fmt.Errorf("ref point %d (cluster %d) is assigned to a different cluster (%d) in ref %s", p, c2, c1, clusterIdMap)
}
} else {
clusterIdMap[c2] = c1
}
} else {
return false, fmt.Errorf("failed to find reference point %d in src", p)
}
}
// Check that after transformation, key contains the same points
arraysEqual := func(a1, a2 []int) bool {
cnt := make(map[int]bool)
for _, a := range a1 {
cnt[a] = true
}
for _, a := range a2 {
if _, ok := cnt[a]; !ok {
return false
}
}
return true
}
newMap := ClusterMap(make(map[int][]int))
for cOld := range other {
cNew := clusterIdMap[cOld]
if !arraysEqual(ref[cNew], other[cOld]) {
return false, fmt.Errorf("Re-labelled cluster %d => %d doesn't contain the same points (%s, %s)", cOld, cNew, ref[cNew], other[cOld])
}
newMap[cNew] = other[cOld]
}
return true, nil
}

750
clustering/dbscan.csv Normal file
View File

@ -0,0 +1,750 @@
0.494260967249,1.45106696541
-1.42808099324,-0.83706376669
0.338559182384,1.03875870939
0.119001013781,-1.05397553336
1.12242460445,1.77493654436
-1.26156989707,0.271881354299
-1.30154774626,-0.762062025148
0.585698651521,-0.339104628157
1.08247212014,0.886855396912
1.01416667809,1.34114022391
-1.21578195893,-0.601021238858
-1.25021782593,-1.05761650335
-1.05160415572,-0.780084156141
1.15263449272,-0.648539905918
-0.783299140581,-1.2248966985
0.202587147419,1.61104848936
-1.43020789851,-1.82380067733
-0.916300845616,-0.480830396598
-0.506013825832,-0.295715454174
0.436426179395,-1.06597144351
0.468034167368,-0.974110220304
0.522354793098,-0.641695891625
0.94533367495,-0.543880951202
0.94661473578,-0.939854758443
-1.38551398913,-0.73950655252
-1.15374916281,-0.250507932367
0.493572698047,-0.949825244593
0.884913340754,1.66591701207
0.249587300835,1.57229126004
1.02800263162,-0.340081504198
0.478275464063,1.19798226443
-1.19268844384,-0.510240121174
-1.85804701232,-1.33021784213
0.528139618545,1.32892750576
-0.918024481532,-0.652157357893
0.756316701741,0.920633635328
0.855048505014,-0.481028310004
0.492824086051,1.78274421923
0.380510951332,1.24884772379
-0.166999182256,-0.0916528008137
0.862512958934,-0.29122649879
-1.28326220483,-0.63402691263
-1.46013480318,-0.722834729597
-1.48000289758,-1.09948040102
-2.19020872323,-0.630588973627
-1.07505211635,-0.474050249508
0.541969904427,1.03090707759
0.824488329821,-0.264039880782
0.456263169078,2.05788223562
-1.58709404439,-0.54480731903
1.32708272612,-0.345071514843
0.68614239282,-0.490086592009
-1.60725507262,0.070747440379
-1.53337705952,-0.570087546452
1.0491125845,-0.574435960384
0.731933094085,-0.608068176075
-1.13848133348,-0.0659881431468
1.36805202458,1.65962813336
0.222462580182,-0.65053906069
-1.18662195919,-0.78239641499
0.357717455186,-0.584924154569
0.588086269107,-0.230283609581
0.78242146637,-0.380417760077
1.2682093931,-0.857019912656
0.549567992097,-0.773931305337
0.981410379535,1.01828533931
0.707839055866,-0.233211620345
0.0165651739637,-0.923844177798
0.158530593126,1.68427935414
0.498933328512,1.18944226235
0.394392460137,1.10697668799
0.52298152277,-0.915281143053
0.363168115217,1.90748256868
0.346568780252,1.26411862836
0.966039504954,-0.4318119363
-1.14222916165,-0.398461611165
-0.134479180583,2.11039748445
-1.18845711973,0.191151161919
0.235515043844,1.71737552151
0.648790787207,-0.936837517765
-1.58852748366,-0.819181976895
-1.04572997888,-0.29002720873
0.467505726335,0.450459334368
0.0198833944692,1.48714816824
0.189992256516,1.10986299053
1.48201717596,1.82713555691
-1.30489683944,-1.15150866165
0.757809431355,-0.47686276961
-1.54387743826,-0.684212390528
0.53240786142,-0.776648241672
0.85665850455,-1.34594223446
0.403144558116,1.57028295161
-1.3011171994,-0.790729653327
0.972620490761,1.21000471162
-1.00025584409,-0.628924362444
1.22425496262,0.501610912038
-1.15175818324,0.22764659828
-1.31816425788,-0.630999410835
0.402531346597,1.15248839326
0.0906743459729,1.61848052292
0.598794476009,-0.744251645998
-1.37198702139,-0.980218172223
0.520218965558,-0.919220905523
0.631969327359,1.19544068432
0.728113832873,-0.518758002884
0.262658464722,0.0128713235313
1.01826270251,-0.800567265699
1.0896513853,-0.503675186289
1.53624088423,0.894604885123
0.511997776458,0.678078694437
1.68745105198,1.27830755696
-1.84237360674,-0.904437839063
-1.19200811061,-0.463511666939
-1.29275263692,0.287881967384
-2.03126575898,-0.895274949124
0.529118462695,0.654914838633
0.468283787666,0.755733587995
-1.638498618,-0.154707320244
0.605617236401,1.70403704905
-0.767697521224,-1.01384394922
0.421112557426,-0.813005680016
-1.1727392859,-0.0801023370369
0.763176137366,1.82318913399
-0.0334381403655,1.44539596918
-1.60758525806,-0.62956732394
0.72250888945,-0.367506703588
-1.48527973153,-0.62861576205
0.978478897202,1.05374904006
0.451784483015,1.13661154122
1.27710347995,-0.491509617737
0.7166105877,1.15073382716
0.705050630765,-1.01884736371
0.535813899767,-1.31595906212
0.279302786611,-1.16319317603
0.29795190705,1.14196446938
-1.5319923175,-1.74146843932
0.485447620689,-0.597755525309
0.407314491616,-0.790408883348
0.381481488856,1.90489980312
-1.60594123991,-0.76522411796
1.23408760826,1.97619040399
0.909343480925,-0.618337223907
0.495887533633,0.855925046745
0.793312516951,0.879279610882
0.346669837831,-0.395258378353
0.463120268974,-0.842105995666
-0.422275985459,-0.190344559422
0.938840781419,-0.223971270792
-1.58434365981,-0.845357036129
1.52307352239,0.741157517894
0.473203974657,-0.605056119142
-1.33430726419,-0.787153064395
-1.30774613959,-0.537830906671
0.44437726176,-0.570907450386
0.302728842099,-1.4022293954
0.498614426707,-0.661820178158
1.02546663264,2.17903746819
-0.888963724459,-0.894519799863
-0.0094375858741,2.06614833436
-1.259326547,-1.33666248485
0.334806319729,0.635350614538
-2.0514671874,-0.491853069487
0.511781097662,0.772058829646
0.635381289585,-1.23415961512
0.840452136147,-0.925641488461
-0.46307453491,-1.26531794688
-1.37224990492,-0.0477233997811
0.128494145161,-0.146277558271
0.629212436152,-0.545489790799
-1.28799441742,-0.218570654523
0.638847594716,1.0198939832
-1.90824567176,-1.24854294321
0.983925587407,-0.980132673476
0.751915912284,-0.434247990685
0.246162045698,-0.972003120401
-1.42184967713,-1.00645441438
-1.36258687372,-0.465192195174
0.729107773809,-1.12124670875
1.28828508776,-1.18972269812
0.936218595433,0.844436650383
-1.41967242002,-1.33553338128
0.451293435185,-0.337043043077
0.889211776584,0.683688380936
0.946264899744,0.846407250351
0.516908027375,-1.13002059107
0.663113490975,0.662420359006
0.985803048039,1.26228271875
-1.4124239618,-0.947706065026
0.642179325842,1.36969227279
-1.32320503558,-0.518361624408
0.389031988291,1.16716527963
-0.806854584638,-0.613264833433
-0.73049432945,-0.484378149065
0.493548378749,-0.761716569457
0.118175433165,-0.443557808199
1.00315780403,1.4310943891
0.778850340762,2.09349071844
-0.745033802864,-0.756441323796
-0.93389892072,-0.103482424997
0.68196176411,-0.273220993773
-1.16459401764,-0.315541399223
0.740399605464,-0.0945591684424
0.856407754419,0.252753351451
0.803410992909,-1.32952562448
0.429896355505,-0.758228537429
0.595823625156,1.74945400458
1.02085295004,-0.440804557414
0.30307695482,1.45762223084
1.18958904168,-0.581519032443
0.96915905519,-0.511234999414
0.697140552761,1.46349275366
0.637227696862,-0.764858659877
1.35045914484,-0.667938023256
0.250651256786,-1.19493208012
1.28347766291,1.37097619103
-0.128975958296,1.09716295281
-1.7517528787,-0.262053681114
-1.3635857203,-1.06031600728
-0.904113999203,0.191818430248
0.165426717861,-0.866647109384
0.232203921427,-0.682948158472
0.350368147923,-0.295280019807
1.5427482888,-0.592939512519
-1.13795423209,-0.133498274187
0.674237889386,-0.632143914378
0.334556478351,-1.20237442694
0.528396459186,1.34497258643
0.268370506258,0.734359941775
0.309361881005,-0.728426362716
0.917435744228,1.30854004814
0.428789300542,1.41209652083
0.199130767118,1.65759766562
-1.17444696491,-0.950375612201
0.597006581866,1.19119789824
-1.45170622969,-0.891168308477
-1.41986354849,-0.273475605125
-1.57409699552,-0.422236366569
1.04184264467,-0.362737479132
-2.14219480292,-0.482272076783
-1.50691533211,-0.200973148817
0.0543420665276,1.33168891813
-1.13144663461,-0.651825483298
1.07155174333,-0.692136570485
0.583387651839,-0.491450887858
-1.14297733022,-0.697948095468
0.0998245638451,0.10950372489
0.220588982913,-0.851548705937
-1.13730048755,-0.564448259501
0.905073179513,1.12779984735
0.72504167988,1.28738215218
-1.06955320593,-0.467663188307
-0.880265370005,-1.02614239598
-1.44264764226,-0.96145282057
1.01333072504,1.24675601661
-1.0093984377,-1.05143861237
0.507657052315,1.36804853004
1.26502785776,-0.711979714262
1.31608042094,1.5734222567
0.334632982453,-0.84147974129
0.802031438762,0.228215838939
1.38250775401,-0.644251339858
0.919614961822,-1.22049235391
0.929729151417,-0.208693463261
-1.53633104344,-0.511275317046
-0.665051865958,-0.739115745001
-0.335795516652,1.56140541417
1.23901518412,1.87882199622
-1.35543673912,-0.601849685925
-1.15154941392,-0.269135444753
0.608439338548,1.46684269694
1.06006794863,1.13065360895
0.942890187819,-0.742929110414
-1.15672050041,-0.436145800526
1.62198216506,0.050201317777
0.854125246175,-0.514807506009
-1.14337683511,-0.490935142717
-1.51048251847,-0.0345004965754
0.880530249926,-0.869888336327
-1.36540418059,-0.756111150943
0.601814512111,-1.21412505961
-0.0621652593321,1.12108597614
0.74067770872,-0.576648130759
-0.183577853633,-0.125433577503
0.417995488425,1.21449387096
-1.1856447963,-0.984315517908
1.07887574968,-0.840413058707
0.090657698723,-1.25434772582
0.0261662265887,1.22429234588
1.13673243898,-0.444139145222
1.23361139042,-1.09421718393
0.351468885092,1.51690258534
0.255831769187,1.27677830087
0.798195414423,-0.18283188485
1.31845143924,1.69400632284
0.938052607202,-0.419433668128
0.388310366276,1.31945848095
1.00904356759,-0.374533562373
-1.08675207316,-0.230719819714
0.956791915728,1.33752493245
0.964894172999,1.3091321864
0.630607763963,1.39287553367
-1.41288695181,-0.864681477113
0.261119656155,-1.02691248837
-0.882375409513,-0.666629249983
0.989911346176,-0.744391801077
0.867329484559,-0.768003291115
1.10613565156,1.4303998032
0.77134497925,-0.692113237484
0.343526184216,-0.991545218203
0.758591550569,1.54398289162
0.707946435833,1.45422137588
0.709604992056,-1.40060170714
-1.62485869339,-0.127799648835
-1.66703749341,0.0158250976471
-1.80730926772,-0.301662933271
-1.45291560869,-0.535118179264
-1.4701829607,-0.667609031391
0.826731842161,1.41567303436
-1.83590114306,-1.10954151061
-1.6332275232,-0.563497927722
-0.7388346936,-0.798186938046
-1.82702823377,0.13893299319
1.08739214482,0.826583726311
0.196057452318,2.06336452546
-0.962783057941,-0.109325188026
-1.19668293625,-1.1087752111
-0.920351459366,-0.706719513233
1.1741662534,1.0387978517
0.489318601459,-0.795493247886
-0.0285631715351,1.48253801626
-1.55996778776,-0.562017909444
0.0907181454452,-0.814517495862
1.04873107616,-0.452078258313
0.641663493277,1.45460629445
0.396805058072,1.10427025972
1.00336963075,-0.459191567668
0.907351763777,1.46562217387
0.904912861981,-1.62473397987
-1.30060206226,-0.639040245494
0.22255248672,1.32737094419
0.41209455966,-0.958675990971
0.941556677173,1.35441829013
1.28361991963,-1.24163477985
-0.376722258575,1.54300064517
0.930527863539,-0.784505897599
1.05101554226,-0.405406154061
1.22185277774,2.04479129366
-1.10897541444,-0.568930353083
0.637361305672,1.47374301327
-0.735046904585,-0.332733398991
0.914105951171,1.81364038611
0.815815323504,-0.428342552091
0.655466878695,-0.869548902941
-1.1045597651,-0.600408464946
-0.915703222184,-0.742626383383
-1.3571704177,-0.68125832152
0.69160775897,-0.893583583689
0.978900301359,1.75109237406
0.53683021324,-1.41620152234
1.09237619762,1.72716832141
0.866591909179,-0.581572078316
-1.80307744469,-0.65461097373
-0.127231346916,-0.409038899099
0.541525702451,-0.201173106705
0.68589072527,1.53390864901
-0.502670916098,-0.757868411152
0.417479823257,0.872860696972
-2.0289141946,-0.993678879688
0.245343426191,1.77834730722
0.316274690117,2.05030729845
1.23151797851,1.52230461678
0.488799329286,1.01622700328
0.736124228521,-0.560102473907
0.0380991755979,1.54458039477
0.348282296735,0.0373035505291
0.791153859839,1.36235109152
-1.89637476785,-0.983716547448
0.529079350094,1.21622740397
-1.2345838948,-0.786033236307
0.206511679327,-0.620187190429
-1.25908731883,-0.301031125224
-1.09843278784,0.0369549195008
-1.10406146313,-1.35048039511
0.983155368445,1.41480769807
-1.7328692309,-1.08216857053
-0.917910107541,-0.0889436794991
0.312585483993,1.0818337627
-0.0811644021867,-0.707691032276
-1.20266214326,-0.217504289139
0.454419137278,2.2457941917
0.471831725992,-0.493824106953
1.29161652352,-0.520992830994
-1.25588057463,-0.721197168795
-1.20377898567,-1.33173379489
1.11899200093,-0.713538916105
0.339906689497,-0.72413604985
0.615417018996,-0.858079193557
-1.01823258109,-0.78714664658
0.816099854449,-0.871668345031
-1.7212991458,-0.777848794878
0.843019145714,-0.498712137992
1.4021067635,1.45886382804
0.878294256485,-1.02266917785
-0.88512932828,-0.853503063368
0.430259456368,-0.453270444086
-1.77952949337,-0.141961490527
0.849914524615,1.24032152147
-1.32980886649,-0.481002489736
0.624470649758,1.26531866728
-1.06157593269,-1.13833962673
-1.3992137138,-0.965470741462
0.896181657602,0.695919911938
-1.418340371,-0.224255463115
0.0738188763056,-0.0563312160229
1.01170961883,0.241023782153
-1.5363281273,0.0159593515193
0.82770781377,0.709297571031
0.545029125045,0.868146825735
0.94527049937,-0.689257336931
-1.19201851393,-0.0979642908923
0.356642444398,-0.521177720048
1.25677847275,-0.948042349321
0.960112654402,-1.1046969869
0.467333609641,-0.297755148203
-1.09928800088,-0.782568121394
0.499876498504,1.34378633999
-0.0980920351721,1.38052928695
-0.233897355292,1.40492904943
0.951304495882,1.12558216168
-1.57107850167,-0.657989767628
0.284198318557,1.14751633136
1.14780923861,-0.398627857264
-1.63748393741,-0.707992965283
0.396760739464,1.1549469915
-0.856392511462,-0.729638141622
0.743336814006,-0.0447286202516
0.213902305912,1.02275520522
0.866879045866,1.22042656018
-0.88179618297,-1.43514524119
0.334722303045,0.736465317357
-1.71828945714,-0.333062709029
-0.918042667376,-0.843035843758
0.929243026125,1.35726190001
-0.431851673719,-1.10093484648
0.703743675795,1.87295209701
0.98717412056,-0.391248211672
0.446786417845,-0.232663277488
0.833397671467,-1.01523684003
-1.31380292373,-0.106348966316
-1.98210412488,-0.520364529607
0.882630413465,-0.204652953696
0.57473870386,1.15343094618
-1.64296177795,-0.545851844001
0.812520126446,1.57046768
-0.221156389297,0.90920018435
-1.31918421048,-1.02294749184
0.756117389326,1.26888096925
-1.00145716326,-1.06765844508
-1.16012367924,-1.17473398971
0.140325452005,-0.427986994764
0.5813642278,-0.83696135172
-0.31645030278,-1.51218920885
0.82452917064,0.93172792002
-0.750534982503,-0.836888860558
0.968658108542,-0.448623907721
1.2006923499,-0.475696442665
-1.26717115594,-0.665599874339
-1.82087781658,-0.868101472932
-1.16838236627,-1.54147890288
-0.981140298879,-1.28505380627
0.141023068843,1.12746333408
0.754032847532,0.960404487137
0.202135095167,1.18555519975
0.849908773169,-0.847682954547
0.744968023152,-0.228079376425
-1.91222754219,-0.796509854232
0.775623691917,-0.695029747499
-0.767188336951,-0.677911431003
0.712466108841,1.55417287552
1.21349899534,1.6388133243
-1.0869979326,-0.648693092282
0.699067612971,-1.40916870622
-1.53255598882,-0.261494722161
1.38939876357,1.88316296941
0.596690144163,1.72643881439
0.804964907977,-0.170902873462
0.40613498617,1.1198979641
-1.20807438507,-0.788501079273
0.728500901715,1.68709745134
0.316645956769,-0.510754409208
-0.823618040446,-0.884384414857
1.01442400059,1.24817740818
0.688659017161,-0.58639380357
0.370731358867,-0.986204337596
-1.02050291971,-0.913802249095
1.07231521798,1.81215231098
0.293755472217,0.389904123007
0.384580005797,1.95282853017
0.731079718128,-0.600671861978
-1.27084815866,-0.599802102819
-1.5506697485,-0.37391302332
0.819305570722,1.43691036146
0.758463908179,-0.257726277971
1.00739359449,1.43935814903
0.296387422059,1.74172031876
-1.56792541994,-0.625734935299
-1.58294937352,-0.212561302929
-1.48429016855,-0.214074430447
-1.57271416628,-0.983949703014
0.535738594277,1.01076484292
-1.47375056852,-0.955937874772
0.568475265758,1.64956338847
-0.862162831203,-0.884179051907
0.544925120741,1.6193204064
0.480499087021,2.02664864155
0.122038139573,0.119143611341
1.08322686266,1.50007405277
-1.26363865114,-1.24824215223
-1.09515150213,-0.580737374373
0.745663888861,-0.797265870367
-0.704911858139,-0.435654296496
-1.08345708839,-0.683728002502
-0.159115840147,1.35521476836
-0.834099861805,-0.571377281807
0.803301570929,1.04060299172
0.882227724909,-1.04635993234
-1.42356222195,-1.11563240162
0.598075641758,1.34363133224
1.00649041199,1.53362494993
-1.74840606346,-0.757167172502
0.665860879827,1.23423673133
-2.27447426719,-1.08752048002
-1.48420811929,-0.38750074543
0.710494890905,-0.0301573663517
0.2452388989,-1.06063486305
-1.30030123852,-0.741203235798
0.722560907798,-1.0887138629
0.845890473528,-0.765476650879
-0.987808045599,-0.300980235798
0.798685296365,-0.0203804886503
-1.27497724309,-0.358325506229
-1.63280019769,-0.540251128077
-1.64088545492,-0.242763376194
-1.27425159086,-0.0278791499227
0.710148737729,-1.00918956356
0.383105045026,0.834657242727
0.838530657897,1.26189497731
1.37406167258,0.78263972991
-1.95053657495,-1.14561235999
0.582792508127,-0.690694356981
0.913359445094,-0.619101104092
0.785580964186,1.58201082262
0.811102347249,-0.425468506696
0.702937953149,1.18281732336
0.532290267793,-0.895553891619
-1.10621476202,0.0215080636159
0.175894375098,1.6356268775
-0.768255477238,-0.558603363551
-1.04310626044,-1.16049754679
1.07207441854,1.56204556067
1.22409867855,1.22724262076
-1.59405917837,-1.18378628891
1.47675154752,-0.673616523166
-1.07509128453,-0.542721555114
0.930232971573,-0.66398380143
0.857366630575,-0.359918879193
0.251247597619,1.17090459393
1.16780804184,-0.28530226059
-1.6384800666,-1.12997990407
-1.3215530792,-1.28470419469
-1.09352620351,0.435204632862
0.944537238213,-0.802446108456
0.514125239901,1.36791043858
0.621920898963,1.97375976496
0.209206751878,-1.11104286684
0.0993365991821,1.11511466724
0.461961063861,-0.637500819694
0.257071325333,-0.87287754892
0.708547376969,1.39741781887
0.475251941501,-1.31719059033
0.610276462303,1.04890351278
-1.52841458815,-0.454742945322
-1.54735702492,-0.751499117222
-0.503751481339,-0.655854045695
-1.43543163548,-0.356638792552
0.472644264313,1.31387413897
0.20594576925,1.13671047633
0.615102823628,1.3826749988
0.634447199559,-0.507752603381
-1.14039960054,-0.69475439419
-1.32947946028,-0.197603144118
-1.20830036549,0.0116873739331
-1.73345855335,-0.132096369529
0.357039754872,-1.10590660431
0.077295305839,-1.13367252031
0.487312167153,-1.06555350588
0.353693691332,0.747606784869
0.72201625169,-0.295881357905
-1.92967429146,-0.682263484159
-0.908678506749,-0.121343269386
0.448752295827,0.926195545738
0.418381709077,1.28661802591
-1.61004687385,-0.988293010227
1.56677839696,1.67458369438
0.727890188144,-0.431864801265
-1.37981436331,-0.709415449061
0.686461132989,-0.0251400314444
-1.60911292662,-1.23835579119
0.165348852234,1.60960575054
1.00429011937,-0.690085482535
1.30821133172,-0.946724989662
1.10257026468,1.23706132126
1.15666930562,0.963710509452
-1.67698616873,-0.808446550696
0.576897088351,0.99280475248
0.94555298466,1.70764263243
0.568459449543,-0.902358290454
0.273923190749,1.4295727757
0.652270914927,2.0019813952
0.60267889291,1.04240532752
0.698937416681,-1.18542553401
0.262702790697,0.705979429324
-0.0487035963106,-0.47844505956
0.278008906473,0.998459028372
0.244071635336,0.754522731174
-1.47458283881,-1.04780342988
-1.41308398904,-1.16512495168
0.376605532983,1.67410945603
0.438984358586,1.46896397357
-0.791357172838,-0.556204685175
0.513404458949,0.148861596075
0.55598980494,-0.734532332917
-0.00629072685579,1.4577693075
0.451340090014,0.847671272714
0.587452946206,2.18519727161
1.32815664066,1.46277983499
1.15868201425,-0.705507183387
-2.19229513315,-0.302285759118
-1.49261826396,-0.821633387241
-1.47130624425,-0.63019322747
1.34514654196,-0.468598808267
-1.58948534345,-1.07365303551
0.279766265285,1.17244610684
0.87120798495,1.44312846654
0.620040716673,-1.14333094168
0.807830356825,-0.835873745532
0.894954831928,0.677891197264
-0.602527884597,-0.69024906938
0.658008384741,-0.400988830169
0.914769130628,1.57740991958
-1.48930440184,-1.37182156567
0.273422769288,-0.11466674929
0.472531390995,-0.0835618146858
-1.12231828159,-0.713669220151
0.241729907099,1.62624331977
0.370860921385,0.99072512802
0.980701101307,0.273732023633
-0.863388034868,-1.63431795709
0.734659138483,-1.29170380626
1.3680516506,0.926799443937
0.149907608089,1.41098618733
0.0734364428587,1.47804655719
0.415481089773,-1.08580981443
1.87043802694,-0.564764189615
1.33224467911,-0.791483035077
0.463346223426,1.54846334002
-1.77220711583,-0.866301255997
-0.566063485459,-0.721836722342
-1.36471735933,-0.972719760591
-1.36476695392,-0.99379395024
-1.28469298601,-0.318880090688
1.51904736282,1.29062985586
0.999041358538,1.43050704451
0.187630466783,-0.83321811689
-0.987675226269,-0.848285797745
0.989408735718,-0.0650375905356
0.915630353951,1.24498035147
-1.43557093403,-0.974714006397
-1.45387959068,-0.481585100397
-0.278976401689,-0.795716253642
0.400148808814,0.441913646796
0.757992930737,-0.758884707769
-1.92697167247,-0.984413224925
-0.946132960141,-0.951642902807
-0.374479291272,-1.13624183449
0.40711034652,-0.252446172482
-1.09764344526,-0.517312637143
0.669488945211,-0.522164749169
0.850151323586,1.34147908285
1.25907388444,-0.386367441721
0.347464827015,-0.533007300891
-1.27564074212,-0.433436163023
0.673862073887,1.42476903402
0.849062018952,1.08302511354
0.144638692788,1.95227594178
-1.42722323034,-0.811204501399
-1.64416438467,-0.543384736216
0.463117573507,-0.274247994439
0.943724941954,1.44571155091
0.870463827056,1.22602060889
1.18495335344,-0.234761356364
0.733969567923,-0.67288952967
-1.79850796029,-0.934840788244
0.888166348926,-0.884107436609
1.27188343182,-0.959291102507
0.841840207037,-0.974022163633
0.945701225098,1.6275104008
0.660977855757,-0.970868100576
-0.965730793499,-0.409989983699
1.03969981683,-0.365715737398
-1.16752822897,-0.477847154481
-1.01284867036,-0.328504389699
-1.54030317305,-0.13349028812
0.624306174222,-0.148540727917
0.667301055225,1.49923194215
0.778588762664,-0.384883563802
0.298516528096,1.32728546211
0.624466159376,-1.19599990114
0.810461715314,-0.542544742288
0.469536296015,1.49442431098
0.133949872378,0.783045014519
1.68141770912,-0.716638871392
-1.19132044269,-1.03412936975
0.0382702789919,0.234517417471
0.478943470729,1.37763420757
1.59302092264,-0.720684680801
0.361166988246,0.985493265361
0.768892000974,0.97473143902
0.962170710559,1.33000155872
-1.1943589351,-0.485554696436
0.306037432346,0.536315500264
1.01845907675,-0.550623430195
-1.26470285038,-0.339699106261
0.633088431313,-1.00774511415
0.800859848663,0.881746319329
-1.90816425794,-0.664624198594
0.403731959752,1.16592477989
0.63308271635,0.852550261268
0.184258505898,-0.476223501919
0.368550995255,0.768785338289
0.674247371136,-0.335924019381
-1.79245127675,-1.4045223247
-1.87656067,-0.476116371583
0.493448265324,-0.820792271427
-1.60183922321,-0.868539405266
0.505927093362,1.21392675643
-1.64046095603,-0.469972586457
-0.0571387622957,-0.909261054305
-1.1693940706,0.0395969246032
0.263229511513,-0.926499490699
1 0.494260967249 1.45106696541
2 -1.42808099324 -0.83706376669
3 0.338559182384 1.03875870939
4 0.119001013781 -1.05397553336
5 1.12242460445 1.77493654436
6 -1.26156989707 0.271881354299
7 -1.30154774626 -0.762062025148
8 0.585698651521 -0.339104628157
9 1.08247212014 0.886855396912
10 1.01416667809 1.34114022391
11 -1.21578195893 -0.601021238858
12 -1.25021782593 -1.05761650335
13 -1.05160415572 -0.780084156141
14 1.15263449272 -0.648539905918
15 -0.783299140581 -1.2248966985
16 0.202587147419 1.61104848936
17 -1.43020789851 -1.82380067733
18 -0.916300845616 -0.480830396598
19 -0.506013825832 -0.295715454174
20 0.436426179395 -1.06597144351
21 0.468034167368 -0.974110220304
22 0.522354793098 -0.641695891625
23 0.94533367495 -0.543880951202
24 0.94661473578 -0.939854758443
25 -1.38551398913 -0.73950655252
26 -1.15374916281 -0.250507932367
27 0.493572698047 -0.949825244593
28 0.884913340754 1.66591701207
29 0.249587300835 1.57229126004
30 1.02800263162 -0.340081504198
31 0.478275464063 1.19798226443
32 -1.19268844384 -0.510240121174
33 -1.85804701232 -1.33021784213
34 0.528139618545 1.32892750576
35 -0.918024481532 -0.652157357893
36 0.756316701741 0.920633635328
37 0.855048505014 -0.481028310004
38 0.492824086051 1.78274421923
39 0.380510951332 1.24884772379
40 -0.166999182256 -0.0916528008137
41 0.862512958934 -0.29122649879
42 -1.28326220483 -0.63402691263
43 -1.46013480318 -0.722834729597
44 -1.48000289758 -1.09948040102
45 -2.19020872323 -0.630588973627
46 -1.07505211635 -0.474050249508
47 0.541969904427 1.03090707759
48 0.824488329821 -0.264039880782
49 0.456263169078 2.05788223562
50 -1.58709404439 -0.54480731903
51 1.32708272612 -0.345071514843
52 0.68614239282 -0.490086592009
53 -1.60725507262 0.070747440379
54 -1.53337705952 -0.570087546452
55 1.0491125845 -0.574435960384
56 0.731933094085 -0.608068176075
57 -1.13848133348 -0.0659881431468
58 1.36805202458 1.65962813336
59 0.222462580182 -0.65053906069
60 -1.18662195919 -0.78239641499
61 0.357717455186 -0.584924154569
62 0.588086269107 -0.230283609581
63 0.78242146637 -0.380417760077
64 1.2682093931 -0.857019912656
65 0.549567992097 -0.773931305337
66 0.981410379535 1.01828533931
67 0.707839055866 -0.233211620345
68 0.0165651739637 -0.923844177798
69 0.158530593126 1.68427935414
70 0.498933328512 1.18944226235
71 0.394392460137 1.10697668799
72 0.52298152277 -0.915281143053
73 0.363168115217 1.90748256868
74 0.346568780252 1.26411862836
75 0.966039504954 -0.4318119363
76 -1.14222916165 -0.398461611165
77 -0.134479180583 2.11039748445
78 -1.18845711973 0.191151161919
79 0.235515043844 1.71737552151
80 0.648790787207 -0.936837517765
81 -1.58852748366 -0.819181976895
82 -1.04572997888 -0.29002720873
83 0.467505726335 0.450459334368
84 0.0198833944692 1.48714816824
85 0.189992256516 1.10986299053
86 1.48201717596 1.82713555691
87 -1.30489683944 -1.15150866165
88 0.757809431355 -0.47686276961
89 -1.54387743826 -0.684212390528
90 0.53240786142 -0.776648241672
91 0.85665850455 -1.34594223446
92 0.403144558116 1.57028295161
93 -1.3011171994 -0.790729653327
94 0.972620490761 1.21000471162
95 -1.00025584409 -0.628924362444
96 1.22425496262 0.501610912038
97 -1.15175818324 0.22764659828
98 -1.31816425788 -0.630999410835
99 0.402531346597 1.15248839326
100 0.0906743459729 1.61848052292
101 0.598794476009 -0.744251645998
102 -1.37198702139 -0.980218172223
103 0.520218965558 -0.919220905523
104 0.631969327359 1.19544068432
105 0.728113832873 -0.518758002884
106 0.262658464722 0.0128713235313
107 1.01826270251 -0.800567265699
108 1.0896513853 -0.503675186289
109 1.53624088423 0.894604885123
110 0.511997776458 0.678078694437
111 1.68745105198 1.27830755696
112 -1.84237360674 -0.904437839063
113 -1.19200811061 -0.463511666939
114 -1.29275263692 0.287881967384
115 -2.03126575898 -0.895274949124
116 0.529118462695 0.654914838633
117 0.468283787666 0.755733587995
118 -1.638498618 -0.154707320244
119 0.605617236401 1.70403704905
120 -0.767697521224 -1.01384394922
121 0.421112557426 -0.813005680016
122 -1.1727392859 -0.0801023370369
123 0.763176137366 1.82318913399
124 -0.0334381403655 1.44539596918
125 -1.60758525806 -0.62956732394
126 0.72250888945 -0.367506703588
127 -1.48527973153 -0.62861576205
128 0.978478897202 1.05374904006
129 0.451784483015 1.13661154122
130 1.27710347995 -0.491509617737
131 0.7166105877 1.15073382716
132 0.705050630765 -1.01884736371
133 0.535813899767 -1.31595906212
134 0.279302786611 -1.16319317603
135 0.29795190705 1.14196446938
136 -1.5319923175 -1.74146843932
137 0.485447620689 -0.597755525309
138 0.407314491616 -0.790408883348
139 0.381481488856 1.90489980312
140 -1.60594123991 -0.76522411796
141 1.23408760826 1.97619040399
142 0.909343480925 -0.618337223907
143 0.495887533633 0.855925046745
144 0.793312516951 0.879279610882
145 0.346669837831 -0.395258378353
146 0.463120268974 -0.842105995666
147 -0.422275985459 -0.190344559422
148 0.938840781419 -0.223971270792
149 -1.58434365981 -0.845357036129
150 1.52307352239 0.741157517894
151 0.473203974657 -0.605056119142
152 -1.33430726419 -0.787153064395
153 -1.30774613959 -0.537830906671
154 0.44437726176 -0.570907450386
155 0.302728842099 -1.4022293954
156 0.498614426707 -0.661820178158
157 1.02546663264 2.17903746819
158 -0.888963724459 -0.894519799863
159 -0.0094375858741 2.06614833436
160 -1.259326547 -1.33666248485
161 0.334806319729 0.635350614538
162 -2.0514671874 -0.491853069487
163 0.511781097662 0.772058829646
164 0.635381289585 -1.23415961512
165 0.840452136147 -0.925641488461
166 -0.46307453491 -1.26531794688
167 -1.37224990492 -0.0477233997811
168 0.128494145161 -0.146277558271
169 0.629212436152 -0.545489790799
170 -1.28799441742 -0.218570654523
171 0.638847594716 1.0198939832
172 -1.90824567176 -1.24854294321
173 0.983925587407 -0.980132673476
174 0.751915912284 -0.434247990685
175 0.246162045698 -0.972003120401
176 -1.42184967713 -1.00645441438
177 -1.36258687372 -0.465192195174
178 0.729107773809 -1.12124670875
179 1.28828508776 -1.18972269812
180 0.936218595433 0.844436650383
181 -1.41967242002 -1.33553338128
182 0.451293435185 -0.337043043077
183 0.889211776584 0.683688380936
184 0.946264899744 0.846407250351
185 0.516908027375 -1.13002059107
186 0.663113490975 0.662420359006
187 0.985803048039 1.26228271875
188 -1.4124239618 -0.947706065026
189 0.642179325842 1.36969227279
190 -1.32320503558 -0.518361624408
191 0.389031988291 1.16716527963
192 -0.806854584638 -0.613264833433
193 -0.73049432945 -0.484378149065
194 0.493548378749 -0.761716569457
195 0.118175433165 -0.443557808199
196 1.00315780403 1.4310943891
197 0.778850340762 2.09349071844
198 -0.745033802864 -0.756441323796
199 -0.93389892072 -0.103482424997
200 0.68196176411 -0.273220993773
201 -1.16459401764 -0.315541399223
202 0.740399605464 -0.0945591684424
203 0.856407754419 0.252753351451
204 0.803410992909 -1.32952562448
205 0.429896355505 -0.758228537429
206 0.595823625156 1.74945400458
207 1.02085295004 -0.440804557414
208 0.30307695482 1.45762223084
209 1.18958904168 -0.581519032443
210 0.96915905519 -0.511234999414
211 0.697140552761 1.46349275366
212 0.637227696862 -0.764858659877
213 1.35045914484 -0.667938023256
214 0.250651256786 -1.19493208012
215 1.28347766291 1.37097619103
216 -0.128975958296 1.09716295281
217 -1.7517528787 -0.262053681114
218 -1.3635857203 -1.06031600728
219 -0.904113999203 0.191818430248
220 0.165426717861 -0.866647109384
221 0.232203921427 -0.682948158472
222 0.350368147923 -0.295280019807
223 1.5427482888 -0.592939512519
224 -1.13795423209 -0.133498274187
225 0.674237889386 -0.632143914378
226 0.334556478351 -1.20237442694
227 0.528396459186 1.34497258643
228 0.268370506258 0.734359941775
229 0.309361881005 -0.728426362716
230 0.917435744228 1.30854004814
231 0.428789300542 1.41209652083
232 0.199130767118 1.65759766562
233 -1.17444696491 -0.950375612201
234 0.597006581866 1.19119789824
235 -1.45170622969 -0.891168308477
236 -1.41986354849 -0.273475605125
237 -1.57409699552 -0.422236366569
238 1.04184264467 -0.362737479132
239 -2.14219480292 -0.482272076783
240 -1.50691533211 -0.200973148817
241 0.0543420665276 1.33168891813
242 -1.13144663461 -0.651825483298
243 1.07155174333 -0.692136570485
244 0.583387651839 -0.491450887858
245 -1.14297733022 -0.697948095468
246 0.0998245638451 0.10950372489
247 0.220588982913 -0.851548705937
248 -1.13730048755 -0.564448259501
249 0.905073179513 1.12779984735
250 0.72504167988 1.28738215218
251 -1.06955320593 -0.467663188307
252 -0.880265370005 -1.02614239598
253 -1.44264764226 -0.96145282057
254 1.01333072504 1.24675601661
255 -1.0093984377 -1.05143861237
256 0.507657052315 1.36804853004
257 1.26502785776 -0.711979714262
258 1.31608042094 1.5734222567
259 0.334632982453 -0.84147974129
260 0.802031438762 0.228215838939
261 1.38250775401 -0.644251339858
262 0.919614961822 -1.22049235391
263 0.929729151417 -0.208693463261
264 -1.53633104344 -0.511275317046
265 -0.665051865958 -0.739115745001
266 -0.335795516652 1.56140541417
267 1.23901518412 1.87882199622
268 -1.35543673912 -0.601849685925
269 -1.15154941392 -0.269135444753
270 0.608439338548 1.46684269694
271 1.06006794863 1.13065360895
272 0.942890187819 -0.742929110414
273 -1.15672050041 -0.436145800526
274 1.62198216506 0.050201317777
275 0.854125246175 -0.514807506009
276 -1.14337683511 -0.490935142717
277 -1.51048251847 -0.0345004965754
278 0.880530249926 -0.869888336327
279 -1.36540418059 -0.756111150943
280 0.601814512111 -1.21412505961
281 -0.0621652593321 1.12108597614
282 0.74067770872 -0.576648130759
283 -0.183577853633 -0.125433577503
284 0.417995488425 1.21449387096
285 -1.1856447963 -0.984315517908
286 1.07887574968 -0.840413058707
287 0.090657698723 -1.25434772582
288 0.0261662265887 1.22429234588
289 1.13673243898 -0.444139145222
290 1.23361139042 -1.09421718393
291 0.351468885092 1.51690258534
292 0.255831769187 1.27677830087
293 0.798195414423 -0.18283188485
294 1.31845143924 1.69400632284
295 0.938052607202 -0.419433668128
296 0.388310366276 1.31945848095
297 1.00904356759 -0.374533562373
298 -1.08675207316 -0.230719819714
299 0.956791915728 1.33752493245
300 0.964894172999 1.3091321864
301 0.630607763963 1.39287553367
302 -1.41288695181 -0.864681477113
303 0.261119656155 -1.02691248837
304 -0.882375409513 -0.666629249983
305 0.989911346176 -0.744391801077
306 0.867329484559 -0.768003291115
307 1.10613565156 1.4303998032
308 0.77134497925 -0.692113237484
309 0.343526184216 -0.991545218203
310 0.758591550569 1.54398289162
311 0.707946435833 1.45422137588
312 0.709604992056 -1.40060170714
313 -1.62485869339 -0.127799648835
314 -1.66703749341 0.0158250976471
315 -1.80730926772 -0.301662933271
316 -1.45291560869 -0.535118179264
317 -1.4701829607 -0.667609031391
318 0.826731842161 1.41567303436
319 -1.83590114306 -1.10954151061
320 -1.6332275232 -0.563497927722
321 -0.7388346936 -0.798186938046
322 -1.82702823377 0.13893299319
323 1.08739214482 0.826583726311
324 0.196057452318 2.06336452546
325 -0.962783057941 -0.109325188026
326 -1.19668293625 -1.1087752111
327 -0.920351459366 -0.706719513233
328 1.1741662534 1.0387978517
329 0.489318601459 -0.795493247886
330 -0.0285631715351 1.48253801626
331 -1.55996778776 -0.562017909444
332 0.0907181454452 -0.814517495862
333 1.04873107616 -0.452078258313
334 0.641663493277 1.45460629445
335 0.396805058072 1.10427025972
336 1.00336963075 -0.459191567668
337 0.907351763777 1.46562217387
338 0.904912861981 -1.62473397987
339 -1.30060206226 -0.639040245494
340 0.22255248672 1.32737094419
341 0.41209455966 -0.958675990971
342 0.941556677173 1.35441829013
343 1.28361991963 -1.24163477985
344 -0.376722258575 1.54300064517
345 0.930527863539 -0.784505897599
346 1.05101554226 -0.405406154061
347 1.22185277774 2.04479129366
348 -1.10897541444 -0.568930353083
349 0.637361305672 1.47374301327
350 -0.735046904585 -0.332733398991
351 0.914105951171 1.81364038611
352 0.815815323504 -0.428342552091
353 0.655466878695 -0.869548902941
354 -1.1045597651 -0.600408464946
355 -0.915703222184 -0.742626383383
356 -1.3571704177 -0.68125832152
357 0.69160775897 -0.893583583689
358 0.978900301359 1.75109237406
359 0.53683021324 -1.41620152234
360 1.09237619762 1.72716832141
361 0.866591909179 -0.581572078316
362 -1.80307744469 -0.65461097373
363 -0.127231346916 -0.409038899099
364 0.541525702451 -0.201173106705
365 0.68589072527 1.53390864901
366 -0.502670916098 -0.757868411152
367 0.417479823257 0.872860696972
368 -2.0289141946 -0.993678879688
369 0.245343426191 1.77834730722
370 0.316274690117 2.05030729845
371 1.23151797851 1.52230461678
372 0.488799329286 1.01622700328
373 0.736124228521 -0.560102473907
374 0.0380991755979 1.54458039477
375 0.348282296735 0.0373035505291
376 0.791153859839 1.36235109152
377 -1.89637476785 -0.983716547448
378 0.529079350094 1.21622740397
379 -1.2345838948 -0.786033236307
380 0.206511679327 -0.620187190429
381 -1.25908731883 -0.301031125224
382 -1.09843278784 0.0369549195008
383 -1.10406146313 -1.35048039511
384 0.983155368445 1.41480769807
385 -1.7328692309 -1.08216857053
386 -0.917910107541 -0.0889436794991
387 0.312585483993 1.0818337627
388 -0.0811644021867 -0.707691032276
389 -1.20266214326 -0.217504289139
390 0.454419137278 2.2457941917
391 0.471831725992 -0.493824106953
392 1.29161652352 -0.520992830994
393 -1.25588057463 -0.721197168795
394 -1.20377898567 -1.33173379489
395 1.11899200093 -0.713538916105
396 0.339906689497 -0.72413604985
397 0.615417018996 -0.858079193557
398 -1.01823258109 -0.78714664658
399 0.816099854449 -0.871668345031
400 -1.7212991458 -0.777848794878
401 0.843019145714 -0.498712137992
402 1.4021067635 1.45886382804
403 0.878294256485 -1.02266917785
404 -0.88512932828 -0.853503063368
405 0.430259456368 -0.453270444086
406 -1.77952949337 -0.141961490527
407 0.849914524615 1.24032152147
408 -1.32980886649 -0.481002489736
409 0.624470649758 1.26531866728
410 -1.06157593269 -1.13833962673
411 -1.3992137138 -0.965470741462
412 0.896181657602 0.695919911938
413 -1.418340371 -0.224255463115
414 0.0738188763056 -0.0563312160229
415 1.01170961883 0.241023782153
416 -1.5363281273 0.0159593515193
417 0.82770781377 0.709297571031
418 0.545029125045 0.868146825735
419 0.94527049937 -0.689257336931
420 -1.19201851393 -0.0979642908923
421 0.356642444398 -0.521177720048
422 1.25677847275 -0.948042349321
423 0.960112654402 -1.1046969869
424 0.467333609641 -0.297755148203
425 -1.09928800088 -0.782568121394
426 0.499876498504 1.34378633999
427 -0.0980920351721 1.38052928695
428 -0.233897355292 1.40492904943
429 0.951304495882 1.12558216168
430 -1.57107850167 -0.657989767628
431 0.284198318557 1.14751633136
432 1.14780923861 -0.398627857264
433 -1.63748393741 -0.707992965283
434 0.396760739464 1.1549469915
435 -0.856392511462 -0.729638141622
436 0.743336814006 -0.0447286202516
437 0.213902305912 1.02275520522
438 0.866879045866 1.22042656018
439 -0.88179618297 -1.43514524119
440 0.334722303045 0.736465317357
441 -1.71828945714 -0.333062709029
442 -0.918042667376 -0.843035843758
443 0.929243026125 1.35726190001
444 -0.431851673719 -1.10093484648
445 0.703743675795 1.87295209701
446 0.98717412056 -0.391248211672
447 0.446786417845 -0.232663277488
448 0.833397671467 -1.01523684003
449 -1.31380292373 -0.106348966316
450 -1.98210412488 -0.520364529607
451 0.882630413465 -0.204652953696
452 0.57473870386 1.15343094618
453 -1.64296177795 -0.545851844001
454 0.812520126446 1.57046768
455 -0.221156389297 0.90920018435
456 -1.31918421048 -1.02294749184
457 0.756117389326 1.26888096925
458 -1.00145716326 -1.06765844508
459 -1.16012367924 -1.17473398971
460 0.140325452005 -0.427986994764
461 0.5813642278 -0.83696135172
462 -0.31645030278 -1.51218920885
463 0.82452917064 0.93172792002
464 -0.750534982503 -0.836888860558
465 0.968658108542 -0.448623907721
466 1.2006923499 -0.475696442665
467 -1.26717115594 -0.665599874339
468 -1.82087781658 -0.868101472932
469 -1.16838236627 -1.54147890288
470 -0.981140298879 -1.28505380627
471 0.141023068843 1.12746333408
472 0.754032847532 0.960404487137
473 0.202135095167 1.18555519975
474 0.849908773169 -0.847682954547
475 0.744968023152 -0.228079376425
476 -1.91222754219 -0.796509854232
477 0.775623691917 -0.695029747499
478 -0.767188336951 -0.677911431003
479 0.712466108841 1.55417287552
480 1.21349899534 1.6388133243
481 -1.0869979326 -0.648693092282
482 0.699067612971 -1.40916870622
483 -1.53255598882 -0.261494722161
484 1.38939876357 1.88316296941
485 0.596690144163 1.72643881439
486 0.804964907977 -0.170902873462
487 0.40613498617 1.1198979641
488 -1.20807438507 -0.788501079273
489 0.728500901715 1.68709745134
490 0.316645956769 -0.510754409208
491 -0.823618040446 -0.884384414857
492 1.01442400059 1.24817740818
493 0.688659017161 -0.58639380357
494 0.370731358867 -0.986204337596
495 -1.02050291971 -0.913802249095
496 1.07231521798 1.81215231098
497 0.293755472217 0.389904123007
498 0.384580005797 1.95282853017
499 0.731079718128 -0.600671861978
500 -1.27084815866 -0.599802102819
501 -1.5506697485 -0.37391302332
502 0.819305570722 1.43691036146
503 0.758463908179 -0.257726277971
504 1.00739359449 1.43935814903
505 0.296387422059 1.74172031876
506 -1.56792541994 -0.625734935299
507 -1.58294937352 -0.212561302929
508 -1.48429016855 -0.214074430447
509 -1.57271416628 -0.983949703014
510 0.535738594277 1.01076484292
511 -1.47375056852 -0.955937874772
512 0.568475265758 1.64956338847
513 -0.862162831203 -0.884179051907
514 0.544925120741 1.6193204064
515 0.480499087021 2.02664864155
516 0.122038139573 0.119143611341
517 1.08322686266 1.50007405277
518 -1.26363865114 -1.24824215223
519 -1.09515150213 -0.580737374373
520 0.745663888861 -0.797265870367
521 -0.704911858139 -0.435654296496
522 -1.08345708839 -0.683728002502
523 -0.159115840147 1.35521476836
524 -0.834099861805 -0.571377281807
525 0.803301570929 1.04060299172
526 0.882227724909 -1.04635993234
527 -1.42356222195 -1.11563240162
528 0.598075641758 1.34363133224
529 1.00649041199 1.53362494993
530 -1.74840606346 -0.757167172502
531 0.665860879827 1.23423673133
532 -2.27447426719 -1.08752048002
533 -1.48420811929 -0.38750074543
534 0.710494890905 -0.0301573663517
535 0.2452388989 -1.06063486305
536 -1.30030123852 -0.741203235798
537 0.722560907798 -1.0887138629
538 0.845890473528 -0.765476650879
539 -0.987808045599 -0.300980235798
540 0.798685296365 -0.0203804886503
541 -1.27497724309 -0.358325506229
542 -1.63280019769 -0.540251128077
543 -1.64088545492 -0.242763376194
544 -1.27425159086 -0.0278791499227
545 0.710148737729 -1.00918956356
546 0.383105045026 0.834657242727
547 0.838530657897 1.26189497731
548 1.37406167258 0.78263972991
549 -1.95053657495 -1.14561235999
550 0.582792508127 -0.690694356981
551 0.913359445094 -0.619101104092
552 0.785580964186 1.58201082262
553 0.811102347249 -0.425468506696
554 0.702937953149 1.18281732336
555 0.532290267793 -0.895553891619
556 -1.10621476202 0.0215080636159
557 0.175894375098 1.6356268775
558 -0.768255477238 -0.558603363551
559 -1.04310626044 -1.16049754679
560 1.07207441854 1.56204556067
561 1.22409867855 1.22724262076
562 -1.59405917837 -1.18378628891
563 1.47675154752 -0.673616523166
564 -1.07509128453 -0.542721555114
565 0.930232971573 -0.66398380143
566 0.857366630575 -0.359918879193
567 0.251247597619 1.17090459393
568 1.16780804184 -0.28530226059
569 -1.6384800666 -1.12997990407
570 -1.3215530792 -1.28470419469
571 -1.09352620351 0.435204632862
572 0.944537238213 -0.802446108456
573 0.514125239901 1.36791043858
574 0.621920898963 1.97375976496
575 0.209206751878 -1.11104286684
576 0.0993365991821 1.11511466724
577 0.461961063861 -0.637500819694
578 0.257071325333 -0.87287754892
579 0.708547376969 1.39741781887
580 0.475251941501 -1.31719059033
581 0.610276462303 1.04890351278
582 -1.52841458815 -0.454742945322
583 -1.54735702492 -0.751499117222
584 -0.503751481339 -0.655854045695
585 -1.43543163548 -0.356638792552
586 0.472644264313 1.31387413897
587 0.20594576925 1.13671047633
588 0.615102823628 1.3826749988
589 0.634447199559 -0.507752603381
590 -1.14039960054 -0.69475439419
591 -1.32947946028 -0.197603144118
592 -1.20830036549 0.0116873739331
593 -1.73345855335 -0.132096369529
594 0.357039754872 -1.10590660431
595 0.077295305839 -1.13367252031
596 0.487312167153 -1.06555350588
597 0.353693691332 0.747606784869
598 0.72201625169 -0.295881357905
599 -1.92967429146 -0.682263484159
600 -0.908678506749 -0.121343269386
601 0.448752295827 0.926195545738
602 0.418381709077 1.28661802591
603 -1.61004687385 -0.988293010227
604 1.56677839696 1.67458369438
605 0.727890188144 -0.431864801265
606 -1.37981436331 -0.709415449061
607 0.686461132989 -0.0251400314444
608 -1.60911292662 -1.23835579119
609 0.165348852234 1.60960575054
610 1.00429011937 -0.690085482535
611 1.30821133172 -0.946724989662
612 1.10257026468 1.23706132126
613 1.15666930562 0.963710509452
614 -1.67698616873 -0.808446550696
615 0.576897088351 0.99280475248
616 0.94555298466 1.70764263243
617 0.568459449543 -0.902358290454
618 0.273923190749 1.4295727757
619 0.652270914927 2.0019813952
620 0.60267889291 1.04240532752
621 0.698937416681 -1.18542553401
622 0.262702790697 0.705979429324
623 -0.0487035963106 -0.47844505956
624 0.278008906473 0.998459028372
625 0.244071635336 0.754522731174
626 -1.47458283881 -1.04780342988
627 -1.41308398904 -1.16512495168
628 0.376605532983 1.67410945603
629 0.438984358586 1.46896397357
630 -0.791357172838 -0.556204685175
631 0.513404458949 0.148861596075
632 0.55598980494 -0.734532332917
633 -0.00629072685579 1.4577693075
634 0.451340090014 0.847671272714
635 0.587452946206 2.18519727161
636 1.32815664066 1.46277983499
637 1.15868201425 -0.705507183387
638 -2.19229513315 -0.302285759118
639 -1.49261826396 -0.821633387241
640 -1.47130624425 -0.63019322747
641 1.34514654196 -0.468598808267
642 -1.58948534345 -1.07365303551
643 0.279766265285 1.17244610684
644 0.87120798495 1.44312846654
645 0.620040716673 -1.14333094168
646 0.807830356825 -0.835873745532
647 0.894954831928 0.677891197264
648 -0.602527884597 -0.69024906938
649 0.658008384741 -0.400988830169
650 0.914769130628 1.57740991958
651 -1.48930440184 -1.37182156567
652 0.273422769288 -0.11466674929
653 0.472531390995 -0.0835618146858
654 -1.12231828159 -0.713669220151
655 0.241729907099 1.62624331977
656 0.370860921385 0.99072512802
657 0.980701101307 0.273732023633
658 -0.863388034868 -1.63431795709
659 0.734659138483 -1.29170380626
660 1.3680516506 0.926799443937
661 0.149907608089 1.41098618733
662 0.0734364428587 1.47804655719
663 0.415481089773 -1.08580981443
664 1.87043802694 -0.564764189615
665 1.33224467911 -0.791483035077
666 0.463346223426 1.54846334002
667 -1.77220711583 -0.866301255997
668 -0.566063485459 -0.721836722342
669 -1.36471735933 -0.972719760591
670 -1.36476695392 -0.99379395024
671 -1.28469298601 -0.318880090688
672 1.51904736282 1.29062985586
673 0.999041358538 1.43050704451
674 0.187630466783 -0.83321811689
675 -0.987675226269 -0.848285797745
676 0.989408735718 -0.0650375905356
677 0.915630353951 1.24498035147
678 -1.43557093403 -0.974714006397
679 -1.45387959068 -0.481585100397
680 -0.278976401689 -0.795716253642
681 0.400148808814 0.441913646796
682 0.757992930737 -0.758884707769
683 -1.92697167247 -0.984413224925
684 -0.946132960141 -0.951642902807
685 -0.374479291272 -1.13624183449
686 0.40711034652 -0.252446172482
687 -1.09764344526 -0.517312637143
688 0.669488945211 -0.522164749169
689 0.850151323586 1.34147908285
690 1.25907388444 -0.386367441721
691 0.347464827015 -0.533007300891
692 -1.27564074212 -0.433436163023
693 0.673862073887 1.42476903402
694 0.849062018952 1.08302511354
695 0.144638692788 1.95227594178
696 -1.42722323034 -0.811204501399
697 -1.64416438467 -0.543384736216
698 0.463117573507 -0.274247994439
699 0.943724941954 1.44571155091
700 0.870463827056 1.22602060889
701 1.18495335344 -0.234761356364
702 0.733969567923 -0.67288952967
703 -1.79850796029 -0.934840788244
704 0.888166348926 -0.884107436609
705 1.27188343182 -0.959291102507
706 0.841840207037 -0.974022163633
707 0.945701225098 1.6275104008
708 0.660977855757 -0.970868100576
709 -0.965730793499 -0.409989983699
710 1.03969981683 -0.365715737398
711 -1.16752822897 -0.477847154481
712 -1.01284867036 -0.328504389699
713 -1.54030317305 -0.13349028812
714 0.624306174222 -0.148540727917
715 0.667301055225 1.49923194215
716 0.778588762664 -0.384883563802
717 0.298516528096 1.32728546211
718 0.624466159376 -1.19599990114
719 0.810461715314 -0.542544742288
720 0.469536296015 1.49442431098
721 0.133949872378 0.783045014519
722 1.68141770912 -0.716638871392
723 -1.19132044269 -1.03412936975
724 0.0382702789919 0.234517417471
725 0.478943470729 1.37763420757
726 1.59302092264 -0.720684680801
727 0.361166988246 0.985493265361
728 0.768892000974 0.97473143902
729 0.962170710559 1.33000155872
730 -1.1943589351 -0.485554696436
731 0.306037432346 0.536315500264
732 1.01845907675 -0.550623430195
733 -1.26470285038 -0.339699106261
734 0.633088431313 -1.00774511415
735 0.800859848663 0.881746319329
736 -1.90816425794 -0.664624198594
737 0.403731959752 1.16592477989
738 0.63308271635 0.852550261268
739 0.184258505898 -0.476223501919
740 0.368550995255 0.768785338289
741 0.674247371136 -0.335924019381
742 -1.79245127675 -1.4045223247
743 -1.87656067 -0.476116371583
744 0.493448265324 -0.820792271427
745 -1.60183922321 -0.868539405266
746 0.505927093362 1.21392675643
747 -1.64046095603 -0.469972586457
748 -0.0571387622957 -0.909261054305
749 -1.1693940706 0.0395969246032
750 0.263229511513 -0.926499490699

188
clustering/dbscan.go Normal file
View File

@ -0,0 +1,188 @@
package clustering
import (
"github.com/gonum/matrix/mat64"
"github.com/sjwhitworth/golearn/base"
"github.com/sjwhitworth/golearn/metrics/pairwise"
"math/big"
)
// DBSCANParameters describes the parameters of the density-based
// clustering algorithm DBSCAN
type DBSCANParameters struct {
ClusterParameters
// Eps represents the "reachability", or the maximum
// distance any point can be before being considered for
// inclusion.
Eps float64
// MinCount represents how many points need to be
// in a cluster before it is considered one.
MinCount int
}
func regionQuery(p int, ret *big.Int, dist *mat64.Dense, eps float64) *big.Int {
rows, _ := dist.Dims()
// Return any points within the Eps neighbourhood
for i := 0; i < rows; i++ {
if dist.At(p, i) <= eps {
ret = ret.SetBit(ret, i, 1) // Mark as neighbour
}
}
return ret
}
func computePairwiseDistances(inst base.FixedDataGrid, attrs []base.Attribute, metric pairwise.PairwiseDistanceFunc) (*mat64.Dense, error) {
// Compute pair-wise distances
// First convert everything to floats
mats, err := base.ConvertAllRowsToMat64(attrs, inst)
if err != nil {
return nil, err
}
// Next, do an n^2 computation of all pairwise distances
_, rows := inst.Size()
dist := mat64.NewDense(rows, rows, nil)
for i := 0; i < rows; i++ {
for j := i + 1; j < rows; j++ {
d := metric.Distance(mats[i], mats[j])
dist.Set(i, j, d)
dist.Set(j, i, d)
}
}
return dist, nil
}
// DBSCAN clusters inst using the parameters allowed in and produces a ClusterId->[RowId] map
func DBSCAN(inst base.FixedDataGrid, params DBSCANParameters) (ClusterMap, error) {
// Compute the distances between each possible point
dist, err := computePairwiseDistances(inst, params.Attributes, params.Metric)
if err != nil {
return nil, err
}
_, rows := inst.Size()
clusterMap := make(map[int][]int)
visited := big.NewInt(0)
clustered := big.NewInt(0)
// expandCluster adds P to a cluster C, visiting any neighbours
expandCluster := func(p int, neighbours *big.Int, c int) {
if clustered.Bit(p) == 1 {
panic("Shouldn't happen!")
}
// Add this point to cluster C
if _, ok := clusterMap[c]; !ok {
clusterMap[c] = make([]int, 0)
}
clusterMap[c] = append(clusterMap[c], p)
clustered.SetBit(clustered, p, 1)
visited.SetBit(visited, p, 1)
for i := 0; i < rows; i++ {
reset := false
if neighbours.Bit(i) == 0 {
// Not a neighbour, so skip
continue
}
if visited.Bit(i) == 0 {
// not yet visited
visited = visited.SetBit(visited, i, 1) // Mark as visited
newNeighbours := big.NewInt(0)
newNeighbours = regionQuery(i, newNeighbours, dist, params.Eps)
if BitCount(newNeighbours) >= params.MinCount {
neighbours = neighbours.Or(neighbours, newNeighbours)
reset = true
}
} else {
continue
}
if clustered.Bit(i) == 0 {
clusterMap[c] = append(clusterMap[c], i)
clustered = clustered.SetBit(clustered, i, 1)
}
if reset {
i = 0
}
}
}
c := 0
for i := 0; i < rows; i++ {
if visited.Bit(i) == 1 {
continue // Already visited here
}
visited.SetBit(visited, i, 1)
neighbours := big.NewInt(0)
neighbours = regionQuery(i, neighbours, dist, params.Eps)
if BitCount(neighbours) < params.MinCount {
// Noise, cluster 0
clustered = clustered.Or(clustered, neighbours)
continue
}
c = c + 1 // Increment cluster count
expandCluster(i, neighbours, c)
}
// Remove anything from the map which doesn't make
// minimum points
rmKeys := make([]int, 0)
for id := range clusterMap {
if len(clusterMap[id]) < params.MinCount {
rmKeys = append(rmKeys, id)
}
}
for _, r := range rmKeys {
delete(clusterMap, r)
}
return ClusterMap(clusterMap), nil
}
// How many bits?
func BitCount(n *big.Int) int {
var count int = 0
for _, b := range n.Bytes() {
count += int(bitCounts[b])
}
return count
}
// The bit counts for each byte value (0 - 255).
var bitCounts = []int8{
// Generated by Java BitCount of all values from 0 to 255
0, 1, 1, 2, 1, 2, 2, 3,
1, 2, 2, 3, 2, 3, 3, 4,
1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5,
3, 4, 4, 5, 4, 5, 5, 6,
1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5,
3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5,
3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7,
1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5,
3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5,
3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5,
3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7,
5, 6, 6, 7, 6, 7, 7, 8,
}

View File

@ -0,0 +1,750 @@
2
0
2
1
2
0
0
1
2
2
0
0
0
1
0
2
-1
0
0
1
1
1
1
1
0
0
1
2
2
1
2
0
0
2
0
2
1
2
2
1
1
0
0
0
0
0
2
1
2
0
1
1
0
0
1
1
0
2
1
0
1
1
1
1
1
2
1
1
2
2
2
1
2
2
1
0
-1
0
2
1
0
0
2
2
2
2
0
1
0
1
1
2
0
2
0
-1
0
0
2
2
1
0
1
2
1
1
1
1
-1
2
-1
0
0
0
0
2
2
0
2
0
1
0
2
2
0
1
0
2
2
1
2
1
1
1
2
-1
1
1
2
0
2
1
2
2
1
1
-1
1
0
-1
1
0
0
1
1
1
2
0
2
0
2
0
2
1
1
-1
0
1
1
0
2
0
1
1
1
0
0
1
1
2
0
1
2
2
1
2
2
0
2
0
2
0
0
1
1
2
2
0
0
1
0
1
1
1
1
2
1
2
1
1
2
1
1
1
2
2
0
0
0
1
1
1
1
0
1
1
2
2
1
2
2
2
0
2
0
0
0
1
0
0
2
0
1
1
0
1
1
0
2
2
0
0
0
2
0
2
1
2
1
1
1
1
1
0
0
2
2
0
0
2
2
1
0
-1
1
0
0
1
0
1
2
1
1
2
0
1
1
2
1
1
2
2
1
2
1
2
1
0
2
2
2
0
1
0
1
1
2
1
1
2
2
1
0
0
0
0
0
2
0
0
0
0
2
2
0
0
0
2
1
2
0
1
1
2
2
1
2
1
0
2
1
2
1
2
1
1
2
0
2
0
2
1
1
0
0
0
1
2
1
2
1
0
1
1
2
0
2
0
2
2
2
2
1
2
1
2
0
2
0
1
0
0
0
2
0
0
2
1
0
2
1
1
0
0
1
1
1
0
1
0
1
2
1
0
1
0
2
0
2
0
0
2
0
1
-1
0
2
2
1
0
1
1
1
1
0
2
2
2
2
0
2
1
0
2
0
1
2
2
0
2
0
0
2
-1
2
1
1
1
0
0
1
2
0
2
2
0
2
0
0
1
1
-1
2
0
1
1
0
0
0
0
2
2
2
1
1
0
1
0
2
2
0
1
0
2
2
1
2
0
2
1
0
2
1
1
0
2
2
2
1
0
0
2
1
2
2
0
0
0
0
2
0
2
0
2
2
1
2
0
0
1
0
0
2
0
2
1
0
2
2
0
2
0
0
1
1
0
1
1
0
1
0
0
0
0
1
2
2
2
0
1
1
2
1
2
1
0
2
0
0
2
2
0
1
0
1
1
2
1
0
0
0
1
2
2
1
2
1
1
2
1
2
0
0
0
0
2
2
2
1
0
0
0
0
1
1
1
2
1
0
0
2
2
0
2
1
0
1
0
2
1
1
2
2
0
2
2
1
2
2
2
1
2
1
2
2
0
0
2
2
0
1
1
2
2
2
2
1
-1
0
0
1
0
2
2
1
1
2
0
1
2
0
1
1
0
2
2
-1
-1
1
2
2
2
1
-1
1
2
0
0
0
0
0
2
2
1
0
1
2
0
0
0
2
1
0
0
-1
1
0
1
2
1
1
0
2
2
2
0
0
1
2
2
1
1
0
1
1
1
2
1
0
1
0
0
0
1
2
1
2
1
1
2
2
1
0
1
2
1
2
2
2
0
2
1
0
1
2
0
2
2
1
2
1
0
0
1
0
2
0
1
0
1
1 2
2 0
3 2
4 1
5 2
6 0
7 0
8 1
9 2
10 2
11 0
12 0
13 0
14 1
15 0
16 2
17 -1
18 0
19 0
20 1
21 1
22 1
23 1
24 1
25 0
26 0
27 1
28 2
29 2
30 1
31 2
32 0
33 0
34 2
35 0
36 2
37 1
38 2
39 2
40 1
41 1
42 0
43 0
44 0
45 0
46 0
47 2
48 1
49 2
50 0
51 1
52 1
53 0
54 0
55 1
56 1
57 0
58 2
59 1
60 0
61 1
62 1
63 1
64 1
65 1
66 2
67 1
68 1
69 2
70 2
71 2
72 1
73 2
74 2
75 1
76 0
77 -1
78 0
79 2
80 1
81 0
82 0
83 2
84 2
85 2
86 2
87 0
88 1
89 0
90 1
91 1
92 2
93 0
94 2
95 0
96 -1
97 0
98 0
99 2
100 2
101 1
102 0
103 1
104 2
105 1
106 1
107 1
108 1
109 -1
110 2
111 -1
112 0
113 0
114 0
115 0
116 2
117 2
118 0
119 2
120 0
121 1
122 0
123 2
124 2
125 0
126 1
127 0
128 2
129 2
130 1
131 2
132 1
133 1
134 1
135 2
136 -1
137 1
138 1
139 2
140 0
141 2
142 1
143 2
144 2
145 1
146 1
147 -1
148 1
149 0
150 -1
151 1
152 0
153 0
154 1
155 1
156 1
157 2
158 0
159 2
160 0
161 2
162 0
163 2
164 1
165 1
166 -1
167 0
168 1
169 1
170 0
171 2
172 0
173 1
174 1
175 1
176 0
177 0
178 1
179 1
180 2
181 0
182 1
183 2
184 2
185 1
186 2
187 2
188 0
189 2
190 0
191 2
192 0
193 0
194 1
195 1
196 2
197 2
198 0
199 0
200 1
201 0
202 1
203 1
204 1
205 1
206 2
207 1
208 2
209 1
210 1
211 2
212 1
213 1
214 1
215 2
216 2
217 0
218 0
219 0
220 1
221 1
222 1
223 1
224 0
225 1
226 1
227 2
228 2
229 1
230 2
231 2
232 2
233 0
234 2
235 0
236 0
237 0
238 1
239 0
240 0
241 2
242 0
243 1
244 1
245 0
246 1
247 1
248 0
249 2
250 2
251 0
252 0
253 0
254 2
255 0
256 2
257 1
258 2
259 1
260 1
261 1
262 1
263 1
264 0
265 0
266 2
267 2
268 0
269 0
270 2
271 2
272 1
273 0
274 -1
275 1
276 0
277 0
278 1
279 0
280 1
281 2
282 1
283 1
284 2
285 0
286 1
287 1
288 2
289 1
290 1
291 2
292 2
293 1
294 2
295 1
296 2
297 1
298 0
299 2
300 2
301 2
302 0
303 1
304 0
305 1
306 1
307 2
308 1
309 1
310 2
311 2
312 1
313 0
314 0
315 0
316 0
317 0
318 2
319 0
320 0
321 0
322 0
323 2
324 2
325 0
326 0
327 0
328 2
329 1
330 2
331 0
332 1
333 1
334 2
335 2
336 1
337 2
338 1
339 0
340 2
341 1
342 2
343 1
344 2
345 1
346 1
347 2
348 0
349 2
350 0
351 2
352 1
353 1
354 0
355 0
356 0
357 1
358 2
359 1
360 2
361 1
362 0
363 1
364 1
365 2
366 0
367 2
368 0
369 2
370 2
371 2
372 2
373 1
374 2
375 1
376 2
377 0
378 2
379 0
380 1
381 0
382 0
383 0
384 2
385 0
386 0
387 2
388 1
389 0
390 2
391 1
392 1
393 0
394 0
395 1
396 1
397 1
398 0
399 1
400 0
401 1
402 2
403 1
404 0
405 1
406 0
407 2
408 0
409 2
410 0
411 0
412 2
413 0
414 1
415 -1
416 0
417 2
418 2
419 1
420 0
421 1
422 1
423 1
424 1
425 0
426 2
427 2
428 2
429 2
430 0
431 2
432 1
433 0
434 2
435 0
436 1
437 2
438 2
439 0
440 2
441 0
442 0
443 2
444 -1
445 2
446 1
447 1
448 1
449 0
450 0
451 1
452 2
453 0
454 2
455 2
456 0
457 2
458 0
459 0
460 1
461 1
462 -1
463 2
464 0
465 1
466 1
467 0
468 0
469 0
470 0
471 2
472 2
473 2
474 1
475 1
476 0
477 1
478 0
479 2
480 2
481 0
482 1
483 0
484 2
485 2
486 1
487 2
488 0
489 2
490 1
491 0
492 2
493 1
494 1
495 0
496 2
497 2
498 2
499 1
500 0
501 0
502 2
503 1
504 2
505 2
506 0
507 0
508 0
509 0
510 2
511 0
512 2
513 0
514 2
515 2
516 1
517 2
518 0
519 0
520 1
521 0
522 0
523 2
524 0
525 2
526 1
527 0
528 2
529 2
530 0
531 2
532 0
533 0
534 1
535 1
536 0
537 1
538 1
539 0
540 1
541 0
542 0
543 0
544 0
545 1
546 2
547 2
548 2
549 0
550 1
551 1
552 2
553 1
554 2
555 1
556 0
557 2
558 0
559 0
560 2
561 2
562 0
563 1
564 0
565 1
566 1
567 2
568 1
569 0
570 0
571 0
572 1
573 2
574 2
575 1
576 2
577 1
578 1
579 2
580 1
581 2
582 0
583 0
584 0
585 0
586 2
587 2
588 2
589 1
590 0
591 0
592 0
593 0
594 1
595 1
596 1
597 2
598 1
599 0
600 0
601 2
602 2
603 0
604 2
605 1
606 0
607 1
608 0
609 2
610 1
611 1
612 2
613 2
614 0
615 2
616 2
617 1
618 2
619 2
620 2
621 1
622 2
623 1
624 2
625 2
626 0
627 0
628 2
629 2
630 0
631 1
632 1
633 2
634 2
635 2
636 2
637 1
638 -1
639 0
640 0
641 1
642 0
643 2
644 2
645 1
646 1
647 2
648 0
649 1
650 2
651 0
652 1
653 1
654 0
655 2
656 2
657 -1
658 -1
659 1
660 2
661 2
662 2
663 1
664 -1
665 1
666 2
667 0
668 0
669 0
670 0
671 0
672 2
673 2
674 1
675 0
676 1
677 2
678 0
679 0
680 0
681 2
682 1
683 0
684 0
685 -1
686 1
687 0
688 1
689 2
690 1
691 1
692 0
693 2
694 2
695 2
696 0
697 0
698 1
699 2
700 2
701 1
702 1
703 0
704 1
705 1
706 1
707 2
708 1
709 0
710 1
711 0
712 0
713 0
714 1
715 2
716 1
717 2
718 1
719 1
720 2
721 2
722 1
723 0
724 1
725 2
726 1
727 2
728 2
729 2
730 0
731 2
732 1
733 0
734 1
735 2
736 0
737 2
738 2
739 1
740 2
741 1
742 0
743 0
744 1
745 0
746 2
747 0
748 1
749 0
750 1

150
clustering/dbscan_test.go Normal file
View File

@ -0,0 +1,150 @@
package clustering
import (
"bufio"
"github.com/gonum/matrix/mat64"
"github.com/sjwhitworth/golearn/base"
"github.com/sjwhitworth/golearn/metrics/pairwise"
. "github.com/smartystreets/goconvey/convey"
"math"
"math/big"
"os"
"strconv"
"testing"
)
func TestDBSCANDistanceQuery(t *testing.T) {
Convey("Should be able to determine which points are in range...", t, func() {
// Read in the synthetic test data
inst, err := base.ParseCSVToInstances("synthetic.csv", false)
So(err, ShouldBeNil)
// Create a neighbours vector
neighbours := big.NewInt(0)
// Compute pairwise distances
dist, err := computePairwiseDistances(inst, inst.AllAttributes(), pairwise.NewEuclidean())
So(dist.At(0, 0), ShouldAlmostEqual, 0)
So(dist.At(0, 1), ShouldAlmostEqual, 1)
So(dist.At(1, 0), ShouldAlmostEqual, 1)
So(dist.At(0, 2), ShouldAlmostEqual, math.Sqrt(5))
So(dist.At(2, 0), ShouldAlmostEqual, math.Sqrt(5))
So(err, ShouldBeNil)
// Do the region query
neighbours = regionQuery(0, neighbours, dist, 1)
So(neighbours.Bit(0), ShouldEqual, 1)
So(neighbours.Bit(1), ShouldEqual, 1)
So(neighbours.Bit(2), ShouldEqual, 0)
So(neighbours.Bit(3), ShouldEqual, 0)
So(neighbours.Bit(4), ShouldEqual, 0)
})
}
func TestDBSCANSynthetic(t *testing.T) {
Convey("Synthetic DBSCAN test should work...", t, func() {
inst, err := base.ParseCSVToInstances("synthetic.csv", false)
So(err, ShouldBeNil)
p := DBSCANParameters{
ClusterParameters{
inst.AllAttributes(),
pairwise.NewEuclidean(),
},
1,
1,
}
m, err := DBSCAN(inst, p)
So(err, ShouldBeNil)
So(len(m), ShouldEqual, 2)
So(m[1], ShouldContain, 0)
So(m[1], ShouldContain, 1)
So(m[1], ShouldContain, 2)
So(m[1], ShouldContain, 3)
})
}
func TestDBSCANDistanceMetric(t *testing.T) {
Convey("Check the distance function is sane...", t, func() {
d1 := mat64.NewDense(1, 2, nil)
d2 := mat64.NewDense(1, 2, nil)
d1.Set(0, 0, 0.494260967249)
d1.Set(0, 1, 1.45106696541)
d2.Set(0, 0, -1.42808099324)
d2.Set(0, 1, -0.83706376669)
e := pairwise.NewEuclidean()
So(e.Distance(d1, d2), ShouldAlmostEqual, 2.9882, 0.001)
})
}
func TestDBSCAN(t *testing.T) {
Convey("Loading some data and labels...", t, func() {
inst, err := base.ParseCSVToInstances("dbscan.csv", false)
So(err, ShouldBeNil)
file, err := os.Open("dbscan_labels.csv")
defer file.Close()
So(err, ShouldBeNil)
clusterMap := ClusterMap(make(map[int][]int))
scanner := bufio.NewScanner(file)
line := -1
for scanner.Scan() {
line = line + 1
v, err := strconv.ParseInt(scanner.Text(), 10, 64)
if err != nil {
panic(err)
}
v = v + 1 // -1 are noise in scikit-learn's DBSCAN
c := int(v)
if c == 0 {
continue
}
if _, ok := clusterMap[c]; !ok {
clusterMap[c] = make([]int, 0)
}
clusterMap[c] = append(clusterMap[c], line)
}
Convey("Our DBSCAN implementation should match...", func() {
p := DBSCANParameters{
ClusterParameters{
inst.AllAttributes(),
pairwise.NewEuclidean(),
},
0.3,
10,
}
m, err := DBSCAN(inst, p)
Convey("There should be nothing in the result that's smaller than MinPts", func() {
for id := range m {
So(len(m[id]), ShouldBeGreaterThanOrEqualTo, 10)
}
})
So(err, ShouldBeNil)
eq, err := clusterMap.Equals(m)
So(err, ShouldBeNil)
So(eq, ShouldBeTrue)
})
})
}

30
clustering/gen_test.py Normal file
View File

@ -0,0 +1,30 @@
#
# Generate sample data for the DBSCAN test
#
# Lifted from http://scikit-learn.org/stable/auto_examples/cluster/plot_dbscan.html#example-cluster-plot-dbscan-py
#
import numpy as np
from sklearn.cluster import DBSCAN
from sklearn import metrics
from sklearn.datasets.samples_generator import make_blobs
from sklearn.preprocessing import StandardScaler
centers = [[1, 1], [-1, -1], [1, -1]]
X, labels_true = make_blobs(n_samples=750, centers=centers, cluster_std=0.4,
random_state=0)
X = StandardScaler().fit_transform(X)
X = X.astype(np.float64)
db = DBSCAN(eps=0.3, min_samples=10, metric='l2', algorithm='brute').fit(X)
core_samples_mask = np.zeros_like(db.labels_, dtype=bool)
core_samples_mask[db.core_sample_indices_] = True
labels = db.labels_
with open('dbscan.csv', 'w') as fscanout:
with open('dbscan_labels.csv', 'w') as fscanlabout:
for i in range(750):
fscanout.write(",".join([str(x) for x in X[i,:]]) + "\n")
fscanlabout.write(str(labels[i]) + "\n")

5
clustering/synthetic.csv Normal file
View File

@ -0,0 +1,5 @@
0,4
1,4
2,3
2,4
3,1
1 0 4
2 1 4
3 2 3
4 2 4
5 3 1