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) krui.deleteUnitList(newunit) krui.saveNet("tmp.net", "testnet") print "finished"
print "Unit 1 has successor", succ[0], print "with link strength", succ[1] num = krui.getNextSuccUnit()[0] while num : print "Next successor:", num num = krui.getNextSuccUnit()[0] print "Deleting a few links" krui.getFirstSuccUnit(9) krui.deleteLink() krui.getFirstSuccUnit(1) krui.getNextSuccUnit() krui.deleteAllInputLinks() krui.getNextSuccUnit() krui.deleteAllOutputLinks() krui.saveNet('foo.net','Testnet') print krui.getLearnFunc() #krui.setLearnFunc('RBF-DDA') print krui.getInitialisationFunc() print krui.getUpdateFunc() patset = krui.loadNewPatterns('encoder.pat') print "Patternset", patset, "loaded." print "Old pattern number:", krui.getPatternNo() # fiddle around with some patterns krui.setPatternNo(8) krui.deletePattern() krui.setPatternNo(5) krui.modifyPattern() krui.setPatternNo(7) krui.showPattern(krui.OUTPUT_OUT) krui.newPattern()
print "Unit 1 has successor", succ[0], print "with link strength", succ[1] num = krui.getNextSuccUnit()[0] while num: print "Next successor:", num num = krui.getNextSuccUnit()[0] print "Deleting a few links" krui.getFirstSuccUnit(9) krui.deleteLink() krui.getFirstSuccUnit(1) krui.getNextSuccUnit() krui.deleteAllInputLinks() krui.getNextSuccUnit() krui.deleteAllOutputLinks() krui.saveNet('foo.net', 'Testnet') print krui.getLearnFunc() #krui.setLearnFunc('RBF-DDA') print krui.getInitialisationFunc() print krui.getUpdateFunc() patset = krui.loadNewPatterns('encoder.pat') print "Patternset", patset, "loaded." print "Old pattern number:", krui.getPatternNo() # fiddle around with some patterns krui.setPatternNo(8) krui.deletePattern() krui.setPatternNo(5) krui.modifyPattern() krui.setPatternNo(7) krui.showPattern(krui.OUTPUT_OUT) krui.newPattern()
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) krui.deleteUnitList(newunit) krui.saveNet("tmp.net","testnet") print "finished"
krui.setCurrentUnit(num) for src in hidden: krui.createLink(src, 0) print "Creating patterns" krui.deleteAllPatterns() patset = krui.allocNewPatternSet() for unum in range(8): for curnum in range(8): for row in inputs, outputs: krui.setUnitActivation(row[curnum], curnum == unum) krui.newPattern() krui.initializeNet(-1, 1) krui.shufflePatterns(1) krui.DefTrainSubPat() print "Training" i = 0 while i < 50000: res = krui.learnAllPatterns(0.2, 0) if not i % 5000: print "Error in learning cycle %d:" % i, res[0] i = i + 1 print "Writing pyencoder.pat" krui.saveNewPatterns('pyencoder.pat', patset) print "Writing pyencoder.net" krui.saveNet('pyencoder.net', 'pyencoder')
krui.setCurrentUnit(num) for src in hidden : krui.createLink(src,0) print "Creating patterns" krui.deleteAllPatterns() patset = krui.allocNewPatternSet() for unum in range(8) : for curnum in range(8) : for row in inputs, outputs : krui.setUnitActivation(row[curnum], curnum == unum) krui.newPattern() krui.initializeNet(-1,1) krui.shufflePatterns(1) krui.DefTrainSubPat() print "Training" i=0 while i < 50000 : res = krui.learnAllPatterns(0.2,0) if not i % 5000 : print "Error in learning cycle %d:" % i, res[0] i = i + 1 print "Writing pyencoder.pat" krui.saveNewPatterns('pyencoder.pat',patset) print "Writing pyencoder.net" krui.saveNet('pyencoder.net','pyencoder')
# druhá fáze (jemnìj¹í) i=0 while i < pruch_2: res = krui.learnAllPatterns(0.03, 0.1) if not i % 100 : print "Fáze 2, chyba v cyklu %d:" % i, res[0] i = i + 1 print "Rekonstruuji pùvodní obrázek" im.blank() for p in xrange(krui.getNoOfPatterns()): krui.setPatternNo(p + 1) krui.showPattern(1); krui.updateNet() block = [] for u in xrange(64 + 16 + 1, 64 * 2 + 16 + 1): block.append(real2pix(krui.getUnitActivation(u))) im.setBlock(p, block) print "Zapisuji výsledný obrázek na disk" im.store("compressed.rgb") print "Vytváøím soubor vzorkù pro SNNS" krui.saveNewPatterns('image.pat', patset) print "Vytváøím soubor sítì pro SNNS" krui.saveNet('image.net','image') # konec