Skip to content

Commit

Permalink
changed "minimum" to "infimum" in betweenness
Browse files Browse the repository at this point in the history
reflects the fact that we actually compute the infimum rather than the
minimum across all alpha-cuts; for backwards-compatibility, also
"minimum" is still accepted
  • Loading branch information
Lucas Bechberger committed Jan 20, 2022
1 parent 5d0c5e8 commit 866b7a9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 37 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Version 1.2.0: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1200230.svg)]

Version 1.3.0: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4312823.svg)](https://doi.org/10.5281/zenodo.4312823) [Release](https://github.com/lbechberger/ConceptualSpaces/releases/tag/v1.3.0)

Version 1.3.1: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5667490.svg)](https://doi.org/10.5281/zenodo.5667490) [Release](https://github.com/lbechberger/ConceptualSpaces/releases/tag/v1.3.1)

This repository contains a thorough implementation of the conceptual spaces framework.

Relevant publications about this implementation and its underlying mathematical formalization include:
Expand Down Expand Up @@ -167,11 +165,11 @@ banana.between(granny_smith, pear)
0.43811732667337056
granny_smith.between(lemon, orange)
0.8789129336237107
apple.between(lemon, orange, method='minimum')
apple.between(lemon, orange, method='infimum')
0.0
banana.between(granny_smith, pear, method='minimum')
banana.between(granny_smith, pear, method='infimum')
0.0
granny_smith.between(lemon, orange, method='minimum')
granny_smith.between(lemon, orange, method='infimum')
0.82471568013506558
```

Expand Down
10 changes: 5 additions & 5 deletions conceptual_spaces/cs/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ def similarity_to(self, other, method="Jaccard"):
else:
raise Exception("Unknown method")

def _between_min(self, first, second):
"""Helper function for the minimum-based betweenness."""
def _between_inf(self, first, second):
"""Helper function for the infimum-based betweenness."""

# if self._mu is greater than any of first and second, the result is automatically zero
if self._mu > first._mu or self._mu > second._mu:
Expand Down Expand Up @@ -699,7 +699,7 @@ def between(self, first, second, method="integral", num_alpha_cuts = 20):
"""Computes the degree to which this concept is between the other two given concepts.
The following methods are avaliable:
'minimum': minimum over all alpha-cuts
'infimum': infimum over all alpha-cuts (for backwards compatibility, also accepts 'minimum')
'integral': coarse approximation of the integral over all alpha-cuts
"""

Expand All @@ -715,8 +715,8 @@ def between(self, first, second, method="integral", num_alpha_cuts = 20):
if not (dom in second._core._domains and second._core._domains[dom] == dims):
return 0.0

if method == "minimum":
return max(self._between_min(first, second), self._between_min(second, first))
if method == "infimum" or method == "minimum":
return max(self._between_inf(first, second), self._between_inf(second, first))

elif method == "integral":
return max(self._between_integral(first, second, num_alpha_cuts), self._between_integral(second, first, num_alpha_cuts))
Expand Down
6 changes: 3 additions & 3 deletions conceptual_spaces/demo/fruit_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ def wait_for_user():
print(" 0.43811732667337056")
print(" granny_smith.between(lemon, orange)")
print(" 0.8789129336237107")
print(" apple.between(lemon, orange, method='minimum')")
print(" apple.between(lemon, orange, method='infimum')")
print(" 0.0")
print(" banana.between(granny_smith, pear, method='minimum')")
print(" banana.between(granny_smith, pear, method='infimum')")
print(" 0.0")
print(" granny_smith.between(lemon, orange, method='minimum')")
print(" granny_smith.between(lemon, orange, method='infimum')")
print(" 0.82471568013506558")
wait_for_user()

Expand Down
48 changes: 24 additions & 24 deletions conceptual_spaces/test/concept_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,8 +1399,8 @@ def test_similarity_subset_combined_space_properties(self):

# between()

# 'minimum'
def test_between_minimum(self):
# 'infimum'
def test_between_infimum(self):
doms = {0:[0],1:[1,2]}
cs.init(3, doms)
c1 = Cuboid([0.00,0.00,0.00],[0.40,0.40,0.40], doms)
Expand All @@ -1421,15 +1421,15 @@ def test_between_minimum(self):
f4 = Concept(s4, 1.0, 1.0, w)
f5 = Concept(s5, 1.0, 1.0, w)

self.assertAlmostEqual(f1.between(f1, f1, method="minimum"), 1.0, places=4)
self.assertAlmostEqual(f3.between(f1, f2, method="minimum"), 1.0, places=4)
self.assertAlmostEqual(f3.between(f2, f1, method="minimum"), 1.0, places=4)
self.assertAlmostEqual(f4.between(f1, f2, method="minimum"), 1.0, places=4)
self.assertAlmostEqual(f4.between(f2, f1, method="minimum"), 1.0, places=4)
self.assertAlmostEqual(f5.between(f1, f2, method="minimum"), 0.33831631165095066, places=4)
self.assertAlmostEqual(f5.between(f2, f1, method="minimum"), 0.33831631165095066, places=4)
self.assertAlmostEqual(f1.between(f1, f1, method="infimum"), 1.0, places=4)
self.assertAlmostEqual(f3.between(f1, f2, method="infimum"), 1.0, places=4)
self.assertAlmostEqual(f3.between(f2, f1, method="infimum"), 1.0, places=4)
self.assertAlmostEqual(f4.between(f1, f2, method="infimum"), 1.0, places=4)
self.assertAlmostEqual(f4.between(f2, f1, method="infimum"), 1.0, places=4)
self.assertAlmostEqual(f5.between(f1, f2, method="infimum"), 0.33831631165095066, places=4)
self.assertAlmostEqual(f5.between(f2, f1, method="infimum"), 0.33831631165095066, places=4)

def test_between_minimum_fruit(self):
def test_between_infimum_fruit(self):
domains = {"color":[0], "shape":[1], "taste":[2]}
dimension_names = ["hue", "round", "sweet"]
cs.init(3, domains, dimension_names)
Expand All @@ -1454,16 +1454,16 @@ def test_between_minimum_fruit(self):
w_banana = Weights({"color":0.75, "shape":1.50, "taste":0.75}, w_dim)
banana = Concept(s_banana, 1.0, 10.0, w_banana)

self.assertAlmostEqual(banana.between(apple, orange, method='minimum'), 0.0, places=4)
self.assertAlmostEqual(banana.between(orange, apple, method='minimum'), 0.0, places=4)
self.assertAlmostEqual(orange.between(apple, banana, method='minimum'), 0.7045928116960077, places=4)
self.assertAlmostEqual(orange.between(banana, apple, method='minimum'), 0.7045928116960077, places=4)
self.assertAlmostEqual(apple.between(orange, banana, method='minimum'), 0.0, places=4)
self.assertAlmostEqual(apple.between(banana, orange, method='minimum'), 0.0, places=4)
self.assertAlmostEqual(apple.between(apple, banana, method='minimum'), 1.0, places=4)
self.assertAlmostEqual(apple.between(orange, apple, method='minimum'), 1.0, places=4)
self.assertAlmostEqual(banana.between(apple, orange, method='infimum'), 0.0, places=4)
self.assertAlmostEqual(banana.between(orange, apple, method='infimum'), 0.0, places=4)
self.assertAlmostEqual(orange.between(apple, banana, method='infimum'), 0.7045928116960077, places=4)
self.assertAlmostEqual(orange.between(banana, apple, method='infimum'), 0.7045928116960077, places=4)
self.assertAlmostEqual(apple.between(orange, banana, method='infimum'), 0.0, places=4)
self.assertAlmostEqual(apple.between(banana, orange, method='infimum'), 0.0, places=4)
self.assertAlmostEqual(apple.between(apple, banana, method='infimum'), 1.0, places=4)
self.assertAlmostEqual(apple.between(orange, apple, method='infimum'), 1.0, places=4)

def test_between_minimum_banana(self):
def test_between_infimum_banana(self):
domains = {"color":[0], "shape":[1], "taste":[2]}
dimension_names = ["hue", "round", "sweet"]
cs.init(3, domains, dimension_names)
Expand All @@ -1486,11 +1486,11 @@ def test_between_minimum_banana(self):
w_banana = Weights({"color":0.75, "shape":1.50, "taste":0.75}, w_dim)
banana = Concept(s_banana, 1.0, 20.0, w_banana)

self.assertAlmostEqual(banana.between(pear, granny_smith, method='minimum'), 0.0, places=4)
self.assertAlmostEqual(banana.between(granny_smith, pear, method='minimum'), 0.0, places=4)
self.assertAlmostEqual(banana.between(pear, granny_smith, method='infimum'), 0.0, places=4)
self.assertAlmostEqual(banana.between(granny_smith, pear, method='infimum'), 0.0, places=4)


def test_between_minimum_pathological(self):
def test_between_infimum_pathological(self):
domains = {0:[0]}
cs.init(1, domains)

Expand All @@ -1509,8 +1509,8 @@ def test_between_minimum_pathological(self):
f3 = Concept(s2, 1.0, 10.0, w)
f4 = Concept(s2, 0.9, 1.0, w)

self.assertAlmostEqual(f3.between(f2, f1, method='minimum'), 0.0, places=4)
self.assertAlmostEqual(f4.between(f2, f1, method='minimum'), 0.0, places=4)
self.assertAlmostEqual(f3.between(f2, f1, method='infimum'), 0.0, places=4)
self.assertAlmostEqual(f4.between(f2, f1, method='infimum'), 0.0, places=4)

# 'integral'
def test_between_integral(self):
Expand Down

0 comments on commit 866b7a9

Please sign in to comment.