Skip to content

Commit

Permalink
Renamed features space to feature space.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed Mar 27, 2024
1 parent 7750a5b commit 959dd0b
Show file tree
Hide file tree
Showing 42 changed files with 410 additions and 411 deletions.
4 changes: 2 additions & 2 deletions bindings/python/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ EXTRA_DIST = \
cconfigspace/rng.py \
cconfigspace/context.py \
cconfigspace/parameter.py \
cconfigspace/features_space.py \
cconfigspace/feature_space.py \
cconfigspace/distribution.py \
cconfigspace/map.py \
cconfigspace/expression_parser.py \
Expand Down Expand Up @@ -43,7 +43,7 @@ EXTRA_DIST = \
test/test_features_tuner.py \
test/test_objective_space.py \
test/test_configuration_space.py \
test/test_features_space.py \
test/test_feature_space.py \
setup.py

if ISMACOS
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/cconfigspace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .distribution_space import *
from .binding import *
from .configuration import *
from .features_space import *
from .feature_space import *
from .features import *
from .objective_space import *
from .evaluation_binding import *
Expand Down
8 changes: 4 additions & 4 deletions bindings/python/cconfigspace/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __str__(self):
ccs_configuration_space = ccs_object
ccs_binding = ccs_object
ccs_configuration = ccs_object
ccs_features_space = ccs_object
ccs_feature_space = ccs_object
ccs_features = ccs_object
ccs_objective_space = ccs_object
ccs_evaluation_binding = ccs_object
Expand Down Expand Up @@ -146,7 +146,7 @@ class ObjectType(CEnumeration):
'OBJECTIVE_SPACE',
'EVALUATION',
'TUNER',
'FEATURES_SPACE',
'FEATURE_SPACE',
'FEATURES',
'FEATURES_EVALUATION',
'FEATURES_TUNER',
Expand Down Expand Up @@ -754,7 +754,7 @@ def _ccs_get_id():
from .configuration_space import ConfigurationSpace
from .distribution_space import DistributionSpace
from .configuration import Configuration
from .features_space import FeaturesSpace
from .feature_space import FeatureSpace
from .features import Features
from .objective_space import ObjectiveSpace
from .evaluation import Evaluation
Expand All @@ -776,7 +776,7 @@ def _ccs_get_id():
ObjectType.EXPRESSION: Expression,
ObjectType.CONFIGURATION_SPACE: ConfigurationSpace,
ObjectType.CONFIGURATION: Configuration,
ObjectType.FEATURES_SPACE: ConfigurationSpace,
ObjectType.FEATURE_SPACE: FeatureSpace,
ObjectType.FEATURES: Features,
ObjectType.OBJECTIVE_SPACE: ObjectiveSpace,
ObjectType.EVALUATION: Evaluation,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import ctypes as ct
from .base import Object, Error, CEnumeration, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_features_space, ccs_features, Datum, ccs_bool
from .base import Object, Error, CEnumeration, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_feature_space, ccs_features, Datum, ccs_bool
from .context import Context
from .parameter import Parameter

ccs_create_features_space = _ccs_get_function("ccs_create_features_space", [ct.c_char_p, ct.c_size_t, ct.POINTER(ccs_parameter), ct.POINTER(ccs_features_space)])
ccs_features_space_check_features = _ccs_get_function("ccs_features_space_check_features", [ccs_features_space, ccs_features, ct.POINTER(ccs_bool)])
ccs_create_feature_space = _ccs_get_function("ccs_create_feature_space", [ct.c_char_p, ct.c_size_t, ct.POINTER(ccs_parameter), ct.POINTER(ccs_feature_space)])
ccs_feature_space_check_features = _ccs_get_function("ccs_feature_space_check_features", [ccs_feature_space, ccs_features, ct.POINTER(ccs_bool)])

class FeaturesSpace(Context):
class FeatureSpace(Context):
def __init__(self, handle = None, retain = False, auto_release = True,
name = "", parameters = None):
if handle is None:
count = len(parameters)
parameters = (ccs_parameter * count)(*[x.handle.value for x in parameters])
handle = ccs_features_space()
res = ccs_create_features_space(str.encode(name), count, parameters, ct.byref(handle))
handle = ccs_feature_space()
res = ccs_create_feature_space(str.encode(name), count, parameters, ct.byref(handle))
Error.check(res)
super().__init__(handle = handle, retain = False)
else:
Expand All @@ -25,7 +25,7 @@ def from_handle(cls, handle, retain = True, auto_release = True):

