Beispiel #1
0
 def initialiseSystem(self, locationofconnections, locationofstates, numberofruns,partialcorrelation=False):
     """This method should create the orignal gain matrix (incl dummy gains)
     and the original connection matrix"""
     if partialcorrelation is False:
         original = localgains(locationofconnections, locationofstates, numberofruns)
         self.originalgain = original.linlocalgainmatrix
         self.originaln =original.n #number of rows or columns of gain matrix
         self.variablelist = original.variables
         self.originaldiff = original.localdiffmatrix
         self.originalconnection = original.connectionmatrix
     else:
         original = localgains(locationofconnections, locationofstates, numberofruns,partialcorrelation)
         self.originalgain = original.partialcorrelationmatrix
         self.variablelist = original.variables
         self.originalconnection = original.connectionmatrix
 def testLGC4x4(self):
     
     testOne = localgains("testOneConnections.csv","testOneIG.txt",4)
     expectedLocalGains = [0,0,0,0, 0,0,0,0, 2,5,0,0, 3,7,0,0]
     
     for element1, element2 in zip(expectedLocalGains, testOne.linlocalgainmatrix.flat):
         self.assertAlmostEquals(element1,element2,5)
 def testLGC7x7(self):
     #this test has 2 recycle streams and 2 inputs
     testThree = localgains("testThreeConnections.csv","testThreeIG.txt",5)
     
     expectedLocalGains = [0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 1,0,0,0,11,0,0, 0,1,0,0,0,13,0, 0,0,2,5,0,0,0, 0,0,3,7,0,0,0, 0,0,0,0,19,17,0 ]
     
     for element1, element2 in zip(expectedLocalGains, testThree.linlocalgainmatrix.flat):
         self.assertAlmostEquals(element1,element2,2) #this one is not very accurate... relatively speaking
    def testLGC4x4(self):

        testOne = localgains("testOneConnections.csv", "testOneIG.txt", 4)
        expectedLocalGains = [0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 0, 0, 3, 7, 0, 0]

        for element1, element2 in zip(expectedLocalGains,
                                      testOne.linlocalgainmatrix.flat):
            self.assertAlmostEquals(element1, element2, 5)
 def testLGC9x9(self):
     #this test has 1 recycle stream and 3 inputs
     #due to an earlier irregularity with variable assigning testfour = testtwo
     #i will talk to you about this... it could potentially be a problem
     testTwo = localgains("testFourConnections.csv","testFourIG.txt",5)
     expectedLocalGains = [0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0,0, 0,1,0,0,0,0,0,11,0, 0,0,1,0,0,0,0,0,0, 0,0,0,2,3,0,0,0,0, 0,0,0,0,7,5,0,0,0, 0,0,0,0,0,0,13,17,0]
     
     for element1, element2 in zip(expectedLocalGains, testTwo.linlocalgainmatrix.flat):
         self.assertAlmostEquals(element1,element2,1) #this one is not very accurate... relatively speaking
Beispiel #6
0
 def initialiseSystem(self,
                      locationofconnections,
                      locationofstates,
                      numberofruns,
                      partialcorrelation=False):
     """This method should create the orignal gain matrix (incl dummy gains)
     and the original connection matrix"""
     if partialcorrelation is False:
         original = localgains(locationofconnections, locationofstates,
                               numberofruns)
         self.originalgain = original.linlocalgainmatrix
         self.originaln = original.n  #number of rows or columns of gain matrix
         self.variablelist = original.variables
         self.originaldiff = original.localdiffmatrix
         self.originalconnection = original.connectionmatrix
     else:
         original = localgains(locationofconnections, locationofstates,
                               numberofruns, partialcorrelation)
         self.originalgain = original.partialcorrelationmatrix
         self.variablelist = original.variables
         self.originalconnection = original.connectionmatrix
    def testLGC7x7(self):
        #this test has 2 recycle streams and 2 inputs
        testThree = localgains("testThreeConnections.csv", "testThreeIG.txt",
                               5)

        expectedLocalGains = [
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 11, 0, 0, 0,
            1, 0, 0, 0, 13, 0, 0, 0, 2, 5, 0, 0, 0, 0, 0, 3, 7, 0, 0, 0, 0, 0,
            0, 0, 19, 17, 0
        ]

        for element1, element2 in zip(expectedLocalGains,
                                      testThree.linlocalgainmatrix.flat):
            self.assertAlmostEquals(
                element1, element2,
                2)  #this one is not very accurate... relatively speaking
    def testLGC9x9(self):
        #this test has 1 recycle stream and 3 inputs
        #due to an earlier irregularity with variable assigning testfour = testtwo
        #i will talk to you about this... it could potentially be a problem
        testTwo = localgains("testFourConnections.csv", "testFourIG.txt", 5)
        expectedLocalGains = [
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 11,
            0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0,
            0, 7, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 17, 0
        ]

        for element1, element2 in zip(expectedLocalGains,
                                      testTwo.linlocalgainmatrix.flat):
            self.assertAlmostEquals(
                element1, element2,
                1)  #this one is not very accurate... relatively speaking
