Github user iyerr3 commented on a diff in the pull request:
https://github.com/apache/incubator-madlib/pull/4#discussion_r45806931
--- Diff: src/ports/postgres/modules/svm/svm.py_in ---
@@ -440,55 +595,68 @@ def _process_epsilon(is_svc, args):
def _extract_params(schema_madlib, params, module='SVM'):
# NOTICE: the type of values in params_default should be consistent
with
# the types specified in params_types
- params_default = {'init_stepsize': 0.01,
- 'decay_factor': 0.9,
- 'max_iter': 100,
- 'tolerance': 1e-10,
- 'lambda': 1.0,
- 'norm': 'L2',
- 'n_folds': 0,
- 'epsilon': 0.01,
- 'eps_table': ''}
-
- params_types = {'init_stepsize': float,
- 'decay_factor': float,
- 'max_iter': int,
- 'tolerance': float,
- 'lambda': list,
- 'norm': str,
- 'n_folds': int,
- 'epsilon': float,
- 'eps_table': str}
+ params_default = {
+ 'init_stepsize': [0.01],
+ 'decay_factor': [0.9],
+ 'max_iter': [100],
+ 'tolerance': 1e-10,
+ 'lambda': [0.01],
+ 'norm': 'L2',
+ 'n_folds': 0,
+ 'validation_result': '',
+ 'epsilon': [0.01],
+ 'eps_table': ''}
+
+ params_types = {
+ 'init_stepsize': list,
+ 'decay_factor': list,
+ 'max_iter': list,
+ 'tolerance': float,
+ 'lambda': list,
+ 'norm': str,
+ 'n_folds': int,
+ 'validation_result': str,
+ 'epsilon': list,
+ 'eps_table': str}
params_vals = extract_keyvalue_params(params,
params_types,
params_default)
-
if params_vals['n_folds'] < 0:
- plpy.error("SVM error: n_folds must be non-negative")
- # FIXME
- _assert(params_vals['n_folds'] <= 1,
- "SVM error: cross-validation has not been implemented")
+ plpy.error("{0} error: n_folds must be
non-negative!".format(module))
# validate lambda
- if hasattr(params_vals['lambda'], '__len__'):
- # this check should be removed after cross validation is added
- if len(params_vals['lambda']) != 1:
- plpy.error("{0} error: lambda must be a scalar or of length 1
when n_folds is 0 or 1".format(module))
- params_vals['lambda'] = params_vals['lambda'][0]
- _assert(params_vals['lambda'] >= 0,
- "SVM error: lambda must be non-negative!")
+ params_vals['lambda'] = map(float, params_vals['lambda'])
+ if [lmd for lmd in params_vals['lambda'] if lmd < 0]:
+ plpy.error("{0} error: lambda must be "
+ "non-negative!".format(module))
+ # validate epsilon
+ params_vals['epsilon'] = map(float, params_vals['epsilon'])
+ if [e for e in params_vals['epsilon'] if e < 0]:
+ plpy.error("{0} error: epsilon must be "
+ "non-negative!".format(module))
+ # validating cross validation is delegated to _cross_validate_svm()
+ params_vals['init_stepsize'] = map(float, params_vals['init_stepsize'])
+ if [e for e in params_vals['init_stepsize'] if e < 0]:
+ plpy.error("{0} error: init_stepsize must be
positive!".format(module))
+
+ params_vals['max_iter'] = map(int, params_vals['max_iter'])
+ if [e for e in params_vals['max_iter'] if e < 0]:
+ plpy.error("{0} error: max_iter must be positive!".format(module))
+
+ params_vals['decay_factor'] = map(float, params_vals['decay_factor'])
+ if [e for e in params_vals['decay_factor'] if e > 1]:
+ plpy.error("{0} error: decay_factor must be <= 1!".format(module))
+
+ if params_vals['validation_result']:
+ output_tbl_valid(params_vals['validation_result'], 'SVM')
+
params_vals['norm'] = params_vals['norm'].lower()
- _assert(params_vals['norm'] == 'l1' or params_vals['norm'] == 'l2',
- "SVM error: norm must be either L1 or L2")
- _assert(params_vals['init_stepsize'] > 0,
- "SVM error: init_stepsize must be positive")
- _assert(params_vals['decay_factor'] <= 1,
- "SVM error: decay_factor must be <= 1")
- _assert(params_vals['max_iter'] > 0,
- "SVM error: max_iter must be positive")
- _assert(params_vals['tolerance'] >= 0,
- "SVM error: tolerance must be non-negative")
- _assert(params_vals['epsilon'] >= 0,
- "SVM error: epsilon cannot be less than 0")
+ if params_vals['norm'] != 'l1' and params_vals['norm'] != 'l2':
+ plpy.error("{0} error: norm must be either L1 or
L2!".format(module))
+ if params_vals['tolerance'] < 0:
+ plpy.error("{0} error: tolerance must be
non-negative!".format(module))
--- End diff --
let's use the `assert` formulation for all the above error messages.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---