def check(self, features):
valid = ccs_bool()
res = ccs_features_space_check_features(self.handle, features.handle, ct.byref(valid))
res = ccs_feature_space_check_features(self.handle, features.handle, ct.byref(valid))
Error.check(res)
return False if valid.value == 0 else True

26 changes: 13 additions & 13 deletions bindings/python/cconfigspace/features.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import ctypes as ct
from .base import Object, Error, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_features_space, ccs_features, Datum, ccs_hash, ccs_int, ccs_bool
from .base import Object, Error, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_feature_space, ccs_features, Datum, ccs_hash, ccs_int, ccs_bool
from .context import Context
from .parameter import Parameter
from .features_space import FeaturesSpace
from .feature_space import FeatureSpace
from .binding import Binding

ccs_create_features = _ccs_get_function("ccs_create_features", [ccs_features_space, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_features)])
ccs_features_get_features_space = _ccs_get_function("ccs_features_get_features_space", [ccs_features, ct.POINTER(ccs_features_space)])
ccs_create_features = _ccs_get_function("ccs_create_features", [ccs_feature_space, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_features)])
ccs_features_get_feature_space = _ccs_get_function("ccs_features_get_feature_space", [ccs_features, ct.POINTER(ccs_feature_space)])
ccs_features_check = _ccs_get_function("ccs_features_check", [ccs_features, ct.POINTER(ccs_bool)])

