This is an automated email from the ASF dual-hosted git repository.

mboehm7 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new 889db1fe42 [SYSTEMDS-3701] New Python API for multimodal data 
alignment (scuro)
889db1fe42 is described below

commit 889db1fe422976152705b14f0caf74494abd98dd
Author: Christina Dionysio <[email protected]>
AuthorDate: Mon Jun 3 09:42:24 2024 +0200

    [SYSTEMDS-3701] New Python API for multimodal data alignment (scuro)
    
    Closes #2023.
---
 src/main/python/systemds/__init__.py               |  3 +-
 src/main/python/systemds/{ => scuro}/__init__.py   |  6 ---
 .../systemds/{ => scuro/aligner}/__init__.py       |  6 ---
 .../python/systemds/scuro/aligner/alignment.py     | 45 ++++++++++++++++++++++
 .../aligner/alignment_strategy.py}                 | 22 +++++++++--
 .../aligner/similarity_measures.py}                | 16 ++++++--
 .../python/systemds/{__init__.py => scuro/main.py} | 21 ++++++++--
 .../systemds/{ => scuro/modality}/__init__.py      |  6 ---
 .../modality/aligned_modality.py}                  | 15 ++++++--
 .../{__init__.py => scuro/modality/modality.py}    | 22 +++++++++--
 .../modality/representation.py}                    | 16 +++++---
 .../modality/video_modality.py}                    | 31 +++++++++++++--
 12 files changed, 160 insertions(+), 49 deletions(-)

diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/__init__.py
index 27d7425566..e0f485df79 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/__init__.py
@@ -22,5 +22,6 @@
 from systemds import context
 from systemds import operator
 from systemds import examples
+from systemds import scuro
 
-__all__ = ["context", "operator", "examples"]
+__all__ = ["context", "operator", "examples", "scuro"]
diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/scuro/__init__.py
similarity index 87%
copy from src/main/python/systemds/__init__.py
copy to src/main/python/systemds/scuro/__init__.py
index 27d7425566..e66abb4646 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/scuro/__init__.py
@@ -18,9 +18,3 @@
 # under the License.
 #
 # -------------------------------------------------------------
-
-from systemds import context
-from systemds import operator
-from systemds import examples
-
-__all__ = ["context", "operator", "examples"]
diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/scuro/aligner/__init__.py
similarity index 87%
copy from src/main/python/systemds/__init__.py
copy to src/main/python/systemds/scuro/aligner/__init__.py
index 27d7425566..e66abb4646 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/scuro/aligner/__init__.py
@@ -18,9 +18,3 @@
 # under the License.
 #
 # -------------------------------------------------------------
-
-from systemds import context
-from systemds import operator
-from systemds import examples
-
-__all__ = ["context", "operator", "examples"]
diff --git a/src/main/python/systemds/scuro/aligner/alignment.py 
b/src/main/python/systemds/scuro/aligner/alignment.py
new file mode 100644
index 0000000000..0e89cdf9e8
--- /dev/null
+++ b/src/main/python/systemds/scuro/aligner/alignment.py
@@ -0,0 +1,45 @@
+# -------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# -------------------------------------------------------------
+from aligner.alignment_strategy import AlignmentStrategy
+from modality.aligned_modality import AlignedModality
+from modality.modality import Modality
+from modality.representation import Representation
+from aligner.similarity_measures import Measure
+
+
+class Alignment:
+    def __init__(self, modality_a: Modality, modality_b: Modality, strategy: 
AlignmentStrategy,
+                 similarity_measure: Measure):
+        """
+        Defines the core of the library where the alignment of two modalities 
is performed
+        :param modality_a: first modality
+        :param modality_b: second modality
+        :param strategy: the alignment strategy used in the alignment process
+        :param similarity_measure: the similarity measure used to check the 
score of the alignment
+        """
+        self.modality_a = modality_a
+        self.modality_b = modality_b
+        self.strategy = strategy
+        self.similarity_measure = similarity_measure
+    
+    def align_modalities(self) -> Modality:
+        return AlignedModality(Representation())
+    
\ No newline at end of file
diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/scuro/aligner/alignment_strategy.py
similarity index 65%
copy from src/main/python/systemds/__init__.py
copy to src/main/python/systemds/scuro/aligner/alignment_strategy.py
index 27d7425566..70d88ee8a8 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/scuro/aligner/alignment_strategy.py
@@ -18,9 +18,23 @@
 # under the License.
 #
 # -------------------------------------------------------------
+from aligner.similarity_measures import Measure
 
-from systemds import context
-from systemds import operator
-from systemds import examples
 
-__all__ = ["context", "operator", "examples"]
+class AlignmentStrategy:
+    def __init__(self):
+        pass
+    
+    def align_chunk(self, chunk_a, chunk_b, similarity_measure: Measure):
+        raise 'Not implemented error'
+
+
+class ChunkedCrossCorrelation(AlignmentStrategy):
+    def __init__(self):
+        super().__init__()
+    
+    def align_chunk(self, chunk_a, chunk_b, similarity_measure: Measure):
+        raise 'Not implemented error'
+
+    
+# TODO: Add additional alignment methods
diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/scuro/aligner/similarity_measures.py
similarity index 85%
copy from src/main/python/systemds/__init__.py
copy to src/main/python/systemds/scuro/aligner/similarity_measures.py
index 27d7425566..31f8ed50c1 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/scuro/aligner/similarity_measures.py
@@ -18,9 +18,17 @@
 # under the License.
 #
 # -------------------------------------------------------------
+class Measure:
+    pass
 
-from systemds import context
-from systemds import operator
-from systemds import examples
 
