starting PreferenceMatrixFactoryTest

This commit is contained in:
frankknoll
2023-11-16 12:01:56 +01:00
parent da6e356e11
commit 4c7da48bf9
5 changed files with 43 additions and 1 deletions

1
.gitignore vendored
View File

@@ -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__

View File

@@ -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

View File

@@ -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

View File

@@ -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]
]))