Skip to content

Commit

Permalink
Made feature block logistic regression outputs use sigmoid
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jul 10, 2012
1 parent 80adbb4 commit 2aba715
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/shogun/classifier/FeatureBlockLogisticRegression.cpp
Expand Up @@ -138,4 +138,33 @@ bool CFeatureBlockLogisticRegression::train_machine(CFeatures* data)
return true;
}

float64_t CFeatureBlockLogisticRegression::apply_one(int32_t vec_idx)
{
return CMath::exp(-(features->dense_dot(vec_idx, w.vector, w.vlen) + bias));
}

SGVector<float64_t> CFeatureBlockLogisticRegression::apply_get_outputs(CFeatures* data)
{
if (data)
{
if (!data->has_property(FP_DOT))
SG_ERROR("Specified features are not of type CDotFeatures\n");

set_features((CDotFeatures*) data);
}

if (!features)
return SGVector<float64_t>();

int32_t num=features->get_num_vectors();
ASSERT(num>0);
ASSERT(w.vlen==features->get_dim_feature_space());

float64_t* out=SG_MALLOC(float64_t, num);
features->dense_dot_range(out, 0, num, NULL, w.vector, w.vlen, bias);
for (int32_t i=0; i<num; i++)
out[i] = 2.0/(1.0+CMath::exp(-out[i])) - 1.0;//*CMath::exp(-CMath::sign(out[i])*out[i]);
return SGVector<float64_t>(out,num);
}

}
6 changes: 5 additions & 1 deletion src/shogun/classifier/FeatureBlockLogisticRegression.h
Expand Up @@ -55,8 +55,12 @@ class CFeatureBlockLogisticRegression : public CSLEPMachine
* @param feature_tree feature tree
*/
void set_feature_relation(CIndexBlockRelation* feature_relation);


virtual float64_t apply_one(int32_t vec_idx);

protected:

virtual SGVector<float64_t> apply_get_outputs(CFeatures* data);

/** train machine */
virtual bool train_machine(CFeatures* data=NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/machine/LinearMachine.h
Expand Up @@ -150,7 +150,7 @@ class CLinearMachine : public CMachine

protected:

SGVector<float64_t> apply_get_outputs(CFeatures* data);
virtual SGVector<float64_t> apply_get_outputs(CFeatures* data);

/** Stores feature data of underlying model. Does nothing because
* Linear machines store the normal vector of the separating hyperplane
Expand Down

0 comments on commit 2aba715

Please sign in to comment.