OrthogonalFunctions 0.0.29
Generate orthogonal set of functions
Requires Python: >=2.7
Keywords: orthogonal-functions regression sympy computer-algebra gram-schmidt

====================
Orthogonal Functions
====================

.. |image01| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/phi_i_perp.svg
.. |image02| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/phi_i.svg
.. |image03| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/interval.svg
.. |image04| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/w.svg
.. |image05| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/delta.svg
.. |image06| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/i_0.svg
.. |image07| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/n.svg
.. |image08| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/L.svg
.. |image09| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/alpha_i.svg
.. |image10| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/a_ij.svg
.. |image11| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/Equation_phi_i.svg
.. |image12| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/Equation_phi_i_perp.svg
.. |image13| image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/Equation_orthogonality.svg

.. include_after_this_line

A python package to generate a set of orthogonal functions.

* `Anaconda package <https://anaconda.org/s-ameli/orthogonalfunctions>`_
* `PyPi package <https://pypi.org/project/OrthogonalFunctions/>`_
* `Source code <https://github.com/ameli/Orthogonal-Functions>`_
* `Documentation <https://ameli.github.io/Orthogonal-Functions/index.html>`_
* `API <https://ameli.github.io/Orthogonal-Functions/_modules/modules.html>`_

---------------------
Build and Test Status
---------------------

|codecov-devel| 

==============  =======================  ===============
Platform        Python versions          Build status
==============  =======================  ===============
Linux (Ubuntu)  2.7, 3.5, 3.6, 3.7, 3.8  |build-linux|
macOS           2.7, 3.5, 3.6, 3.7, 3.8  |build-macos|
Windows         2.7, 3.5, 3.6, 3.7, 3.8  |build-windows|
==============  =======================  ===============

-----------
Description
-----------

This package generates a set of orthonormal functions, called |image01|, based on the set of non-orthonormal functions |image02| defined by

|image11|

The orthonormalized functions |image01| are the linear combination of the functions |image02| by

|image12|

The functions |image01| are orthonormal in the interval |image03| with respect to the weight function |image04|. That is,

|image13|

where |image05| is the Kronecker delta function. The orthogonal functions are generated by `Gram-Schmidt orthogonalization process <https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process>`__. This script produces the symbolic functions using `Sympy <https://www.sympy.org>`__, a Python computer algebraic package. An application of these orthogonal functions can be found in [Ameli-2020]_.

-------
Install
-------

Install using either of the following three methods.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Install from Anaconda Cloud
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

|conda-version| |conda-platform|

Install using `Anaconda cloud <https://anaconda.org/s-ameli/traceinv>`_ by

::

    conda install -c s-ameli orthogonalfunctions

~~~~~~~~~~~~~~~~~~~~
2. Install from PyPi
~~~~~~~~~~~~~~~~~~~~

|pypi| |pyversions| |format| 

Install using the package available on `PyPi <https://pypi.org/project/OrthogonalFunctions>`__ by

::

  pip install OrtthogonalFunctions

~~~~~~~~~~~~~~~~~~~~~~~~~~~
3. Install from Source Code
~~~~~~~~~~~~~~~~~~~~~~~~~~~

|release| |licence| |implementation|

Install directly from the source code by

::

  git clone https://github.com/ameli/Orthogonal-Functions.git
  cd Orthogonal-Functions
  pip install .

-------
Testing
-------

To test the package, download the source code and use one of the following methods in the directory of the source code:

- *Method 1*: test locally by:

  ::
      
      python setup.py test

- *Method 2*: test in a virtual environment using ``tox``:

  ::

      pip install tox
      tox

-----
Usage
-----

The package can be used in two ways:

~~~~~~~~~~~~~~~~~~~~~
1. Import as a Module
~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

    >>> from OrthogonalFunctions import OrthogonalFunctions
    
    >>> # Create an object
    >>> OF = OrthogonalFunctions()
    
    >>> # Generate Functions
    >>> OF.Process()
    
    >>> # Print Functions
    >>> OF.Print()
    
    >>> # Check mutual orthogonality of Functions
    >>> OF.Check()
    
    >>> # Plot Functions
    >>> OF.Plot()

