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

    https://github.com/apache/madlib/pull/243#discussion_r175949965
  
    --- Diff: src/ports/postgres/modules/convex/mlp_igd.py_in ---
    @@ -222,67 +243,83 @@ def mlp(schema_madlib, source_table, output_table, 
independent_varname,
         it_args.update({
             'group_by_clause': group_by_clause,
             'using_clause': using_clause,
    -        'grouping_str_comma': grouping_str_comma
    +        'grouping_str_comma': grouping_str_comma,
         })
     
         first_try = True
         temp_output_table = unique_string(desp='temp_output_table')
    +
    +    layer_sizes = [num_input_nodes] + hidden_layer_sizes + 
[num_output_nodes]
    +
         for _ in range(n_tries):
    +        prev_state = None
             if not warm_start:
                 coeff = []
    -            for i in range(len(layer_sizes) - 1):
    -                fan_in = layer_sizes[i]
    -                fan_out = layer_sizes[i + 1]
    +            for fan_in, fan_out in zip(layer_sizes, layer_sizes[1:]):
                     # Initalize according to Glorot and Bengio (2010)
                     # See design doc for more info
                     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}*2*(random()-0.5))
    -                                       AS random
    -                                       FROM generate_series(0,{dim})
    -                        """.format(span=span, dim=dim))[0]["random"]
    +                dim = (fan_in + 1) * fan_out
    +                rand = [span * (random() - 0.5) for _ in range(dim)]
    --- End diff --
    
    Its supposed to be explained in the design doc as per the comment. I think 
these formulae are taken from a research paper.


---

Reply via email to