class Features(Binding):
def __init__(self, handle = None, retain = False, auto_release = True,
features_space = None, values = None):
feature_space = None, values = None):
if handle is None:
count = 0
if values:
Expand All @@ -23,7 +23,7 @@ def __init__(self, handle = None, retain = False, auto_release = True,
else:
vals = None
handle = ccs_features()
res = ccs_create_features(features_space.handle, count, vals, ct.byref(handle))
res = ccs_create_features(feature_space.handle, count, vals, ct.byref(handle))
Error.check(res)
super().__init__(handle = handle, retain = False)
else:
Expand All @@ -34,14 +34,14 @@ def from_handle(cls, handle, retain = True, auto_release = True):
return cls(handle = handle, retain = retain, auto_release = auto_release)

@property
def features_space(self):
if hasattr(self, "_features_space"):
return self._features_space
v = ccs_features_space()
res = ccs_features_get_features_space(self.handle, ct.byref(v))
def feature_space(self):
if hasattr(self, "_feature_space"):
return self._feature_space
v = ccs_feature_space()
res = ccs_features_get_feature_space(self.handle, ct.byref(v))
Error.check(res)
self._features_space = ConfigurationSpace.from_handle(v)
return self._features_space
self._feature_space = FeatureSpace.from_handle(v)
return self._feature_space

def check(self):
valid = ccs_bool()
Expand Down
32 changes: 16 additions & 16 deletions bindings/python/cconfigspace/features_tuner.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ctypes as ct
from .base import Object, Error, CEnumeration, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_configuration_space, ccs_configuration, ccs_features_space, ccs_features, Datum, ccs_objective_space, ccs_features_evaluation, ccs_features_tuner, ccs_retain_object, _register_vector, _unregister_vector
from .base import Object, Error, CEnumeration, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_configuration_space, ccs_configuration, ccs_feature_space, ccs_features, Datum, ccs_objective_space, ccs_features_evaluation, ccs_features_tuner, ccs_retain_object, _register_vector, _unregister_vector
from .context import Context
from .parameter import Parameter
from .configuration_space import ConfigurationSpace
from .configuration import Configuration
from .features_space import FeaturesSpace
from .feature_space import FeatureSpace
from .features import Features
from .objective_space import ObjectiveSpace
from .features_evaluation import FeaturesEvaluation
Expand All @@ -18,7 +18,7 @@ class FeaturesTunerType(CEnumeration):
ccs_features_tuner_get_name = _ccs_get_function("ccs_features_tuner_get_name", [ccs_features_tuner, ct.POINTER(ct.c_char_p)])
ccs_features_tuner_get_configuration_space = _ccs_get_function("ccs_features_tuner_get_configuration_space", [ccs_features_tuner, ct.POINTER(ccs_configuration_space)])
ccs_features_tuner_get_objective_space = _ccs_get_function("ccs_features_tuner_get_objective_space", [ccs_features_tuner, ct.POINTER(ccs_objective_space)])
ccs_features_tuner_get_features_space = _ccs_get_function("ccs_features_tuner_get_features_space", [ccs_features_tuner, ct.POINTER(ccs_features_space)])
ccs_features_tuner_get_feature_space = _ccs_get_function("ccs_features_tuner_get_feature_space", [ccs_features_tuner, ct.POINTER(ccs_feature_space)])
ccs_features_tuner_ask = _ccs_get_function("ccs_features_tuner_ask", [ccs_features_tuner, ccs_features, ct.c_size_t, ct.POINTER(ccs_configuration), ct.POINTER(ct.c_size_t)])
ccs_features_tuner_tell = _ccs_get_function("ccs_features_tuner_tell", [ccs_features_tuner, ct.c_size_t, ct.POINTER(ccs_features_evaluation)])
ccs_features_tuner_get_optima = _ccs_get_function("ccs_features_tuner_get_optima", [ccs_features_tuner, ccs_features, ct.c_size_t, ct.POINTER(ccs_features_evaluation), ct.POINTER(ct.c_size_t)])
Expand Down Expand Up @@ -70,14 +70,14 @@ def objective_space(self):
return self._objective_space

@property
def features_space(self):
if hasattr(self, "_features_space"):
return self._features_space
v = ccs_features_space()
res = ccs_features_tuner_get_features_space(self.handle, ct.byref(v))
def feature_space(self):
if hasattr(self, "_feature_space"):
return self._feature_space
v = ccs_feature_space()
res = ccs_features_tuner_get_feature_space(self.handle, ct.byref(v))
Error.check(res)
self._features_space = FeaturesSpace.from_handle(v)
return self._features_space
self._feature_space = FeatureSpace.from_handle(v)
return self._feature_space

@property
def configuration_space(self):
Expand Down Expand Up @@ -143,14 +143,14 @@ def suggest(self, features):
Error.check(res)
return Configuration(handle = config, retain = False)

ccs_create_random_features_tuner = _ccs_get_function("ccs_create_random_features_tuner", [ct.c_char_p, ccs_configuration_space, ccs_features_space, ccs_objective_space, ct.POINTER(ccs_features_tuner)])
ccs_create_random_features_tuner = _ccs_get_function("ccs_create_random_features_tuner", [ct.c_char_p, ccs_configuration_space, ccs_feature_space, ccs_objective_space, ct.POINTER(ccs_features_tuner)])

class RandomFeaturesTuner(FeaturesTuner):
def __init__(self, handle = None, retain = False, auto_release = True,
name = "", configuration_space = None, features_space = None, objective_space = None):
name = "", configuration_space = None, feature_space = None, objective_space = None):
if handle is None:
handle = ccs_features_tuner()
res = ccs_create_random_features_tuner(str.encode(name), configuration_space.handle, features_space.handle, objective_space.handle, ct.byref(handle))
res = ccs_create_random_features_tuner(str.encode(name), configuration_space.handle, feature_space.handle, objective_space.handle, ct.byref(handle))
Error.check(res)
super().__init__(handle = handle, retain = False)
else:
Expand Down Expand Up @@ -178,7 +178,7 @@ class UserDefinedFeaturesTunerVector(ct.Structure):
('serialize', ccs_user_defined_features_tuner_serialize_type),
('deserialize', ccs_user_defined_features_tuner_deserialize_type) ]

ccs_create_user_defined_features_tuner = _ccs_get_function("ccs_create_user_defined_features_tuner", [ct.c_char_p, ccs_configuration_space, ccs_features_space, ccs_objective_space, ct.POINTER(UserDefinedFeaturesTunerVector), ct.py_object, ct.POINTER(ccs_features_tuner)])
ccs_create_user_defined_features_tuner = _ccs_get_function("ccs_create_user_defined_features_tuner", [ct.c_char_p, ccs_configuration_space, ccs_feature_space, ccs_objective_space, ct.POINTER(UserDefinedFeaturesTunerVector), ct.py_object, ct.POINTER(ccs_features_tuner)])
ccs_user_defined_features_tuner_get_tuner_data = _ccs_get_function("ccs_user_defined_features_tuner_get_tuner_data", [ccs_features_tuner, ct.POINTER(ct.c_void_p)])