The ``OrthogonalFunctions`` also accepts some parameters:

.. code-block:: python

    >>> # Specify any or all of the three parameters below
    >>> OF = OrthogonalFunctions(
    ...        StartFunctionIndex=1,
    ...        NumFunctions=9,
    ...        EndInterval=1)
    
    >>> # The rest is the same as before.

The parameters are:

- ``StartFunctionIndex``: the index of the starting function, |image06|. The default is ``1``.
- ``NumFunctions``: number of orthogonal functions to generate, |image07|. The default is ``9``.
- ``EndInterval``: the right interval of orthogonality, |image08|. The default is ``1``.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2. Use As Standalone Application
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The standalone application can be executed in the terminal in two ways:

#. If you have installed the package, call ``gen-ortho`` executable in terminal:

   ::

       gen-ortho [options]

   The optional argument ``[options]`` will be explained in the next section. When the package *OrthogonalFunctions* is installed, the executable ``gen-ortho`` is located in the ``/bin`` directory of the python.

#. Without installing the package, the main script of the package can be executed directly from the source code by

   ::

       # Download the package
       git clone https://github.com/ameli/Orthogonal-Functions.git

       # Go to the package source directory
       cd OrthogonalFunctions

       # Execute the main script of the package
       python -m OrthogonalFunctions [options]

~~~~~~~~~~~~~~~~~~
Optional arguments
~~~~~~~~~~~~~~~~~~

When the *standalone application* (the second method in the above) is called, the executable accepts some optional arguments as follows.

+--------------------------------------+------------------------------------------------------------------------------------------+
| Option                               | Description                                                                              |
+======================================+==========================================================================================+
| ``-h``, ``--help``                   | Prints a help message.                                                                   |
+--------------------------------------+------------------------------------------------------------------------------------------+
| ``-v``, ``--version``                | Prints version.                                                                          |
+--------------------------------------+------------------------------------------------------------------------------------------+
| ``-l``, ``--license``                | Prints author info, citation and license.                                                |
+--------------------------------------+------------------------------------------------------------------------------------------+
| ``-n``, ``--num-func[=int]``         | Number of orthogonal functions to generate. Positive integer. Default is 9.              |
+--------------------------------------+------------------------------------------------------------------------------------------+
| ``-s``, ``--start-func[=int]``       | Starting function index. Non-negative integer. Default is 1.                             |
+--------------------------------------+------------------------------------------------------------------------------------------+
| ``-e``, ``--end-interval[=float]``   | End of the interval of functions domains. A real number greater than zero. Default is 1. |
+--------------------------------------+------------------------------------------------------------------------------------------+
| ``-c``,\ ``--check``                 | Checks orthogonality of generated functions.                                             |
+--------------------------------------+------------------------------------------------------------------------------------------+
| ``-p``, ``--plot``                   | Plots generated functions, also saves the plot as pdf file in the current directory.     |
+--------------------------------------+------------------------------------------------------------------------------------------+

~~~~~~~~~~
Parameters
~~~~~~~~~~

The variables |image06|, |image07|, and |image08| can be set in the script by the following arguments,

+-------------+--------------------------+---------------------------------+
| Variable    | Variable in script       | Option                          |
+=============+==========================+=================================+
| |image06|   | ``StartFunctionIndex``   | ``-s``, or ``--start-func``     |
+-------------+--------------------------+---------------------------------+
| |image07|   | ``NumFunctions``         | ``-n``, or ``--num-func``       |
+-------------+--------------------------+---------------------------------+
| |image08|   | ``EndInterval``          | ``-e``, or ``--end-interval``   |
+-------------+--------------------------+---------------------------------+

~~~~~~~~
Examples
~~~~~~~~

#. Generate nine orthogonal functions from index 1 to 9 (defaults)

   ::

        gen-ortho

#. Generate eight orthogonal functions from index 1 to 8

   ::

        gen-ortho -n 8

#. Generate nine orthogonal functions from index 0 to 8

   ::

        gen-ortho -s 0

#. Generate nine orthogonal functions that are orthonormal in the interval [0,10]

   ::

        gen-ortho -e 10

#. Check orthogonality of each two functions, plot the orthonormal functions and save the plot to pdf

   ::

        gen-ortho -c -p

#. A complete example:

   ::

        gen-ortho -n 9 -s 1 -e 1 -c -p

------
Output
------

-  Displays the orthogonal functions as computer algebraic symbolic functions. An example a set of generated functions is shown below.

::

    phi_1(t) =  sqrt(x)
    phi_2(t) =  sqrt(6)*(5*x**(1/3) - 6*sqrt(x))/3
    phi_3(t) =  sqrt(2)*(21*x**(1/4) - 40*x**(1/3) + 20*sqrt(x))/2
    phi_4(t) =  sqrt(10)*(84*x**(1/5) - 210*x**(1/4) + 175*x**(1/3) - 50*sqrt(x))/5
    phi_5(t) =  sqrt(3)*(330*x**(1/6) - 1008*x**(1/5) + 1134*x**(1/4) - 560*x**(1/3) + 105*sqrt(x))/3
    phi_6(t) =  sqrt(14)*(1287*x**(1/7) - 4620*x**(1/6) + 6468*x**(1/5) - 4410*x**(1/4) + 1470*x**(1/3) - 196*sqrt(x))/7
    phi_7(t) =  5005*x**(1/8)/2 - 10296*x**(1/7) + 17160*x**(1/6) - 14784*x**(1/5) + 6930*x**(1/4) - 1680*x**(1/3) + 168*sqrt(x)
    phi_8(t) =  sqrt(2)*(19448*x**(1/9) - 90090*x**(1/8) + 173745*x**(1/7) - 180180*x**(1/6) + 108108*x**(1/5) - 37422*x**(1/4) + 6930*x**(1/3) - 540*sqrt(x))/3
    phi_9(t) =  sqrt(5)*(75582*x**(1/10) - 388960*x**(1/9) + 850850*x**(1/8) - 1029600*x**(1/7) + 750750*x**(1/6) - 336336*x**(1/5) + 90090*x**(1/4) - 13200*x**(1/3) + 825*sqrt(x))/5

-  Displays readable coefficients, |image09| and |image10| of the functions. For instance,

::

      i      alpha_i                                    a_[ij]
    ------  ----------   -----------------------------------------------------------------------
    i = 1:  +sqrt(2/2)   [1                                                                    ]
    i = 2:  -sqrt(2/3)   [6,   -5                                                              ]
    i = 3:  +sqrt(2/4)   [20,  -40,    21                                                      ]
    i = 4:  -sqrt(2/5)   [50,  -175,   210,   -84                                              ]
    i = 5:  +sqrt(2/6)   [105, -560,   1134,  -1008,   330                                     ]
    i = 6:  -sqrt(2/7)   [196, -1470,  4410,  -6468,   4620,   -1287                           ]
    i = 7:  +sqrt(2/8)   [336, -3360,  13860, -29568,  34320,  -20592,   5005                  ]
    i = 8:  -sqrt(2/9)   [540, -6930,  37422, -108108, 180180, -173745,  90090,  -19448        ]
    i = 9:  +sqrt(2/10)  [825, -13200, 90090, -336336, 750750, -1029600, 850850, -388960, 75582]

-  Displays the matrix of the mutual inner product of functions to check orthogonality (using option ``-c``). An example of the generated matrix of the mutual inner product of functions is shown below.

::

    [[1 0 0 0 0 0 0 0 0]
     [0 1 0 0 0 0 0 0 0]
     [0 0 1 0 0 0 0 0 0]
     [0 0 0 1 0 0 0 0 0]
     [0 0 0 0 1 0 0 0 0]
     [0 0 0 0 0 1 0 0 0]
     [0 0 0 0 0 0 1 0 0]
     [0 0 0 0 0 0 0 1 0]
     [0 0 0 0 0 0 0 0 1]]

-  Plots the set of functions (using option ``-p``) and saves the plot in the current directory. An example of a generated plot is shown below.

