Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Math-KDTree #5

Merged
merged 1 commit into from

2 participants

@WernerK

i added a directory Math-KDTree.
would you be so kind to have look, whether i did that correctly. this git thing makes me nervous.
werner

werner kassens Math-KDTree 842ef55
@djuber djuber merged commit 24812a4 into from
@djuber
Collaborator
@WernerK
@djuber
Collaborator
@WernerK
@djuber
Collaborator
@WernerK
@djuber
Collaborator
@djuber
Collaborator

Okay, once I have the right package structure, Nautilus gives me the option of committing to the smaller section. Very happy to have gotten that out of the way.

Thanks for your help, Werner.

Dan

@WernerK
@WernerK
@djuber
Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 13, 2012
  1. Math-KDTree

    werner kassens authored
This page is out of date. Refresh to see the latest.
Showing with 323 additions and 0 deletions.
  1. +1 −0  Math-KDTree/.filetree
  2. +4 −0 Math-KDTree/Math-KDTree.package/.filetree
  3. +1 −0  Math-KDTree/Math-KDTree.package/IndexedKDTree.class/README.md
  4. +6 −0 Math-KDTree/Math-KDTree.package/IndexedKDTree.class/class/withAll..st
  5. +12 −0 Math-KDTree/Math-KDTree.package/IndexedKDTree.class/instance/addData.at..st
  6. +7 −0 Math-KDTree/Math-KDTree.package/IndexedKDTree.class/instance/nnSearch.i..st
  7. +8 −0 Math-KDTree/Math-KDTree.package/IndexedKDTree.class/instance/nnSearch.near..st
  8. +16 −0 Math-KDTree/Math-KDTree.package/IndexedKDTree.class/properties.json
  9. +1 −0  Math-KDTree/Math-KDTree.package/KDTree.class/README.md
  10. +6 −0 Math-KDTree/Math-KDTree.package/KDTree.class/class/withAll..st
  11. +11 −0 Math-KDTree/Math-KDTree.package/KDTree.class/instance/addData.at..st
  12. +3 −0  Math-KDTree/Math-KDTree.package/KDTree.class/instance/farChild..st
  13. +3 −0  Math-KDTree/Math-KDTree.package/KDTree.class/instance/left.st
  14. +3 −0  Math-KDTree/Math-KDTree.package/KDTree.class/instance/nearChild..st
  15. +8 −0 Math-KDTree/Math-KDTree.package/KDTree.class/instance/nnSearch.i..st
  16. +8 −0 Math-KDTree/Math-KDTree.package/KDTree.class/instance/nnSearch.near..st
  17. +11 −0 Math-KDTree/Math-KDTree.package/KDTree.class/instance/printOn..st
  18. +3 −0  Math-KDTree/Math-KDTree.package/KDTree.class/instance/right.st
  19. +19 −0 Math-KDTree/Math-KDTree.package/KDTree.class/properties.json
  20. +1 −0  Math-KDTree/Math-KDTree.package/KDTreeTest.class/README.md
  21. +3 −0  Math-KDTree/Math-KDTree.package/KDTreeTest.class/instance/setUp.st
  22. +21 −0 Math-KDTree/Math-KDTree.package/KDTreeTest.class/instance/testKDTree1Dimension.st
  23. +17 −0 Math-KDTree/Math-KDTree.package/KDTreeTest.class/instance/testKDTree2Dimensions.st
  24. +14 −0 Math-KDTree/Math-KDTree.package/KDTreeTest.class/instance/testKDTree4Dimensions.st
  25. +16 −0 Math-KDTree/Math-KDTree.package/KDTreeTest.class/properties.json
  26. +3 −0  Math-KDTree/Math-KDTree.package/NNStore.class/README.md
  27. +3 −0  Math-KDTree/Math-KDTree.package/NNStore.class/class/new..st
  28. +4 −0 Math-KDTree/Math-KDTree.package/NNStore.class/class/new.st
  29. +5 −0 Math-KDTree/Math-KDTree.package/NNStore.class/class/newFrom..st
  30. +5 −0 Math-KDTree/Math-KDTree.package/NNStore.class/class/withAll..st
  31. +6 −0 Math-KDTree/Math-KDTree.package/NNStore.class/instance/add..st
  32. +4 −0 Math-KDTree/Math-KDTree.package/NNStore.class/instance/completeData.st
  33. +3 −0  Math-KDTree/Math-KDTree.package/NNStore.class/instance/copyEmpty.st
  34. +4 −0 Math-KDTree/Math-KDTree.package/NNStore.class/instance/data.st
  35. +4 −0 Math-KDTree/Math-KDTree.package/NNStore.class/instance/freeIndex..st
  36. +4 −0 Math-KDTree/Math-KDTree.package/NNStore.class/instance/initialize.st
  37. +3 −0  Math-KDTree/Math-KDTree.package/NNStore.class/instance/isEmpty.st
  38. +3 −0  Math-KDTree/Math-KDTree.package/NNStore.class/instance/isFull.st
  39. +4 −0 Math-KDTree/Math-KDTree.package/NNStore.class/instance/maxDistance.st
  40. +4 −0 Math-KDTree/Math-KDTree.package/NNStore.class/instance/sort.st
  41. +6 −0 Math-KDTree/Math-KDTree.package/NNStore.class/instance/sortFor..st
  42. +17 −0 Math-KDTree/Math-KDTree.package/NNStore.class/properties.json
  43. +1 −0  Math-KDTree/Math-KDTree.package/StupidNN.class/README.md
  44. +9 −0 Math-KDTree/Math-KDTree.package/StupidNN.class/instance/nnSearch.i..st
  45. +6 −0 Math-KDTree/Math-KDTree.package/StupidNN.class/instance/sortFor..st
  46. +16 −0 Math-KDTree/Math-KDTree.package/StupidNN.class/properties.json
  47. +1 −0  Math-KDTree/Math-KDTree.package/monticello.meta/categories.st
  48. 0  Math-KDTree/Math-KDTree.package/monticello.meta/initializers.st
  49. +1 −0  Math-KDTree/Math-KDTree.package/monticello.meta/package
  50. +1 −0  Math-KDTree/Math-KDTree.package/monticello.meta/version
  51. +2 −0  Math-KDTree/Math-KDTree.package/properties.json
  52. BIN  Math-KDTree/NNPlot.jpg
  53. +1 −0  Math-KDTree/README.md
