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

    https://github.com/apache/incubator-madlib/pull/162#discussion_r132060205
  
    --- Diff: src/ports/postgres/modules/convex/mlp_igd.py_in ---
    @@ -122,206 +181,349 @@ def mlp(schema_madlib, source_table, output_table, 
independent_varname,
                         {layer_sizes},
                         ({step_size})::FLOAT8,
                         {activation},
    -                    {is_classification}) as curr_state
    -            FROM {source_table} AS _src
    -            """.format(schema_madlib=schema_madlib,
    -                       independent_varname=independent_varname,
    -                       dependent_varname=dependent_varname,
    -                       prev_state=prev_state_str,
    -                       # C++ uses double internally
    -                       layer_sizes=py_list_to_sql_string(layer_sizes,
    -                                                         
array_type="double precision"),
    -                       step_size=step_size,
    -                       source_table=source_table,
    -                       activation=activation_index,
    -                       is_classification=int(is_classification))
    +                    {is_classification},
    +                    ({weights})::DOUBLE PRECISION,
    +                    {warm_start},
    +                    ({warm_start_coeff})::DOUBLE PRECISION[],
    +                    {n_tuples},
    +                    {lmbda},
    +                    {x_means},
    +                    {x_stds}
    +                    ) as curr_state
    +            FROM {source_table} as _src
    +            """.format(
    +                schema_madlib=schema_madlib,
    +                independent_varname=independent_varname,
    +                dependent_varname=dependent_varname,
    +                prev_state=prev_state_str,
    +                # c++ uses double internally
    +                layer_sizes=py_list_to_sql_string(
    +                    layer_sizes, array_type="DOUBLE PRECISION"),
    +                step_size=step_size,
    +                source_table=source_table,
    +                activation=activation_index,
    +                is_classification=int(is_classification),
    +                weights=weights,
    +                warm_start=warm_start,
    +                warm_start_coeff=py_list_to_sql_string(
    +                    coeff, array_type="DOUBLE PRECISION"),
    +                n_tuples=n_tuples,
    +                lmbda=lmbda,
    +                x_means=x_means,
    +                x_stds=x_stds)
                 curr_state = plpy.execute(train_sql)[0]["curr_state"]
                 dist_sql = """
    -                SELECT {schema_madlib}.internal_mlp_igd_distance(
    -                        {prev_state},
    -                        {curr_state}) as state_dist
    -                """.format(schema_madlib=schema_madlib,
    -                           prev_state=prev_state_str,
    -                           curr_state=py_list_to_sql_string(curr_state, 
"double precision"))
    +            SELECT {schema_madlib}.internal_mlp_igd_distance(
    +                    {prev_state},
    +                    {curr_state}) as state_dist
    +            """.format(
    +                schema_madlib=schema_madlib,
    +                prev_state=prev_state_str,
    +                curr_state=py_list_to_sql_string(curr_state,
    +                                                 "DOUBLE PRECISION"))
                 state_dist = plpy.execute(dist_sql)[0]["state_dist"]
    -            if ((state_dist and state_dist < tolerance) or
    -                    current_iteration > n_iterations):
    +            if verbose and 1<current_iteration<=n_iterations:
    +                loss = plpy.execute("""
    +                SELECT
    +                    (result).loss  AS loss
    +                FROM (
    +                    SELECT
    +                        {schema_madlib}.internal_mlp_igd_result(
    +                            {final_state_str}
    +                        ) AS result
    +                ) rel_state_subq
    +                """.format(
    +                    schema_madlib=schema_madlib,
    +                    
final_state_str=py_list_to_sql_string(curr_state)))[0]["loss"]
    --- End diff --
    
    This query is repeated to find the `final_loss` below. That should be 
refactored and pulled out to a new function.


---
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