PLearn 0.1
Public Member Functions | Protected Attributes | Private Types
PLearn::SDBVMFieldMultiDiscrete Class Reference

#include <SDBVMat.h>

Inheritance diagram for PLearn::SDBVMFieldMultiDiscrete:
Inheritance graph
[legend]
Collaboration diagram for PLearn::SDBVMFieldMultiDiscrete:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SDBVMFieldMultiDiscrete (const FieldArray &fields, real missing_values_mapping=MISSING_VALUE, SDBVMOutputCoding oc=SDBVMNumeric, VMField::FieldType ft=VMField::DiscrGeneral)
const FieldArraygetFields () const
 Accessor and mutator for field array.
void setFields (const FieldArray &fields)
virtual real getDiscreteValue (const SDBWithStats &sdb, const Row &row) const
 virtual int fieldWidth() const;

Protected Attributes

FieldArray fields_
Vec field_multipliers_
 factor by which to multiply

Private Types

typedef SDBVMFieldDiscrete inherited

Detailed Description

Definition at line 866 of file SDBVMat.h.


Member Typedef Documentation

Reimplemented from PLearn::SDBVMFieldDiscrete.

Definition at line 868 of file SDBVMat.h.


Constructor & Destructor Documentation

PLearn::SDBVMFieldMultiDiscrete::SDBVMFieldMultiDiscrete ( const FieldArray fields,
real  missing_values_mapping = MISSING_VALUE,
SDBVMOutputCoding  oc = SDBVMNumeric,
VMField::FieldType  ft = VMField::DiscrGeneral 
)

The constructor accepts an array of discrete fields; this class assumes ownership of the fields; the array can be empty, and later set with setFields().

Definition at line 899 of file SDBVMat.cc.

References setFields().

    : inherited(FieldPtr() /* "null pointer" */, 0,
                missing_values_mapping, oc, ft)
{
    setFields(fields);
}

Here is the call graph for this function:


Member Function Documentation

real PLearn::SDBVMFieldMultiDiscrete::getDiscreteValue ( const SDBWithStats sdb,
const Row row 
) const [virtual]

virtual int fieldWidth() const;

Compute the "array index" corresponding to the fields

Implements PLearn::SDBVMFieldDiscrete.

Definition at line 929 of file SDBVMat.cc.

References field_multipliers_, fields_, i, n, PLERROR, and PLearn::TVec< T >::size().

{
    int index = 0;
    int n = fields_.size();
    for (int i=0; i<n; ++i) {
        real value = fields_[i]->getDiscreteValue(sdb,row);
        if (value != int(value) || value < 0)
            PLERROR("SDBVMFieldMultiDiscrete::getDiscreteValue: negative or "
                    "non-integer value %f returned for field %d", value, i);
        index += int(value)*int(field_multipliers_[i]);
    }
    return real(index);
}

Here is the call graph for this function:

const FieldArray& PLearn::SDBVMFieldMultiDiscrete::getFields ( ) const [inline]

Accessor and mutator for field array.

Definition at line 881 of file SDBVMat.h.

                                        {
        return fields_;
    }
void PLearn::SDBVMFieldMultiDiscrete::setFields ( const FieldArray fields)

Definition at line 909 of file SDBVMat.cc.

References field_multipliers_, fields_, i, n, PLearn::TVec< T >::resize(), PLearn::SDBVMFieldDiscrete::setNumClasses(), and PLearn::TVec< T >::size().

Referenced by SDBVMFieldMultiDiscrete().

{
    fields_ = fields;
    int n = fields.size();
    field_multipliers_.resize(n);
    setNumClasses(0);

    // Compute all partial products from i to n
    if (n>0) {
        int prod = 1;
        field_multipliers_[n-1] = 1;
        for (int i=n-2; i>=0; --i) {
            prod *= fields[i+1]->getNumClasses();
            field_multipliers_[i] = prod;
        }
        prod *= fields[0]->getNumClasses();
        setNumClasses(prod);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

factor by which to multiply

Definition at line 894 of file SDBVMat.h.

Referenced by getDiscreteValue(), and setFields().

Definition at line 893 of file SDBVMat.h.

Referenced by getDiscreteValue(), and setFields().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines