-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Documenter.jl
committed
Oct 12, 2023
1 parent
f231f57
commit 8e1b784
Showing
15 changed files
with
1,118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.1.1 | ||
v0.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.1.1 | ||
v0.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"documenter":{"julia_version":"1.6.7","generation_timestamp":"2023-10-12T08:24:53","documenter_version":"1.1.1"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Readme · MiniObserve.jl</title><meta name="title" content="Readme · MiniObserve.jl"/><meta property="og:title" content="Readme · MiniObserve.jl"/><meta property="twitter:title" content="Readme · MiniObserve.jl"/><meta name="description" content="Documentation for MiniObserve.jl."/><meta property="og:description" content="Documentation for MiniObserve.jl."/><meta property="twitter:description" content="Documentation for MiniObserve.jl."/><script data-outdated-warner src="../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.050/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../search_index.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href="../">MiniObserve.jl</a></span></div><button class="docs-search-query input is-rounded is-small is-clickable my-2 mx-auto py-1 px-2" id="documenter-search-query">Search docs (Ctrl + /)</button><ul class="docs-menu"><li><a class="tocitem" href="../">Home</a></li><li class="is-active"><a class="tocitem" href>Readme</a><ul class="internal"><li><a class="tocitem" href="#Usage"><span>Usage</span></a></li><li><a class="tocitem" href="#Example"><span>Example</span></a></li><li><a class="tocitem" href="#Additional-parameters"><span>Additional parameters</span></a></li><li><a class="tocitem" href="#Statistics"><span>Statistics</span></a></li></ul></li><li><a class="tocitem" href="../obs/">Observation</a></li><li><a class="tocitem" href="../stats/">Stats Accumulators</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><a class="docs-sidebar-button docs-navbar-link fa-solid fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Readme</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Readme</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/mhinsch/MiniObserve.jl" title="View the repository on GitHub"><span class="docs-icon fa-brands"></span><span class="docs-label is-hidden-touch">GitHub</span></a><a class="docs-navbar-link" href="https://github.com/mhinsch/MiniObserve.jl/blob/main/docs/src/README.md" title="Edit source on GitHub"><span class="docs-icon fa-solid"></span></a><a class="docs-settings-button docs-navbar-link fa-solid fa-gear" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-article-toggle-button fa-solid fa-chevron-up" id="documenter-article-toggle-button" href="javascript:;" title="Collapse all docstrings"></a></div></header><article class="content" id="documenter-page"><h1 id="MiniObserve.jl"><a class="docs-heading-anchor" href="#MiniObserve.jl">MiniObserve.jl</a><a id="MiniObserve.jl-1"></a><a class="docs-heading-anchor-permalink" href="#MiniObserve.jl" title="Permalink"></a></h1><p>Minimalist (and minimally intrusive) macro set for extracting information from complex objects.</p><p>Given a complex object <code>MiniObserve</code> lets you generate functions to extract and print information from that object by means of a simple declarative interface. It can for example be used to extract information from a simulation model at each time step and write that information to a file.</p><p>Using MiniObserve has several advantages over hand-written analysis code:</p><ul><li>a concise declarative interface that puts all information in one place</li><li>output variables are declared once and output is automatically formatted correctly => adding and removing output variables becomes much less error-prone</li><li>a lot of tedious, repetitive and thus brittle code can be avoided</li></ul><h2 id="Usage"><a class="docs-heading-anchor" href="#Usage">Usage</a><a id="Usage-1"></a><a class="docs-heading-anchor-permalink" href="#Usage" title="Permalink"></a></h2><p>Most of the heavy lifting is done by the <code>@observe</code> macro:</p><pre><code class="language-Julia hljs">@observe(statstype, model [, user_arg1...], declarations)</code></pre><p>It will generate a custom data type to hold the desired information and an overload of the <code>observe</code> function that - given a model object - will calculate the information and return a data object.</p><h2 id="Example"><a class="docs-heading-anchor" href="#Example">Example</a><a id="Example-1"></a><a class="docs-heading-anchor-permalink" href="#Example" title="Permalink"></a></h2><p>As a simple example, let us assume we have the following <code>@observe</code> declaration:</p><pre><code class="language-Julia hljs">@observe Data model user1 user2 begin | ||
@record "time" model.time | ||
@record "N" Int length(model.population) | ||
|
||
@for ind in model.population begin | ||
@stat("capital", MaxMinAcc{Float64}, MeanVarAcc{FloatT}) <| ind.capital | ||
@stat("n_alone", CountAcc) <| has_neighbours(ind) | ||
end | ||
|
||
@record u1 user1 | ||
@record u2 user1 * user2 | ||
end</code></pre><p>Then a type <code>Data</code> will be generated that provides (at least) the following members:</p><pre><code class="language-Julia hljs">struct Data | ||
time :: Float64 | ||
N :: Int | ||
capital :: @NamedTuple{max :: Float64, min :: Float64, mean :: Float64, var :: Float64} | ||
n_alone :: @NamedTuple{N :: Int} | ||
u1 :: Float64 | ||
u2 :: Float64 | ||
end</code></pre><p>Now we can call <code>observe</code> to obtain a data object filled with the corresponding values:</p><pre><code class="language-Julia hljs">m = Model() | ||
data = observe(Data, m, 1, 2)</code></pre><p>And use <code>print_header</code> and <code>log_results</code> (both exported from MiniObserve) to print the content of that data object to a CSV file or a stream:</p><pre><code class="language-Julia hljs">print_header(stdout, Data) | ||
log_results(stdout, data)</code></pre><h2 id="Additional-parameters"><a class="docs-heading-anchor" href="#Additional-parameters">Additional parameters</a><a id="Additional-parameters-1"></a><a class="docs-heading-anchor-permalink" href="#Additional-parameters" title="Permalink"></a></h2><p>Note that <code>@observe</code> can take arbitrarily many parameters. Of these only the first two (the name of the data type and a model) and the last (the declaration itself) are required. All parameters between the second and the last are passed through unchanged and can for example be used to print additional information that is not part of the model object. </p><p>In fact there is nothing preventing a user from using <code>@observe</code> on several complex objects at the same time by for example passing two different model objects to <code>observe</code>.</p><h2 id="Statistics"><a class="docs-heading-anchor" href="#Statistics">Statistics</a><a id="Statistics-1"></a><a class="docs-heading-anchor-permalink" href="#Statistics" title="Permalink"></a></h2><p>An important part of MiniObserve is the ability to analyse collections of items by funneling them through "accumulator" objects. This is particularly important for models that operate on populations of objects, such as agent-based or individual-based models.</p><p>In the example above this is used in the expression</p><pre><code class="language-Julia hljs"> @for ind in model.population begin | ||
@stat("capital", MaxMinAcc{Float64}, MeanVarAcc{FloatT}) <| ind.capital | ||
@stat("n_alone", CountAcc) <| has_neighbours(ind) | ||
end</code></pre><p>The code generated by the macro iterates through <code>model.population</code> and adds some properties of each element to several accumulators that calculate maximum, minimum, variance and mean or count the number of true predicate values, respectively.</p><p>A few simple accumulators are provided in <code>StatsAccumulator</code>. </p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Home</a><a class="docs-footer-nextpage" href="../obs/">Observation »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.1.1 on <span class="colophon-date" title="Thursday 12 October 2023 08:24">Thursday 12 October 2023</span>. Using Julia version 1.6.7.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
Oops, something went wrong.