You might also want to think about using BitVectors to store the 
information about whether a person was infected, vaccinated, or deceased 
(which would take only 3 bits per person), and then you could easily 
perform operations to find out the number of people infected, etc. using 
the bit vectors.

On Saturday, June 4, 2016 at 10:48:29 AM UTC-4, Christopher Fisher wrote:
>
> Thank you for your help. 
>
> So my basic goal is to be able to perform operations on the individual and 
> population level. In this case, population.infected would return an 
> Array{Int64,1} indicating which individuals in the population are infected. 
> For example, population.infected[1]  = 1 would indicate the first 
> individual is infected. Something like mean(population.infected .== 1) 
> would indicate the percentage infected in the population. Similarly, if I 
> queried population[1], this would allow me to inspect all of the properties 
> assigned to individual 1. 
>
> Does that make sense?
>
> On Saturday, June 4, 2016 at 10:26:52 AM UTC-4, Ford Ox wrote:
>>
>> Could you please specify what should population.infected return? Could 
>> you provide an interface?
>>
>> Right now it seems like you want something like this:
>>
>> type Individual end
>>
>> type Population
>>     individuals::Vector{Individual}
>> end
>>
>> setindex!(p::Population, i::Individual, index...) = p.individuals[index
>> ...] = i
>> getindex(p::Population, index) = p.individuals[index]
>> infected(i::Individual) = i.infected
>> vaccinated(i::Individual) = i.vaccinated
>>
>> Usage:
>> population[index] = Individual() # set new individual
>> infected(population[index])      # gets the infected property of 
>> individual at index
>> vaccinated(population[index])    # ...
>>
>> But you don't really need functions for these things...
>>
>>
>> On Saturday, June 4, 2016 at 2:19:02 PM UTC+2, Christopher Fisher wrote:
>>>
>>> I was wondering if someone would be willing to help me with creating 
>>> user-defined types. I've been using Julia for about two years now but I am 
>>> new to the idea of creating custom types. I'm trying to create a population 
>>> of agents/individuals in a simple epidemiological simulation. I would like 
>>> the population of individuals to be structured as a  2 dimensional array 
>>> with rows as individuals and columns as properties. This would be somewhat 
>>> similar to a DataFrame, but potentially more flexible. I want to be able to 
>>> index an individual like so: population[1]. This woud list all of the 
>>> information for individual 1.  I would also like to be able to look at an 
>>> attribute across individuals: population.infected or population[:infected]. 
>>> At the same time, I would like to have to flexibility of using an array to 
>>> keep track of individuals: typeof(population.history[1]) is Array{Int64,1}. 
>>> Based on existing documentation and examples, I have only been able to 
>>> create individuals but cannot figure out how to create a population as 
>>> described above:
>>>
>>> type Person
>>>     infected::Int64
>>>     vaccinated::Int64
>>>     dead::Int64
>>>    history::Array{Int64,1}
>>> end
>>>
>>> Any help would be greatly appreciated. 
>>>
>>

Reply via email to