Skip to content

Commit

Permalink
fixed a typo
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkerlin committed Dec 19, 2015
1 parent b3dd119 commit fcc1a6a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
28 changes: 26 additions & 2 deletions src/shogun/optimization/ElasticNetPenalty.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ namespace shogun
* ElasticNet(w)= \lambda \| w \|_1 + (1.0-\lambda) \| w \|_2
* \f]
* where \f$\lambda\f$ is the l1_ratio.
*
* Reference:
* Zou, Hui, and Trevor Hastie. "Regularization and variable selection via the elastic net."
* Journal of the Royal Statistical Society: Series B (Statistical Methodology) 67.2 (2005): 301-320.
*/

class ElasticNetPenalty: public SparsePenalty
Expand Down Expand Up @@ -83,6 +87,12 @@ class ElasticNetPenalty: public SparsePenalty
return penalty;
}

/** Return the gradient of the penalty wrt a target variable
*
* @param variable value of a target variable
* @param gradient_of_variable unregularized/unpenalized gradient of the variable
* @return the gradient of the penalty wrt the variable
*/
virtual float64_t get_penalty_gradient(float64_t variable,
float64_t gradient_of_variable)
{
Expand All @@ -92,11 +102,20 @@ class ElasticNetPenalty: public SparsePenalty
return grad;
}

virtual void set_rounding_eplison(float64_t eplison)
/** Set the rounding epslion for L1 penalty
*
* @param epslion rounding epslion
*
*/
virtual void set_rounding_epslion(float64_t epslion)
{
m_l1_penalty->set_rounding_eplison(eplison);
m_l1_penalty->set_rounding_epslion(epslion);
}

/** Do proximal projection/operation in place
* @param variable the raw variable
* @param penalty_weight weight of the penalty
*/
virtual void update_variable_for_proximity(SGVector<float64_t> variable,
float64_t proximal_weight)
{
Expand Down Expand Up @@ -127,6 +146,11 @@ class ElasticNetPenalty: public SparsePenalty
m_l2_penalty->load_from_context(context);
}

/** Get the sparse variable
* @param variable the raw variable
* @param penalty_weight weight of the penalty
* @return sparse value of the variable
*/
virtual float64_t get_sparse_variable(float64_t variable, float64_t penalty_weight)
{
check_ratio();
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/optimization/StochasticMinimizers_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ TEST(L1PenaltyForTG, test1)
opt->set_penalty_weight(0.01);
L1Penalty* penalty_type=new L1PenaltyForTG();

penalty_type->set_rounding_eplison(0);
penalty_type->set_rounding_epslion(0);
opt->set_penalty_type(penalty_type);
opt->set_number_passes(1);
opt->set_learning_rate(rate);
Expand Down Expand Up @@ -1079,7 +1079,7 @@ TEST(L1PenaltyForTG, test2)

opt->set_penalty_weight(0.01);
L1Penalty* penalty_type=new L1PenaltyForTG();
penalty_type->set_rounding_eplison(0);
penalty_type->set_rounding_epslion(0);

opt->set_penalty_type(penalty_type);
opt->set_number_passes(1);
Expand All @@ -1104,7 +1104,7 @@ TEST(L1PenaltyForTG, test2)
opt2->set_gradient_updater(updater2);
opt2->set_penalty_weight(0.01);
L1Penalty* penalty_type2=new L1PenaltyForTG();
penalty_type2->set_rounding_eplison(0);
penalty_type2->set_rounding_epslion(0);

opt2->set_penalty_type(penalty_type2);
opt2->set_number_passes(1);
Expand Down Expand Up @@ -1225,7 +1225,7 @@ TEST(SMIDASMinimizer, test1)

opt->set_penalty_weight(0.01);
L1Penalty* penalty_type=new L1Penalty();
penalty_type->set_rounding_eplison(1e-8);
penalty_type->set_rounding_epslion(1e-8);
opt->set_penalty_type(penalty_type);
opt->set_number_passes(1);
opt->set_learning_rate(rate);
Expand All @@ -1250,7 +1250,7 @@ TEST(SMIDASMinimizer, test1)
opt2->set_mapping_function(mapping2);
opt2->set_penalty_weight(0.01);
L1Penalty* penalty_type2=new L1Penalty();
penalty_type2->set_rounding_eplison(1e-8);
penalty_type2->set_rounding_epslion(1e-8);
opt2->set_penalty_type(penalty_type2);
opt2->set_number_passes(1);
opt2->set_learning_rate(rate2);
Expand Down

0 comments on commit fcc1a6a

Please sign in to comment.