-__all__ = ["context", "operator", "examples"]
+class EuclideanDistance(Measure):
+    pass
+
+
+class CosineSimilarity(Measure):
+    pass
+
+
+class PearsonCorrelation(Measure):
+    pass
diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/scuro/main.py
similarity index 52%
copy from src/main/python/systemds/__init__.py
copy to src/main/python/systemds/scuro/main.py
index 27d7425566..9a6349568c 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/scuro/main.py
@@ -18,9 +18,22 @@
 # under the License.
 #
 # -------------------------------------------------------------
+from aligner.alignment import Alignment
+from aligner.alignment_strategy import ChunkedCrossCorrelation
+from modality.representation import PixelRepresentation
+from modality.video_modality import VideoModality
+from aligner.similarity_measures import CosineSimilarity
 
-from systemds import context
-from systemds import operator
-from systemds import examples
+# Setup modalities
+file_path_a = ''
+file_path_b = ''
+representation_a = PixelRepresentation()  # Concrete Representation
+representation_b = PixelRepresentation()  # Concrete Representation
+modality_a = VideoModality(file_path_a, representation_a)
+modality_b = VideoModality(file_path_b, representation_b)
 
-__all__ = ["context", "operator", "examples"]
+# Align modalities
+alignment_strategy = ChunkedCrossCorrelation()  # Concrete Alignment Strategy
+similarity_measure = CosineSimilarity()
+aligner = Alignment(modality_a, modality_b, alignment_strategy, 
similarity_measure)
+aligned_modality = aligner.align_modalities()
diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/scuro/modality/__init__.py
similarity index 87%
copy from src/main/python/systemds/__init__.py
copy to src/main/python/systemds/scuro/modality/__init__.py
index 27d7425566..e66abb4646 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/scuro/modality/__init__.py
@@ -18,9 +18,3 @@
 # under the License.
 #
 # -------------------------------------------------------------
-
-from systemds import context
-from systemds import operator
-from systemds import examples
-
-__all__ = ["context", "operator", "examples"]
diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/scuro/modality/aligned_modality.py
similarity index 64%
copy from src/main/python/systemds/__init__.py
copy to src/main/python/systemds/scuro/modality/aligned_modality.py
index 27d7425566..ef6a102472 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/scuro/modality/aligned_modality.py
@@ -18,9 +18,16 @@
 # under the License.
 #
 # -------------------------------------------------------------
+from modality.modality import Modality
+from modality.representation import Representation
 
-from systemds import context
-from systemds import operator
-from systemds import examples
 
-__all__ = ["context", "operator", "examples"]
+class AlignedModality(Modality):
+    def __init__(self, representation: Representation):
+        """
+        Defines the modality that is created during the alignment process
+        :param representation: The representation for the aligned modality
+                              (made up of the #columns from the modalities 
that are being aligned)
+        """
+        super().__init__(representation)
+    
\ No newline at end of file
diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/scuro/modality/modality.py
similarity index 57%
copy from src/main/python/systemds/__init__.py
copy to src/main/python/systemds/scuro/modality/modality.py
index 27d7425566..d82ac3e989 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/scuro/modality/modality.py
@@ -19,8 +19,22 @@
 #
 # -------------------------------------------------------------
 
-from systemds import context
-from systemds import operator
-from systemds import examples
+from modality.representation import Representation
 
-__all__ = ["context", "operator", "examples"]
+
+class Modality:
+    
+    def __init__(self, representation: Representation, start_index: int = 0):
+        """
+        Defines the modality that is to be aligned
+        :param representation: Specifies how the data should be represented 
for a specific modality
+        :param start_index: Defines the first index used for the alignment
+        """
+        self.representation = representation
+        self.start_index = start_index
+    
+    def read_chunk(self):
+        """
+        Extracts a data chunk of the modality according to the window size 
specified in params
+        """
+        raise NotImplementedError
diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/scuro/modality/representation.py
similarity index 84%
copy from src/main/python/systemds/__init__.py
copy to src/main/python/systemds/scuro/modality/representation.py
index 27d7425566..cdf9bf9e93 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/scuro/modality/representation.py
@@ -18,9 +18,13 @@
 # under the License.
 #
 # -------------------------------------------------------------
-
-from systemds import context
-from systemds import operator
-from systemds import examples
-
-__all__ = ["context", "operator", "examples"]
+class Representation:
+    def __init__(self):
+        pass
+    
+    
+class PixelRepresentation(Representation):
+    def __init__(self):
+        super().__init__()
+    
+    
\ No newline at end of file
diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/scuro/modality/video_modality.py
similarity index 50%
copy from src/main/python/systemds/__init__.py
copy to src/main/python/systemds/scuro/modality/video_modality.py
index 27d7425566..04ed24cf7c 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/scuro/modality/video_modality.py
@@ -18,9 +18,32 @@
 # under the License.
 #
 # -------------------------------------------------------------
+import os
 
-from systemds import context
-from systemds import operator
-from systemds import examples
+from modality.modality import Modality
+from modality.representation import Representation
 
-__all__ = ["context", "operator", "examples"]
+
+class VideoModality(Modality):
+    def __init__(self, file_path: str, representation: Representation, 
start_index: int = 0):
+        super().__init__(representation, start_index)
+        self.file_path = file_path
+    
+    def file_sanity_check(self):
+        """
+        Checks if the file can be found is not empty
+        """
+        try:
+            file_size = os.path.getsize(self.file_path)
+        except:
+            raise (f"Error: File {0} not found!".format(self.file_path))
+        
+        if file_size == 0:
+            raise ("File {0} is empty".format(self.file_path))
+    
+    def read_chunk(self):
+        # Read chunk (self.params.window_size)
+        # self.representation.apply_representation()
+        # additional preprocessing?
+        # return numpy array
+        pass

Reply via email to