{"action":"created","issue":{"url":"https://api.github.com/repos/brian-team/brian2/issues/450","labels_url":"https://api.github.com/repos/brian-team/brian2/issues/450/labels{/name}","comments_url":"https://api.github.com/repos/brian-team/brian2/issues/450/comments","events_url":"https://api.github.com/repos/brian-team/brian2/issues/450/events","html_url":"https://github.com/brian-team/brian2/issues/450","id":69025898,"number":450,"title":"Problem calculating weight ","user":{"login":"ManuNeuro","id":11985689,"avatar_url":"https://avatars.githubusercontent.com/u/11985689?v=3","gravatar_id":"","url":"https://api.github.com/users/ManuNeuro","html_url":"https://github.com/ManuNeuro","followers_url":"https://api.github.com/users/ManuNeuro/followers","following_url":"https://api.github.com/users/ManuNeuro/following{/other_user}","gists_url":"https://api.github.com/users/ManuNeuro/gists{/gist_id}","starred_url":"https://api.github.com/users/ManuNeuro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManuNeuro/subscriptions","organizations_url":"https://api.github.com/users/ManuNeuro/orgs","repos_url":"https://api.github.com/users/ManuNeuro/repos","events_url":"https://api.github.com/users/ManuNeuro/events{/privacy}","received_events_url":"https://api.github.com/users/ManuNeuro/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-16T22:59:28Z","updated_at":"2015-04-17T09:16:15Z","closed_at":"2015-04-17T09:16:15Z","body":"Hello !\r\n\r\nFirstly, I would thank you for your potential help !\r\n\r\nI'm a french student, I'm pretty new on Github and Brian2, I got a problem and saw all the tuto that was available on the internet, and I'm still stuck on it...\r\n\r\nSo, the problem is : \r\n\r\nI have an image, and I want to use neurons group to do the segmentation...\r\n\r\n# So, I created a grid of neurons like this : \r\nG = NeuronGroup(rows * cols, '''x : 1\r\n                                y : 1''',eqs ,threshold= 'v > 5*mV', reset = 'v = 0*mV')\r\n\r\n# Then, initialize the grid positions\r\nG.x = 'int((i / rows) * grid_dist) '\r\nG.y = 'int((i % rows) * grid_dist) '\r\n\r\n# Here is my synaptic connections : \r\ndistance = 2\r\nS = Synapses(G, G,'w : volt',pre = 'v+=w')\r\nS.connect('sqrt((x_pre - x_post)**2 + (y_pre - y_post)**2) < distance')\r\n(I wanted all the neurons to be connected with his neighbors)\r\n\r\nNow, I want to create the weight associated with my synapse connections, using the following formula : \r\nw_max*(1-(1/(1+math.exp(-alpha))*(abs( image(i)) - image(j) +delta)))\r\n\r\nWhat I want, is to access to the pixel associated to the neuron at index 'i', and the same for 'j'\r\n\r\nBut when I do this : \r\nS.w = \"w_max*(1-(1/(1+math.exp(-alpha))*(abs( image(i)) - image(j) +delta)))\"\r\nit doesn't work, because the compiler can't access to an array, he needs scalar value.\r\n\r\nSo, I know that i could use a double \"for\" loop to calculate the weight, but i'll have to set up all the conditions at the border of the picture... \r\n\r\nHow tu use the easy computing of Brian ? I don't want to program like a 'c' program... \r\n\r\nWhat I tried is to use the \"image\" as a class, with the attribute \"pixel\", which can be access through 'index'\r\nclass onbjet_img:\r\n    \"\"\"Classe enveloppe d'un dictionnaire\"\"\"\r\n    def __init__(self):\r\n        \"\"\"Notre classe n'accepte aucun parametre\"\"\"\r\n        self.pixel = {}\r\n    def __getitem__(self, index):\r\n        \"\"\"Cette methode speciale est appelee quand on fait objet[index]\r\n        Elle redirige vers self._dictionnaire[index]\"\"\"\r\n        \r\n        return self.pixel[index]\r\n    def __setitem__(self, index, valeur):\r\n        \"\"\"Cette methode est appelee quand on ecrit objet[index] = valeur\r\n        On redirige vers self._dictionnaire[index] = valeur\"\"\"\r\n        \r\n        self.pixel[index] = valeur\r\n    \r\n#Creation de l'objet image\r\n\r\nimg = objet_img()\r\n\r\nfor i in xrange(len(image)):\r\n    img[i] = image[i]\r\n\r\nSo iI wanted to use a function which can give me the possibility to have a direct access to the scalar values\r\ndef accede_pixel(index):\r\n    return img.pixel[index]\r\n\r\nI wanted to use this ineasted : \r\nS.w = \"w_max*(1-(1/(1+math.exp(-alpha))*(abs( accede_pixel(i)) - accede_pixel(j) +delta)))\"\r\nBut it doesn't work anyhow...\r\n\r\n=> 'The identifier \"accede_pixel\" could not be resolved.'\r\n\r\nSo if someone could help me, it would be really appreciated :) I'm working on it since... I don't remember, i'm becoming crasy ! ahah"},"comment":{"url":"https://api.github.com/repos/brian-team/brian2/issues/comments/93949911","html_url":"https://github.com/brian-team/brian2/issues/450#issuecomment-93949911","issue_url":"https://api.github.com/repos/brian-team/brian2/issues/450","id":93949911,"user":{"login":"thesamovar","id":2903870,"avatar_url":"https://avatars.githubusercontent.com/u/2903870?v=3","gravatar_id":"","url":"https://api.github.com/users/thesamovar","html_url":"https://github.com/thesamovar","followers_url":"https://api.github.com/users/thesamovar/followers","following_url":"https://api.github.com/users/thesamovar/following{/other_user}","gists_url":"https://api.github.com/users/thesamovar/gists{/gist_id}","starred_url":"https://api.github.com/users/thesamovar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thesamovar/subscriptions","organizations_url":"https://api.github.com/users/thesamovar/orgs","repos_url":"https://api.github.com/users/thesamovar/repos","events_url":"https://api.github.com/users/thesamovar/events{/privacy}","received_events_url":"https://api.github.com/users/thesamovar/received_events","type":"User","site_admin":false},"created_at":"2015-04-17T09:16:15Z","updated_at":"2015-04-17T09:16:15Z","body":"Hi,\r\n\r\nCould you post this to our email list for brian2?\r\n\r\nhttps://groups.google.com/forum/#!forum/brian-development"}}