From: bagjohn <bag...@gm...> - 2017-02-03 13:49:30
|
I am trying to build a custom dataset. I need to define my datasources. I need to call functions that return not only single values from agents but also double[] arrays which I want then to process. The dataset editor does not let me do that. I ve seen previous posts <http://repast.10935.n7.nabble.com/Data-collection-without-GUI-wizard-td3051.html> mentioning the problem and tried to do what is mentioned in one of them <http://repast.10935.n7.nabble.com/Custom-Data-Source-Help-Repast-Smphony-2-1-td10373.html#a10376> : implement AggregateDataSource in my main agent class, where I want to retrieve data from. But I guess I don't do it right, because after I put my class name to the custom dataset editor line and press ADD i get (The class is not instantiated). So just to be sure: Let's say i have a class of agents Mouse.class (e.g. n is the number of mouses in the simulation in the current tick) and want to get a double[m] array from each one of them at every tick (m the dimension of the array retrieved from each agent), perform some operation on the complete double[n][m] array that represents the population of agents at every tick and return a double[m] array for the current tick. Do that for subsequent ticks and watch that array's evolution through time. So i have : public class Mouse implements AggregateDataSource And the interface methods are automatically created. Here is what I did on them : @Override public String getId() { // I just made up an id. Do I have to put something specific here? return "Mouse"; } @Override public Class<?> getDataType() { // I just return the datatype i will retrieve from each agent. Correct ? return double[].class; } @Override public Class<?> getSourceType() { // I just return the class this method is in, which is the same as the one from which the data will be retrieved. return Mouse.class; } @Override public double[] get(Iterable<?> context, int size) { // I do not really understand what to do here. My iterable will be the current context which i will scan for objects of type Mouse context = ContextUtils.getContext(this); List<double[]> Synapse_strengths_list = new ArrayList<double[]>(); while(context.iterator().hasNext()) { if (context.iterator().next() instanceof Mouse){ Object mouse = context.iterator().next(); Synapse_strengths_list.add(((Mouse) mouse).getSynapse_strength()); } } double[][] Synapse_strengths = new double[ Synapse_strengths_list.size()][]; Synapse_strengths_list.toArray(Synapse_strengths); double[] mean_synapse_strengths = new double[Synapse_strengths[0].length]; for (int j=0; j<Synapse_strengths[0].length; j++) { double sum = 0; for (int i=0; i<Synapse_strengths.length; i++){ sum = sum + Synapse_strengths[i][j]; } mean_synapse_strengths[j] = sum / Synapse_strengths.length; } return mean_synapse_strengths; } @Override public void reset() { // Do I do something here? } I guess my problem is this: Who calls these methods? What arguments should I put? And is it right to implement the AggregateDataSource on the agent class? Thank you Panos -- View this message in context: http://repast.10935.n7.nabble.com/Data-Source-instantiation-tp11871.html Sent from the repast-interest mailing list archive at Nabble.com. |