Github user njayaram2 commented on a diff in the pull request:

    https://github.com/apache/incubator-madlib/pull/162#discussion_r132058905
  
    --- Diff: src/ports/postgres/modules/convex/mlp_igd.py_in ---
    @@ -59,60 +63,115 @@ def mlp(schema_madlib, source_table, output_table, 
independent_varname,
         Returns:
             None
         """
    -    with MinWarning('warning'):
    -        optimizer_params = _get_optimizer_params(optimizer_param_str or "")
    -        summary_table = add_postfix(output_table, "_summary")
    -        _validate_args(source_table, output_table, summary_table, 
independent_varname,
    -                       dependent_varname, hidden_layer_sizes,
    -                       optimizer_params, is_classification)
    -
    -        current_iteration = 1
    -        prev_state = None
    -        tolerance = optimizer_params["tolerance"]
    -        n_iterations = optimizer_params["n_iterations"]
    -        step_size = optimizer_params["step_size"]
    -        n_tries = optimizer_params["n_tries"]
    -        activation_name = _get_activation_function_name(activation)
    -        activation_index = _get_activation_index(activation_name)
    -        num_input_nodes = array_col_dimension(
    -            source_table, independent_varname)
    -        num_output_nodes = 0
    -        classes = []
    -        dependent_type = get_expr_type(dependent_varname, source_table)
    -        original_dependent_varname = dependent_varname
    -
    -        if is_classification:
    -            dependent_variable_sql = """
    -                SELECT DISTINCT {dependent_varname}
    -                FROM {source_table}
    -                """.format(dependent_varname=dependent_varname,
    -                           source_table=source_table)
    -            labels = plpy.execute(dependent_variable_sql)
    -            one_hot_dependent_varname = 'ARRAY['
    -            num_output_nodes = len(labels)
    -            for label_obj in labels:
    -                label = _format_label(label_obj[dependent_varname])
    -                classes.append(label)
    -                one_hot_dependent_varname += dependent_varname + \
    -                    "=" + str(label) + ","
    -            # Remove the last comma
    -            one_hot_dependent_varname = one_hot_dependent_varname[:-1]
    -            one_hot_dependent_varname += ']::integer[]'
    -            dependent_varname = one_hot_dependent_varname
    -        else:
    -            if "[]" not in dependent_type:
    -                dependent_varname = "ARRAY[" + dependent_varname + "]"
    -            num_output_nodes = array_col_dimension(
    -                source_table, dependent_varname)
    -        layer_sizes = [num_input_nodes] + \
    -            hidden_layer_sizes + [num_output_nodes]
    +    warm_start = bool(warm_start)
    +    optimizer_params = _get_optimizer_params(optimizer_param_str or "")
    +    summary_table = add_postfix(output_table, "_summary")
    +    weights = '1' if not weights or not weights.strip() else 
weights.strip()
    +    hidden_layer_sizes = hidden_layer_sizes or []
    +    activation = _get_activation_function_name(activation)
    +    learning_rate_policy = _get_learning_rate_policy_name(
    +        optimizer_params["learning_rate_policy"])
    +    activation_index = _get_activation_index(activation)
    +
    +    _validate_args(source_table, output_table, summary_table, 
independent_varname,
    +                   dependent_varname, hidden_layer_sizes,
    +                   optimizer_params, is_classification, weights,
    +                   warm_start, activation)
    +
    +    current_iteration = 1
    +    prev_state = None
    +    tolerance = optimizer_params["tolerance"]
    +    n_iterations = optimizer_params["n_iterations"]
    +    step_size_init = optimizer_params["learning_rate_init"]
    +    iterations_per_step = optimizer_params["iterations_per_step"]
    +    power = optimizer_params["power"]
    +    gamma = optimizer_params["gamma"]
    +    step_size = step_size_init
    +    n_tries = optimizer_params["n_tries"]
    +    # lambda is a reserved word in python
    +    lmbda = optimizer_params["lambda"]
    +    iterations_per_step = optimizer_params["iterations_per_step"]
    +    num_input_nodes = array_col_dimension(source_table,
    +                                          independent_varname)
    +    num_output_nodes = 0
    +    classes = []
    +    dependent_type = get_expr_type(dependent_varname, source_table)
    +    original_dependent_varname = dependent_varname
    +    dimension, n_tuples = _tbl_dimension_rownum(
    +        schema_madlib, source_table, independent_varname)
    +    x_scales = __utils_ind_var_scales(
    +        source_table, independent_varname, dimension, schema_madlib)
    +    x_means = py_list_to_sql_string(
    +        x_scales["mean"], array_type="DOUBLE PRECISION")
    +    filtered_stds = [x if x!=0 else 1 for x in x_scales["std"]]
    +    x_stds = py_list_to_sql_string(
    +        filtered_stds, array_type="DOUBLE PRECISION")
     
    +    if is_classification:
    +        dependent_variable_sql = """
    +        SELECT DISTINCT {dependent_varname}
    +        FROM {source_table}
    +        """.format(
    +            dependent_varname=dependent_varname, source_table=source_table)
    +        labels = plpy.execute(dependent_variable_sql)
    +        one_hot_dependent_varname = 'ARRAY['
    +        num_output_nodes = len(labels)
    +        for label_obj in labels:
    +            label = _format_label(label_obj[dependent_varname])
    +            classes.append(label)
    +        classes.sort()
    +        for c in classes:
    +            one_hot_dependent_varname += dependent_varname + \
    +                "=" + str(c) + ","
    +        # Remove the last comma
    +        one_hot_dependent_varname = one_hot_dependent_varname[:-1]
    +        one_hot_dependent_varname += ']::integer[]'
    +        dependent_varname = one_hot_dependent_varname
    +    else:
    +        if "[]" not in dependent_type:
    +            dependent_varname = "ARRAY[" + dependent_varname + "]"
    +        num_output_nodes = array_col_dimension(
    +            source_table, dependent_varname)
    +    layer_sizes = [num_input_nodes] + \
    +        hidden_layer_sizes + [num_output_nodes]
    +
    +    # Need layers sizes before validating for warm_start
    +    coeff = []
    +    for i in range(len(layer_sizes)-1):
    +        fan_in = layer_sizes[i]
    +        fan_out = layer_sizes[i+1]
    +        span = math.sqrt(6.0/(fan_in+fan_out))
    +        dim = (layer_sizes[i]+1)*layer_sizes[i+1]
    +        rand = plpy.execute("""SELECT array_agg({span}*(random()-0.5))
    +                               AS random
    +                               FROM generate_series(0,{dim})
    +                """.format(span=span,dim=dim))[0]["random"]
    +        coeff+=rand
    +
    +    if warm_start:
    +        coeff,x_means,x_stds = _validate_warm_start(source_table, 
output_table, summary_table, independent_varname,
    --- End diff --
    
    Trim this line to 80 chars.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to