Created
September 29, 2025 19:26
-
-
Save MohamedGouaouri/579637c139e6915cafaa177fe2b0d512 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package poweraware | |
| import ( | |
| "math" | |
| "gonum.org/v1/gonum/mat" | |
| ) | |
| func normalizeMatrix(matrix *mat.Dense) *mat.Dense { | |
| r, c := matrix.Dims() | |
| normalized := mat.NewDense(r, c, nil) | |
| for j := 0; j < c; j++ { | |
| var sumSquares float64 | |
| for i := 0; i < r; i++ { | |
| val := matrix.At(i, j) | |
| sumSquares += val * val | |
| } | |
| normFactor := math.Sqrt(sumSquares) | |
| for i := 0; i < r; i++ { | |
| if normFactor == 0 { | |
| normalized.Set(i, j, matrix.At(i, j)/0.000001) | |
| } else { | |
| normalized.Set(i, j, matrix.At(i, j)/normFactor) | |
| } | |
| } | |
| } | |
| return normalized | |
| } | |
| func weightMatrix(matrix *mat.Dense, weights []float64) *mat.Dense { | |
| r, c := matrix.Dims() | |
| weighted := mat.NewDense(r, c, nil) | |
| for j := 0; j < c; j++ { | |
| for i := 0; i < r; i++ { | |
| weighted.Set(i, j, matrix.At(i, j)*weights[j]) | |
| } | |
| } | |
| return weighted | |
| } | |
| func idealSolutions(matrix *mat.Dense) (ideal []float64, negativeIdeal []float64) { | |
| r, c := matrix.Dims() | |
| ideal = make([]float64, c) | |
| negativeIdeal = make([]float64, c) | |
| for j := 0; j < c; j++ { | |
| var maxVal, minVal float64 | |
| for i := 0; i < r; i++ { | |
| val := matrix.At(i, j) | |
| if i == 0 || val > maxVal { | |
| maxVal = val | |
| } | |
| if i == 0 || val < minVal { | |
| minVal = val | |
| } | |
| } | |
| ideal[j] = maxVal | |
| negativeIdeal[j] = minVal | |
| } | |
| return ideal, negativeIdeal | |
| } | |
| func separationMeasure(matrix *mat.Dense, ideal []float64, negativeIdeal []float64) (separationIdeal []float64, separationNegative []float64) { | |
| r, c := matrix.Dims() | |
| separationIdeal = make([]float64, r) | |
| separationNegative = make([]float64, r) | |
| for i := 0; i < r; i++ { | |
| var sumIdeal, sumNegative float64 | |
| for j := 0; j < c; j++ { | |
| // Euclidean distance from ideal solution | |
| sumIdeal += math.Pow(matrix.At(i, j)-ideal[j], 2) | |
| // Euclidean distance from negative ideal solution | |
| sumNegative += math.Pow(matrix.At(i, j)-negativeIdeal[j], 2) | |
| } | |
| separationIdeal[i] = math.Sqrt(sumIdeal) | |
| separationNegative[i] = math.Sqrt(sumNegative) | |
| } | |
| return separationIdeal, separationNegative | |
| } | |
| func relativeCloseness(separationIdeal []float64, separationNegative []float64) []float64 { | |
| r := len(separationIdeal) | |
| relativeCloseness := make([]float64, r) | |
| for i := 0; i < r; i++ { | |
| relativeCloseness[i] = separationNegative[i] / (separationIdeal[i] + separationNegative[i]) | |
| } | |
| return relativeCloseness | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment