Personality generator: draws traits from a weighted catalogue, shaped by Big Five axes, conflicts and synergies.
More...
|
|
| trtg ()=default |
| | Default constructor — creates an empty generator with no data.
|
| |
|
| trtg (const trtg &)=delete |
| | Not copyable.
|
| |
|
trtg & | operator= (const trtg &)=delete |
| | Not copyable.
|
| |
|
| trtg (trtg &&) noexcept=default |
| | Movable.
|
| |
|
trtg & | operator= (trtg &&) noexcept=default |
| | Movable.
|
| |
|
| ~trtg ()=default |
| | Destructor.
|
| |
| personality | get_personality (const trait_request &request) |
| | Generate a random personality as requested. Use trait_request{} for three traits without constraints.
|
| |
| personality | get_personality (const trait_request &request, std::uint64_t call_seed) const |
| | Generate a deterministic personality as requested.
|
| |
| std::vector< personality > | get_personality_batch (const trait_request &request, const core::batch_options &options) |
| | Generate a batch of personality results from a seed drawn like get_personality() draws its own.
|
| |
| std::vector< personality > | get_personality_batch (const trait_request &request, const core::batch_options &options, std::uint64_t batch_seed) const |
| | Generate a batch of personality results, deterministically.
|
| |
| template<typename Sink > |
| void | for_each_personality (const trait_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const |
| | Stream a batch of personality results to a sink without holding the whole batch.
|
| |
| template<typename Sink > |
| void | for_each_personality (const trait_request &request, const core::batch_options &options, Sink &&sink) |
| | Stream a batch of personality results with a batch seed drawn like get_personality() draws its own.
|
| |
| bool | has_data () const |
| | Check whether any data has been loaded.
|
| |
| std::size_t | trait_count () const |
| | Return the number of loaded traits.
|
| |
| std::size_t | axis_count () const |
| | Return the number of loaded axes.
|
| |
| bool | has_trait (std::string_view key) const |
| | Whether a trait is loaded.
|
| |
| const std::vector< std::string > & | unresolved () const |
| | Loadings and relations that name a trait or axis that is not loaded. They are ignored, so removing a trait needs no other change; this lists them to catch misspelt names.
|
| |
| void | load (const std::filesystem::path &dir) |
| | Load a resource directory, replacing all data and layers loaded before.
|
| |
| bool | load (dataset tier) |
| | Load a dataset tier, replacing all data and layers loaded before.
|
| |
| void | extend (const std::filesystem::path &path, core::layer_mode mode=core::layer_mode::override) |
| | Add data layers from a directory or a file.
|
| |
| const core::layer_info & | extend (table which, core::tsv_document doc, core::layer_mode mode=core::layer_mode::override) |
| | Add a data layer to one table.
|
| |
| const core::layer_info & | extend_from_string (table which, std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override) |
| | Add a data layer to one table from TSV text (for example from a WebAssembly host).
|
| |
| const std::vector< core::layer_info > & | layers (table which) const |
| | The layers in effect for one table, in order.
|
| |
| std::uint64_t | data_hash () const |
| | Hash of the loaded data (all four tables), recorded in each result's signature().
|
| |
Personality generator: draws traits from a weighted catalogue, shaped by Big Five axes, conflicts and synergies.
The generation pipeline, each step drawing from its own stream split from the call seed:
- Each axis draws a base value from normal(mean, sd) (stream
"axis:<key>"; an axis with sd 0 takes its mean).
- Each trait's weight is multiplied by its affinity,
exp(sum of loading * standardised base value), so a person high in an axis is likelier to have the traits that load on it.
- Included traits are taken; then traits are drawn one at a time (stream
"traits"), skipping traits already chosen, excluded, conflicting with a chosen trait or in a chosen trait's group, and multiplying weights by the synergy factors of the chosen traits.
- Each axis value is its base plus the loadings of the chosen traits.
The catalogue is four tables (see table), extended by layers. Output is identical on every compiler and platform (dasmig-core).
Can be used as a singleton via instance() or constructed independently.
- Thread safety
- Each instance is independent. Concurrent calls to get_personality() on the same instance require external synchronisation.
Definition at line 230 of file traitgen.hpp.
| void dasmig::trtg::extend |
( |
const std::filesystem::path & |
path, |
|
|
core::layer_mode |
mode = core::layer_mode::override |
|
) |
| |
|
inline |
Add data layers from a directory or a file.
A directory may hold any of traits.tsv, axes.tsv, loadings.tsv and relations.tsv; all are applied together or, if any fails, none. A file must have one of those names.
- Parameters
-
| path | Directory or file. |
| mode | How the layers combine with the data loaded before. |
- Exceptions
-
| core::tsv_error | If a file cannot be read or a row is invalid; the data is then unchanged. |
| std::invalid_argument | If path is a file with another name. |
Definition at line 460 of file traitgen.hpp.
| std::vector< personality > dasmig::trtg::get_personality_batch |
( |
const trait_request & |
request, |
|
|
const core::batch_options & |
options, |
|
|
std::uint64_t |
batch_seed |
|
) |
| const |
|
inline |
Generate a batch of personality results, deterministically.
Item i is exactly get_personality(request, core::item_seed(batch_seed, options.first + i)), so an item replays on its own, a range can be generated directly, two batches that follow each other equal one, and the output does not depend on options.threads.
- Parameters
-
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness (see core::unique_rule; the rule must be made for personality). |
| batch_seed | Seed of the whole batch. |
- Returns
- The results, in index order.
- Exceptions
-
| std::invalid_argument | If the request or options are invalid. |
| std::runtime_error | If no data has been loaded, or a unique batch runs out of attempts. |
Definition at line 323 of file traitgen.hpp.
| bool dasmig::trtg::load |
( |
dataset |
tier | ) |
|
|
inline |
Load a dataset tier, replacing all data and layers loaded before.
Uses the compiled-in copy when the library is built with DASMIG_TRAIT_EMBED, otherwise searches resources/, ../resources, trait-generator/resources and ../trait-generator/resources.
- Parameters
-
- Returns
- False when the tier was not found.
- Exceptions
-
| core::tsv_error | If a file is malformed. |
Definition at line 433 of file traitgen.hpp.