print "Loadnet:" try: headline("general kernel information") funcnum = krui.getNoOfFunctions() print "Available functions:" for i in range(funcnum)[1:] : params = krui.getFuncInfo(i) print "Function:", params[0], print " Type: ", print util.func_types[params[1] & krui.FUNC_TYPE_MASK], print " i/o params: ", print krui.getFuncParamInfo(params[0],params[1]) headline("some fixed dimension example (encoder.*)") net = krui.loadNet("encoder.net") print "Net loaded: " + net print krui.getMemoryManagerInfo() print "Number of input units:", krui.getNoOfTTypeUnits(krui.INPUT) print "Number of output units:", krui.getNoOfOutputUnits() print "Total number of units:", krui.getNoOfUnits() print "Number of special input units:", krui.getNoOfSpecialInputUnits() print krui.getNetInfo() print krui.getSymbolTable() if krui.setFirstFTypeEntry() : print "First prototype name:", krui.getFTypeName() else : print "No prototypes found." krui.createFTypeEntry("myftype","Act_Identity","Out_Identity") if krui.setFirstFTypeEntry() : print "New prototype defined:", krui.getFTypeName()
oldnum = krui.getNoOfFunctions() print "Builtin functions:", oldnum util.registerFunction(outtestfunc, "outtestfunc", krui.OUT_FUNC, 0, 0) util.registerFunction(outtestfunc2, "outtestfunc2", krui.OUT_FUNC, 0, 0) util.registerFunction(acttest, "acttest", krui.ACT_FUNC, 0, 0) util.registerFunction(actderivtest, "acttest", krui.ACT_DERIV_FUNC, 0, 0) util.registerFunction(actderiv2test, "acttest", krui.ACT_2_DERIV_FUNC, 0, 0) newnum = krui.getNoOfFunctions() print "After adding:", newnum for num in range(oldnum - 2, newnum + 1): print "Function number", num, "Info:", krui.getFuncInfo(num) print krui.loadNet('encoder.net') for num in [1, 10, 19]: krui.setUnitOutFunc(num, "outtestfunc") for num in [2, 11, 18]: krui.setUnitOutFunc(num, "outtestfunc2") for num in [3, 9, 17]: krui.setUnitActFunc(num, "acttest") krui.loadNewPatterns('encoder.pat') krui.DefTrainSubPat() print "Learning one pattern" krui.learnSinglePattern(1, (0.2, 0)) krui.setUnitDefaults(1.0, 0, krui.INPUT, 0, 1, "acttest", "outtestfunc") newunit = krui.createDefaultUnit() print "New unit:", newunit print "Act func name:", krui.getUnitActFuncName(newunit)
print "Loadnet:" try: headline("general kernel information") funcnum = krui.getNoOfFunctions() print "Available functions:" for i in range(funcnum)[1:]: params = krui.getFuncInfo(i) print "Function:", params[0], print " Type: ", print util.func_types[params[1] & krui.FUNC_TYPE_MASK], print " i/o params: ", print krui.getFuncParamInfo(params[0], params[1]) headline("some fixed dimension example (encoder.*)") net = krui.loadNet("encoder.net") print "Net loaded: " + net print krui.getMemoryManagerInfo() print "Number of input units:", krui.getNoOfTTypeUnits(krui.INPUT) print "Number of output units:", krui.getNoOfOutputUnits() print "Total number of units:", krui.getNoOfUnits() print "Number of special input units:", krui.getNoOfSpecialInputUnits() print krui.getNetInfo() print krui.getSymbolTable() if krui.setFirstFTypeEntry(): print "First prototype name:", krui.getFTypeName() else: print "No prototypes found." krui.createFTypeEntry("myftype", "Act_Identity", "Out_Identity") if krui.setFirstFTypeEntry(): print "New prototype defined:", krui.getFTypeName()
#!/usr/bin/python # shows the coordinates of the winner neurons for the som_cube example from snns import krui, util krui.loadNet('som_cube.net') krui.loadNewPatterns('som_cube.pat') patnum = krui.getNoOfPatterns() units = krui.getNoOfUnits() for pat in range(1,patnum+1) : krui.setPatternNo(pat) krui.showPattern(krui.OUTPUT_NOTHING) krui.updateNet(()) results = [] for unit in range(1,units+1) : if krui.getUnitTType(unit) == krui.HIDDEN : results.append((krui.getUnitActivation(unit),unit)) bestact, bestunit = min(results) rawpos = krui.getUnitPosition(bestunit)[:2] print "Pattern", pat, "Act", bestact, "Unit", bestunit, print "Grid Position", (rawpos[0]-4, rawpos[1])
oldnum = krui.getNoOfFunctions() print "Builtin functions:", oldnum util.registerFunction(outtestfunc,"outtestfunc",krui.OUT_FUNC,0,0) util.registerFunction(outtestfunc2,"outtestfunc2",krui.OUT_FUNC,0,0) util.registerFunction(acttest,"acttest",krui.ACT_FUNC,0,0) util.registerFunction(actderivtest,"acttest",krui.ACT_DERIV_FUNC,0,0) util.registerFunction(actderiv2test,"acttest",krui.ACT_2_DERIV_FUNC,0,0) newnum = krui.getNoOfFunctions() print "After adding:", newnum for num in range(oldnum - 2, newnum + 1) : print "Function number", num, "Info:",krui.getFuncInfo(num) print krui.loadNet('encoder.net') for num in [1,10,19] : krui.setUnitOutFunc(num,"outtestfunc") for num in [2,11,18] : krui.setUnitOutFunc(num,"outtestfunc2") for num in [3,9,17] : krui.setUnitActFunc(num,"acttest") krui.loadNewPatterns('encoder.pat') krui.DefTrainSubPat() print "Learning one pattern" krui.learnSinglePattern(1,(0.2,0)) krui.setUnitDefaults(1.0,0,krui.INPUT,0,1,"acttest","outtestfunc") newunit = krui.createDefaultUnit() print "New unit:", newunit print "Act func name:", krui.getUnitActFuncName(newunit)