def _wrap_user_defined_features_tuner_callbacks(delete, ask, tell, get_optima, get_history, suggest, serialize, deserialize):
Expand Down Expand Up @@ -346,7 +346,7 @@ def deserialize_wrapper(tun, size_history, p_history, num_optima, p_optima, stat

class UserDefinedFeaturesTuner(FeaturesTuner):
def __init__(self, handle = None, retain = False, auto_release = True,
name = "", configuration_space = None, features_space = None, objective_space = None, delete = None, ask = None, tell = None, get_optima = None, get_history = None, suggest = None, serialize = None, deserialize = None, tuner_data = None ):
name = "", configuration_space = None, feature_space = None, objective_space = None, delete = None, ask = None, tell = None, get_optima = None, get_history = None, suggest = None, serialize = None, deserialize = None, tuner_data = None ):
if handle is None:
if ask is None or tell is None or get_optima is None or get_history is None:
raise Error(Result(Result.ERROR_INVALID_VALUE))
Expand Down Expand Up @@ -381,7 +381,7 @@ def __init__(self, handle = None, retain = False, auto_release = True,
c_tuner_data = ct.py_object(tuner_data)
else:
c_tuner_data = None
res = ccs_create_user_defined_features_tuner(str.encode(name), configuration_space.handle, features_space.handle, objective_space.handle, ct.byref(vec), c_tuner_data, ct.byref(handle))
res = ccs_create_user_defined_features_tuner(str.encode(name), configuration_space.handle, feature_space.handle, objective_space.handle, ct.byref(vec), c_tuner_data, ct.byref(handle))
Error.check(res)
super().__init__(handle = handle, retain = False)
_register_vector(handle, [delete_wrapper, ask_wrapper, tell_wrapper, get_optima_wrapper, get_history_wrapper, suggest_wrapper, serialize_wrapper, deserialize_wrapper, delete_wrapper_func, ask_wrapper_func, tell_wrapper_func, get_optima_wrapper_func, get_history_wrapper_func, suggest_wrapper_func, serialize_wrapper_func, deserialize_wrapper_func, tuner_data])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
sys.path.insert(1, '..')
import cconfigspace as ccs

class TestFeaturesSpace(unittest.TestCase):
class TestFeatureSpace(unittest.TestCase):

def test_create(self):
h1 = ccs.NumericalParameter.Float(lower = 0.0, upper = 1.0)
h2 = ccs.NumericalParameter.Float(lower = 0.0, upper = 1.0)
h3 = ccs.NumericalParameter.Float(lower = 0.0, upper = 1.0)
cs = ccs.FeaturesSpace(name = "space", parameters = [h1, h2, h3])
self.assertEqual( ccs.ObjectType.FEATURES_SPACE, cs.object_type )
cs = ccs.FeatureSpace(name = "space", parameters = [h1, h2, h3])
self.assertEqual( ccs.ObjectType.FEATURE_SPACE, cs.object_type )
self.assertEqual( "space", cs.name )
self.assertEqual( 3, cs.num_parameters )
self.assertEqual( h1, cs.parameter(0) )
Expand Down
16 changes: 8 additions & 8 deletions bindings/python/test/test_features_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ def create_tuning_problem(self):
e2 = ccs.Expression.Variable(parameter = v2)
os = ccs.ObjectiveSpace(name = "ospace", parameters = [v1, v2], objectives = [e1, e2])
f1 = ccs.CategoricalParameter(values = [True, False])
fs = ccs.FeaturesSpace(name = "fspace", parameters = [f1])
fs = ccs.FeatureSpace(name = "fspace", parameters = [f1])
return (cs, fs, os)

def test_create_random(self):
(cs, fs, os) = self.create_tuning_problem()
t = ccs.RandomFeaturesTuner(name = "tuner", configuration_space = cs, features_space = fs, objective_space = os)
t = ccs.RandomFeaturesTuner(name = "tuner", configuration_space = cs, feature_space = fs, objective_space = os)
t2 = ccs.Object.from_handle(t.handle)
self.assertEqual("tuner", t.name)
self.assertEqual(ccs.FeaturesTunerType.RANDOM, t.type)
func = lambda x, y, z: [(x-2)*(x-2), sin(z+y)]
features_on = ccs.Features(features_space = fs, values = [True])
features_off = ccs.Features(features_space = fs, values = [False])
features_on = ccs.Features(feature_space = fs, values = [True])
features_off = ccs.Features(feature_space = fs, values = [False])
evals = [ccs.FeaturesEvaluation(objective_space = os, configuration = c, features = features_on, values = func(*(c.values))) for c in t.ask(features_on, 50)]
t.tell(evals)
evals = [ccs.FeaturesEvaluation(objective_space = os, configuration = c, features = features_off, values = func(*(c.values))) for c in t.ask(features_off, 50)]
Expand Down Expand Up @@ -119,16 +119,16 @@ def suggest(tuner, features):
return choice(optis).configuration

(cs, fs, os) = self.create_tuning_problem()
t = ccs.UserDefinedFeaturesTuner(name = "tuner", configuration_space = cs, features_space = fs, objective_space = os, delete = delete, ask = ask, tell = tell, get_optima = get_optima, get_history = get_history, suggest = suggest, tuner_data = TunerData())
t = ccs.UserDefinedFeaturesTuner(name = "tuner", configuration_space = cs, feature_space = fs, objective_space = os, delete = delete, ask = ask, tell = tell, get_optima = get_optima, get_history = get_history, suggest = suggest, tuner_data = TunerData())
t2 = ccs.Object.from_handle(t.handle)
self.assertEqual("tuner", t.name)
self.assertEqual(ccs.FeaturesTunerType.USER_DEFINED, t.type)
self.assertEqual(cs.handle.value, t.configuration_space.handle.value)
self.assertEqual(fs.handle.value, t.features_space.handle.value)
self.assertEqual(fs.handle.value, t.feature_space.handle.value)
self.assertEqual(os.handle.value, t.objective_space.handle.value)
func = lambda x, y, z: [(x-2)*(x-2), sin(z+y)]
features_on = ccs.Features(features_space = fs, values = [True])
features_off = ccs.Features(features_space = fs, values = [False])
features_on = ccs.Features(feature_space = fs, values = [True])
features_off = ccs.Features(feature_space = fs, values = [False])
evals = [ccs.FeaturesEvaluation(objective_space = os, configuration = c, features = features_on, values = func(*(c.values))) for c in t.ask(features_on, 50)]
t.tell(evals)
evals = [ccs.FeaturesEvaluation(objective_space = os, configuration = c, features = features_off, values = func(*(c.values))) for c in t.ask(features_off, 50)]
Expand Down
4 changes: 2 additions & 2 deletions bindings/ruby/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ EXTRA_DIST = \
lib/cconfigspace/tree_tuner.rb \
lib/cconfigspace/binding.rb \
lib/cconfigspace/tree_space.rb \
lib/cconfigspace/features_space.rb \
lib/cconfigspace/feature_space.rb \
lib/cconfigspace/base.rb \
lib/cconfigspace/configuration_space.rb \
lib/cconfigspace/distribution_space.rb \
Expand All @@ -28,7 +28,7 @@ EXTRA_DIST = \
lib/cconfigspace/error_stack.rb \
lib/cconfigspace/tree_configuration.rb \
lib/cconfigspace/context.rb \
test/test_features_space.rb \
test/test_feature_space.rb \
test/test_expression.rb \
test/test_tree_evaluation.rb \
test/test_interval.rb \
Expand Down
2 changes: 1 addition & 1 deletion bindings/ruby/lib/cconfigspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
require_relative 'cconfigspace/distribution_space'
require_relative 'cconfigspace/binding'
require_relative 'cconfigspace/configuration'
require_relative 'cconfigspace/features_space'
require_relative 'cconfigspace/feature_space'
require_relative 'cconfigspace/features'
require_relative 'cconfigspace/objective_space'
require_relative 'cconfigspace/evaluation_binding'
Expand Down
Loading

0 comments on commit 959dd0b

Please sign in to comment.