ahp trade study tools
Project description
krispy
Matrix Operations (Matrix class)
The following matrix operations are available to the user. (Suppose we import krispy as kp)
Matrix(upper_right)
takes the upper right triangle of a matrix as a list, e.g. [1, 3, 6] to create a matrix object.
my_matrix = kp.Matrix(upper_right_list)
Now that we have a matrix, we can perform matrix calculations on my_matrix.
-
len(my_matrix)
will give you the length of the matrix. (This is like height) -
str(my_matrix)
will give you the matrix as a string (for printing purposes). -
Matrix.from_matrix_array(my_matrix)
this accepts a matrix instead of upper right array. This is particularly useful if you already have a built matrix in your code and just need the eigenvector or consistency. -
.normalized()
gives you the normalized matrix
my_norm_matrix = my_matrix.normalized()
.eigenvector
will give you the eigenvector of your matrix. This is a property so we don't need parentheses.
my_eigenvec = my_matrix.eigenvector
.consistency
gives you the calculated consistency value. This is a property so we don't need parentheses.
c_value = my_matrix.consistency
Getting Scores and Alternative Weights
-
.get_scores(criteria_eigenvector, tech_spec_eigenvector1, tech_spec_eigenvector2,...)
You can use this function to calculate the overall results of the trade study. Notice that
get_scores
takes in a variable number of arguments but the criteria eigenvector comes first.Suppose you have
criteria_eig
and a list of all the eigenvectorseigenmatrix = [eig1, eig2, eig3,...,eign]
and you want to calculate the results. Then you can callget_scores
like this:
results = kp.get_scores(criteria_eig, *eigenmatrix)
The asterisk in front of eigenmatrix
unpacks everything in there so that we're sending a variable number of lists instead of a list of lists.
.get_scores
will return a list of scores, e.g. [.42, .22, .21, .12]
.
-
.get_alternative_weights(criteria_eigenvector, tech_spec_eigenvector1, tech_spec_eigenvector2,...)
You can use this function to get just the alternative weights as a matrix. This is useful for calling the
sensitivity
function.Suppose you have
criteria_eig
and a list of all the eigenvectorseigenmatrix = [eig1, eig2, eig3,...,eign]
and you want to calculate the alternative weights. Then you can callget_alternative_weights
like this:
results = kp.get_alternative_weights(criteria_eig, *eigenmatrix)
The asterisk in front of eigenmatrix
unpacks everything in there so that we're sending a variable number of lists instead of a list of lists.
Graphing
.graph(results, names, 'filename_for_saving.png')
There are two different uses for graph
.
- The first usage is for getting the initial graph of the results. For this usage, we want to send the results wrapped in a list. So if you have
results = [.42, .22, .21, .12]
, then you want to wrap this in a list...i.e.wrapped_results = [results]
.
You also want to send the list of the names of the alternatives. If we are comparing cheese, an example names list would be names = ['pepper jack', 'cheddar', 'swiss', 'stilton']
.
Finally, give a save location. An example of this would be save_loc = '/images/result_graph.png'
.
Thus your function call would be:
kp.graph(wrapped_results, names, save_loc)
- The second usage is for getting the graph of the sensitivity analysis data. For this usage, we want to send the results of the sensitivity analysis. The sensitivity analysis will send back a list of lists like this
sens_results = [[1, 4, 2], [3, 6, 9], [4, 2, 2], [5, 8, 1]]
.
We also want to send the list of the names of the tech specs or criteria. If this trade study is about cheese, and exmaple name list would be names = ['cost', 'flavor', 'odor', 'texture']
.
Finally, give a save location. An example of this would be save_loc = '/images/sens_result_graph.png'
.
Thus your function call would be:
kp.graph(sens_results, names, save_loc)
Sensitivity Analysis
-
get_sensitivity(criteria_list, alt_weight_matrix)
will produce a list of lists. Each list represents a run of the trade study, but remember, we remove each criterion for the runs to see if the results change. An example:[[1, 4, 2], [3, 6, 9], [4, 2, 2], [5, 8, 1]]
.If you want to calculate the sensitivity analysis results, first save the
criteria_list
. Next, you need to get a matrix of the alternative weights (a matrix is a list of lists). To do this, make analt_weight_matrix
variable and callget_alternative_weights
(explained above).
sens_results = kp.get_sensitivity(criteria_list, alt_weight_matrix)
Thank you for reading through this! Don't hesitate to reach out to me to ask questions.
If you are not Hayden, then I ask that you buy me a hot tea, kava, or GF/DF muffin if we ever meet in person and you have used krispy.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file krispy-1.0.4.tar.gz
.
File metadata
- Download URL: krispy-1.0.4.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be680a949fc99ac0d49357707d4f3ec30ee3a5c9d0430e57737a294aafd3d849 |
|
MD5 | 067e37a830b13aea4431cfb183a3ef29 |
|
BLAKE2b-256 | c0f78511e15c390c90acc6901c61541980e760dcdbebcb29562776aef888b485 |
File details
Details for the file krispy-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: krispy-1.0.4-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d128109b62adb3b493f87332b3191e7b5978290e3ad489a72ca9f3c1149e379c |
|
MD5 | 4f2f6302b166360f5b781764835bf4b7 |
|
BLAKE2b-256 | 67575d5b155d8403c5c881bc448474fb1ebf15870367cd3155c34fd5e271c9e2 |