Giter Site home page Giter Site logo

ahpanalysis's Introduction

Instructions

函数1:calculate_weights(comparison_matrix):

计算权重: $$W_i = \frac{1}{n} \sum_{j=1}^{n} \frac{a_{ij}}{\sum_{k=1}^{n} a_{kj}}, \quad i = 1,2, \ldots, n$$
归一化: $$\frac{a_{ij}}{\sum_{k=1}^{n} a_{kj}}$$
描述:

此函数接收一个比较矩阵,并计算其权重。首先,它将比较矩阵标准化,然后对标准化矩阵的行进行求和,最后通过将行和除以矩阵的长度来计算权重。

参数:

  • comparison_matrix (numpy array): 一个比较矩阵。

返回:

  • 权重 (numpy array): 计算得出的权重。

示例:

comparison_matrix = np.array([[1, 2], [3, 4]])
weights = calculate_weights(comparison_matrix)
print(weights)

输出:

[0.33333333 0.66666667]

此函数在需要计算比较矩阵权重的场景中非常有用,例如在多属性决策分析中。

函数2:create_comparison_matrix(elements)

描述:

此函数接收一个元素列表,并将其重塑为一个平方矩阵。列表中的元素数量必须是完全平方数(即,元素数量的平方根应为整数),否则会导致 ValueError

参数:

  • elements (list): 一个数值列表。此列表的长度应为完全平方数。

返回:

  • 一个2D numpy数组(矩阵),其中输入列表的元素被重塑为一个平方矩阵。

错误说明:

  • ValueError:如果输入列表中的元素数量不是完全平方数。

示例:

elements = [1, 2, 3, 4]
matrix = create_comparison_matrix(elements)
print(matrix)

输出:

[[1 2]
 [3 4]]

函数3:calculate_comprehensive_weights(first_layer_weights, *second_layer_weight_matrices)

描述:

此函数接收第一层权重和多个第二层权重矩阵,并计算其综合权重。首先,它初始化一个数组来保存综合权重,然后将每个第二层权重矩阵乘以其对应的第一层权重,并将结果相加以得到综合权重。

参数:

  • first_layer_weights (numpy array): 第一层的权重。
  • *second_layer_weight_matrices (numpy array): 一个或多个第二层权重矩阵。

返回:

  • 综合权重 (numpy array): 计算得出的综合权重。

示例:

first_layer_weights = np.array([0.3, 0.4, 0.3])
second_layer_weight_matrices = np.array([[0.1, 0.2, 0.7], [0.2, 0.3, 0.5], [0.3, 0.4, 0.3]])
comprehensive_weights = calculate_comprehensive_weights(first_layer_weights, *second_layer_weight_matrices)
print(comprehensive_weights)

输出:

[0.14 0.26 0.6]

ahpanalysis's People

Contributors

sxsx-g avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.