Reference 〉 Function

Data.agentReporter(keystr, primstrNone, breedstrNone, goodstrNone, statstr'mean', percentileslist[int][], stdfloatNone)

Generates a reporter function that takes the model object and returns a summary statistic over all the values of an agent property.

Parameters

  • key str, required

    The name of the agent property the generated function should summarize.

  • prim str, optional

    The agent primitive whose properties should be gathered. A value of None will select the first primitive in order, usually 'agent' unless that primitive has been removed or reordered.

    Default value: None

  • breed str, optional

    Whether to limit the statistic to a particular breed.

    Default value: None

  • good str, optional

    The good argument can be used to specify a dict key if the property is a dict of values rather than a numeric value itself. For example, because agent.stocks is a dict, the good name would need to be specified here in order to return inventories of a specific good.

    Default value: None

  • stat str, optional

    The summary statistic to be reported. Possible values are 'mean', 'sum', 'gmean' (for geometric mean), 'std' (for standard deviation), or 'percentile-nn', where nn is a number from 0-100. (Note this last option would be to record only the percentile statistic. Percentiles can be drawn alongside a main statistic using the following argument)

    Default value: 'mean'

  • percentiles list[int], optional

    Augments the reporter with percentiles corresponding to the list values. If drawn using TimeSeriesPlot.addSeries, the percentiles will show as lighter and dotted lines on the same plot alongside the main series, or as error bars if drawn using Chart.addBar and if there are two list items. The percentiles will also be recorded as new columns in the data with the same name, postfixed by -nn-pctile.

    Default value: []

  • std float, optional

    Augments the reporter with two additional reporters for the mean ± some multiple of the standard deviation. If drawn using TimeSeriesPlot.addSeries, the bounds will be drawn as lighter and dotted lines on the same plot alongside the main series, or as error bars if drawn using Chart.addBar.

    Default value: None

Return Value func(Model)|tuple(func(model),list[func])

A function that takes the model object and returns a numeric value, or a tuple with the first element being such a function, and the second being a list of subplot functions (e.g. for percentiles or ± standard deviations).

Notes and Examples

  1. charwick

    Mar 23, 2020 at 3:17

    This example generates a reporter for aggregate expected consumption and average target real balances for each breed, and passes it to data.addReporter().

    for breed in heli.primitives['agent']['breeds']:
    	econsReporter = heli.data.agentReporter('expCons', 'agent', breed=breed, stat='sum')
    	heli.data.addReporter('eCons-'+breed, econsReporter)
    
    	rbalReporter = heli.data.agentReporter('realBalances', 'agent', breed=breed)
    	heli.data.addReporter('rBal-'+breed, rbalReporter)

    This example generates reporters for average inventories of each registered good, across all breeds of the 'store' primitive, along with 25th and 75th percentiles that will draw along with it if the registered reporter is passed to model.addSeries().

    for good in heli.goods.nonmonetary:
    	goodReporter = heli.data.agentReporter('stocks', 'store', good=good, percentiles=[25,75])
    	heli.data.addReporter('inv-'+good, goodReporter)
  2. charwick

    Mar 23, 2020 at 3:25

    Functions generated by agentReporter do not have to be used exclusively with data.addReporter(). In fact, they can be used anywhere a live value for an aggregate statistic is needed. Note however that iterating over many agents multiple times each period is computationally expensive, so it may be wise to pull the already-aggregated variable from data.getLast() instead if the reporter is being collected already, and if a live value is not needed.

    This example creates a property of the model object that uses an agent reporter to tally up the quantity of the monetary good existing in the model economy. Note that a reporter always takes one argument, the model object, which is passed to the generated function in order to return the value of the reporter rather than the reporter function.

    def M0(self):
    	return self.data.agentReporter('stocks', 'all', good=self.moneyGood, stat='sum')(self)
    heli.M0 = property(M0)
  3. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.

History