Reference 〉 Function

Data.addReporter(keystr, funcfunc(Model), smoothintNone)

Registers a column in the data to be collected each period. Typically used in conjunction with the various reporter methods of Data, but user functions can also be used with the @reporter decorator.

Parameters

  • key str, required

    A unique name to refer to the column.

  • func func(Model), required

    A reporter function (such as one generated by data.modelReporter() or data.agentReporter()) that takes one argument, the model object, and returns a value to be entered in that period's row of the column.

  • smooth int, optional

    Replaces the series with a decaying average for the purposes of visualization. Higher values smooth the data more strongly. The original data is recorded in a new column with the same name but postfixed with -unsmooth.

    Default value: None

Return Value Reporter

The newly created Reporter object. This object can also be accessed after the fact at model.data.reporters[key].

Notes and Examples

  1. charwick

    Aug 06, 2020 at 4:50

    Often reporter functions can be generated automatically. This line uses Data.agentReporter() to generate a reporter function that saves the average of the 'wage' property of 'store'-primitive agents to the 'wage' column of the data.

    heli.data.addReporter('wage', heli.data.agentReporter('wage', 'store'))

    Reporters can also be lambda functions.

    heli.data.addReporter('ngdp', lambda model: model.cb.ngdp)

    Or regular functions (though in this case, the @reporter decorator is typically easier).

    def hsum(model):
    	upop = model.agent('urban')
    	return sum([a.H for a in model.agent('urban')]) if len(upop) > 0 else 1
    heli.data.addReporter('hsum', hsum)
  2. 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