A fuzzy logic C++ library
|
Abstract data point, can hold several numerical and string attributes. More...
#include <data_point.hpp>
Public Member Functions | |
Constructors | |
DATA_POINT () | |
Constructor 1, does no allocation. | |
DATA_POINT (const DATAFILE_INFO &dfi, DATA_SET *pDataSet=0) | |
Constructor 2, allocates the number of fields depending on dfi . | |
DATA_POINT (size_t NbFields) | |
Constructor 3, allocates NbFields fields. | |
General information on point | |
size_t | GetNbFields () const |
size_t | GetPointId () const |
Assigning values | |
void | SetValue (size_t idx, double value) |
Assigns numerical value value at position idx , does the requested memory allocation if needed. | |
void | SetValue (size_t idx, std::string value) |
Assigns string value value at position idx , does the requested memory allocation if needed. | |
void | SetValue (size_t idx, size_t value) |
Assigns index-type value value at position idx , does the requested memory allocation if needed. | |
void | AddValue (double value) |
void | AddValue (std::string value) |
Retrieving values | |
EN_DATA_FIELD_TYPE | GetDataType (size_t idx) const |
Returns type of field at index idx . | |
double | GetInputValue (size_t idx, const DATA_DESCR &descr) const |
Returns floating-point input value. | |
VALUE_PTR | GetOutputValue (const DATA_DESCR &descr) const |
VALUE_PTR | GetValue (size_t idx, bool ReturnRawValue=false) const |
Returns value of field idx (0-based index) | |
double | GetValue_f (size_t idx) const |
Returns floating-point value of field idx (0-based index) | |
std::string | GetValue_s (size_t idx) const |
Returns string value of field idx (0-based index) | |
void | FillWithInputValues (std::vector< double > &v_values, const DATA_DESCR &descr) const |
Fills vector v_values with the input values from data point (vector's size is automatically adjusted) | |
I/O | |
EN_READ_LINE_STATUS | ReadDataFields (DATAFILE_INFO &dfi) |
Reads the fields of the point in the next line of file. | |
void | Print (FILE *f, const char *msg=0) const |
Private Member Functions | |
void | P_AllocateIfNeeded (size_t idx) |
Allocates enough size for the vector to put in element of index idx , and fills empty elements with numerical values. | |
void | P_DP_Init (size_t idx) |
Common init function called by all constructors (private) | |
Private Attributes | |
std::vector< VALUE_PTR > | _v_value |
vector of arbitrary type values, holds a boost shared pointer type. | |
size_t | _pt_id |
DATA_SET * | _p_ADS |
Pointer on associated data set, =0 is data point is autonomous (the point actually holds the data). | |
Static Private Attributes | |
static size_t | _s_index_count = 0 |
counter for assigning point Id |
Abstract data point, can hold several numerical and string attributes.
A DATA_POINT object can be assigned a description (what values are inputs, what value is output), allowing the user to ask for a given input value. This description is static, so is common for all data points.
It can filled with strings or numerical values in a very simple way, for instance:
DATA_POINT dpt; dpt.AddValue( 1.23 ); dpt.AddValue( "aze" ); dpt.AddValue( "rty" ); dpt.AddValue( 4.56 );
Every field is typed with slifis::EN_DATA_FIELD_TYPE, and it can be fetched with DATA_POINT::GetDataType()
One can also add values at arbitrary positions, memory allocation for the underlying container is done silently under the hood, user does not have to care about it. For example:
DATA_POINT dpt; dpt.SetValue( 8, 1.23 ); dpt.SetValue( 2, 4.56 ); dpt.SetValue( 11, "qwerty" ); ...
The "empty" allocated fields are allocated by default as numerical type, but anyway, it is also possible to rewrite a different type to the same position without any problem. For example, the following code works without any trouble:
DATA_POINT dpt; dpt.SetValue( 8, 1.23 ); dpt.SetValue( 8, "qwerty" ); dpt.SetValue( 8, 4.56 );
Constructor 1, does no allocation.
slifis::DATA_POINT::DATA_POINT | ( | const DATAFILE_INFO & | dfi, |
DATA_SET * | pDataSet = 0 |
||
) |
Constructor 2, allocates the number of fields depending on dfi
.
References slifis::DATAFILE_INFO::GetNeededNbFields().
slifis::DATA_POINT::DATA_POINT | ( | size_t | NbFields | ) |
Constructor 3, allocates NbFields
fields.
size_t slifis::DATA_POINT::GetNbFields | ( | ) | const [inline] |
References _v_value.
size_t slifis::DATA_POINT::GetPointId | ( | ) | const [inline] |
References _pt_id.
Referenced by slifis::DATA_SET::Print().
void slifis::DATA_POINT::SetValue | ( | size_t | idx, |
double | value | ||
) |
void slifis::DATA_POINT::SetValue | ( | size_t | idx, |
std::string | value | ||
) |
Assigns string value value
at position idx
, does the requested memory allocation if needed.
References __IN__, __OUT__, slifis::ERR_DATA_BAD_TYPE, and SLIFIS_ERROR.
void slifis::DATA_POINT::SetValue | ( | size_t | idx, |
size_t | value | ||
) |
void slifis::DATA_POINT::AddValue | ( | double | value | ) | [inline] |
void slifis::DATA_POINT::AddValue | ( | std::string | value | ) | [inline] |
References __IN__, __OUT__, _p_ADS, _v_value, slifis::ERR_DATA_BAD_TYPE, and SLIFIS_ERROR.
EN_DATA_FIELD_TYPE slifis::DATA_POINT::GetDataType | ( | size_t | idx | ) | const [inline] |
Returns type of field at index idx
.
References __IN__, __OUT__, _v_value, slifis::ERR_DATA_BAD_INDEX, and SLIFIS_ERROR_2.
Referenced by slifis::DATA_SET::GetFieldType().
double slifis::DATA_POINT::GetInputValue | ( | size_t | idx, |
const DATA_DESCR & | descr | ||
) | const |
Returns floating-point input value.
References __IN__, __OUT__, slifis::DT_NUMERIC, slifis::ERR_DATA_BAD_TYPE, slifis::ERR_DATA_NO_DESCRIPTION, slifis::DATA_DESCR::GetInputIndex(), slifis::DATA_DESCR::IsSet(), SLIFIS_ERROR, and SLIFIS_ERROR_2.
Referenced by slifis::DATA_SET::GetSubset(), and slifis::SLIFIS::SetInputValues().
VALUE_PTR slifis::DATA_POINT::GetOutputValue | ( | const DATA_DESCR & | descr | ) | const [inline] |
References slifis::DATA_DESCR::GetOutputIndex(), and GetValue().
Referenced by slifis::SLIFIS::BuildRuleBaseFromData(), and main().
VALUE_PTR slifis::DATA_POINT::GetValue | ( | size_t | idx, |
bool | ReturnRawValue = false |
||
) | const |
Returns value of field idx
(0-based index)
The second argument is useful only is the field is a 'string' attribute:
ReturnRawValue
is true, then the function will return the index of that string in the table of stringsReturnRawValue
is false, then it will return the string value References __IN__, __OUT__, slifis::DT_STRING_INDEX, slifis::ERR_DATA_BAD_INDEX, SLIFIS_DEBUG_LOG, and SLIFIS_ERROR_2.
Referenced by slifis::DATA_SET::GetInputValues(), GetOutputValue(), slifis::DATA_SET::GetOutValue(), slifis::DATASET_PROPERTIES::P_ComputeProps(), and slifis::DATA_SET::Print().
double slifis::DATA_POINT::GetValue_f | ( | size_t | idx | ) | const [inline] |
Returns floating-point value of field idx
(0-based index)
References __IN__, __OUT__, _v_value, slifis::ERR_DATA_BAD_INDEX, and SLIFIS_ERROR_2.
Referenced by slifis::RULE_IDX::ComputeTSError(), slifis::DATASET_PROPERTIES::P_ComputeProps(), and process_numeric().
std::string slifis::DATA_POINT::GetValue_s | ( | size_t | idx | ) | const [inline] |
Returns string value of field idx
(0-based index)
References __IN__, __OUT__, _v_value, slifis::ERR_DATA_BAD_INDEX, and SLIFIS_ERROR_2.
void slifis::DATA_POINT::FillWithInputValues | ( | std::vector< double > & | v_values, |
const DATA_DESCR & | descr | ||
) | const |
Fills vector v_values
with the input values from data point (vector's size is automatically adjusted)
Throws an error if one of the requested points is not a numeric value.
References __IN__, __OUT__, slifis::DT_NUMERIC, slifis::ERR_DATA_BAD_TYPE, slifis::ERR_DATA_NO_DESCRIPTION, slifis::DATA_DESCR::GetInputIndex(), slifis::DATA_DESCR::GetNbInputs(), slifis::DATA_DESCR::IsSet(), SLIFIS_ERROR, and SLIFIS_ERROR_2.
Referenced by slifis::SLIFIS::BuildRuleBaseFromData(), and slifis::DATA_SET::GetSubset().
Reads the fields of the point in the next line of file.
Requirements for using this function:
dfi
References __IN__, __OUT__, slifis::DT_NUMERIC, slifis::DT_STRING, slifis::ERR_DATA_BAD_TYPE, slifis::DATAFILE_INFO::FieldIsRequested(), slifis::DATAFILE_INFO::FileIsOpen(), slifis::DATAFILE_INFO::GetDelimChar(), slifis::DATAFILE_INFO::GetFieldType(), slifis::DATAFILE_INFO::GetFileName(), slifis::DATAFILE_INFO::GetNeededNbFields(), slifis::DATAFILE_INFO::GetTotNbFields(), slifis::LineHasContent(), slifis::DATAFILE_INFO::P_ReadLine(), SLIFIS_DEBUG_LOG, SLIFIS_ERROR_1, SLIFIS_ERROR_LOG, SLIFIS_WARNING_1, SLIFIS_WARNING_2, slifis::ST_COMMENT, slifis::ST_DATALINE, slifis::ST_FAILURE, slifis::TokensList(), and slifis::TrimCR().
Referenced by main(), and slifis::DATA_SET::ReadData().
void slifis::DATA_POINT::Print | ( | FILE * | f, |
const char * | msg = 0 |
||
) | const |
References __IN__, __OUT__, slifis::DT_NUMERIC, slifis::DT_STRING, slifis::GetString(), and SWITCH_ERROR.
void slifis::DATA_POINT::P_AllocateIfNeeded | ( | size_t | idx | ) | [private] |
void slifis::DATA_POINT::P_DP_Init | ( | size_t | idx | ) | [private] |
Common init function called by all constructors (private)
std::vector<VALUE_PTR> slifis::DATA_POINT::_v_value [private] |
vector of arbitrary type values, holds a boost shared pointer type.
Referenced by AddValue(), GetDataType(), GetNbFields(), GetValue_f(), and GetValue_s().
size_t slifis::DATA_POINT::_pt_id [private] |
Referenced by GetPointId().
size_t slifis::DATA_POINT::_s_index_count = 0 [static, private] |
counter for assigning point Id
DATA_SET* slifis::DATA_POINT::_p_ADS [private] |
Pointer on associated data set, =0 is data point is autonomous (the point actually holds the data).
If allocated, means that string data is held by associated DATA_SET, NOT by the data point. In that case, the value will be of type STRING_INDEX, and will hold the index on the corresponding vector in DATA_SET.
Referenced by AddValue().