Package: krispy
krispyGithub linkMatrix 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 matrixmy_norm_matrix=my_matrix.normalized().eigenvectorwill give you the eigenvector of your matrix. This is apropertyso we don't need parentheses.my_eigenvec=my_matrix.eigenvector.consistencygives you the calculated consistency value. This is apropertyso we don't need parentheses.c_value=my_matrix.consistencyGetting 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 thatget_scorestakes in a variable number of arguments butthe criteria eigenvector comes first.Suppose you havecriteria_eigand a list of all the eigenvectorseigenmatrix = [eig1, eig2, eig3,...,eign]and you want to calculate the results. Then you can callget_scoreslike this:results=kp.get_scores(criteria_eig,*eigenmatrix)The asterisk in front ofeigenmatrixunpackseverything in there so that we're sending a variable number of lists instead of a list of lists..get_scoreswill 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 getjust the alternative weightsas a matrix. This is useful for calling thesensitivityfunction.Suppose you havecriteria_eigand a list of all the eigenvectorseigenmatrix = [eig1, eig2, eig3,...,eign]and you want to calculate the alternative weights. Then you can callget_alternative_weightslike this:results=kp.get_alternative_weights(criteria_eig,*eigenmatrix)The asterisk in front ofeigenmatrixunpackseverything 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 forgraph.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 haveresults = [.42, .22, .21, .12], then you want to wrap this in a list...i.e.wrapped_results = [results].You also want to sendthe list of the names of the alternatives. If we are comparing cheese, an example names list would benames = ['pepper jack', 'cheddar', 'swiss', 'stilton'].Finally, give a save location. An example of this would besave_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 thissens_results = [[1, 4, 2], [3, 6, 9], [4, 2, 2], [5, 8, 1]].We also want to sendthe list of the names of the tech specs or criteria. If this trade study is about cheese, and exmaple name list would benames = ['cost', 'flavor', 'odor', 'texture'].Finally, give a save location. An example of this would besave_loc = '/images/sens_result_graph.png'.Thus your function call would be:kp.graph(sens_results,names,save_loc)Sensitivity Analysisget_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 thecriteria_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_matrixvariable 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.