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

    https://github.com/apache/incubator-madlib/pull/162#discussion_r132060382
  
    --- 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"]
    +                plpy.info("Iteration: "+str(current_iteration-1) + ", 
Loss: " +str(loss))
    +            if ((state_dist and state_dist < tolerance)
    +                    or current_iteration > n_iterations):
                     break
                 prev_state = curr_state
                 current_iteration += 1
    -        _build_model_table(schema_madlib, output_table,
    -                           curr_state, n_iterations)
    -        layer_sizes_str = py_list_to_sql_string(
    -            layer_sizes, array_type="integer")
    -        classes_str = py_list_to_sql_string(
    -            [strip_end_quotes(cl, "'") for cl in classes],
    -            array_type=dependent_type)
    -        summary_table_creation_query = """
    -        CREATE TABLE {summary_table}(
    -            source_table TEXT,
    -            independent_varname TEXT,
    -            dependent_varname TEXT,
    -            tolerance FLOAT,
    -            step_size FLOAT,
    -            n_iterations INTEGER,
    -            n_tries INTEGER,
    -            layer_sizes INTEGER[],
    -            activation_function TEXT,
    -            is_classification BOOLEAN,
    -            classes {dependent_type}[]
    -        )""".format(summary_table=summary_table,
    -                    dependent_type=dependent_type)
    -
    -        summary_table_update_query = """
    -            INSERT INTO {summary_table} VALUES(
    -                '{source_table}',
    -                '{independent_varname}',
    -                '{original_dependent_varname}',
    -                {tolerance},
    -                {step_size},
    -                {n_iterations},
    -                {n_tries},
    -                {layer_sizes_str},
    -                '{activation_name}',
    -                {is_classification},
    -                {classes_str}
    -            )
    -            """.format(**locals())
    -        plpy.execute(summary_table_creation_query)
    -        plpy.execute(summary_table_update_query)
    -# ----------------------------------------------------------------------
    -
    -
    -def _build_model_table(schema_madlib, output_table, final_state, 
n_iterations):
    +        final_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 --
    
    Is it possible to avoid calling this query if `verbose=True`, since the 
last known `loss` value would then be the same as `final_loss`?


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