def create_aspfile(FnameCSV, FnameASP, TemplateClassifier, TemplateObjective): params_classifier = interfaces.templates.read_classifier( TemplateClassifier) params_objective = interfaces.templates.read_objective(TemplateObjective) CLASSIFIER_SCRIPT.csv2asp( FnameCSV=FnameCSV, FnameASP=FnameASP, LowerBoundInputs=params_classifier['LowerBoundInputs'], UpperBoundInputs=params_classifier['UpperBoundInputs'], LowerBoundGates=params_classifier['LowerBoundGates'], UpperBoundGates=params_classifier['UpperBoundGates'], GateTypes=params_classifier['GateTypes'], EfficiencyConstraint=params_objective['EfficiencyConstraint'], OptimizationStrategy=params_objective['OptimizationStrategy'], BreakSymmetries=params_objective['BreakSymmetries'], Silent=True, UniquenessConstraint=params_objective['UniquenessConstraint'], PerfectClassifier=params_objective['PerfectClassifier'], UpperBoundFalsePos=params_objective['UpperBoundFalsePos'], UpperBoundFalseNeg=params_objective['UpperBoundFalseNeg'])
def create_asp_prog(input_file, config_file_name): """ Function to create ASP program. Parameters ---------- input_file : str name of input train data file config_file_name : str name of constraint file Returns ------- instance : str ASP instance program : str ASP program """ config_file = configparser.ConfigParser() config_file.read(config_file_name) FnameCSV = input_file FnameASP = input_file.replace(".csv", ".asp") GateTypes = [] GateType1 = { "LowerBoundPos": int(config_file['GATE SPECIFICATION']['GateType1_LowerBoundPos']), "LowerBoundNeg": int(config_file['GATE SPECIFICATION']['GateType1_LowerBoundNeg']), "UpperBoundPos": int(config_file['GATE SPECIFICATION']['GateType1_UpperBoundPos']), "UpperBoundNeg": int(config_file['GATE SPECIFICATION']['GateType1_UpperBoundNeg']), "UpperBoundOcc": int(config_file['GATE SPECIFICATION']['GateType1_UpperBoundOcc']), } GateType2 = { "LowerBoundPos": int(config_file['GATE SPECIFICATION']['GateType2_LowerBoundPos']), "LowerBoundNeg": int(config_file['GATE SPECIFICATION']['GateType2_LowerBoundNeg']), "UpperBoundPos": int(config_file['GATE SPECIFICATION']['GateType2_UpperBoundPos']), "UpperBoundNeg": int(config_file['GATE SPECIFICATION']['GateType2_UpperBoundNeg']), "UpperBoundOcc": int(config_file['GATE SPECIFICATION']['GateType2_UpperBoundOcc']), } GateTypes = [GateType1, GateType2] instance, program = \ classifier.csv2asp(fname_csv=FnameCSV, fname_asp=FnameASP, lower_bound_inputs=int(config_file['CLASSIFIER CONSTRAINTS']['LowerBoundInputs']), upper_bound_inputs=int(config_file['CLASSIFIER CONSTRAINTS']['UpperBoundInputs']), lower_bound_gates=int(config_file['CLASSIFIER CONSTRAINTS']['LowerBoundGates']), upper_bound_gates=int(config_file['CLASSIFIER CONSTRAINTS']['UpperBoundGates']), gate_types=GateTypes, efficiency_constraint=config_file.getboolean('OPTIONAL', 'EfficiencyConstraint'), optimization_strategy=int(config_file['OPTIMIZATION']['OptimizationStrategy']), break_symmetries=config_file.getboolean('OPTIONAL', 'BreakSymmetries'), silent=config_file.getboolean('OPTIONAL', 'Silent'), uniqueness_constraint=config_file.getboolean('CLASSIFIER CONSTRAINTS', 'UniquenessConstraint'), boolean_function_form=int(config_file['CLASSIFIER CONSTRAINTS']['BooleanFunctionForm']), perfect_classifier=config_file.getboolean('ERROR CONSTRAINTS', 'PerfectClassifier'), add_bounds_on_errors=config_file.getboolean('ERROR CONSTRAINTS', 'AddBoundsOnErrors'), upper_bound_false_pos=int(config_file['ERROR CONSTRAINTS']['UpperBoundFalsePos']), upper_bound_false_neg=int(config_file['ERROR CONSTRAINTS']['UpperBoundFalseNeg'])) instance = "\n".join(instance) program = "\n".join(program) return instance, program
import sys sys.path = ["../"] + sys.path import classifier if __name__=="__main__": if 0 : classifier.check_csv(FnameCSV) classifier.csv2asp(FnameCSV, FnameASP, LowerBoundInputs, UpperBoundInputs, LowerBoundGates, UpperBoundGates, GateTypes, EfficiencyConstraint, OptimizationStrategy, BreakSymmetries, Silent, UniquenessConstraint, PerfectClassifier, UpperBoundFalsePos, UpperBoundFalseNeg ) if 1 : # basel classifier GateInputs = "gate_input(1,negative,g7) gate_input(2,negative,g6) gate_input(3,negative,g4) gate_input(4,negative,g3) " GateInputs+= "gate_input(5,positive,g1) gate_input(5,positive,g2) gate_input(5,positive,g8) " GateInputs+= "gate_input(6,positive,g1) gate_input(6,positive,g5) gate_input(6,positive,g8)" classifier.check_classifier(FnameCSV, GateInputs)
OptimizationStrategy = 1 BreakSymmetries = True import sys sys.path = ["../"] + sys.path import classifier if __name__=="__main__": if 1 : classifier.csv2asp( FnameCSV, FnameASP, LowerBoundInputs, UpperBoundInputs, LowerBoundGates, UpperBoundGates, GateTypes, EfficiencyConstraint, OptimizationStrategy, BreakSymmetries) if 1 : GateInputs = "gate_input(1,negative,g5) gate_input(2,negative,g4) gate_input(3,negative,g3) gate_input(4,negative,g2) " GateInputs+= "gate_input(5,positive,g1) gate_input(5,positive,g6) " GateInputs+= "gate_input(6,positive,g1) gate_input(6,positive,g7)" classifier.check_classifier(FnameCSV, GateInputs) if 0 : GateInputs = "gate_input(2,positive,g2) gate_input(1,negative,g1)" FnamePDF = "toy_classifier.pdf"
"LowerBoundNeg": 0, "UpperBoundNeg": 1, "UpperBoundOcc": 4 }] EfficiencyConstraint = True OptimizationStrategy = 1 BreakSymmetries = True import sys sys.path = ["../"] + sys.path import classifier if __name__ == "__main__": if 1: classifier.csv2asp(FnameCSV, FnameASP, LowerBoundInputs, UpperBoundInputs, LowerBoundGates, UpperBoundGates, GateTypes, EfficiencyConstraint, OptimizationStrategy, BreakSymmetries) if 1: GateInputs = "gate_input(1,negative,g8) gate_input(2,negative,g7) gate_input(3,negative,g6) gate_input(4,negative,g6) " GateInputs += "gate_input(5,positive,g1) gate_input(5,positive,g2) gate_input(5,positive,g3) " GateInputs += "gate_input(6,positive,g1) gate_input(6,positive,g3) gate_input(6,positive,g4)" classifier.check_classifier(FnameCSV, GateInputs) if 0: GateInputs = "gate_input(2,positive,g2) gate_input(1,negative,g1)" FnamePDF = "toy_classifier.pdf" classifier.gateinputs2pdf(FnamePDF, GateInputs) if 0: FnameMAT = "casestudy01.mat"
UpperBoundFalseNeg = 0 import classifier if __name__=="__main__": if 1: classifier.csv2asp( FnameCSV, FnameASP, LowerBoundInputs, UpperBoundInputs, LowerBoundGates, UpperBoundGates, GateTypes, EfficiencyConstraint, OptimizationStrategy, BreakSymmetries, Silent, UniquenessConstraint, PerfectClassifier, UpperBoundFalsePos, UpperBoundFalseNeg) if 1: GateInputs = "gate_input(1,positive,g2) gate_input(2,positive,g3) gate_input(2,negative,g1)" classifier.check_classifier(FnameCSV, GateInputs) if 1: GateInputs = "gate_input(1,positive,g2) gate_input(2,positive,g3) gate_input(2,negative,g1)" Fname = "toy.pdf"