Exemplo n.º 1
0
def chiFun(k1,k2):
    rr.reset()
    rr.setValue("k1", k1)
    rr.setValue("k2", k2)          
    data = rr.simulate(timeStart, timeEnd, nrPoints - 1)            
    chiSquare.ModelData = tel.getDataSeries(data)
    
    if not chiSquare.execute():
        raise Exception( tel.getLastError() )
           
    return chiSquare.ReducedChiSquare                   
    chiSquare.ExperimentalData = expData
    chiSquare.NrOfModelParameters = 1

    ptn = 0
    kStart = 0.3
    kEnd = 1.5
    kStep = .01
    for k in np.arange(kStart, kEnd, kStep):
        rr.setValue("k1", k)
        rr.reset()
        timeStart = 0
        timeEnd = 1.5
        nrPoints = 15

        data = rr.simulate(timeStart, timeEnd, nrPoints - 1)
        chiSquare.ModelData = tel.getDataSeries(data)
        if not chiSquare.execute():
            raise Exception(tel.getLastError())

        redChi = chiSquare.ReducedChiSquare
        print 'ptn, k, chisquare = ' + ` ptn ` + ', ' + ` k ` + ', ' + ` redChi `
        x = np.append(x, k)
        y = np.append(y, redChi)
        ptn = ptn + 1

    plt.subplot(1, 3, 1)
    plt.plot(x, y, '-o', label="Reduced ChiSquare")
    plt.legend()
    plt.xlabel("k1")
    plt.ylabel("ChiSquare")
 kEnd = 2.5
 kStep = .01
 
 #Sweep the k value
 for k in np.arange(kStart, kEnd, kStep):      
       
     rr.setValue("k1", k)   
     rr.reset()
     #Simulate using the same numbers as in the 'Experimental' data
     data = rr.simulate(0,10,14)
     #roadrunner.plot(data)
 
     #Get chi square plugin and set it up
     chiSquare =  tel.Plugin("tel_chisquare")    
     chiSquare.ExperimentalData = expData
     chiSquare.ModelData = tel.getDataSeries(data)
     chiSquare.NrOfModelParameters = 1
 
     #Calculate the Chi Square
     chiSquare.execute()        
            
     redChi = chiSquare.ReducedChiSquare               
     print  'k, Reduced Chisquare = ' + `k` +', '+  `redChi` 
     x = np.append(x, k) 
     y = np.append(y, redChi)         
 
 plt.plot(x,y, '-o', label="Reduced ChiSquare")
 plt.legend()
 plt.xlabel("k1")
 
 plt.show()
Exemplo n.º 4
0
    chiPlugin = tel.Plugin("tel_chisquare")

    #Retrieve a SBML model from plugin
    modelPlugin = tel.Plugin("tel_test_model")
    test_model = modelPlugin.Model

    # Create a roadrunner instance and create some data
    rr = roadrunner.RoadRunner()
    rr.load(test_model)
    data = rr.simulate(0, 10, 15000)

    #Add noise to the data
    noisePlugin = tel.Plugin("tel_add_noise")

    # Get the dataseries from data returned by roadrunner
    d = tel.getDataSeries(data)

    # Assign the dataseries to the plugin inputdata
    noisePlugin.InputData = d

    # Set parameter for the 'size' of the noise
    noisePlugin.Sigma = 3.e-6

    # Add the noise
    noisePlugin.execute()
    fName = 'testData3.dat'
    noisePlugin.InputData.writeDataSeries(fName)
    #===================================================================

    lmPlugin = tel.Plugin("tel_levenberg_marquardt")
    experimentalData = tel.DataSeries.readDataSeries(fName)
Exemplo n.º 5
0
    chiPlugin   = tel.Plugin("tel_chisquare")

    #Retrieve a SBML model from plugin        
    modelPlugin= tel.Plugin("tel_test_model")        
    sbmlModel= modelPlugin.Model   

    # Create a roadrunner instance and create some data
    rr = roadrunner.RoadRunner()
    rr.load(sbmlModel)
    data = rr.simulate(0, 10, 15)

    #Add noise to the data
    noisePlugin = tel.Plugin ("tel_add_noise")

    # Get the dataseries from data returned by roadrunner
    d = tel.getDataSeries (data)

    # Assign the dataseries to the plugin inputdata
    noisePlugin.InputData = d

    # Set parameter for the 'size' of the noise
    noisePlugin.Sigma = 8.e-6

    # Add the noise
    noisePlugin.execute()
    fName = 'testData3.dat'
    noisePlugin.InputData.writeDataSeries (fName)
    #=========== FIT DATA =============================================

    lm = tel.Plugin ("tel_levenberg_marquardt")
    experimentalData = tel.DataSeries.readDataSeries (fName)