Beispiel #9
0
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 14 23:52:18 2012

@author: St Elmo Wilken
"""
""" This should test the recycle """
"""All the imports"""
from RGABristol import RGA
from gainRank import gRanking
from localGainCalculator import localgains
import networkx as nx
import matplotlib.pyplot as plt
from numpy import array, transpose
"""Test system one: pairings should be obvious"""
localdata = localgains("btest3.csv", "btest3.txt", 3)
G = nx.DiGraph()
connectionmatrix = localdata.connectionmatrix
localgainmatrix = localdata.linlocalgainmatrix
variablenames = localdata.variables
localgaindict = dict()
"""Displays the causality with calculated local gains"""
for u in range(localdata.n):
    for v in range(localdata.n):
        if (connectionmatrix[u, v] == 1):
            G.add_edge(variablenames[v], variablenames[u])
            localgaindict[(variablenames[u],
                           variablenames[v])] = localgainmatrix[u, v]

posdict = {
    variablenames[0]: array([0, 5]),
Beispiel #10
0
"""

"""System Description:
    This is a simple 2 input 2 output system"""

"""All the imports"""
from RGABristol import RGA
from gainRank import gRanking
from localGainCalculator import localgains
import networkx as nx
import matplotlib.pyplot as plt
from numpy import array, transpose


"""Test system one: pairings should be obvious"""
localdata = localgains("btest1.csv","btest1ObviousConnections.txt",3)
G = nx.DiGraph()
connectionmatrix = localdata.connectionmatrix
localgainmatrix = localdata.linlocalgainmatrix 
variablenames = localdata.variables
localgaindict = dict()
"""Displays the causality with calculated local gains"""
for u in range(localdata.n):
    for v in range(localdata.n):
        if (connectionmatrix[u,v]==1):
            G.add_edge(variablenames[v], variablenames[u])
            localgaindict[(variablenames[u],variablenames[v])] = localgainmatrix[u,v]
posdict = {variablenames[0]: array([1,1]), variablenames[1]: array([1,2]), variablenames[2]: array([4,1]), variablenames[3]: array([4,2])} #position dictionary
plt.figure(1)
plt.subplot(311)
plt.suptitle("RGA Implementation",size='x-large')
Beispiel #11
0
@author: St Elmo Wilken
"""

"""This system tests a 2 input 3 measured variable system and tries to fix the eigenvector approach"""

"""All the imports"""
from RGABristol import RGA
from gainRank import gRanking
from localGainCalculator import localgains
import networkx as nx
import matplotlib.pyplot as plt
from numpy import array, transpose


"""Test system one: pairings should be obvious"""
localdata = localgains("btest2fix.csv","btest2GreedyConnectionsfix.txt",3)
G = nx.DiGraph()
connectionmatrix = localdata.connectionmatrix
localgainmatrix = localdata.linlocalgainmatrix 
variablenames = localdata.variables
localgaindict = dict()
"""Displays the causality with calculated local gains"""
for u in range(localdata.n):
    for v in range(localdata.n):
        if (connectionmatrix[u,v]==1):
            G.add_edge(variablenames[v], variablenames[u])
            localgaindict[(variablenames[u],variablenames[v])] = localgainmatrix[u,v]
posdict = {variablenames[0]: array([0.5,2]), variablenames[1]: array([0.5,1]), variablenames[2]: array([7,2]), variablenames[3]: array([7,1]), variablenames[4]: array([10,1.5]), variablenames[5]: array([0.5,3]), variablenames[6]: array([0.5,0]), variablenames[7]: array([7,3]), variablenames[8]: array([7,0])} #position dictionary

plt.figure(1)
plt.subplot(311)
Beispiel #12
0
@author: St Elmo Wilken
"""

