def run(): # specify input: name_database = 'perturbation_example.sqlite' ID_model = 30 # all inputs specified db = Database.Analysis(name_database) model = db.readModel() partargets = db.export(ID_model)[0] db.close() #print partargets print 'Model ', ID_model, ' from ', name_database, ' represented by logical expressions for all pairs of component and target value:' for comp in model.components: localpars = [] for par in model.parameters: if par.owner.name == comp.name: localpars.append(par) localvars = [c[0].name for c in localpars[0].context.items()] localmax = [c[0].max for c in localpars[0].context.items()] localindex = dict( zip([c[0] for c in localpars[0].context.items()], range(len(localvars)))) LF = Logicfun(localvars, localmax) # a list with truthtables for all values for all components (all empty now): ttbls = [[] for c in xrange(comp.max + 1)] # now check for every state (cmpltt contains all) which parameters are active for i, bstate in enumerate(LF.cmpltt): for lpar in localpars: for r in lpar.context.items( ): # check the context, r[0] is the regulator, # r[1] the values, where it is active # if one regulator is not active, parameter cant be neither, so break if not ((i // LF.levprod[localindex[r[0]]]) % LF.nlevs[localindex[r[0]]]) in r[1]: break else: # if instead all regulators are active this state is #added to the truthtable of the parameter ttbls[partargets[lpar]].append(bstate) #print LF.cmpltt #print TTbls print '\nTarget values of ', comp.name, ' and their conditions:' for j, v in enumerate(ttbls): # now the truthtables are translated to minimal DNFs primecov = LF.minimise(v) #get a prime cover expr = LF.writeexpr2( primecov, 'brackets') # get a explicit expression of the minimal DNF print comp.name, '-> %d : ' % j, expr
def run(): Db_name = 'Carbon.sqlite' Restriction = '' db = Database.Analysis(Db_name) db.select(Restriction) selected = db.count() print print 'Analysis of parameter values' print ' -finds values common to all parametrizations' print ' -finds value ranges of all parameters' print model = db.readModel() model.info() print print 'Database name: ', "'" + Db_name + "'" print 'Restriction: ', "'" + Restriction + "'" print 'Models in database: ', db.size print 'Models selected: ', selected cps = Parser.Interface(model) print print 'Ranges of parameter values:' for comp in model.components: print comp for p in comp.parameters: sql = 'SELECT DISTINCT ' + str( p ) + ' FROM Parametrizations WHERE ' + Database.SELECTION + '=1' db.cur.execute(sql) values = sorted([str(row[str(p)]) for row in db.cur]) print(' %s:' % p).ljust(15) + ','.join(values) db.close()
def run(Parameters): Db_name = Parameters['Db_name'] Restriction = Parameters['Restriction'] Property_name = Parameters['Property_name'] Property_type = Parameters['Property_type'] Description = Parameters['Description'] TimeSeries = Parameters['TimeSeries'] Monotony = Parameters['Monotony'] print print 'Annotation by Saschas A*-graph traversal' print ' -checks a time series with monotony spec' print db = Database.Modification(Db_name) if Property_name in db.property_names: print 'Property', Property_name, 'is reset.' db.reset(Property_name) db.close() db = Database.Analysis(Db_name) db.select(Restriction) selected = db.count() Model = db.readModel() db.close() Model.info() print print 'Database name: ', "'" + Db_name + "'" print 'Restriction: ', "'" + Restriction + "'" print 'Models in database: ', db.size print 'Models selected: ', selected print 'Property name: ', Property_name print 'Time Series: ' for row in TimeSeries: print row print 'Monotony' for row in Monotony: print row db = Database.Annotation(Db_name) db.newProperty(Property_name, Property_type, Description) db.select(Property_name, Restriction) print print 'Starting annotations, please wait..' freqs = {'F': 0, 'T': 0} count = 0 walker = Walker(Model) walker.set_timeseries(TimeSeries, Monotony) param, labels, rowid = db.next() while param: count += 1 label = 'F' walker.set_parameterset(param) if walker.is_compatible(): label = 'T' db.label('rowid=%i' % rowid, label) freqs[label] += 1 param, labels, rowid = db.next() print '\rProgress: %2.3f%%' % (100. * count / selected), sys.stdout.flush() db.close() print print "Label 'T': ", freqs['T'] print "Label 'F': ", freqs['F'] print
def run(): Db_name = 'Carbon.sqlite' Property = 'SuperCoiling' Correlation_set = [] Restriction = '' Minimal = True print print print 'Analysis of Correlations' print ' -finds correlations between a property and a given correlation superset' print db = Database.Analysis(Db_name) if not db.property_names: print "No properties in DB '" + Db_name + "'", "please add annotations." db.close() return if not Property: print 'Please name the property you are interested in.' db.close() return if not Property in db.property_names: print 'Property ' + "'" + Property + "'", 'is not in', Db_name print 'Choose one of', ','.join(db.property_names) db.close() return for p in Correlation_set: if not p in db.property_names: print 'Property', p, "is not in '" + Db_name + "', it is automatically removed from the analysis." Correlation_set = [ p for p in Correlation_set if p in db.property_names and p != Property ] if not Correlation_set: Correlation_set = list(db.property_names) Correlation_set.remove(Property) if len(Correlation_set) < 2: print 'Correlation set, currently', Correlation_set, 'must contain at least two properties, please add some.' db.close() return db.select(Restriction) selected = db.count() model = db.readModel() model.info() print print 'Database name: ', "'" + Db_name + "'" print 'Restriction: ', "'" + Restriction + "'" print 'Models in database: ', db.size print 'Models selected: ', selected print 'Properties in DB: ', ','.join([n for n in db.property_names]) print 'Property: ', Property print 'Correlation superset: ', ','.join(Correlation_set) print 'Find minimal sets: ', Minimal print print 'Label coverage' for p in Correlation_set + [Property]: sql = p + ' IS NOT NULL' count = db.count(sql) print '%s %i (%2.1f%%)' % ( (' ' + p + ':').ljust(19), count, 100. * count / selected) #labels = db.labels(Properties1.union(Properties2), Selection=True) correlations = [] hit = False for r in range(2, len(Correlation_set) + 1): if hit and Minimal: break func = {} for C in IT.combinations(Correlation_set, r): props = C + (Property, ) sql = 'SELECT DISTINCT ' + ','.join( props ) + ' FROM Parametrizations WHERE ' + Database.SELECTION + '=1' db.cur.execute(sql) for row in db.cur: key = tuple([row[p] for p in C]) if key in func: if func[key] != row[Property]: func = {} break func[key] = row[Property] if func: hit = True correlations.append(sorted(C)) db.close() if correlations: print print 'Correlations:' for c in correlations: print ' ', Property, 'correlates with', '{' + ','.join(c) + '}' else: print print 'Found no correlations for', Property, 'in', Correlation_set print
def run(Parameters, verbose=-1): print "unstable, revise" raise Exception for key in Parameters: if not key in keywords: print ' ** Unknown parameter: "%s"' % key print ' Parameters must belong to:', ','.join(keywords) raise Exception Db_name = Parameters['Db_name'] Components = Parameters['Components'] Interactions = Parameters['Interactions'] Constraint = Parameters['Constraint'] Model = Models.Interface(Components, Interactions) if verbose > -1: Model.info() if os.path.isfile(Db_name): if 1: os.remove(Db_name) Database.New(Db_name, Model) else: Database.New(Db_name, Model) cps = Parser.Interface(Model) cps.parse(Constraint) db = Database.Instantiation(Db_name) db.newProperty(Property_name, 'int') roots = 0 for params in cps.solutions(): roots += 1 db.insert(params, {Property_name: 0}) for depth in range(1, Perturbation_depth + 1): for perturbed in itertools.combinations(Model.parameters, depth): options = [] for p in perturbed: options.append( [i for i in p.range if abs(i - params[p]) == 1]) for choice in itertools.product(*options): items = zip(perturbed, choice) new_params = dict(params.items() + items) db.insert(new_params, {Property_name: depth}) db.close() db = Database.Analysis(Db_name) size = db.size - roots db.close() if verbose > -1: print print '---Perturbations of a pool defined by CP' print 'Created database: ', "'" + Db_name + "'" print 'Perturbation depth: ', Perturbation_depth print 'Perturbation name in DB: ', "'" + Property_name + "'" print 'Constraint: ', "'" + Constraint + "'" print 'Initial parametrizations: ', roots print 'Perturbed parametrizations: ', size