-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.py
More file actions
31 lines (24 loc) · 737 Bytes
/
Node.py
File metadata and controls
31 lines (24 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
class Node:
"""
Contains self.vector with random normalised values.
"""
def __init__(self, x, y, length):
self.x = x
self.y = y
self.vector = np.random.rand(length)
def dist(self, vector):
return np.linalg.norm(self.vector - vector)
def similarity(self, vector):
return 1/ self.dist(vector)
# TESTING
def similarityTest(self):
a = Node(0, 0, 5)
b = Node(0, 0, 5)
a.vector = np.array([0, 1])
b.vector = np.array([0, 6])
assert(a.similarity(b) == 5)
def __str__(self):
return "({},{}): {}".format(self.x, self.y, self.vector.__str__())
def __repr__(self):
return self.__str__()