""" This should test the recycle """

"""All the imports"""
from RGABristol import RGA
from gainRank import gRanking
from localGainCalculator import localgains
import networkx as nx
import matplotlib.pyplot as plt
from numpy import array, transpose


"""Test system one: pairings should be obvious"""
localdata = localgains("btest3.csv","btest3.txt",3)
G = nx.DiGraph()
connectionmatrix = localdata.connectionmatrix
localgainmatrix = localdata.linlocalgainmatrix 
variablenames = localdata.variables
localgaindict = dict()
"""Displays the causality with calculated local gains"""
for u in range(localdata.n):
    for v in range(localdata.n):
        if (connectionmatrix[u,v]==1):
            G.add_edge(variablenames[v], variablenames[u])
            localgaindict[(variablenames[u],variablenames[v])] = localgainmatrix[u,v]

posdict = {variablenames[0]: array([0,5]),
            variablenames[1]: array([0,2]),
            variablenames[2]: array([4,5]),
Beispiel #13
0
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 26 23:24:42 2012

@author: St Elmo Wilken
"""

from localGainCalculator import localgains
from gainRank import gRanking
from RGABristol import RGA
import numpy as np

import matplotlib.pyplot as plt

test1 = localgains("testFourConnections.csv", "testFourIG.txt", 5)
gainm = test1.normaliseGainMatrix(test1.linlocalgainmatrix)
varm = test1.variables
googlem = test1.normaliseGainMatrix(test1.connectionmatrix)
test2 = gRanking(googlem, varm)

#print(test2.sortedRankingsKey)
#print(test2.sortedRankingsValue)
#test2.showConnectRank()

localdiffsm = test1.localdiffmatrix
test3 = RGA(varm, localdiffsm, 5, 3) #remember to change me for each case!!!
#print(test3.pairedvariables)
haha = test3.bristolmatrix
print(haha)
#print(test3.openloopmatrix)
np.savetxt("rgatest.txt",haha)
Beispiel #14
0
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 11 00:07:50 2012

@author: St Elmo Wilken
"""

from localGainCalculator import localgains
from gainRank import gRanking
from RGABristol import RGA
import numpy as np
from numpy import array, zeros

test1 = localgains("connectionsTE.csv", "scaledinputs005h5.txt", 13)
gainm = test1.normaliseGainMatrix(test1.linlocalgainmatrix)
varm = test1.variables
googlem = test1.normaliseGainMatrix(test1.connectionmatrix)

test2 = gRanking(gainm, varm)

test2.showConnectRank()
gainnc = array(test2.rankArray).reshape(-1, 1)

test2 = gRanking(googlem, varm)
test2.showConnectRank()

googlenc = array(test2.rankArray).reshape(-1, 1)

rationc = array(gainnc / googlenc).reshape(-1, 1)
"""**************"""
Beispiel #15
0
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 11 00:07:50 2012

@author: St Elmo Wilken
"""

from localGainCalculator import localgains
from gainRank import gRanking
from RGABristol import RGA
import numpy as np
from numpy import array, zeros

test1 = localgains("connectionsTE.csv", "scaledinputs005h5.txt", 13)
gainm = test1.normaliseGainMatrix(test1.linlocalgainmatrix)
varm = test1.variables
googlem = test1.normaliseGainMatrix(test1.connectionmatrix)

test2 = gRanking(gainm, varm)

test2.showConnectRank()
gainnc = array(test2.rankArray).reshape(-1,1)

test2 = gRanking(googlem, varm)
test2.showConnectRank()

googlenc = array(test2.rankArray).reshape(-1,1)

rationc = array(gainnc/googlenc).reshape(-1,1)

"""**************"""