.. image:: https://raw.githubusercontent.com/ameli/Orthogonal-Functions/main/docs/images/OrthogonalFunctions.svg
    :align: center

--------
Citation
--------

.. [Ameli-2020] Ameli, S., and Shadden. S. C. (2020). Interpolating the Trace of the Inverse of Matrix **A** + t **B**. `arXiv:2009.07385 <https://arxiv.org/abs/2009.07385>`__ [math.NA]

::

    @misc{AMELI-2020,
        title={Interpolating the Trace of the Inverse of Matrix $\mathbf{A} + t \mathbf{B}$},
        author={Siavash Ameli and Shawn C. Shadden},
        year={2020},
        month = sep,
        eid = {arXiv:2009.07385},
        eprint={2009.07385},
        archivePrefix={arXiv},
        primaryClass={math.NA},
        howpublished={\emph{arXiv}: 2009.07385 [math.NA]},
    }

.. |travis-devel| image:: https://img.shields.io/travis/com/ameli/Orthogonal-Functions
   :target: https://travis-ci.com/github/ameli/Orthogonal-Functions
.. |codecov-devel| image:: https://img.shields.io/codecov/c/github/ameli/Orthogonal-Functions
   :target: https://codecov.io/gh/ameli/Orthogonal-Functions
.. |licence| image:: https://img.shields.io/github/license/ameli/Orthogonal-Functions
   :target: https://opensource.org/licenses/MIT
.. |travis-devel-linux| image:: https://img.shields.io/travis/com/ameli/Orthogonal-Functions?env=BADGE=linux&label=build&branch=main
   :target: https://travis-ci.com/github/ameli/Orthogonal-Functions
.. |travis-devel-osx| image:: https://img.shields.io/travis/com/ameli/Orthogonal-Functions?env=BADGE=osx&label=build&branch=main
   :target: https://travis-ci.com/github/ameli/Orthogonal-Functions
.. |travis-devel-windows| image:: https://img.shields.io/travis/com/ameli/Orthogonal-Functions?env=BADGE=windows&label=build&branch=main
   :target: https://travis-ci.com/github/ameli/Orthogonal-Functions
.. |implementation| image:: https://img.shields.io/pypi/implementation/OrthogonalFunctions
.. |pyversions| image:: https://img.shields.io/pypi/pyversions/OrthogonalFunctions
.. |format| image:: https://img.shields.io/pypi/format/OrthogonalFunctions
.. |pypi| image:: https://img.shields.io/pypi/v/OrthogonalFunctions
.. |build-linux| image:: https://github.com/ameli/Orthogonal-Functions/workflows/build-linux/badge.svg
   :target: https://github.com/ameli/Orthogonal-Functions/actions?query=workflow%3Abuild-linux 
.. |build-macos| image:: https://github.com/ameli/Orthogonal-Functions/workflows/build-macos/badge.svg
   :target: https://github.com/ameli/Orthogonal-Functions/actions?query=workflow%3Abuild-macos
.. |build-windows| image:: https://github.com/ameli/Orthogonal-Functions/workflows/build-windows/badge.svg
   :target: https://github.com/ameli/Orthogonal-Functions/actions?query=workflow%3Abuild-windows
.. |conda| image:: https://anaconda.org/s-ameli/orthogonalfunctions/badges/installer/conda.svg
   :target: https://anaconda.org/s-ameli/orthogonalfunctions
.. |platforms| image:: https://img.shields.io/conda/pn/s-ameli/orthogonalfunctions?color=orange?label=platforms
   :target: https://anaconda.org/s-ameli/orthogonalfunctions
.. |conda-version| image:: https://img.shields.io/conda/v/s-ameli/orthogonalfunctions
   :target: https://anaconda.org/s-ameli/orthogonalfunctions
.. |release| image:: https://img.shields.io/github/v/tag/ameli/Orthogonal-Functions
   :target: https://github.com/ameli/Orthogonal-Functions/releases/
.. |conda-platform| image:: https://anaconda.org/s-ameli/orthogonalfunctions/badges/platforms.svg
   :target: https://anaconda.org/s-ameli/orthogonalfunctions