View
1  Math-KDTree/.filetree
@@ -0,0 +1 @@
+{ "packageExtension" : ".package" }
View
4 Math-KDTree/Math-KDTree.package/.filetree
@@ -0,0 +1,4 @@
+{
+ "noMethodMetaData" : true,
+ "separateMethodMetaAndSource" : false,
+ "useCypressPropertiesFile" : true }
View
1  Math-KDTree/Math-KDTree.package/IndexedKDTree.class/README.md
@@ -0,0 +1 @@
+IndexedKDTree returns the indices of the nearest neighbours instead of the nearest neighbours itself.
View
6 Math-KDTree/Math-KDTree.package/IndexedKDTree.class/class/withAll..st
@@ -0,0 +1,6 @@
+instance creation
+withAll: aCollectionOfCollections
+"make a KDTree from aCollectionOfCollections ,which is a Collection of points in a n-dimensional space"
+|c|
+c :=aCollectionOfCollections withIndexCollect: [:v :i| {i.v.}] .
+^super withAll: c.
View
12 Math-KDTree/Math-KDTree.package/IndexedKDTree.class/instance/addData.at..st
@@ -0,0 +1,12 @@
+initialize
+addData: anOrderedCollection at: dimension
+|sorted cut nextdim|
+dim :=dimension .
+anOrderedCollection size =1 ifTrue: [value :=anOrderedCollection first . index :=value first. value :=value at: 2. ^self ].
+sorted :=anOrderedCollection sort:[:a :b| ((a at: 2) at: dimension) < ((b at: 2) at: dimension) ].
+cut :=sorted size + 1// 2.
+value :=sorted at: cut .
+index :=value first. value :=value at: 2.
+nextdim :=dimension \\(value size) +1.
+cut >1 ifTrue: [left :=self class new addData: (sorted copyFrom: 1 to: cut -1 ) at: nextdim].
+right :=self class new addData: (sorted copyFrom: cut +1 to: sorted size) at: nextdim.
View
7 Math-KDTree/Math-KDTree.package/IndexedKDTree.class/instance/nnSearch.i..st
@@ -0,0 +1,7 @@
+evaluating
+nnSearch: aCollection i: anInt
+"search for i nearest neighbours of vector aCollection and return the indices; and distances (if i>1, at second position)"
+|n|
+n :=NNStore new: anInt .
+self nnSearch: aCollection near: n .
+^anInt =1 ifTrue: [n data first first ] ifFalse: [n completeData collect: [:i | {(i at:2)first . i first}] ]
View
8 Math-KDTree/Math-KDTree.package/IndexedKDTree.class/instance/nnSearch.near..st
@@ -0,0 +1,8 @@
+evaluating
+nnSearch: aCollection near: aNNStore
+|dist|
+(self nearChild: aCollection)ifNotNilDo:[:c| c nnSearch: aCollection near: aNNStore ].
+(aNNStore maxDistance)<( (dist := (value at: dim) - (aCollection at: dim) ) * dist ) ifTrue:[^self ].
+dist := ((dist:= aCollection - value)*dist )sum.
+(aNNStore maxDistance >dist ) ifTrue: [aNNStore add: {dist . {index . value}} ] .
+(self farChild: aCollection)ifNotNilDo:[:c| c nnSearch: aCollection near: aNNStore].
View
16 Math-KDTree/Math-KDTree.package/IndexedKDTree.class/properties.json
@@ -0,0 +1,16 @@
+{
+ "category" : "Math-KDTree",
+ "classinstvars" : [
+ ],
+ "classtraitcomposition" : "{}",
+ "classvars" : [
+ ],
+ "commentStamp" : "WernerKassens 7/20/2011 13:48",
+ "instvars" : [
+ "index" ],
+ "name" : "IndexedKDTree",
+ "pools" : [
+ ],
+ "super" : "KDTree",
+ "traitcomposition" : "{}",
+ "type" : "normal" }
View
1  Math-KDTree/Math-KDTree.package/KDTree.class/README.md
@@ -0,0 +1 @@
+KDTree is a space partitioning data structure to store points of that space with "KDTree withAll: aCollectionOfVectors", where a vector can be any collection of numbers that understands "at:". you can then find nearest neighbours of aVector with "nnSearch: aVector i: numberOfNearestNeighbours".
View
6 Math-KDTree/Math-KDTree.package/KDTree.class/class/withAll..st
@@ -0,0 +1,6 @@
+instance creation
+withAll: aCollectionOfCollections
+"make a KDTree from aCollectionOfCollections ,which is a Collection of points in a n-dimensional space"
+(aCollectionOfCollections allSatisfy: [:c|c isCollection ])ifFalse:
+ [self error: 'KDTree withAll: expects a collection of collections'].
+^self new addData: aCollectionOfCollections asOrderedCollection at:1.
View
11 Math-KDTree/Math-KDTree.package/KDTree.class/instance/addData.at..st
@@ -0,0 +1,11 @@
+initialize
+addData: anOrderedCollection at: dimension
+|sorted cut nextdim|
+dim :=dimension .
+anOrderedCollection size =1 ifTrue: [value :=anOrderedCollection first . ^self ].
+sorted :=anOrderedCollection sort:[:a :b| (a at: dimension) < (b at: dimension) ].
+cut :=sorted size + 1// 2.
+value :=sorted at: cut .
+nextdim :=dimension \\(value size) +1.
+cut >1 ifTrue: [left :=self class new addData: (sorted copyFrom: 1 to: cut -1 ) at: nextdim].
+right :=self class new addData: (sorted copyFrom: cut +1 to: sorted size) at: nextdim.
View
3  Math-KDTree/Math-KDTree.package/KDTree.class/instance/farChild..st
@@ -0,0 +1,3 @@
+accessing
+farChild: aVector
+^((value at: dim) < (aVector at: dim)) ifTrue: [left ] ifFalse: [right ]
View
3  Math-KDTree/Math-KDTree.package/KDTree.class/instance/left.st
@@ -0,0 +1,3 @@
+accessing
+left
+^left
View
3  Math-KDTree/Math-KDTree.package/KDTree.class/instance/nearChild..st
@@ -0,0 +1,3 @@
+accessing
+nearChild: aVector
+^((value at: dim) < (aVector at: dim)) ifTrue: [right ] ifFalse: [left ]
View
8 Math-KDTree/Math-KDTree.package/KDTree.class/instance/nnSearch.i..st
@@ -0,0 +1,8 @@
+evaluating
+nnSearch: aCollection i:anInt
+"search for i nearest neighbours of vector aCollection "
+|n|
+n :=NNStore new: anInt .
+self nnSearch: aCollection near: n .
+n :=n data .
+^anInt =1 ifTrue: [n first ] ifFalse: [n]
View
8 Math-KDTree/Math-KDTree.package/KDTree.class/instance/nnSearch.near..st
@@ -0,0 +1,8 @@
+evaluating
+nnSearch: aCollection near: aNNStore
+|dist|
+(self nearChild: aCollection)ifNotNilDo:[:c| c nnSearch: aCollection near: aNNStore ].
+(aNNStore maxDistance)<( (dist := (value at: dim) - (aCollection at: dim) ) * dist ) ifTrue:[^self ].
+dist := ((dist:= aCollection - value)*dist )sum.
+(aNNStore maxDistance >dist ) ifTrue: [aNNStore add: {dist . value} ] .
+(self farChild: aCollection)ifNotNilDo:[:c| c nnSearch: aCollection near: aNNStore].
View
11 Math-KDTree/Math-KDTree.package/KDTree.class/instance/printOn..st
@@ -0,0 +1,11 @@
+printing
+printOn: aStream
+ aStream nextPutAll: 'KDTree (dim: ';
+ print: dim ;
+ nextPutAll: ' value: ';
+ print: value ;
+ nextPutAll: ' left: ';
+ print: left ;
+ nextPutAll: ' right: ';
+ print: right ;
+ nextPut: $) .
View
3  Math-KDTree/Math-KDTree.package/KDTree.class/instance/right.st
@@ -0,0 +1,3 @@
+accessing
+right
+^right
View
19 Math-KDTree/Math-KDTree.package/KDTree.class/properties.json
@@ -0,0 +1,19 @@
+{
+ "category" : "Math-KDTree",
+ "classinstvars" : [
+ ],
+ "classtraitcomposition" : "{}",
+ "classvars" : [
+ ],
+ "commentStamp" : "WernerKassens 5/5/2011 15:45",
+ "instvars" : [
+ "left",
+ "right",
+ "dim",
+ "value" ],
+ "name" : "KDTree",
+ "pools" : [
+ ],
+ "super" : "Object",
+ "traitcomposition" : "{}",
+ "type" : "normal" }
View
1  Math-KDTree/Math-KDTree.package/KDTreeTest.class/README.md
@@ -0,0 +1 @@
+KDTreeTest makes random checks of KDTree, comparing results with results of StupidNN. is not too fast.
View
3  Math-KDTree/Math-KDTree.package/KDTreeTest.class/instance/setUp.st
@@ -0,0 +1,3 @@
+running
+setUp
+rand :=Random new.
View
21 Math-KDTree/Math-KDTree.package/KDTreeTest.class/instance/testKDTree1Dimension.st
@@ -0,0 +1,21 @@
+tests
+testKDTree1Dimension
+|m tree stupid vec aResult bResult|
+m :=(rand next:200) collect: [:n| Array with: n]."1-dimensional data, just some numbers"
+stupid :=StupidNN withAll: m.
+tree :=KDTree withAll: m.
+1 to: 11do:[:v|vec :={1/ v asFloat }.
+ aResult :=stupid nnSearch: vec i:3. "3 nearest numbers to vec"
+ bResult :=tree nnSearch: vec i:3. "3 nearest numbers to vec using KDTree"
+ self assert: ( (aResult with: bResult collect: [:a :b|a hasEqualElements: b]) allSatisfy: [:e|e]) ] .
+m :=(1 to: 20) collect: [:index | Array with: (rand nextInt: 10)]. "only integers, obviously with multiples. test distances because nn are not necessarily the same"
+stupid :=StupidNN withAll: m.
+tree :=KDTree withAll: m.
+0 to: 11do:[:v|vec :={v}.
+ aResult :=(vec first - (stupid nnSearch: vec i:3))abs. "distances between 3 nearest numbers and vec"
+ bResult :=(vec first - (tree nnSearch: vec i:3))abs. "distances using KDTree"
+ self assert: ( (aResult with: bResult collect: [:a :b|a hasEqualElements: b]) allSatisfy: [:e|e]) ] .
+tree :=KDTree withAll: #(#(1)). "extreme case"
+bResult :=tree nnSearch: #(2) i: 3.
+self assert: (bResult size =1).
+self assert: (bResult first = #(1) )
View
17 Math-KDTree/Math-KDTree.package/KDTreeTest.class/instance/testKDTree2Dimensions.st
@@ -0,0 +1,17 @@
+tests
+testKDTree2Dimensions
+|m tree stupid vec aResult bResult|
+m :=(1 to: 2000) collect: [:n| (rand next:2)]. "2-dimensional data"
+stupid :=StupidNN withAll: m.
+tree :=KDTree withAll: m.
+100 timesRepeat: [vec :=rand next:2.
+ aResult :=stupid nnSearch: vec i:3.
+ bResult :=tree nnSearch: vec i:3.
+ self assert: ( (aResult with: bResult collect: [:a :b|a hasEqualElements: b]) allSatisfy: [:e|e]) ] .
+m:= (1 to: 200) collect: [:index | Array with: (rand nextInt: 10) with: (rand nextInt: 10 )]. "integers"
+stupid :=StupidNN withAll: m.
+tree :=KDTree withAll: m.
+100 timesRepeat: [vec :=(rand next: 2)*11.
+ aResult :=stupid nnSearch: vec i:3.
+ bResult :=tree nnSearch: vec i:3.
+ self assert: ( (aResult with: bResult collect: [:a :b|a hasEqualElements: b]) allSatisfy: [:e|e]) ] .
View
14 Math-KDTree/Math-KDTree.package/KDTreeTest.class/instance/testKDTree4Dimensions.st
@@ -0,0 +1,14 @@
+tests
+testKDTree4Dimensions
+|m tree stupid vec aResult bResult|
+m :=(1 to: 2000) collect: [:n| (rand next:4)]. "4-dimensional data"
+stupid :=StupidNN withAll: m.
+tree :=KDTree withAll: m.
+50 timesRepeat: [vec :=(rand next: 4)- 0.5.
+ aResult :=stupid nnSearch: vec i:2. "2 nearest neighbours"
+ bResult :=tree nnSearch: vec i:2.
+ self assert: ( (aResult with: bResult collect: [:a :b|a hasEqualElements: b]) allSatisfy: [:e|e]) ] .
+50 timesRepeat: [vec :=rand next: 4.
+ aResult :=stupid nnSearch: vec i:1. "just the nearest neighbour"
+ bResult :=tree nnSearch: vec i:1.
+ self assert: (aResult hasEqualElements: bResult ) ] .
View
16 Math-KDTree/Math-KDTree.package/KDTreeTest.class/properties.json
@@ -0,0 +1,16 @@
+{
+ "category" : "Math-KDTree",
+ "classinstvars" : [
+ ],
+ "classtraitcomposition" : "{}",
+ "classvars" : [
+ ],
+ "commentStamp" : "WernerKassens 5/3/2011 22:27",
+ "instvars" : [
+ "rand" ],
+ "name" : "KDTreeTest",
+ "pools" : [
+ ],
+ "super" : "TestCase",
+ "traitcomposition" : "{}",
+ "type" : "normal" }
View
3  Math-KDTree/Math-KDTree.package/NNStore.class/README.md
@@ -0,0 +1,3 @@
+NNStore stores neighbours together with distances and uses the distances for sorting.
+
+can easily be subclassed if one needs an Array sorted depending on some outside data. see StupidNN for a simple example and comment on "withAll:" or just use "newFrom:".
View
3  Math-KDTree/Math-KDTree.package/NNStore.class/class/new..st
@@ -0,0 +1,3 @@
+instance creation
+new: anInt
+^((super new: anInt) atAllPut: {Float infinity. nil} )initialize
View
4 Math-KDTree/Math-KDTree.package/NNStore.class/class/new.st
@@ -0,0 +1,4 @@
+instance creation
+new
+"a NNStore of size 0 can lead to errors that are probably unnecessary to catch"
+^self new: 1
View
5 Math-KDTree/Math-KDTree.package/NNStore.class/class/newFrom..st
@@ -0,0 +1,5 @@
+instance creation
+newFrom: aCollectionWithSortingIndex
+"example:
+( NNStore newFrom:#(#(3 1.0) #(0 '2')) ) data. #('2' 1.0)"
+^((super newFrom: aCollectionWithSortingIndex )freeIndex: aCollectionWithSortingIndex size +1)sort
View
5 Math-KDTree/Math-KDTree.package/NNStore.class/class/withAll..st
@@ -0,0 +1,5 @@
+instance creation
+withAll: aCollection
+"this is the peferable form of instance creation for subclasses since freeIndex is correctly initialized this way. then 'sortFor:' must be overwritten and called at least once (an example is StupidNN). the other possibility is to use 'new:' and to fill NNStore subclass with 'add:' . the advantage is, that NNStore has not to be filled completely this way and the sorting logic can be applied outside of the subclass.
+you cant enter the sorting index with this method. if you want to do that, use 'newFrom:' instead"
+^(super withAll: (aCollection collect: [:coll| {nil. coll}]))freeIndex: aCollection size +1
View
6 Math-KDTree/Math-KDTree.package/NNStore.class/instance/add..st
@@ -0,0 +1,6 @@
+adding
+add: distAndNeighbour
+"if NNStore is full, further data will be added at the last position and the last data will be overwrittten"
+ self at: (self isFull ifTrue: [ self size ] ifFalse: [ freeIndex ]) put: distAndNeighbour.
+ freeIndex := freeIndex + 1.
+ self isFull ifTrue: [ self sort ].
View
4 Math-KDTree/Math-KDTree.package/NNStore.class/instance/completeData.st
@@ -0,0 +1,4 @@
+accessing
+completeData
+"return the sorted data with distance (at first place)"
+^self isFull ifTrue: [self] ifFalse: [(self copyFrom: 1 to: freeIndex -1)sort: [:a :b| a first < b first ] ] .
View
3  Math-KDTree/Math-KDTree.package/NNStore.class/instance/copyEmpty.st
@@ -0,0 +1,3 @@
+copying
+copyEmpty
+ ^ self species new: (self size min: (freeIndex -1 max: 1))
View
4 Math-KDTree/Math-KDTree.package/NNStore.class/instance/data.st
@@ -0,0 +1,4 @@
+accessing
+data
+"return the sorted data"
+^self completeData collect: [:e|e at:2] as:Array
View
4 Math-KDTree/Math-KDTree.package/NNStore.class/instance/freeIndex..st
@@ -0,0 +1,4 @@
+accessing
+freeIndex: anInt
+"method is necessary for subclass initialization (see withAll:)"
+freeIndex :=anInt .
View
4 Math-KDTree/Math-KDTree.package/NNStore.class/instance/initialize.st
@@ -0,0 +1,4 @@
+initialize-release
+initialize
+freeIndex :=1.
+maxDistance :=Float infinity .
View
3  Math-KDTree/Math-KDTree.package/NNStore.class/instance/isEmpty.st
@@ -0,0 +1,3 @@
+testing
+isEmpty
+^freeIndex =1
View
3  Math-KDTree/Math-KDTree.package/NNStore.class/instance/isFull.st
@@ -0,0 +1,3 @@
+testing
+isFull
+^freeIndex >self size
View
4 Math-KDTree/Math-KDTree.package/NNStore.class/instance/maxDistance.st
@@ -0,0 +1,4 @@
+accessing
+maxDistance
+"the maximum sorting index, if NNStore is full, if not then Infinity"
+^maxDistance
View
4 Math-KDTree/Math-KDTree.package/NNStore.class/instance/sort.st
@@ -0,0 +1,4 @@
+sorting
+sort
+self sort: [:a :b| a first < b first ] .
+maxDistance := self last first
View
6 Math-KDTree/Math-KDTree.package/NNStore.class/instance/sortFor..st
@@ -0,0 +1,6 @@
+sorting
+sortFor: whatever
+"should be overwritten by subclasses"
+
+"self do:[:e|e at: 1 put: somethingDependingOnWhatever ]."
+self sort .
View
17 Math-KDTree/Math-KDTree.package/NNStore.class/properties.json
@@ -0,0 +1,17 @@
+{
+ "category" : "Math-KDTree",
+ "classinstvars" : [
+ ],
+ "classtraitcomposition" : "{}",
+ "classvars" : [
+ ],
+ "commentStamp" : "WernerKassens 5/5/2011 14:40",
+ "instvars" : [
+ "freeIndex",
+ "maxDistance" ],
+ "name" : "NNStore",
+ "pools" : [
+ ],
+ "super" : "Array",
+ "traitcomposition" : "{}",
+ "type" : "variable" }
View
1  Math-KDTree/Math-KDTree.package/StupidNN.class/README.md
@@ -0,0 +1 @@
+StupidNN is a naive nearest neighbour search. KDTree is faster though if you have to do several searches.
View
9 Math-KDTree/Math-KDTree.package/StupidNN.class/instance/nnSearch.i..st
@@ -0,0 +1,9 @@
+evaluating
+nnSearch: aCollection i:anInt
+"search for i nearest neighbours of vector aCollection "
+|d|
+self sortFor: aCollection .
+d :=self data .
+anInt =1 ifTrue:[^d first ].
+^d size >anInt ifTrue: [d copyFrom: 1 to: anInt]ifFalse: [d]
+
View
6 Math-KDTree/Math-KDTree.package/StupidNN.class/instance/sortFor..st
@@ -0,0 +1,6 @@
+sorting
+sortFor: aCollection
+"sort nearest neighbours of aCollection "
+|i|
+self do:[:e| i :=aCollection -(e at:2) . e at: 1 put: (i*i)sum ].
+self sort .
View
16 Math-KDTree/Math-KDTree.package/StupidNN.class/properties.json
@@ -0,0 +1,16 @@
+{
+ "category" : "Math-KDTree",
+ "classinstvars" : [
+ ],
+ "classtraitcomposition" : "{}",
+ "classvars" : [
+ ],
+ "commentStamp" : "WernerKassens 5/5/2011 16:32",
+ "instvars" : [
+ ],
+ "name" : "StupidNN",
+ "pools" : [
+ ],
+ "super" : "NNStore",
+ "traitcomposition" : "{}",
+ "type" : "variable" }
View
1  Math-KDTree/Math-KDTree.package/monticello.meta/categories.st
@@ -0,0 +1 @@
+SystemOrganization addCategory: #'Math-KDTree'!
View
0  Math-KDTree/Math-KDTree.package/monticello.meta/initializers.st
No changes.
View
1  Math-KDTree/Math-KDTree.package/monticello.meta/package
@@ -0,0 +1 @@
+(name 'Math-KDTree')
View
1  Math-KDTree/Math-KDTree.package/monticello.meta/version
@@ -0,0 +1 @@
+(name 'Math-KDTree-wernerkassens.6' message 'empty log message' id '2c4ff847-82f6-4c0e-89c5-0da2acc4182b' date '13 May 2012' time '1:18:33.479 am' author 'wernerkassens' ancestors ((name 'Math-KDTree-wernerkassens.5' message 'another try to get it into the correct directory' id 'f9fee45f-17f3-4d08-a9b2-7fbbe0b36d37' date '12 May 2012' time '2:44:14.334 pm' author 'wernerkassens' ancestors ((name 'Math-KDTree-wernerkassens.4' message 'just a try to get thing into the right directory' id 'b0c7bf2b-b733-42bc-a1db-e0887e6ef4e0' date '12 May 2012' time '2:30:53.73 pm' author 'wernerkassens' ancestors ((name 'Math-KDTree-wk.3' message 'empty log message' id 'dc1e159b-d47a-4198-ac6a-0fd73f622b33' date '11 May 2012' time '3:16:47 pm' author 'wk' ancestors ((name 'Math-KDTree-wk.2' message 'metod categories corrected' id 'b09cb2ef-ffa6-49c8-8924-c717e8946fff' date '11 May 2012' time '2:53:04 pm' author 'wk' ancestors ((name 'Math-KDTree-wernerkassens.1' message 'renamed package' id 'fa8f16c0-29fd-4675-8848-7b1d437f257e' date '11 May 2012' time '1:03:54.189 pm' author 'wernerkassens' ancestors () stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())
View
2  Math-KDTree/Math-KDTree.package/properties.json
@@ -0,0 +1,2 @@
+{
+ }
View
BIN  Math-KDTree/NNPlot.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
1  Math-KDTree/README.md
@@ -0,0 +1 @@
+A kd-tree is a data structure to store multidimensional points in such a way, that it is easy and fast to *repeatedly* find nearest neighbours.
Something went wrong with that request. Please try again.