Skip to content

Commit

Permalink
Fixed Plif and PlifMatrix SGVectors handling routines
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed May 9, 2012
1 parent 49462e7 commit ad0868b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
9 changes: 3 additions & 6 deletions src/shogun/structure/Plif.cpp
Expand Up @@ -23,9 +23,9 @@ using namespace shogun;
CPlif::CPlif(int32_t l)
: CPlifBase()
{
limits=NULL;
penalties=NULL;
cum_derivatives=NULL;
limits=SGVector<float64_t>();
penalties=SGVector<float64_t>();
cum_derivatives=SGVector<float64_t>();
id=-1;
transform=T_LINEAR;
name=NULL;
Expand All @@ -42,11 +42,8 @@ CPlif::CPlif(int32_t l)

CPlif::~CPlif()
{
SG_FREE(limits);
SG_FREE(penalties);
SG_FREE(name);
SG_FREE(cache);
SG_FREE(cum_derivatives);
}

bool CPlif::set_transform_type(const char *type_str)
Expand Down
29 changes: 13 additions & 16 deletions src/shogun/structure/Plif.h
Expand Up @@ -112,7 +112,7 @@ class CPlif: public CPlifBase
const float64_t * get_cum_derivative(int32_t & p_len) const
{
p_len = len;
return cum_derivatives;
return cum_derivatives.vector;
}

/** set transform type
Expand Down Expand Up @@ -255,8 +255,7 @@ class CPlif: public CPlifBase
{
ASSERT(len==p_limits.vlen);

for (int32_t i=0; i<len; i++)
limits[i]=p_limits.vector[i];
limits = p_limits;

invalidate_cache();
penalty_clear_derivative();
Expand All @@ -271,8 +270,7 @@ class CPlif: public CPlifBase
{
ASSERT(len==p_penalties.vlen);

for (int32_t i=0; i<len; i++)
penalties[i]=p_penalties.vector[i];
penalties = p_penalties;

invalidate_cache();
penalty_clear_derivative();
Expand All @@ -287,20 +285,18 @@ class CPlif: public CPlifBase
if (len!=p_len)
{
len=p_len;
SG_FREE(limits);
SG_FREE(penalties);
SG_FREE(cum_derivatives);

SG_DEBUG( "set_plif len=%i\n", p_len);
limits=SG_MALLOC(float64_t, len);
penalties=SG_MALLOC(float64_t, len);
cum_derivatives=SG_MALLOC(float64_t, len);
limits = SGVector<float64_t>(len);
penalties = SGVector<float64_t>(len);
cum_derivatives = SGVector<float64_t>(len);
}

for (int32_t i=0; i<len; i++)
{
limits[i]=0.0;
penalties[i]=0.0;
cum_derivatives[i]=0.0;
}

invalidate_cache();
Expand All @@ -313,7 +309,7 @@ class CPlif: public CPlifBase
*/
float64_t* get_plif_limits()
{
return limits;
return limits.vector;
}

/** get plif penalty
Expand All @@ -322,8 +318,9 @@ class CPlif: public CPlifBase
*/
float64_t* get_plif_penalties()
{
return penalties;
return penalties.vector;
}

/** set maximum value
*
* @param p_max_value maximum value
Expand Down Expand Up @@ -434,11 +431,11 @@ class CPlif: public CPlifBase
/** len */
int32_t len;
/** limits */
float64_t *limits;
SGVector<float64_t> limits;
/** penalties */
float64_t *penalties;
SGVector<float64_t> penalties;
/** cum derivatives */
float64_t *cum_derivatives;
SGVector<float64_t> cum_derivatives;
/** maximum value */
float64_t max_value;
/** minimum value */
Expand Down
10 changes: 4 additions & 6 deletions src/shogun/structure/PlifMatrix.cpp
Expand Up @@ -109,16 +109,15 @@ void CPlifMatrix::set_plif_limits(SGMatrix<float64_t> limits)
m_num_plifs, m_num_limits, limits.num_rows, limits.num_cols);
}

float64_t* lim = SG_MALLOC(float64_t, m_num_limits);
for (int32_t i=0; i<m_num_plifs; i++)
{
SGVector<float64_t> lim(m_num_limits);
for (int32_t k=0; k<m_num_limits; k++)
lim[k] = limits.matrix[i*m_num_limits+k];

int32_t id=get_plif_id(i);
m_PEN[id]->set_plif_limits(SGVector<float64_t>(lim, m_num_limits));
m_PEN[id]->set_plif_limits(lim);
}
SG_FREE(lim);
}

void CPlifMatrix::set_plif_penalties(SGMatrix<float64_t> penalties)
Expand All @@ -129,17 +128,16 @@ void CPlifMatrix::set_plif_penalties(SGMatrix<float64_t> penalties)
m_num_plifs, m_num_limits, penalties.num_rows, penalties.num_cols);
}

float64_t* pen = SG_MALLOC(float64_t, m_num_limits);
for (int32_t i=0; i<m_num_plifs; i++)
{
SGVector<float64_t> pen(m_num_limits);

for (int32_t k=0; k<m_num_limits; k++)
pen[k] = penalties.matrix[i*m_num_limits+k];

int32_t id=get_plif_id(i);
m_PEN[id]->set_plif_penalty(SGVector<float64_t>(pen, m_num_limits));
m_PEN[id]->set_plif_penalty(pen);
}
SG_FREE(pen);
}

void CPlifMatrix::set_plif_names(SGString<char>* names, int32_t num_values, int32_t maxlen)
Expand Down

0 comments on commit ad0868b

Please sign in to comment.