{"id":15912132,"url":"https://github.com/ulf1/scipy-psdm","last_synced_at":"2025-06-29T22:34:25.014Z","repository":{"id":43408093,"uuid":"249910726","full_name":"ulf1/scipy-psdm","owner":"ulf1","description":"transform an ill-conditioned quadratic matrix to a positive semidefinite matrix","archived":false,"fork":false,"pushed_at":"2025-05-06T08:02:28.000Z","size":72,"stargazers_count":2,"open_issues_count":24,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-06T13:44:48.160Z","etag":null,"topics":["positive-semi-definite","random-correlation-matrices","random-numbers"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ulf1.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["ulf1","KikeM"]}},"created_at":"2020-03-25T07:10:52.000Z","updated_at":"2022-04-23T08:37:50.000Z","dependencies_parsed_at":"2023-12-06T18:40:05.747Z","dependency_job_id":"d1ea7867-a374-4e0c-bb45-0f59c989b92d","html_url":"https://github.com/ulf1/scipy-psdm","commit_stats":{"total_commits":36,"total_committers":4,"mean_commits":9.0,"dds":"0.33333333333333337","last_synced_commit":"674acea2d9f133c4aef91a6bc16210ea7792044d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ulf1/scipy-psdm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulf1%2Fscipy-psdm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulf1%2Fscipy-psdm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulf1%2Fscipy-psdm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulf1%2Fscipy-psdm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ulf1","download_url":"https://codeload.github.com/ulf1/scipy-psdm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ulf1%2Fscipy-psdm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262678679,"owners_count":23347414,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["positive-semi-definite","random-correlation-matrices","random-numbers"],"created_at":"2024-10-06T16:02:04.951Z","updated_at":"2025-06-29T22:34:24.849Z","avatar_url":"https://github.com/ulf1.png","language":"Python","funding_links":["https://github.com/sponsors/ulf1","https://github.com/sponsors/KikeM"],"categories":[],"sub_categories":[],"readme":"[![PyPI version](https://badge.fury.io/py/scipy-psdm.svg)](https://badge.fury.io/py/scipy-psdm)\n[![PyPi downloads](https://img.shields.io/pypi/dm/scipy-psdm)](https://img.shields.io/pypi/dm/scipy-psdm)\n\n# scipy-psdm\nTransform an ill-conditioned quadratic matrix into a positive semi-definite matrix.\n\n## Installation\nThe `scipy-psdm` [git repo](http://github.com/ulf1/scipy-psdm) is available as [PyPi package](https://pypi.org/project/scipy-psdm)\n\n```bash\npip install scipy-psdm\n```\n\n## Usage\nLurie-Goldberg Algorithm to transform an ill-conditioned quadratic matrix into a positive semi-definite matrix.\n\n```python\nimport scipy_psdm as psdm\nimport numpy as np\n\n# A matrix with subjectively set correlations\nmat = [[ 1.   , -0.948,  0.099, -0.129],\n       [-0.948,  1.   , -0.591,  0.239],\n       [ 0.099, -0.591,  1.   ,  0.058],\n       [-0.129,  0.239,  0.058,  1.   ]]\nmat = np.array(mat)\n\n# Convert to a positive semi-definite matrix\nrho = psdm.approximate_correlation_matrix(mat)\nprint(rho.round(3))\n```\n\nGenerate correlated random numbers\n\n```python\nimport scipy_psdm as psdm\nX, rho = psdm.randcorr(n_obs=100, n_vars=5, random_state=42)\n\n# compare\nimport numpy as np\nprint(rho.round(3))\nprint(np.corrcoef(X, rowvar=False).round(3))\n```\n\nCheck the [examples](https://github.com/ulf1/scipy-psdm/tree/master/examples) folder for notebooks.\n\n\n## Appendix\n\n### Install a virtual environment\n\n```bash\npython3 -m venv .venv\nsource .venv/bin/activate\npip3 install -r requirements.txt\npip3 install -r requirements-dev.txt\npip3 install -r requirements-demo.txt\n```\n\n(If your git repo is stored in a folder with whitespaces, then don't use the subfolder `.venv`. Use an absolute path without whitespaces.)\n\n### Python commands\n\n* Start virtual env: `source .venv/bin/activate`\n* Jupyter for the examples: `jupyter lab`\n* Check syntax: `flake8 --ignore=F401 --exclude=$(grep -v '^#' .gitignore | xargs | sed -e 's/ /,/g')`\n* Run Unit Tests: `pytest -v`\n\nPublish\n```\npandoc README.md --from markdown --to rst -s -o README.rst\npython setup.py sdist \ntwine upload -r pypi dist/*\n```\n\n### Clean up \n\n```bash\nfind . -type f -name \"*.pyc\" | xargs rm\nfind . -type d -name \"__pycache__\" | xargs rm -r\nrm -r .pytest_cache\nrm -r .venv\n```\n\n### Support\nPlease [open an issue](https://github.com/ulf1/scipy-psdm/issues/new) for support.\n\n\n### Contributing\nPlease contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch, add commits, and [open a pull request](https://github.com/ulf1/scipy-psdm/compare/).\n\n## Contributers\n- [@KikeM Enrique Millán Valbuena](https://github.com/KikeM)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulf1%2Fscipy-psdm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fulf1%2Fscipy-psdm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulf1%2Fscipy-psdm/lists"}