Struct biodivine_sketchbook::sketchbook::observations::_dataset::Dataset
source · pub struct Dataset {
name: String,
annotation: String,
observations: Vec<Observation>,
variables: Vec<VarId>,
index_map: HashMap<ObservationId, usize>,
}
Expand description
An ordered list of observations for given variables. The order is important for some datasets, for example, to be able to capture time series.
Dataset
provides classical Rust API for modifications. It also manages its observations
through event-based API. However, this API is limited, and only serves as an extension to that
of the ObservationManager
.
Fields§
§name: String
§annotation: String
§observations: Vec<Observation>
List of binarized observations.
variables: Vec<VarId>
Variables captured by the observations.
index_map: HashMap<ObservationId, usize>
Index map from observation IDs to their index in vector, for faster searching.
Implementations§
source§impl Dataset
impl Dataset
Creating new Dataset
instances.
sourcepub fn new(
name: &str,
observations: Vec<Observation>,
var_names: Vec<&str>,
) -> Result<Self, String>
pub fn new( name: &str, observations: Vec<Observation>, var_names: Vec<&str>, ) -> Result<Self, String>
Create new dataset from a list of observations and variables.
Length of each observation and number of variables must match. Observation IDs must be valid identifiers and must be unique. Annotation is empty (for annotated version, check Dataset::new_annotated)
sourcepub fn new_annotated(
name: &str,
annotation: &str,
observations: Vec<Observation>,
var_names: Vec<&str>,
) -> Result<Self, String>
pub fn new_annotated( name: &str, annotation: &str, observations: Vec<Observation>, var_names: Vec<&str>, ) -> Result<Self, String>
Create new dataset from a list of observations and variables.
Length of each observation and number of variables must match. Observation IDs must be valid identifiers and must be unique.
sourcepub fn new_empty(name: &str, var_names: Vec<&str>) -> Result<Self, String>
pub fn new_empty(name: &str, var_names: Vec<&str>) -> Result<Self, String>
Shorthand to create new empty
dataset over given variables, with empty annotation.
source§impl Dataset
impl Dataset
Editing Dataset
instances.
sourcepub fn set_annotation(&mut self, annotation: &str)
pub fn set_annotation(&mut self, annotation: &str)
Set dataset’s annotation string.
sourcepub fn push_obs(&mut self, obs: Observation) -> Result<(), String>
pub fn push_obs(&mut self, obs: Observation) -> Result<(), String>
Add observation at the end of the dataset.
The observation must have the same length as is the number of dataset’s variables, and its id must not be already present in the dataset.
sourcepub fn pop_obs(&mut self)
pub fn pop_obs(&mut self)
Remove observation from the end of the dataset. If no observations, nothing happens.
sourcepub fn remove_obs(&mut self, id: &ObservationId) -> Result<(), String>
pub fn remove_obs(&mut self, id: &ObservationId) -> Result<(), String>
Remove observation with given ID from the dataset. The ID must be valid
This operation might be very costly, as we must reindex all subsequent observations.
sourcepub fn insert_obs(
&mut self,
index: usize,
obs: Observation,
) -> Result<(), String>
pub fn insert_obs( &mut self, index: usize, obs: Observation, ) -> Result<(), String>
Add observation to a given index in the dataset.
This operation might be very costly, as we must reindex all subsequent observations.
sourcepub fn remove_var(&mut self, var_id: &VarId) -> Result<(), String>
pub fn remove_var(&mut self, var_id: &VarId) -> Result<(), String>
Remove variable and all the values corresponding to it (decrementing dimension of the dataset in process).
sourcepub fn remove_var_by_str(&mut self, id: &str) -> Result<(), String>
pub fn remove_var_by_str(&mut self, id: &str) -> Result<(), String>
Remove variable and all the values corresponding to it (decrementing dimension of the dataset in process).
sourcepub fn add_var_default(
&mut self,
var_id: VarId,
index: usize,
) -> Result<(), String>
pub fn add_var_default( &mut self, var_id: VarId, index: usize, ) -> Result<(), String>
Add variable to a specific index, and fill its values in all observations with “*” placeholders.
sourcepub fn add_var_default_by_str(
&mut self,
id: &str,
index: usize,
) -> Result<(), String>
pub fn add_var_default_by_str( &mut self, id: &str, index: usize, ) -> Result<(), String>
Add variable to a specific index, and fill its values in all observations with “*” placeholders.
sourcepub fn set_observation_raw(
&mut self,
id: &ObservationId,
obs: Observation,
) -> Result<(), String>
pub fn set_observation_raw( &mut self, id: &ObservationId, obs: Observation, ) -> Result<(), String>
Swap the whole observation data for given ID.
sourcepub fn swap_obs_values(
&mut self,
id: &ObservationId,
new_values: Vec<VarValue>,
) -> Result<(), String>
pub fn swap_obs_values( &mut self, id: &ObservationId, new_values: Vec<VarValue>, ) -> Result<(), String>
Swap value vector for an observation with given ID. The new vector of values must be of the same length as the original.
sourcepub fn set_var_id(
&mut self,
original_id: &VarId,
new_id: VarId,
) -> Result<(), String>
pub fn set_var_id( &mut self, original_id: &VarId, new_id: VarId, ) -> Result<(), String>
Set the id of variable with original_id
to new_id
.
sourcepub fn set_var_id_by_str(
&mut self,
original_id: &str,
new_id: &str,
) -> Result<(), String>
pub fn set_var_id_by_str( &mut self, original_id: &str, new_id: &str, ) -> Result<(), String>
Set the id of variable given by string original_id
to new_id
.
sourcepub fn set_all_variables(
&mut self,
new_variables_list: Vec<VarId>,
) -> Result<(), String>
pub fn set_all_variables( &mut self, new_variables_list: Vec<VarId>, ) -> Result<(), String>
Set the list of all variable IDs (essentially renaming some/all of them). The length of the new list must be the same as existing one (only renaming, not adding/removing variables).
sourcepub fn set_all_variables_by_str(
&mut self,
new_variables_list: Vec<&str>,
) -> Result<(), String>
pub fn set_all_variables_by_str( &mut self, new_variables_list: Vec<&str>, ) -> Result<(), String>
Set the list with all variable IDs (essentially renaming some/all of them) using string names. The length of the new list must be the same as existing one (only renaming, not adding/removing variables).
sourcepub fn set_obs_id(
&mut self,
original_id: &ObservationId,
new_id: ObservationId,
) -> Result<(), String>
pub fn set_obs_id( &mut self, original_id: &ObservationId, new_id: ObservationId, ) -> Result<(), String>
Set the id of an observation with original_id
to new_id
.
sourcepub fn set_obs_id_by_str(
&mut self,
original_id: &str,
new_id: &str,
) -> Result<(), String>
pub fn set_obs_id_by_str( &mut self, original_id: &str, new_id: &str, ) -> Result<(), String>
Set the id of observation given by string original_id
to new_id
.
sourcepub fn set_obs_name(
&mut self,
id: &ObservationId,
new_name: &str,
) -> Result<(), String>
pub fn set_obs_name( &mut self, id: &ObservationId, new_name: &str, ) -> Result<(), String>
Set name of a given observation.
sourcepub fn set_obs_annot(
&mut self,
id: &ObservationId,
new_annot: &str,
) -> Result<(), String>
pub fn set_obs_annot( &mut self, id: &ObservationId, new_annot: &str, ) -> Result<(), String>
Set annotation of a given observation.
source§impl Dataset
impl Dataset
Observing Dataset
instances.
sourcepub fn get_annotation(&self) -> &str
pub fn get_annotation(&self) -> &str
Annotation string of the dataset.
sourcepub fn num_observations(&self) -> usize
pub fn num_observations(&self) -> usize
Number of observations in the dataset.
sourcepub fn num_variables(&self) -> usize
pub fn num_variables(&self) -> usize
Number of variables tracked by the dataset.
sourcepub fn is_valid_variable(&self, var: &VarId) -> bool
pub fn is_valid_variable(&self, var: &VarId) -> bool
Check if variable is tracked in this dataset.
sourcepub fn is_valid_obs(&self, id: &ObservationId) -> bool
pub fn is_valid_obs(&self, id: &ObservationId) -> bool
Check if observation is present in this dataset.
sourcepub fn get_obs_on_idx(&self, index: usize) -> Result<&Observation, String>
pub fn get_obs_on_idx(&self, index: usize) -> Result<&Observation, String>
Observation on given index (indexing starts at 0).
sourcepub fn get_obs(&self, id: &ObservationId) -> Result<&Observation, String>
pub fn get_obs(&self, id: &ObservationId) -> Result<&Observation, String>
Observation with given ID.
sourcepub fn get_obs_id(&self, index: usize) -> &ObservationId
pub fn get_obs_id(&self, index: usize) -> &ObservationId
ID of an observation on given index.
sourcepub fn get_obs_id_by_str(&self, id: &str) -> Result<ObservationId, String>
pub fn get_obs_id_by_str(&self, id: &str) -> Result<ObservationId, String>
ID of an observation on given index.
sourcepub fn get_obs_index(&self, id: &ObservationId) -> Result<usize, String>
pub fn get_obs_index(&self, id: &ObservationId) -> Result<usize, String>
Get index of given observation, or None (if not present). Indexing starts at 0.
sourcepub fn observations(&self) -> &Vec<Observation>
pub fn observations(&self) -> &Vec<Observation>
Vector of all observations.
sourcepub fn variable_names(&self) -> Vec<String>
pub fn variable_names(&self) -> Vec<String>
Vector of all variable names.
sourcepub fn get_var_id(&self, id: &str) -> Result<&VarId, String>
pub fn get_var_id(&self, id: &str) -> Result<&VarId, String>
Get VarId
for a corresponding string identifier, if it is valid.
sourcepub fn to_debug_string(&self, list_all: bool) -> String
pub fn to_debug_string(&self, list_all: bool) -> String
Make a string describing this Dataset
in a human-readable format.
If list_all
is set to true
, all observation vectors are listed. Otherwise, just
a summary is given (number of observations).
This is mainly for debug purposes, as it is different than classical string serialization.
sourcefn assert_no_obs(&self, id: &ObservationId) -> Result<(), String>
fn assert_no_obs(&self, id: &ObservationId) -> Result<(), String>
(internal) Utility method to ensure there is no observation with given ID yet.
sourcefn assert_valid_obs(&self, id: &ObservationId) -> Result<(), String>
fn assert_valid_obs(&self, id: &ObservationId) -> Result<(), String>
(internal) Utility method to ensure there is a observation with given ID.
source§impl Dataset
impl Dataset
Implementation for events related to modifying observations
in a particular Dataset
.
Dataset
does not implement SessionState
trait directly. Instead, it just offers methods
to perform certain events, after the preprocessing is done by ObservationManager
.
sourcepub(in sketchbook::observations) fn event_push_observation(
&mut self,
event: &Event,
dataset_id: DatasetId,
) -> Result<Consumed, DynError>
pub(in sketchbook::observations) fn event_push_observation( &mut self, event: &Event, dataset_id: DatasetId, ) -> Result<Consumed, DynError>
Perform event of adding a new observation
to the end of this Dataset
.
sourcepub(in sketchbook::observations) fn event_push_empty_observation(
&mut self,
event: &Event,
dataset_id: DatasetId,
) -> Result<Consumed, DynError>
pub(in sketchbook::observations) fn event_push_empty_observation( &mut self, event: &Event, dataset_id: DatasetId, ) -> Result<Consumed, DynError>
Perform event of adding a completely new “empty” observation
to the end of this Dataset
.
All its values are unspecified
and its Id is newly generated.
sourcepub(in sketchbook::observations) fn event_pop_observation(
&mut self,
event: &Event,
dataset_id: DatasetId,
) -> Result<Consumed, DynError>
pub(in sketchbook::observations) fn event_pop_observation( &mut self, event: &Event, dataset_id: DatasetId, ) -> Result<Consumed, DynError>
Perform event of removing the last observation from this Dataset
.
pub(in sketchbook::observations) fn event_modify_observation( &mut self, event: &Event, action: &str, dataset_id: DatasetId, obs_id: ObservationId, ) -> Result<Consumed, DynError>
source§impl Dataset
impl Dataset
Methods for safely generating new valid (unique) instances of identifiers for
the current Dataset
.
sourcepub fn generate_obs_id(
&self,
ideal_id: &str,
start_index: Option<usize>,
) -> ObservationId
pub fn generate_obs_id( &self, ideal_id: &str, start_index: Option<usize>, ) -> ObservationId
Generate valid ObservationId
that’s currently not used by any observation in this
Dataset
.
First, the given ideal_id
and its transformation by replacing invalid characters are
tried. If they are both invalid (non-unique), a numerical identifier is added at the end.
By specifying start_index
, the index search starts directly at that number (e.g., when
ideal ID is “obs” and start index is 3, search for ID starts with “obs_3”, “obs_4”, …)
Warning: Do not use this to pre-generate more than one id at a time, as the process is deterministic and might generate the same IDs. Always generate an Id, add that observation, and then repeat for other observations.
sourcepub fn generate_var_id(
&self,
ideal_id: &str,
start_index: Option<usize>,
) -> VarId
pub fn generate_var_id( &self, ideal_id: &str, start_index: Option<usize>, ) -> VarId
Generate valid VarId
that’s currently not used by any variable in this Dataset
.
First, the given ideal_id
and its transformation by replacing invalid characters are
tried. If they are both invalid (non-unique), a numerical identifier is added at the end.
By specifying start_index
, the index search starts directly at that number (e.g., when
ideal ID is “var” and start index is 3, search for ID starts with “var_3”, “var_4”, …)
Warning: Do not use this to pre-generate more than one id at a time, as the process is deterministic and might generate the same IDs. Always generate an Id, add that variable, and then repeat for other variables.
Trait Implementations§
source§impl Manager for Dataset
impl Manager for Dataset
source§fn generate_id<T>(
&self,
ideal_id: &str,
is_taken: &dyn Fn(&Self, &T) -> bool,
num_indices: usize,
start_index: Option<usize>,
) -> T
fn generate_id<T>( &self, ideal_id: &str, is_taken: &dyn Fn(&Self, &T) -> bool, num_indices: usize, start_index: Option<usize>, ) -> T
T
for a certain component of a manager (e.g., generate a
VariableId
for a Variable
in a ModelState
). Read moresource§fn assert_ids_unique_and_used<T>(
&self,
id_list: &Vec<&str>,
assert_id_is_managed: &dyn Fn(&Self, &T) -> Result<(), String>,
) -> Result<(), String>
fn assert_ids_unique_and_used<T>( &self, id_list: &Vec<&str>, assert_id_is_managed: &dyn Fn(&Self, &T) -> Result<(), String>, ) -> Result<(), String>
source§fn assert_ids_unique_and_new<T>(
&self,
id_list: &Vec<&str>,
assert_id_is_new: &dyn Fn(&Self, &T) -> Result<(), String>,
) -> Result<(), String>
fn assert_ids_unique_and_new<T>( &self, id_list: &Vec<&str>, assert_id_is_new: &dyn Fn(&Self, &T) -> Result<(), String>, ) -> Result<(), String>
source§impl SessionHelper for Dataset
impl SessionHelper for Dataset
source§fn starts_with<'a, 'b>(
prefix: &str,
at_path: &'a [&'b str],
) -> Option<&'a [&'b str]>
fn starts_with<'a, 'b>( prefix: &str, at_path: &'a [&'b str], ) -> Option<&'a [&'b str]>
at_path
starts with a specific first segment.
If yes, returns the remaining part of the path.source§fn matches(expected: &[&str], at_path: &[&str]) -> bool
fn matches(expected: &[&str], at_path: &[&str]) -> bool
at_path
is exactlysource§fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError>
fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError>
source§fn invalid_path_error_specific<T>(
path: &[&str],
component: &str,
) -> Result<T, DynError>
fn invalid_path_error_specific<T>( path: &[&str], component: &str, ) -> Result<T, DynError>
component
.source§fn clone_payload_str(event: &Event, component: &str) -> Result<String, DynError>
fn clone_payload_str(event: &Event, component: &str) -> Result<String, DynError>
impl Eq for Dataset
impl StructuralPartialEq for Dataset
Auto Trait Implementations§
impl Freeze for Dataset
impl RefUnwindSafe for Dataset
impl Send for Dataset
impl Sync for Dataset
impl Unpin for Dataset
impl UnwindSafe for Dataset
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.