Skip to content

Latest commit

 

History

History
270 lines (196 loc) · 12.3 KB

README.MD

File metadata and controls

270 lines (196 loc) · 12.3 KB

PracCodes

Repository for mathematical codes ( 2 variants - optimized, non-optimized )


Last Update

Update 05.10.2024 INFO:

  • optimized.lineq.lineq_sub.
    • add functions for linear equations systems
      • iter_solve_simple(matrix, vector, eps=1e-12, max_iter=1000, eigen_max_iter=1000, eigen_eps=1e-12):
        Simple iteration to solve a system of linear equations.
        Need positive definite and symmetric matrix.
        

$\text{Sylvester's criterion}$

Sylvester's criterion states that a $n \times n$ Hermitian matrix $M$ is positive-definite if and only if all the following matrices have a positive determinant:

  • the upper left 1-by-1 corner of $M$,
  • the upper left 2-by-2 corner of $M$,
  • the upper left 3-by-3 corner of $M$,
  • $\quad \vdots$
  • $M$ itself.

In other words, all of the leading principal minors must be positive. By using appropriate permutations of rows and columns of $M$, it can also be shown that the positivity of any nested sequence of $n$ principal minors of $M$ is equivalent to $M$ being positive-definite.

Iterative Methods

Important

  • Disabled GIL for lowlevel functions.
  • Be careful.
  • Fixed memory leak in optimized.lineq.lineq_sub.
  • Fixed memory leak in optimized.lineq.matrix_methods.
  • Fixed random_double function in optimized.lineq.matrix_methods. -> now work correctly.
  • Fixed random in optimized.lineq.matrix_methods.Module.module MatrixMethods class -> now work correctly.
  • Fixed variables definitions in .pyx files in optimized.lineq.matrix_methods, optimized.lineq.lineq_sub, optimized.lineq.generator, optimized.lineq.checker.

Update 28.09.2024 INFO:

  • optimized.lineq.lineq_sub.
    • development started.
    • add functions for linear equations systems:
      • solve_tridiagonal(matrix, vector):

        Solve a system of linear equations with tridiagonal matrix
        

        Matrix must be tridiagonal:

        $a_{11}$ $b_{12}$ 0 ... ... ... 0
        $c_{21}$ $a_{22}$ $b_{23}$ ... ... ... 0
        0 $c_{32}$ $a_{33}$ $b_{34}$ ... ... 0
        ... 0 $c_{43}$ $a_{44}$ $b_{45}$ ... 0
        ... ... ... ... ... ... 0
        0 0 ... 0 $c_{n-1 \ n-2}$ $a_{n-1 \ n-1}$ $b_{n-1 \ n}$
        0 0 ... 0 0 $c_{n \ n-1}$ $a_{nn}$

        Tridiagonal matrix algorithm (Thomas algorithm)

      • solve_gauss(matrix, vector):

        Solve a system of linear equations with gauss method
        

        Gaussian elimination

      • solve_lu(matrix, vector):

        Solve a system of linear equations with LU method
        

$$ \begin{aligned} (1) \ & A\cdot\bar{x} = \bar{b} \\ (2) \ & A = L \cdot U \\ (3) \ & L \cdot U = A \\ (4) \ & U \cdot \bar{x} = \bar{y}\\ (5) \ & L \cdot \bar{y} = \bar{b} \\ (6) \ & L \text{ is a lower triangular matrix, so (5) is easy to solve for } \bar{y} \\ (7) \ & U \text{ is an upper triangular matrix, so (4) is easy to solve for } \bar{x} \\ \end{aligned} $$

$$ \begin{aligned} \text{Algorithm complexity:} \ LU_{\text{complexity}} & => \frac{2 \cdot n^3}{3} + O(n^2) \\ \text{Solving (5) and (4)} & => n^2 + O(n) \end{aligned} $$


UPDATE 01.09.2024 INFO:

  • run_api.py updated.
    • Argparser added.

Tip

usage: optimized_api [-h] [-r]

optimized_api FLASK app

options:

-h, --help show this help message and exit
-r, --rebuild, -re Rebuild optimized_api


UPDATE #2 23.08.2024 INFO:

  • GUI updated.
    • Add dark mode.
    • Add new accordion fields.
    • Add new input fields.
    • Add result copy button.
    • Add global_info and global_info.GlobalRet return fields.
    • Add new styles to statics.
    • Add new .js files to statics.

Note

api_key in config.ini does not work.

  • Enjoy 😸

UPDATE 23.08.2024 INFO:

  • Started creating GUI for API. Now you can use only lineq.generator GUI.

  • GUI LOCAL link -> localhost:8000/main (localhost:8000/ works too (without GUI)) after running run_api.py.

  • Examples -> images.api_gui

    [] [] []

    [] [] []


Update 22.08.2024 INFO:


Update 19.08.2024 INFO:

  • Continued working on API after a break. API for generator, checker will be finished soon. Then I will continue optimizing the rest of the modules, namely lineq.lineq, ( lineq.Utils.Prettier, lineq.Utils.S_R may not be changed, but will be moved to a new module without optimization, or will be completely removed ). lineq.Utils.timer will be definitely removed.

  • optimized.lineq.matrix_methods.python_interface API is ready for 100% use.


Update 10.08.2024 INFO:

  • Fixed a bug in the rand function of the optimized/lineq/matrix_methods/lowlevel/mm.c file (file). The function was returning extremely large numbers instead of a random number within the specified range.

  • Updated the docstrings in the optimized.lineq.generator.python_interface module. optimized.lineq.generator.python_interface

  • Added new information to the API data.json file. API-DATA.

  • Added new API functions. Check the Current Api Support for all functions.

  • New API return system -> Added in each return global_info -> request.headers, host, url, etc...

    • some screenshots


Update #2 04.08.2024 INFO:

Add new API functions Current Api Support Check usage instructions in API-DATA or just run run_api.py and check home page. All info in:

Update 04.08.2024 INFO:

Started developing the API for the optimized codes. Already ready for use determinant function API. Info in data. To run the API, run run_api. Local API is available at http://127.0.0.1:8000/.

  • Use examples:

    • browser list mode (img1): http://127.0.0.1:5000/det/?type=list&matrix=[[1,2,3],[4,5,6],[7,1.2,7]]

    • browser str mode (img2): http://127.0.0.1:5000/det/?matrix=1%202%203\n4%205%206\n7%208%209

    • curl list mode (img3):

    curl `http://127.0.0.1:5000/det/?type=list&matrix=%5B%5B1%2C2%2C3%5D%2C%5B4%2C5%2C6%5D%2C%5B7%2C1.2%2C7%5D%5D`


Update 02.08.2024 INFO:

Rewritted build.py script.

New Build System

  • Build Management: Manages cleaning up previous builds, compiling modules, and organizing build artifacts.
  • Dependency Check: Automatically checks for and installs necessary dependencies such as Cython.
  • Configuration Loading: Loads build settings and module configurations from the file cfg. If the file does not exist, a default configuration is created.
  • Build Result Visualization: Displays a tree structure with icons indicating the success or failure of each module.
  • Automated Testing: Runs tests on successfully built libraries to ensure their correctness.

Update 29.07.2024 INFO:

I have rewritten the Checker module and updated matrix filling in matrix_methods module.

  • Introduced the Checker class for matrix validation

    • Methods included:
      • diagonal_domination(matrix) -> bool: Checks matrix diagonal domination
      • symmetric_check(matrix) -> bool: Checks matrix symmetry
      • sylvesters_criterion(matrix) -> bool: Checks matrix against Sylvester's criterion
  • I also updated the matrix filling in both the matrix_methods and Checker modules. I replaced the cycle with a for loop and used memset(*, 0, sizeof(*)) to set the matrix elements to zero.


Update 26.07.2024 INFO:

The updated Python interface for optimized.lineq.matrix_methods is now ready for use. It is optimized for 100% efficiency.

The new code is significantly faster, with an average improvement of more than 50 times.

The Generator has also been rewritten.


Update 26.07.2024 INFO:

In the lineq/LinEq/Utils/Matrix_methods.py file, the determinant function has been fixed.

I have started rewriting the code. In the Optimized-Experimental directory, you will find experimental versions of the codes with optimizations. These versions are about 50 times faster. However, you need the Cython library for this!

I have rewritten the lineq.matrix_methods module in the optimized/lineq/matrix_methods/ directory.

Here are the links to the source code:

  • The C code can be found in the code file.
  • The Python code is available in the code file. This file is ready for 50% use. All functions work if imported from the build.matrix_methods file. However, in the Python file, only 50% of the code is implemented.

The source codes are located in the optimized/{module_name}/{util_name}/lowlevel directory, where {module_name} represents the module name and {util_name} represents the utility name.

To build the optimized version, run the build.bat [DELETED, use python script]UPD 02.08.2024 build.py file from the optimized directory. Please note that this feature does not work with older versions of the project. Wait for a new version to be ready with all optimizations implemented.