Simbrain Network in agent-based simulation

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Simbrain Network in agent-based simulation

bagjohn
Hello
I am trying to use simbrain networks for an agent based simulation.
I have created a network in simbrain and saved it in xml format.
I have a simulation written in java (repast simphony) and in each time step i want to do the following
-create a vector of doubles
-feed it to the network
-get output in a vector of doubles
In the next time step i want to use the same neural network with any updates already made.

I have already classpathed the simbrain.jar in my project in eclipse and i need to create a function like
function(Vector<Double> input, NeuralNetwork in xml)-> (Vector<Double> output, UpdatedNeuralNetwork) which will iterate the network once with the given input and return the updated version of the net (to use in the next time step) and the output vector.

Is there any way to achieve this?

Thanks

Panos
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Simbrain Network in agent-based simulation

jyoshimi
Administrator
Hi Panos,

You should be able to access the network from xml using something like this

Network newNetwork = (Network) Network.getXStream().fromXML(xmlFile);

Once you have a network object the rest of what you are doing should be straightforward.  You can consult the scripts for example code.

I'd suggest creating the network from xml somewhere else in your code, rather than repeatedly opening from xml every time you want to get an input / output pair.

- Jeff
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Simbrain Network in agent-based simulation

bagjohn
Hello Jeff and thanks for the immediate answer

I try to do it with the following simple class but it doesn't seem to work

import org.simbrain.network.core.Network;
public class test {
    public static void main(String[] args) {
        Network newNetwork = (Network) Network.getXStream().fromXML("Mousebrain.xml");
        }
}

Of course there is a Mousebrain.xml file in the same folder as he test.java
Also, the library is imported normally.

I get the following error message

Exception in thread "main" com.thoughtworks.xstream.io.StreamException:  : Content is not allowed in prolog.

Any help would be helpful, as I am far from expert on xml handling in Java

Thanks

Panos

PS1. The xml file starts with <org.simbrain.network.core.Network>. Is that normal?
PS2. Even if i retrieve the network, will i be able to update it and save it for the next iteration?


2017-01-30 21:11 GMT+02:00 jyoshimi [via Simbrain] <[hidden email]>:
Hi Panos,

You should be able to access the network from xml using something like this

Network newNetwork = (Network) Network.getXStream().fromXML(xmlFile);

Once you have a network object the rest of what you are doing should be straightforward.  You can consult the scripts for example code.

I'd suggest creating the network from xml somewhere else in your code, rather than repeatedly opening from xml every time you want to get an input / output pair.

- Jeff



If you reply to this email, your message will be added to the discussion below:
http://simbrain.963258.n4.nabble.com/Simbrain-Network-in-agent-based-simulation-tp4640460p4640461.html
To unsubscribe from Simbrain Network in agent-based simulation, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Simbrain Network in agent-based simulation

jyoshimi
Administrator
Hi there,

Could you try it on a simple network you create in simbrain first.  Also, have you confirmed that that xml file opens fine from Simbrain gui?

- Jeff
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Simbrain Network in agent-based simulation

bagjohn
Nope. It doesn't work.
Even the simplest network, saved in xml file, which opens normally via the Simbrain GUI, produces the same error when trying to read it using

Network newNetwork = (Network) Network.getXStream().fromXML(xmlFile);

Anyway, I decided to use the simbrain.jar as library and create the network from within eclipse, and that seems to work. I do not have access though to various classes (eg Neuron). Maybe you know how the whole source code could be accessible?

I was also thinking to use Simbrain the other way around. Maybe after creating a network in eclipse with simbrain.jar, i could load it on Simbrain through copying to bsh file? Maybe with some minor changes?

Thank you

Panos

2017-02-01 17:10 GMT+02:00 jyoshimi [via Simbrain] <[hidden email]>:
Hi there,

Could you try it on a simple network you create in simbrain first.  Also, have you confirmed that that xml file opens fine from Simbrain gui?

- Jeff


If you reply to this email, your message will be added to the discussion below:
http://simbrain.963258.n4.nabble.com/Simbrain-Network-in-agent-based-simulation-tp4640460p4640465.html
To unsubscribe from Simbrain Network in agent-based simulation, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Simbrain Network in agent-based simulation

jyoshimi
Administrator
Hi there,

Ok I created my own project and now I get the same error as you.   It seems to be some weird xstream bug.  To fix I had to deserialize the xml with a FileReader, like this

Network newNetwork = (Network) Network.getXStream().fromXML(new FileReader(FILE_NAME));

Then I was able to open the file from the command line.

Let me know if that works. If not I can post the simple test code I used.

- Jeff
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Simbrain Network in agent-based simulation

bagjohn
Yeap! It works!
Thanks a lot Jeff!

2017-02-11 0:05 GMT+02:00 jyoshimi [via Simbrain] <[hidden email]>:
Hi there,

Ok I created my own project and now I get the same error as you.   It seems to be some weird xstream bug.  To fix I had to deserialize the xml with a FileReader, like this

Network newNetwork = (Network) Network.getXStream().fromXML(new FileReader(FILE_NAME));

Then I was able to open the file from the command line.

Let me know if that works. If not I can post the simple test code I used.

- Jeff


If you reply to this email, your message will be added to the discussion below:
http://simbrain.963258.n4.nabble.com/Simbrain-Network-in-agent-based-simulation-tp4640460p4640468.html
To unsubscribe from Simbrain Network in agent-based simulation, click here.
NAML

Loading...