starting PreferenceMatrixFactoryTest
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ google-chrome-stable_current_amd64*
|
|||||||
src/captcha/__pycache__
|
src/captcha/__pycache__
|
||||||
src/GoogleAnalytics/__pycache__
|
src/GoogleAnalytics/__pycache__
|
||||||
src/SymptomsCausedByVaccines/__pycache__
|
src/SymptomsCausedByVaccines/__pycache__
|
||||||
|
src/SymptomsCausedByVaccines/MultiLineFitting/__pycache__
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
name: howbadismybatch-venv
|
name: howbadismybatch-venv
|
||||||
channels:
|
channels:
|
||||||
- defaults
|
- defaults
|
||||||
# - conda-forge
|
- conda-forge
|
||||||
dependencies:
|
dependencies:
|
||||||
- python=3.9
|
- python=3.9
|
||||||
- ipykernel
|
- ipykernel
|
||||||
- numpy
|
- numpy
|
||||||
- pandas
|
- pandas
|
||||||
- scikit-learn
|
- scikit-learn
|
||||||
|
- scikit-spatial
|
||||||
- urllib3
|
- urllib3
|
||||||
- requests
|
- requests
|
||||||
- bs4
|
- bs4
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import numpy as np
|
||||||
|
from skspatial.objects import Line
|
||||||
|
|
||||||
|
class PreferenceMatrixFactory:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def createPreferenceMatrix(points, lines, consensusThreshold):
|
||||||
|
preferenceMatrix = np.zeros([len(points), len(lines)], dtype = int)
|
||||||
|
for pointIndex, point in enumerate(points):
|
||||||
|
for lineIndex, line in enumerate(lines):
|
||||||
|
preferenceMatrix[pointIndex, lineIndex] = 1 if line.distance_point(point) <= consensusThreshold else 0
|
||||||
|
|
||||||
|
return preferenceMatrix
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import unittest
|
||||||
|
import numpy as np
|
||||||
|
from numpy.testing import assert_array_equal
|
||||||
|
from skspatial.objects import Line
|
||||||
|
from SymptomsCausedByVaccines.MultiLineFitting.PreferenceMatrixFactory import PreferenceMatrixFactory
|
||||||
|
|
||||||
|
|
||||||
|
class PreferenceMatrixFactoryTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_createPreferenceMatrix(self):
|
||||||
|
# Given
|
||||||
|
points = [(1, 3), (10, 20)]
|
||||||
|
lines = [Line.from_points([0, 0], [100, 0])]
|
||||||
|
consensusThreshold = 4.0
|
||||||
|
|
||||||
|
# When
|
||||||
|
preferenceMatrix = PreferenceMatrixFactory.createPreferenceMatrix(points, lines, consensusThreshold)
|
||||||
|
|
||||||
|
# Then
|
||||||
|
assert_array_equal(
|
||||||
|
preferenceMatrix,
|
||||||
|
np.array(
|
||||||
|
[
|
||||||
|
[1],
|
||||||
|
[0]
|
||||||
|
]))
|
||||||
Reference in New Issue
Block a user