#
# Copyright 2018 Analytics Zoo Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from zoo.pipeline.api.autograd import *
from zoo.pipeline.api.keras.layers import *
from zoo.pipeline.api.keras.models import *


def mean_absolute_error(y_true, y_pred):
    result = mean(abs(y_true - y_pred), axis=1)
    return result


def add_one_func(x):
    return x + 1.0


if __name__ == "__main__":
    data_len = 1000
    X_ = np.random.uniform(0, 1, (1000, 2))
    Y_ = ((2 * X_).sum(1) + 0.4).reshape([data_len, 1])

    a = Input(shape=(2,))
    b = Dense(1)(a)
    c = Lambda(function=add_one_func)(b)
    model = Model(input=a, output=c)

    model.compile(optimizer=SGD(learningrate=1e-2),
                  loss=mean_absolute_error)

    model.set_tensorboard('./log', 'customized layer and loss')

    model.fit(x=X_,
              y=Y_,
              batch_size=32,
              nb_epoch=500,
              distributed=False)

    model.save_graph_topology('./log')

    w = model.get_weights()
    print(w)
    pred = model.predict_local(X_)

@@ -712,16 +712,49 @@
 mport *%0A
+from optparse import OptionParser
 %0A%0Adef me
@@ -925,16 +925,164 @@
 ain__%22:%0A
+    parser = OptionParser()%0A    parser.add_option(%22--nb_epoch%22, dest=%22nb_epoch%22, default=%22500%22)%0A%0A    (options, args) = parser.parse_args(sys.argv)%0A%0A
     data
@@ -1573,19 +1573,37 @@
 b_epoch=
-500
+int(options.nb_epoch)
 ,%0A      

Update run-example-tests.sh (#176)