import teplugins as tel p = tel.Plugin("tel_add_noise") data = tel.DataSeries.readDataSeries("testData.dat") data.plot() p.InputData = data p.Sigma = 0.00005 print 'Sigma is now:' + ` p.Sigma ` p.execute() p.InputData.plot()
try: #Read some 'experimental' data expData = tel.DataSeries() #This does not look right.. but it works.. expData = expData.readDataSeries('ExperimentalData.dat') test_model = 'two_parameters.xml' # Create a roadrunner instance and create some MODEL data rr = roadrunner.RoadRunner() rr.load(test_model) #Get chi square plugin and set it up chiSquare = tel.Plugin("tel_chisquare") chiSquare.ExperimentalData = expData chiSquare.NrOfModelParameters = 2 k1 = 1.3; k2 = 2.5 timeStart = 0; timeEnd = 1.5 ; nrPoints = 15 eta = 6.0e-6 H = np.matrix('0.0 0.0; 0.0 0.0') #Diagonal elements H[0,0] = getHessElement(1, 1, k1, k2, eta) H[0,1] = getHessElement(1, 2, k1, k2, eta) H[1,0] = getHessElement(2, 1, k1, k2, eta) H[1,1] = getHessElement(2, 2, k1, k2, eta)
#------------------------------------------------------------------------------- # Purpose: Example demonstrating how to calculate the ChiSquare, using the # ChiSquare plugin, as a function of a model parameter. # Author: Totte Karlsson ([email protected]) #------------------------------------------------------------------------------- import roadrunner import numpy as np import matplotlib.pyplot as plt import teplugins as tel try: # Config.setValue(Config.LOADSBMLOPTIONS_CONSERVED_MOIETIES, False) # Config.setValue(Config.SIMULATEOPTIONS_STRUCTURED_RESULT, True) noisePlugin = tel.Plugin("tel_add_noise") modelPlugin = tel.Plugin("tel_test_model") test_model = modelPlugin.Model modelPlugin.execute() #Use the testModel plugins property TestDataWithNoise as the 'Experimental' data expData = modelPlugin.TestDataWithNoise # Create a roadrunner instance and create some MODEL data rr = roadrunner.RoadRunner() rr.load(test_model) #Create variables to be used in the loop x = np.array([]) y = np.array([]) kStart = 0.1
#------------------------------------------------------------------------------- # Purpose: Example demonstrating how to access and plot various statistics from # a fitting session, e.g. RESIDUALS, STANDARDIZED RESIDUALS and # NORMAL PROBABILITY OF RESIDUALS (Q-Q plot) # # Author: Totte Karlsson ([email protected]) #------------------------------------------------------------------------------- import roadrunner import numpy as np import matplotlib.pyplot as plt import teplugins as tel from roadrunner import Config try: Config.setValue(Config.LOADSBMLOPTIONS_CONSERVED_MOIETIES, False) Config.setValue(Config.SIMULATEOPTIONS_STRUCTURED_RESULT, True) 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)
import ctypes import teplugins as tel #Get a lmfit plugin object chiPlugin = tel.Plugin("tel_chisquare") lm = tel.Plugin("tel_levenberg_marquardt") #========== EVENT FUNCTION SETUP =========================== def pluginIsProgressing(lmP): # The plugin don't know what a python object is. # We need to cast it here, to a proper python object lmObject = ctypes.cast(lmP, ctypes.py_object).value print 'Iterations = ' + `lmObject.getProperty("NrOfIter")` \ + '\tNorm = ' + `lmObject.getProperty("Norm")` try: progressEvent = tel.NotifyEventEx(pluginIsProgressing) #The ID of the plugin is passed as the last argument in the assignOnProgressEvent. #The plugin ID is later on retrieved in the plugin Event handler, see above theId = id(lm) tel.assignOnProgressEvent(lm.plugin, progressEvent, theId) #============================================================ #Retrieve a SBML model from plugin test_model = tel.readAllText('two_parameters.xml') #Setup lmfit properties. lm.SBML = test_model
import numpy as np import matplotlib.pyplot as plt import teplugins as tel def firstDerivative(p2, p1, h): return (p2 - p1) / (2.0*h) try: #Read some 'experimental' data expData = tel.DataSeries() #This does not look right.. but it works.. expData = expData.readDataSeries('ExperimentalData.dat') #Get a model modelPlugin = tel.Plugin("tel_test_model") test_model = modelPlugin.Model # Create a roadrunner instance and create some MODEL data rr = roadrunner.RoadRunner() rr.load(test_model) #Simulate using the same numbers as in the 'Experimental data x = np.array([]) y = np.array([]) #Get chi square plugin and set it up chiSquare = tel.Plugin("tel_chisquare") chiSquare.ExperimentalData = expData chiSquare.NrOfModelParameters = 1
#------------------------------------------------------------------------------- # Purpose: Example demonstrating how to setup and use the TestModel plugin # This example also shows how to plot data and how to view a plugins # embedded manual # # Author: Totte Karlsson ([email protected]) #------------------------------------------------------------------------------- import teplugins as tel try: modelPlugin = tel.Plugin("tel_test_model") #Test model plugin depends on the add_noise plugin noisePlugin = tel.Plugin("tel_add_noise") #Generate internal test data modelPlugin.execute() test_data = modelPlugin.TestData test_data_with_noise = modelPlugin.TestDataWithNoise test_data.plot() test_data_with_noise.plot() #modelPlugin.viewManual() print 'Plugin version: ' + ` modelPlugin.getVersion() ` except Exception as e: print 'Problem: ' + ` e `
import ctypes import teplugins as tel #Get a lmfit plugin object chiPlugin = tel.Plugin("tel_chisquare") lm = tel.Plugin("tel_levenberg_marquardt") #========== EVENT FUNCTION SETUP =========================== def pluginIsProgressing(lmP): # The plugin don't know what a python object is. # We need to cast it here, to a proper python object lmObject = ctypes.cast(lmP, ctypes.py_object).value print 'Iterations = ' + `lmObject.getProperty("NrOfIter")` \ + '\tNorm = ' + `lmObject.getProperty("Norm")` try: progressEvent = tel.NotifyEventEx(pluginIsProgressing) #The ID of the plugin is passed as the last argument in the assignOnProgressEvent. #The plugin ID is later on retrieved in the plugin Event handler, see above theId = id(lm) tel.assignOnProgressEvent(lm.plugin, progressEvent, theId) #============================================================ #Retrieve a SBML model from plugin modelPlugin = tel.Plugin("tel_test_model") test_model = modelPlugin.Model #Setup lmfit properties. lm.SBML = test_model
import teplugins as tel try: p = tel.Plugin('tel_AddPlugin') p.x = 1.2 p.y = 3.6 print p.execute() print p.z except Exception as e: print e
import roadrunner import teplugins as tel try: #Retrieve test 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, 511) roadrunner.plot(data) print "done" except Exception as e: print 'Problem: ' + ` e `
import ctypes import teplugins as tel #Get a nmfit plugin object chiPlugin = tel.Plugin("tel_chisquare") nm = tel.Plugin("tel_nelder_mead") #========== EVENT FUNCTION SETUP =========================== def pluginIsProgressing(nmP): # The plugin don't know what a python object is. # We need to cast it here, to a proper python object nmObject = ctypes.cast(nmP, ctypes.py_object).value print 'Iterations = ' + `nmObject.getProperty("NrOfIter")` \ + 'FuncIterations = ' + `nmObject.getProperty("NrOfFuncIter")` \ + '\tNorm = ' + `nmObject.getProperty("Norm")` try: progressEvent = tel.NotifyEventEx(pluginIsProgressing) #The ID of the plugin is passed as the last argument in the assignOnProgressEvent. #The plugin ID is later on retrieved in the plugin Event handler, see above theId = id(nm) tel.assignOnProgressEvent(nm.plugin, progressEvent, theId) #============================================================ #Retrieve a SBML model from plugin modelPlugin = tel.Plugin("tel_test_model") test_model = modelPlugin.Model #Setup nmfit properties.