Medial Code Documentation
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
MedSample Class Reference

MedSample represents a signle sample: id + time (date)
Additional (optinal) entries: outcome, outcome_date, split and prediction
More...

#include <MedSamples.h>

Inheritance diagram for MedSample:
SerializableObject

Public Member Functions

 MedSample ()
 Constructor.
 
 MedSample (int _id, int _time, int _outcome, int _outcomeTime)
 
 ~MedSample ()
 Destructor.
 
void print (const string prefix)
 printing the sample (with a prefix)
 
void print ()
 printing the sample
 
int parse_from_string (string &s, int time_unit)
 Get sample from tab-delimited string, in old or new format (<split> and <prediction> optional, <predictions> can be several numbers (tab delimited))
old format: EVENT <id> <time> <outcome> <outcomeLen(dummy here)> <outcomeTime> <split> <predictions>
new format: SAMPLE <id> <time> <outcome> <outcomeTime> <split> <predictions>

 
int parse_from_string (string &s, const map< string, int > &pos, const vector< int > &pred_pos, const map< string, int > &attr_pos, const map< string, int > &str_attr_pos, int time_unit, int raw_format, const string &delimeter="\t")
 Get sample from tab-delimited string, where pos indicate the position of each field (fields are id,date,outcome,outcome_date,split,pred or pred_,attr_NAME) if pos is empty, check old and new formats.
 
int parse_from_string (const vector< string > &fields, const map< string, int > &pos, const vector< int > &pred_pos, const map< string, int > &attr_pos, const map< string, int > &str_attr_pos, int time_unit, int raw_format, const string &delimeter)
 
void write_to_string (string &s, int time_unit, bool write_attrib=true, const string &delimeter="\t", int pred_precision=-1) const
 Write to string in new format.
 
int get_all_attributes (vector< string > &attributes, vector< string > &str_attributes) const
 Get sample attributes.
 
- Public Member Functions inherited from SerializableObject
virtual int version () const
 Relevant for serializations.
 
virtual string my_class_name () const
 For better handling of serializations it is highly recommended that each SerializableObject inheriting class will implement the next method.
 
virtual void serialized_fields_name (vector< string > &field_names) const
 The names of the serialized fields.
 
virtual void * new_polymorphic (string derived_name)
 for polymorphic classes that want to be able to serialize/deserialize a pointer * to the derived class given its type one needs to implement this function to return a new to the derived class given its type (as in my_type)
 
virtual void pre_serialization ()
 
virtual void post_deserialization ()
 
virtual size_t get_size ()
 Gets bytes sizes for serializations.
 
virtual size_t serialize (unsigned char *blob)
 Serialiazing object to blob memory. return number ob bytes wrote to memory.
 
virtual size_t deserialize (unsigned char *blob)
 Deserialiazing blob to object. returns number of bytes read.
 
size_t serialize_vec (vector< unsigned char > &blob)
 
size_t deserialize_vec (vector< unsigned char > &blob)
 
virtual size_t serialize (vector< unsigned char > &blob)
 
virtual size_t deserialize (vector< unsigned char > &blob)
 
virtual int read_from_file (const string &fname)
 read and deserialize model
 
virtual int write_to_file (const string &fname)
 serialize model and write to file
 
virtual int read_from_file_unsafe (const string &fname)
 read and deserialize model without checking version number - unsafe read
 
int init_from_string (string init_string)
 Init from string.
 
int init_params_from_file (string init_file)
 
int init_param_from_file (string file_str, string &param)
 
virtual int init (map< string, string > &map)
 Virtual to init object from parsed fields.
 
int update_from_string (const string &init_string)
 
virtual int update (map< string, string > &map)
 Virtual to update object from parsed fields.
 
virtual string object_json () const
 

Data Fields

int id = -1
 Patient id.
 
int split = -1
 Cross-validation split. -1 if not given. Proper use is to set the same split for all samples of a given id (MedIdSamples), but this is not enforced.
 
int time = 0
 Time (Date)
 
float outcome = 0
 Outcome.
 
int outcomeTime = 0
 Outcome time (date)
 
vector< float > prediction
 Prediction(s) - empty if non given.
 
map< string, float > attributes
 Attribute(s) - empty if non given.
 
map< string, string > str_attributes
 Attribute(s) - empty if non given.
 
json jrec
 a json record that can be built along side the sample to contain any information in a nice json format
 

Detailed Description

MedSample represents a signle sample: id + time (date)
Additional (optinal) entries: outcome, outcome_date, split and prediction

Member Function Documentation

◆ parse_from_string() [1/2]

int MedSample::parse_from_string ( string &  s,
const map< string, int > &  pos,
const vector< int > &  pred_pos,
const map< string, int > &  attr_pos,
const map< string, int > &  str_attr_pos,
int  time_unit,
int  raw_format,
const string &  delimeter = "\t" 
)

Get sample from tab-delimited string, where pos indicate the position of each field (fields are id,date,outcome,outcome_date,split,pred or pred_,attr_NAME) if pos is empty, check old and new formats.

Returns
0 upon success, -1 upon failure to parse

◆ parse_from_string() [2/2]

int MedSample::parse_from_string ( string &  s,
int  time_unit 
)

Get sample from tab-delimited string, in old or new format (<split> and <prediction> optional, <predictions> can be several numbers (tab delimited))
old format: EVENT <id> <time> <outcome> <outcomeLen(dummy here)> <outcomeTime> <split> <predictions>
new format: SAMPLE <id> <time> <outcome> <outcomeTime> <split> <predictions>

Returns
0 upon success, -1 if string does not fit any of the formats

The documentation for this class was generated from the following files: