Turi Create  4.0
turi::ml_data_row_reference Class Reference

#include <ml/ml_data/row_reference.hpp>

Public Member Functions

template<typename Entry >
GL_HOT_INLINE void fill (std::vector< Entry > &x) const
 
template<typename EigenXpr >
GL_HOT_INLINE_FLATTEN void fill (EigenXpr &&x, typename std::enable_if< std::is_convertible< EigenXpr, DenseVector >::value >::type *=0) const
 
void fill_untranslated_values (std::vector< flexible_type > &x) const
 
template<typename EigenXpr >
GL_HOT_INLINE_FLATTEN void fill_eigen (EigenXpr &&x) const
 
template<typename ElementWriteFunction , typename ColumnEndFunction >
GL_HOT_INLINE_FLATTEN void unpack (ElementWriteFunction &&ewf, ColumnEndFunction &&cef) const
 
double target_value () const GL_HOT_INLINE_FLATTEN
 
size_t target_index () const GL_HOT_INLINE_FLATTEN
 
const std::shared_ptr< ml_metadata > & metadata () const
 

Static Public Member Functions

static GL_HOT ml_data_row_reference from_row (const std::shared_ptr< ml_metadata > &metadata, const flex_dict &row, ml_missing_value_action none_action=ml_missing_value_action::USE_NAN)
 

Detailed Description

A class containing a reference to the row of an ml_data instance, providing access to the underlying data.

In other words, you can do

it->fill(x);

or

auto row_ref = *it;

// do stuff ... row_ref.fill(x);

The data block pointed to by this reference is kept alive as long as this reference class exists.

Another example of how it is used is below:

sframe X = make_integer_testing_sframe( {"C1", "C2"}, { {0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4} } );

ml_data data;

data.fill(X);

// Get row references

std::vector<ml_data_row_reference> rows(data.num_rows());

for(auto it = data.get_iterator(); !it.done(); ++it) { rows[it.row_index()] = *it; }

// Now go through and make sure that each of these hold the // correct answers.

std::vector<ml_data_entry> x;

for(size_t i = 0; i < rows.size(); ++i) {

// The metadata for the row is the same as that in the data. ASSERT_TRUE(rows[i].metadata().get() == data.metadata().get());

rows[i].fill(x);

ASSERT_EQ(x.size(), 2);

ASSERT_EQ(x[0].column_index, 0); ASSERT_EQ(x[0].index, 0); ASSERT_EQ(x[0].value, i);

ASSERT_EQ(x[1].column_index, 1); ASSERT_EQ(x[1].index, 0); ASSERT_EQ(x[1].value, i); } }

Definition at line 87 of file row_reference.hpp.

Member Function Documentation

◆ fill() [1/2]

template<typename Entry >
GL_HOT_INLINE void turi::ml_data_row_reference::fill ( std::vector< Entry > &  x) const
inline

Fill an observation vector, represented as an ml_data_entry struct. (column_index, index, value) pairs, from this row reference. For each column:

Categotical: Returns (col_id, v, 1) Numeric : Returns (col_id, 0, v) Vector : Returns (col_id, i, v) for each (i,v) in vector.

Example use is given by the following code:

std::vector<ml_data_entry> x;

row_ref.fill(x); double y = row_ref.target_value(); ...

Definition at line 259 of file row_reference.hpp.

◆ fill() [2/2]

template<typename EigenXpr >
GL_HOT_INLINE_FLATTEN void turi::ml_data_row_reference::fill ( EigenXpr &&  x,
typename std::enable_if< std::is_convertible< EigenXpr, DenseVector >::value >::type *  = 0 
) const
inline

Fill a row of an Eigen expression in the current location in the iteration.

Example:

Eigen::MatrixXd X;

...

it.fill(X.row(row_idx));


Parameters
[in,out]xAn eigen row expression.

Definition at line 142 of file row_reference.hpp.

◆ fill_eigen()

template<typename EigenXpr >
GL_HOT_INLINE_FLATTEN void turi::ml_data_row_reference::fill_eigen ( EigenXpr &&  x) const
inline

The explicit version to fill an eigen expression.

Definition at line 287 of file row_reference.hpp.

◆ fill_untranslated_values()

void turi::ml_data_row_reference::fill_untranslated_values ( std::vector< flexible_type > &  x) const

Fill an observation vector with the untranslated columns, if any have been specified at setup time. These columns are simply mapped back to their sarray counterparts.

◆ from_row()

static GL_HOT ml_data_row_reference turi::ml_data_row_reference::from_row ( const std::shared_ptr< ml_metadata > &  metadata,
const flex_dict row,
ml_missing_value_action  none_action = ml_missing_value_action::USE_NAN 
)
static

Create an ml_data_row_reference from a single sframe row reference.

Row must be in the format {column_name, value} and columns correspond to the columns in metadata. Missing columns are treated as missing values.

Returns a single row reference.

◆ metadata()

const std::shared_ptr<ml_metadata>& turi::ml_data_row_reference::metadata ( ) const
inline

Returns a pointer to the metadata class that describes the data that this row reference refers to.

Definition at line 222 of file row_reference.hpp.

◆ target_index()

size_t turi::ml_data_row_reference::target_index ( ) const
inline

Returns the current categorical target index, if present, or 0 if not present.

Definition at line 215 of file row_reference.hpp.

◆ target_value()

double turi::ml_data_row_reference::target_value ( ) const
inline

Returns the current target value, if present, or 1 if not present. If the target column is supposed to be a categorical value, then use target_index().

Definition at line 208 of file row_reference.hpp.

◆ unpack()

template<typename ElementWriteFunction , typename ColumnEndFunction >
GL_HOT_INLINE_FLATTEN void turi::ml_data_row_reference::unpack ( ElementWriteFunction &&  ewf,
ColumnEndFunction &&  cef 
) const
inline

A generic function to unpack the values into a particular format. This allows, e.g. custom distance functions and stuff to work out well.

// Called for every element. // mode: What type of column it is. // feature_index: index within the column // index_size: number of features in this column. // index_offset: The global index would be index_offset + feature_index // value: the value of the feature.

auto unpack_function = [&](ml_column_mode mode, size_t column_index, size_t feature_index, double value, size_t index_size, size_t index_offset) { ... };

// Called after every column is done unpacking. auto column_end_function = [&](ml_column_mode mode, size_t column_index, size_t index_size) { ... };

Definition at line 189 of file row_reference.hpp.


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