Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ce230db
Class Point / K-means algorithm
May 5, 2021
0b33eac
number of clusters in parameters / test on datasets
May 6, 2021
8b89af6
radon cc in k_means_init / pylinting
May 11, 2021
4c7d872
Default constructor, addition between two points, multiplication by s…
May 25, 2021
ee14622
parrallel optimization in k_means_init
May 25, 2021
057457c
fix: init instead of from_seq
May 26, 2021
87000f9
Division of a point
May 26, 2021
0d9b023
parallel optimization, assign_cluster and update_cluster
May 26, 2021
da4a4d6
pylinting, typing
May 27, 2021
9f1e0fc
FIX: bad list initialization parallel list
May 27, 2021
a8d0385
Changing sample type from custom type "Point" to Tuple
Ak-iu May 27, 2021
63f5991
Merge remote-tracking branch 'origin/master'
Ak-iu May 27, 2021
c617aad
Add point_interface and changing the class Point to Point_2D
Ak-iu May 28, 2021
1ca4503
Merge remote-tracking branch 'origin/master'
Ak-iu May 28, 2021
ff39d0b
FIX: input_list type form Tuple to Point_2D
Ak-iu May 28, 2021
32f557e
Add class point_3D.py
Ak-iu May 28, 2021
7e6966d
rand_point_2D_list / rand_point_3D_list
Ak-iu May 28, 2021
9b147eb
Point_3D update
Ak-iu May 28, 2021
5b89f49
Typing Point_2D -> Point_Interface
Ak-iu May 28, 2021
eb792d5
optimization update_centroids
May 28, 2021
a9327a7
Merge remote-tracking branch 'origin/master'
May 28, 2021
f921c83
Merge remote-tracking branch 'clement/master'
May 28, 2021
467b33b
refactoring because of new point implementation
May 28, 2021
8c2cf82
use of parallelism random choice first centroid
May 31, 2021
27a5039
add point dimensions in k-means-main's options
Jun 1, 2021
84f2daa
interface convention
Jun 2, 2021
82b7a7d
parallel optimization update_centroids
Jun 4, 2021
08a4dd6
adding option to show clusters graph of 2D points
Jun 4, 2021
f6f46cd
k-means clustering documentation
Jun 7, 2021
42c7506
3d representation for Point_3D clusters
Ak-iu Jun 8, 2021
810c54b
error subtraction in distance
Jun 8, 2021
5cba1e9
adding colors 3D graph result, fix warning matplotlib
Jun 8, 2021
eb16d4c
adding Point Interface section
Jun 8, 2021
529498e
change show-clusters display message
Jun 8, 2021
04d1037
dot_product documentation
Jun 9, 2021
6c8eed9
adding for each example how to run it
Jun 9, 2021
c73d1f3
fft documentation, how to run in parallel
Jun 10, 2021
fad0ab3
last examples documentation functions
Jun 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 160 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,161 @@
PySke API
=========
#########

PySke API offer applications implemented with list and tree skeletons.
The user can use the sequential or parallel version.
The parallel version allows a faster execution time when its launched on several processors, cores or computers.

Run examples with parallel computing:

.. code-block:: console

mpirun -np NB_CORES python3 PROGRAM_NAME [OPTIONS]

Examples without :code:`--data` option are only runnable in parallel.

List Examples
=============

Dot Product
-----------

.. py:module:: pyske.examples.list.dot_product


Dot Product functions
^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: opt_dot_product

.. autofunction:: dot_product

Running Example
^^^^^^^^^^^^^^^

.. autoprogram:: pyske.examples.list.util:dot_product_parser()
:prog: dot_product_main.py


Discrete Fast Fourier Transform
-------------------------------
.. py:module:: pyske.examples.list.fft

Fast Fourier Transform function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: fft

Running Example
^^^^^^^^^^^^^^^

.. autoprogram:: pyske.examples.list.util:standard_parser(data_arg=False)
:prog: fft_main.py


K-means Clustering
------------------

K-means clustering is an unsupervised algorithm that aims to partition group of points in k clusters.

K-means function
^^^^^^^^^^^^^^^^

.. py:module:: pyske.examples.list.k_means

.. autofunction:: k_means

Initialization functions
^^^^^^^^^^^^^^^^^^^^^^^^

This is the standard method that initializes the centroids. This method chooses the centroids in order that each point is as far as possible from the other.

.. autofunction:: k_means_init


Point Interface
^^^^^^^^^^^^^^^

K-means algorithm takes a list of points in parameters. For now two versions implement this class, one for 2 dimension points and another for 3 dimension points.

Point 2D class implementation:

.. autoclass:: pyske.core.util.point_2D.Point_2D
:members:
:special-members:
:member-order: bysource

Running Example
^^^^^^^^^^^^^^^

.. autoprogram:: pyske.examples.list.util:k_means_parser()
:prog: k_means_main.py


Maximum Prefix Sum
------------------

.. py:module:: pyske.examples.list.maximum_prefix_sum

Maximum Prefix Sum function
^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: mps

Running Example
^^^^^^^^^^^^^^^

.. autoprogram:: pyske.examples.list.util:standard_parser()
:prog: maximum_prefix_sum_main.py

Maximum Segment Sum
-------------------

Running Example
^^^^^^^^^^^^^^^

.. autoprogram:: pyske.examples.list.util:standard_parser()
:prog: maximum_segment_sum_main.py

Parallel Regular Sampling Sort
------------------------------

.. py:module:: pyske.examples.list.regular_sampling_sort


Broadcast function
^^^^^^^^^^^^^^^^^^

.. autofunction:: bcast

Sort function
^^^^^^^^^^^^^

.. autofunction:: pssr


Running Example
^^^^^^^^^^^^^^^

.. autoprogram:: pyske.examples.list.util:standard_parser()
:prog: regular_sampling_sort_main.py

Variance Example
----------------

.. py:module:: pyske.examples.list.variance

Variance function
^^^^^^^^^^^^^^^^^

.. autofunction:: variance

Running Example
^^^^^^^^^^^^^^^

.. autoprogram:: pyske.examples.list.util:standard_parser()
:prog: variance_main.py


Tree Examples
=============

10 changes: 6 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import os
import sys
sys.path.insert(0, os.path.abspath('../'))


# -- Project information -----------------------------------------------------
Expand All @@ -31,6 +31,8 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinxcontrib.autoprogram"
]

# Add any paths that contain templates here, relative to this directory.
Expand All @@ -52,4 +54,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ['_static']
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Welcome to PySke's documentation!
=================================

.. toctree::
:maxdepth: 2
:maxdepth: 3
:caption: Contents:

intro
Expand Down
91 changes: 91 additions & 0 deletions pyske/core/util/point_2D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""
A module to represent a 2D point
"""

from math import sqrt
from pyske.core.util.point_Interface import Point_Interface


class Point_2D(Point_Interface):
"""A class to represent a 2D point"""

def __init__(self, x=0, y=0):
self.__x = x
self.__y = y

def __repr__(self):
return "(%s, %s)" % (self.__x, self.__y)

def __eq__(self, other):
"""
Equality between two points
"""
if isinstance(other, Point_2D):
return self.__x == other.__x and self.__y == other.__y
return False

def __add__(self, other):
"""
Addition of two points

Examples::

>>> p1 = Point_2D(5,5)
>>> p2 = Point_2D(5,7)
>>> p1 + p2
(10, 12)
"""
if isinstance(other, Point_2D):
return Point_2D(self.x + other.x, self.y + other.y)

def __mul__(self, other):
"""
Multiplication by a point or a scalar

Examples::

>>> p1 = Point_2D(5,5)
>>> p2 = Point_2D(5,7)
>>> p1 * 5
(25, 25)
>>> p1 * p2
(25, 35)
"""
if isinstance(other, Point_2D):
return Point_2D(self.x * other.x, self.y * other.y)
if isinstance(other, int) or isinstance(other, float):
return Point_2D(self.x * other, self.y * other)

def __truediv__(self, other):
if isinstance(other, int):
return Point_2D(self.x / other, self.y / other)

@property
def x(self):
"""X getter"""
return self.__x

@property
def y(self):
"""Y getter"""
return self.__y

def distance(self, other: 'Point_2D'):
"""
Returns the distance from another point.

Examples::

>>> from pyske.core.util.point_2D import Point_2D
>>> p1 = Point_2D(5,5)
>>> p2 = Point_2D(5,7)
>>> p1.distance(p2)
2.0

:param other: a point
:return: distance from other point

"""
dx = self.__x - other.x
dy = self.__y - other.y
return sqrt(dx ** 2 + dy ** 2)
95 changes: 95 additions & 0 deletions pyske/core/util/point_3D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""
A module to represent a 3D point
"""

from math import sqrt
from pyske.core.util.point_Interface import Point_Interface


class Point_3D(Point_Interface):
"""A class to represent a 3D point"""

def __init__(self, x=0, y=0, z=0):
self.__x = x
self.__y = y
self.__z = z

def __repr__(self):
return "(%s, %s, %s)" % (self.__x, self.__y, self.__z)

def __eq__(self, other):
if isinstance(other, Point_3D):
return self.__x == other.__x and self.__y == other.__y and self.__z == other.__z
return False

def __add__(self, other):
"""
Addition of two points

Examples::

>>> p1 = Point_3D(5,5,2)
>>> p2 = Point_3D(5,7,1)
>>> p1 + p2
(10, 12, 3)
"""
if isinstance(other, Point_3D):
return Point_3D(self.x + other.x, self.y + other.y, self.z + other.z)

def __mul__(self, other):
"""
Multiplication by a point or a scalar

Examples::

>>> p1 = Point_3D(5,5,2)
>>> p2 = Point_3D(5,7,1)
>>> p1 * 5
(25, 25, 10)
>>> p1 * p2
(25, 35, 2)
"""
if isinstance(other, Point_3D):
return Point_3D(self.x * other.x, self.y * other.y, self.z * other.z)
if isinstance(other, int) or isinstance(other, float):
return Point_3D(self.x * other, self.y * other, self.z * other.z)

def __truediv__(self, other):
if isinstance(other, int):
return Point_3D(self.x / other, self.y / other, self.z / other)

@property
def x(self):
"""X getter"""
return self.__x

@property
def y(self):
"""Y getter"""
return self.__y

@property
def z(self):
"""Z getter"""
return self.__z

def distance(self, other):
"""
Returns the distance from another 3D point.

Examples::

>>> from pyske.core.util.point_2D import Point_2D
>>> p1 = Point_3D(5,5,2)
>>> p2 = Point_3D(5,7,1)
>>> p1.distance(p2)
2.24

:param other: a point
:return: distance from other point

"""
dx = self.__x - other.x
dy = self.__y - other.y
dz = self.__z - other.z
return sqrt(dx ** 2 + dy ** 2 + dz ** 2)
Loading