Skip to content

Commit

Permalink
Read only property (#4549)
Browse files Browse the repository at this point in the history
* example implementation
* replaced put with init in kernel
  • Loading branch information
Gil authored and karlnapf committed Mar 12, 2019
1 parent 51b600b commit 463b648
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
3 changes: 2 additions & 1 deletion examples/meta/src/gaussian_process/regression.sg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Labels labels_test = labels(f_labels_test)
#![create_features]

#![create_appropriate_kernel_and_mean_function]
Kernel k = kernel("GaussianKernel", lhs=features_train, rhs=features_train, log_width=0.0)
Kernel k = kernel("GaussianKernel", log_width=0.0)
k.init(features_train, features_train)
MeanFunction mean = gp_mean("ZeroMean")
#![create_appropriate_kernel_and_mean_function]

Expand Down
3 changes: 2 additions & 1 deletion examples/meta/src/gaussian_process/sparse_regression.sg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ RegressionLabels labels_test(f_labels_test)
#![create_features]

#![create_kernel_and_mean_function]
Kernel k = kernel("GaussianKernel", lhs=features_train, rhs=features_train, log_width=0.0)
Kernel k = kernel("GaussianKernel", log_width=0.0)
k.init(features_train, features_train)
ZeroMean mean_function()
#![create_kernel_and_mean_function]

Expand Down
3 changes: 2 additions & 1 deletion src/shogun/base/AnyParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace shogun
HYPER = 1u << 0,
GRADIENT = 1u << 1,
MODEL = 1u << 2,
AUTO = 1u << 10
AUTO = 1u << 10,
READONLY = 1u << 11
};

enableEnumClassBitmask(ParameterProperties);
Expand Down
10 changes: 9 additions & 1 deletion src/shogun/base/SGObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,15 @@ void CSGObject::create_parameter(

void CSGObject::update_parameter(const BaseTag& _tag, const Any& value)
{
self->update(_tag, value);
if (!self->map[_tag].get_properties().has_property(
ParameterProperties::READONLY))
self->update(_tag, value);
else
{
SG_ERROR(
"%s::%s is marked as read-only and cannot be modified", get_name(),
_tag.name().c_str());
}
self->map[_tag].get_properties().remove_property(ParameterProperties::AUTO);
}

Expand Down
3 changes: 2 additions & 1 deletion src/shogun/features/DenseFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,8 @@ template<class ST> void CDenseFeatures<ST>::init()
SG_ADD(&num_vectors, "num_vectors", "Number of vectors.");
SG_ADD(&num_features, "num_features", "Number of features.");
SG_ADD(&feature_matrix, "feature_matrix",
"Matrix of feature vectors / 1 vector per column.");
"Matrix of feature vectors / 1 vector per column.",
ParameterProperties::READONLY);
}

#define GET_FEATURE_TYPE(f_type, sg_type) \
Expand Down
11 changes: 7 additions & 4 deletions src/shogun/kernel/Kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,11 +920,14 @@ void CKernel::save_serializable_post() throw (ShogunException)
void CKernel::register_params()
{
SG_ADD(&cache_size, "cache_size", "Cache size in MB.");
SG_ADD(&lhs, "lhs", "Feature vectors to occur on left hand side.");
SG_ADD(&rhs, "rhs", "Feature vectors to occur on right hand side.");
SG_ADD(
&lhs_equals_rhs, "lhs_equals_rhs",
"If features on lhs are the same as on rhs.");
&lhs, "lhs", "Feature vectors to occur on left hand side.",
ParameterProperties::READONLY);
SG_ADD(
&rhs, "rhs", "Feature vectors to occur on right hand side.",
ParameterProperties::READONLY);
SG_ADD(&lhs_equals_rhs, "lhs_equals_rhs",
"If features on lhs are the same as on rhs.");
SG_ADD(&num_lhs, "num_lhs", "Number of feature vectors on left hand side.");
SG_ADD(
&num_rhs, "num_rhs", "Number of feature vectors on right hand side.");
Expand Down

0 comments on commit 463b648

Please sign in to comment.