Reference 〉Function

Data.addReporter( str key, func(Model) func, int smooth = None )

Registers a column in the data to be collected each period. Typically used in conjunction with the various reporter methods of the Data class, but open-ended 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 graphing. 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

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.