Skip to main content

Tool for calculating risk of change propagation in a system.

Project description

DOI

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 0, to sub-system 3
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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpm-lib-1.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cpm_lib-1.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file cpm-lib-1.1.0.tar.gz.

File metadata

  • Download URL: cpm-lib-1.1.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.4

File hashes

Hashes for cpm-lib-1.1.0.tar.gz
Algorithm Hash digest
SHA256 efb11a80b56c6c2372b219dd4ba0274e479695571c983aea0fd862523481a921
MD5 29d984d7287b20202304514971317879
BLAKE2b-256 bbba5f240744f27d7670756da3c91dbf3089096f8ef4ec1e6024b8f20d7f2de5

See more details on using hashes here.

File details

Details for the file cpm_lib-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: cpm_lib-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.4

File hashes

Hashes for cpm_lib-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78256636d5174a8928f2213974d33fb55ef41dbeccd695300d1180ac6f0b11b6
MD5 b5cb8e74f1c865058d231edf512b1374
BLAKE2b-256 11dde79247f255b4085abbdfa801289a66c545fb37dceffc5a8dec08aae73478

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page