You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by ch...@apache.org on 2023/09/06 03:52:10 UTC

[singa] branch dev-postgresql updated: Add implementation for sum error loss for model selection

This is an automated email from the ASF dual-hosted git repository.

chrishkchris pushed a commit to branch dev-postgresql
in repository https://gitbox.apache.org/repos/asf/singa.git


The following commit(s) were added to refs/heads/dev-postgresql by this push:
     new 94e8e43d Add implementation for sum error loss for model selection
     new 210d7a64 Merge pull request #1085 from daoducanhc/chris-sep-6th
94e8e43d is described below

commit 94e8e43d0c789d107501d899952d92f9b885155e
Author: daoducanhc <da...@gmail.com>
AuthorDate: Wed Sep 6 11:16:37 2023 +0800

    Add implementation for sum error loss for model selection
---
 examples/model_selection_psql/msmlp/model.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/examples/model_selection_psql/msmlp/model.py b/examples/model_selection_psql/msmlp/model.py
index 44cf44f9..886be20b 100644
--- a/examples/model_selection_psql/msmlp/model.py
+++ b/examples/model_selection_psql/msmlp/model.py
@@ -32,6 +32,28 @@ np_dtype = {"float16": np.float16, "float32": np.float32}
 
 singa_dtype = {"float16": tensor.float16, "float32": tensor.float32}
 
+#### self-defined loss begin
+
+### reference from autograd.py
+class SumError(Operator):
+
+    def __init__(self):
+        super(SumError, self).__init__()
+        # self.t = t.data
+
+    def forward(self, x):
+        # self.err = singa.__sub__(x, self.t)
+        self.data_x = x
+        # sqr = singa.Square(self.err)
+        # loss = singa.SumAll(sqr)
+        loss = singa.SumAll(x)
+        # self.n = 1
+        # for s in x.shape():
+        #     self.n *= s
+        # loss /= self.n
+        return loss
+    
+
 class MSMLP(model.Model):
 
     def __init__(self, data_size=10, perceptron_size=100, num_classes=10):