def hopfield_energy_view(request): schema = SchemaHopfieldEnergy() myform = Form(schema, buttons=('submit',)) js_tags, css_tags = get_resources(request, myform) result = {'title': u"Hopfield računanje energije", "js_tags": js_tags, "css_tags": css_tags, "hopfield_energy": True} appstruct = { 'vhod': [[1, 1, -1, -1]], 'utez': [[0, 1, 0, -2], [1, 0, -2, 0], [0, -2, 0, -3], [-2, 0, -3, 0]] } if 'submit' in request.POST: controls = request.POST.items() try: appstruct = myform.validate(controls) #print appstruct nn = Hopfield(text_output=[]) nn.weight_matrix = appstruct['utez'] #nn.calc_energy(appstruct['vhod'], appstruct['multiply']) nn.calc_energy(appstruct['vhod']) result["text_izhod"] = nn.text_output #print appstruct except ValidationFailure, e: result['form'] = e.render() return result except Exception, e: #print e request.ext.flash_error(unicode(e), title="Napaka pri podatkih") result["form"] = myform.render(appstruct=appstruct) return result
def hopfield_view(request): schema = SchemaHopfield() myform = Form(schema, buttons=('submit',)) js_tags, css_tags = get_resources(request, myform) result = {'title': u"Hopfield", "js_tags": js_tags, "css_tags": css_tags, "hopfield": True} appstruct = { 'utez': [[0, 1, -1], [1, 0, 1], [-1, 1, 0]] } if 'submit' in request.POST: controls = request.POST.items() try: appstruct = myform.validate(controls) #print appstruct nn = Hopfield(appstruct['function_type'], text_output=[]) nn.weight_matrix = appstruct['utez'] nn.get_stable_states() result["tabela"] = nn.table result["text_izhod"] = nn.text_output #print appstruct except ValidationFailure, e: result['form'] = e.render() return result except Exception, e: #print e request.ext.flash_error(unicode(e), title="Napaka pri podatkih") result["form"] = myform.render(appstruct=appstruct) return result