swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] Basic Swarm to HDF5 question


From: Kerimcan Ozcan
Subject: Re: [Swarm-Support] Basic Swarm to HDF5 question
Date: Sat, 8 Sep 2007 19:30:10 -0700 (PDT)

Dear Marcus,

Thanks so much for the crystal-clear tutorial and
illustration. I am very grateful for your prompt
response too. Now I can go on programming happily on a
bright Sunday. :-)

Kerimcan

--- "Marcus G. Daniels" <address@hidden> wrote:

> Hi Kerimcan,
> > I want to create my experimental
> > parameters and variable values (some agent
> variable
> > values) in R. These parameters and variable values
> > will be in the form of several vectors (e.g. a
> vector
> > for the age of each agent) and matrices (e.g. a
> social
> > network matrix) of possibly different types
> (integer,
> > double, character etc.). Then I will save them as
> one
> > HDF5 file (so that one file contains all
> > parameters/variable values for one experimental
> > configuration). Then I will read that file from
> within
> > SWARM.
> >   
> Ok, here's how I'd do it.  First thing to note is
> that the Swarm 
> reader/writer wants to work in objects. 
> To make an object in R is just making a named list
> referencing your 
> vectors:
> 
>  expData <- list(pars=pars,net=net)
> 
> .. and then attaching a `type' attribute to that
> object.   The Swarm 
> reader will use that type name to be the object name
> to instantiate.
> 
>  attr(expData,"type") <- "ExpData"
> 
> Then it's just a matter of having `ExpData' ready on
> the Swarm end with 
> the methods you want.  Actually you don't need to
> make this class at 
> all, if you are willing to use probes to read and
> write its values.
> 
> [fyi, HDF5, the `objects' are stored as HDF5 groups
> and the fields 
> (either scalars, vectors, or matrices) are stored as
> HDF5 datasets.
> The R attributes, e.g. `type' are stored as HDF5
> attributes on the group.]
> 
> Marcus
> > library(hdf5)
> 
> pars <- rnorm(10)
> net <- rnorm(100)
> dim(net) <- c(10,10)
> 
> expData <- list(pars=pars,net=net)
> attr(expData,"type") <- "ExpData"
> 
> print(pars)
> print(net)
> 
> hdf5save("sup-ex.hdf","expData")
> > #import <simtools.h> // initSwarm
> #import <objectbase.h> // VarProbe
> #import <defobj.h> // Archiver
> 
> #import <objectbase/SwarmObject.h>
> 
> @interface ExpData: SwarmObject
> 
> {
>   double pars[10];
>   double net[10][10];
> }
> - print;
> @end
> 
> @implementation ExpData
> - print
> {
>   unsigned i, j;
> 
>   printf ("pars:");
>   for (i = 0; i < 10; i++)
>     printf (" %.3f", pars[i]);
> 
>   printf ("\n\nnet:\n");
>   for (i = 0; i < 10; i++) {
>     for (j = 0; j < 10; j++)
>       printf (" %.3f", net[i][j]);
>     printf ("\n");
>   }
> }
> @end
> 
> int
> main (int argc, const char **argv)
> {
>   id <Archiver> archiver;
>   id item;
> 
>   initSwarmBatch (argc, argv);
> 
>   archiver = [[[HDF5Archiver createBegin:
> globalZone]
>                  setPath: "sup-ex.hdf"]
>              createEnd];
> 
>   printf ("Getting object\n");
>   item = [archiver getObject: "expData"];
>   printf ("`%s'\n", [item getName]);
>   [item print];
> }
> /*
> Local Variables:
> compile-command: "$HOME/packages/bin/libtool-swarm
> --mode=link gcc -I$HOME/packages/include -o test -g
> -Wno-import test.m -L$HOME/packages/lib -lswarm"
> End:
> */
> > _______________________________________________
> Support mailing list
> address@hidden
> http://www.swarm.org/mailman/listinfo/support
> 



       
____________________________________________________________________________________
Sick sense of humor? Visit Yahoo! TV's 
Comedy with an Edge to see what's on, when. 
http://tv.yahoo.com/collections/222


reply via email to

[Prev in Thread] Current Thread [Next in Thread]