Change Prediction Library
This library is intended to assist in the calculation of
change prediction/propagation (Clarkson et al., 2004) in a system.
The library takes to DSMs as an input: one for likelihoods and
one for impacts. These DSMs should be in a CSV format.
Once the DSMs are loaded, a ChangePropagationTree can be
constructed for each possible interaction. The
ChangePropagationTree can then be polled for the
risk and probability of changes.
Install
pip install cpm-lib
Use
First, create the DSMs using CSV-files as inputs. This is done
using cpm.parse.parse_csv(), which returns a DSM created from
the input CSV. Then, use the DSMs to form a ChangePropagationTree. This
tree will calculate the risk of change propagating
from one part of the system, to another.
import cpm.parse as parse
from cpm.models import ChangePropagationTree
dsm_likelihood = parse.parse_csv('./dsm-likelihoods.csv')
dsm_impact = parse.parse_csv('./dsm-impacts.csv')
# Calculate the risk of change propagating
# from sub-system 3, to sub-system 0
start_index = 3
target_index = 0
cpt = ChangePropagationTree(start_index, target_index, dsm_impact, dsm_likelihood)
cpt.propagate(search_depth=4)
risk = cpt.get_risk()
probability = cpt.get_probability()
In this example, assuming a 4x4 DSM with the columns: A, B, C, and D, with the respective indices 0, 1, 2, and 3, the code above will calculate the risk of propagation from sub-system D to sub-system A.
The search depth determines the maximum length of change propagation. It is recommended by Clarkson et al., 2004 to keep this at 4 or lower. Higher values will be computationally expensive and produce uninteresting results.
Granted the functions above, it is also possible to create CPM DSMs by running the CPM algorithm on all the elements of a matrix that contains likelihoods and a second matrix that contains impacts. Here is an example:
from typing import Union
from cpm.parse import parse_csv
from cpm.models import ChangePropagationTree
# Run change propagation on entire matrix
# Create DSMs for Impacts and Likelihoods
dsm_i = parse_csv('dsm-impacts.csv')
dsm_l = parse_csv('dsm-likelihoods.csv')
# Create a matrix in which the results can be stored
res_mtx: list[list[Union[float, str]]] = []
for i, icol in enumerate(dsm_l.columns):
res_mtx.append([icol])
for j, jcol in enumerate(dsm_l.columns):
# Run change propagation on each possible pairing
cpt = ChangePropagationTree(j, i, dsm_impact=dsm_i, dsm_likelihood=dsm_l)
cpt.propagate(search_depth=4)
# Store results in matrix
res_mtx[i].append(cpt.get_risk())
# Create CSV string
delimiter = "; "
csv = "\t"+delimiter
csv += delimiter.join(dsm_l.columns) + "\n"
for line in res_mtx:
csv_line = delimiter.join(map(str, line))
csv_line += "\n"
csv += csv_line
# Write to file
with open("cpm.csv", "w") as file:
file.write(csv)
print(csv)
Expected CSV format
The CSV files are expected to have a header on the first row and the first column. Here is an example with 4 sub-systems. The direction of propagation is the same as in Clarkson et al., 2004: Columns are instigators of change, and rows are the receivers. So, in the example below, the potential interaction between C and B is bi-directional, while change can also propagate from D to C.
| A | B | C | D | |
|---|---|---|---|---|
| A | A | |||
| B | B | 0.5 | ||
| C | 0.5 | C | 0.5 | |
| D | D |
Changing DSM directionality
If it is desirable to instead have instigation occur from rows to columns, then it is possible to instantiate the DSMs with this as a keyword attribute:
dsm = DSM(matrix=data, columns=column_names, instigator="row")
The default is instigator='column'.
This can also be utilized when parsing a CSV-file, like this:
dsm = parse_csv(filepath, instigator='row')
Note that changing instigator will completely change the results of propagation.
References
Clarkson, P. J., Caroline, S., & Claudia, E. (2004). Predicting Change Propagation in Complex Design. Journal of Mechanical Design, 126(5), 788–797. https://doi.org/10.1115/1.1765117
Metadata
Release files for cpm-lib 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cpm-lib-1.1.1.tar.gz | 12.1 kB | Without provenance | Details for cpm-lib-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cpm_lib-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for cpm_lib-1.1.1-py3-none-any.whl |
Total release size: 24.2 kB
Release files / cpm-lib-1.1.1.tar.gz
| Download URL | cpm-lib-1.1.1.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
046fb467e26e90ab2ae26d71434ff8c4465d8c5e3f8216fb3b3db54211cc34f0
|
|
BLAKE2b-256 checksum How to use checksums |
31cefffe2dfc77846ad69f7fa3cedf0fb1f4794cb6ecdbab6858d40b70660878
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.4
|
Release files / cpm_lib-1.1.1-py3-none-any.whl
| Download URL | cpm_lib-1.1.1-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9887b3e5ef0958ec361039de1b1b497fa996b93d1d6cd62071c26c6082b7a1c
|
|
BLAKE2b-256 checksum How to use checksums |
73386cba4b9cd9b03d15387a2ca3e5175800239774f1bba824777846feb9355d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.4
|
Security for cpm-lib 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.