A simple singular modularity index calculator in python3 [eng]

This small python3 script features a simple implementation of the Eq. (6) of the paper „Degree of Modularity in Engineering Systems and Products
with Technical and Business Constraints“.

The singular value decomposition is performed using the numpy library. Just input your matrix and run the script to get a brute-force minimization in the range of (0,10]. This may have to be adapted for larger matrices, but as the paper features no alpha values of over 6, it seemed like a fair choice to end at 10. As the minization is pretty fast, one could also choose maybe (0,100]. This is the result of a collaboration with David Bögelein from the Hochschule Ravensburg-Weingarten.

The script can directly be run in jupyter on any OS.

 


'''
Chris "VdoP" Regali, 2017

@package SMICalc
'''

import numpy as np
import math

s=np.array([0]);

def SMI(x):
    retVal=0.0
    for i in range(0,len(s)):
        retVal += abs(s[i]/s[0] - math.exp(-float(i)/x[0]))
        
    return retVal;

#Über-brutale minimierung, die dimensionalität ist klein - hier zu optimieren wäre quatsch
def bruteMin():
    alphaMin = 0.;
    currentMin = 1000000;
    for i in range(0,10000):
        currentAlpha = i/1000.+0.0001;
        currVal = SMI(np.array([currentAlpha]));
        if currVal < currentMin:
            currentMin = currVal;
            alphaMin = currentAlpha;
        
    print("Alpha",alphaMin);
    print("SMI",alphaMin/len(s));

a = np.matrix("""0 1 1 1 1 1 1 ;
                 1 0 1 1 1 1 1 ;
                 1 1 0 1 1 1 1 ;
                 1 1 1 0 1 1 1 ;
                 1 1 1 1 0 1 1 ;
                 1 1 1 1 1 0 1 ;
                 1 1 1 1 1 1 0
                 """);

            
U, s, V = np.linalg.svd(a, full_matrices=True);
#s ist die Sigma-Matrix aus dem Paper
print(s)

#jetzt suchen wir das minimum von alpha (argmin)
bruteMin();                    

print("Werte für Exponentialplot:")
for i in range(0,len(s)):
    print(s[i]/s[0]);

Schreibe einen Kommentar