• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tonegas / nnodely / 13520426074

25 Feb 2025 11:43AM UTC coverage: 95.385% (-0.01%) from 95.395%
13520426074

Pull #63

github

web-flow
Merge 6e8d2fa3d into 16b35cf8f
Pull Request #63: 49 general bug fix

185 of 189 new or added lines in 16 files covered. (97.88%)

5 existing lines in 3 files now uncovered.

10521 of 11030 relevant lines covered (95.39%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.7
/tests/test_network_element.py
1
import unittest, sys, os, torch
1✔
2

3
from nnodely import *
1✔
4
from nnodely.relation import Stream
1✔
5
from nnodely import relation
1✔
6
import numpy as np
1✔
7
relation.CHECK_NAMES = False
1✔
8

9
from nnodely.logger import logging, nnLogger
1✔
10
log = nnLogger(__name__, logging.CRITICAL)
1✔
11
log.setAllLevel(logging.CRITICAL)
1✔
12

13
sys.path.append(os.getcwd())
1✔
14

15
# 11 Tests
16
# This file tests the dimensions and the of the element created in the pytorch environment
17

18
class ModelyNetworkBuildingTest(unittest.TestCase):
1✔
19

20
    def TestAlmostEqual(self, data1, data2, precision=4):
1✔
21
        assert np.asarray(data1, dtype=np.float32).ndim == np.asarray(data2, dtype=np.float32).ndim, f'Inputs must have the same dimension! Received {type(data1)} and {type(data2)}'
1✔
22
        if type(data1) == type(data2) == list:
1✔
23
            self.assertEqual(len(data1),len(data2))
1✔
24
            for pred, label in zip(data1, data2):
1✔
25
                self.TestAlmostEqual(pred, label, precision=precision)
1✔
26
        else:
27
            self.assertAlmostEqual(data1, data2, places=precision)
1✔
28

29
    def test_network_building_very_simple(self):
1✔
30

31
        input1 = Input('in1').last()
1✔
32
        rel1 = Fir(input1)
1✔
33
        fun = Output('out', rel1)
1✔
34

35
        test = Modely(visualizer=None)
1✔
36
        test.addModel('fun',fun)
1✔
37
        test.neuralizeModel(0.01)
1✔
38

39
        list_of_dimensions = [[1, 1], [1, 1]]
1✔
40
        for ind, (key, value) in enumerate({k: v for k, v in test.model.relation_forward.items() if 'Fir' in k}.items()):
1✔
41
            self.assertEqual(list_of_dimensions[ind],list(value.weights.shape))
1✔
42
      
43
    def test_network_building_simple(self):
1✔
44
        Stream.reset_count()
1✔
45
        input1 = Input('in1')
1✔
46
        rel1 = Fir(input1.tw(0.05))
1✔
47
        rel2 = Fir(input1.tw(0.01))
1✔
48
        fun = Output('out',rel1+rel2)
1✔
49

50
        test = Modely(visualizer=None)
1✔
51
        test.addModel('fun',fun)
1✔
52
        test.neuralizeModel(0.01)
1✔
53
        
54
        list_of_dimensions = {'Fir2':[5,1],'Fir5':[1,1]}
1✔
55
        for key, value in {k:v for k,v in test.model.relation_forward.items() if 'Fir' in k}.items():
1✔
56
            self.assertEqual(list_of_dimensions[key],list(value.weights.shape))
1✔
57

58
    def test_network_building_tw(self):
1✔
59
        Stream.reset_count()
1✔
60
        input1 = Input('in1')
1✔
61
        input2 = Input('in2')
1✔
62
        rel1 = Fir(input1.tw(0.05))
1✔
63
        rel2 = Fir(input1.tw(0.01))
1✔
64
        rel3 = Fir(input2.tw(0.05))
1✔
65
        rel4 = Fir(input2.tw([-0.02,0.02]))
1✔
66
        fun = Output('out',rel1+rel2+rel3+rel4)
1✔
67

68
        test = Modely(visualizer=None)
1✔
69
        test.addModel('fun',fun)
1✔
70
        test.neuralizeModel(0.01)
1✔
71
        
72
        list_of_dimensions = {'Fir2':[5,1], 'Fir5':[1,1], 'Fir8':[5,1], 'Fir11':[4,1]}
1✔
73
        for key, value in {k:v for k,v in test.model.relation_forward.items() if 'Fir' in k}.items():
1✔
74
            self.assertEqual(list_of_dimensions[key],list(value.weights.shape))
1✔
75
    
76
    def test_network_building_tw2(self):
1✔
77
        Stream.reset_count()
1✔
78
        input2 = Input('in2')
1✔
79
        rel3 = Fir(input2.tw(0.05))
1✔
80
        rel4 = Fir(input2.tw([-0.02,0.02]))
1✔
81
        rel5 = Fir(input2.tw([-0.03,0.03]))
1✔
82
        rel6 = Fir(input2.tw([-0.03, 0]))
1✔
83
        rel7 = Fir(input2.tw(0.03))
1✔
84
        fun = Output('out',rel3+rel4+rel5+rel6+rel7)
1✔
85

86
        test = Modely(visualizer=None)
1✔
87
        test.addModel('fun',fun)
1✔
88
        test.neuralizeModel(0.01)
1✔
89

90
        self.assertEqual(test.max_n_samples, 8) # 5 samples + 3 samples of the horizon
1✔
91
        self.assertEqual({'in2': 8} , test.input_n_samples)
1✔
92
        
93
        list_of_dimensions = {'Fir2':[5,1], 'Fir5':[4,1], 'Fir8':[6,1], 'Fir11':[3,1], 'Fir14':[3,1]}
1✔
94
        for  key, value in {k:v for k,v in test.model.relation_forward.items() if 'Fir' in k}.items():
1✔
95
            self.assertEqual(list_of_dimensions[key],list(value.weights.shape))
1✔
96

97
    def test_network_building_tw3(self):
1✔
98
        input2 = Input('in2')
1✔
99
        rel3 = Fir(input2.tw(0.05))
1✔
100
        rel4 = Fir(input2.tw([-0.01,0.03]))
1✔
101
        rel5 = Fir(input2.tw([-0.04,0.01]))
1✔
102
        fun = Output('out',rel3+rel4+rel5)
1✔
103

104
        test = Modely(visualizer=None)
1✔
105
        test.addModel('fun',fun)
1✔
106
        test.neuralizeModel(0.01)
1✔
107

108
        list_of_dimensions = [[5,1], [4,1], [5,1]]
1✔
109
        for ind, (key, value) in enumerate({k:v for k,v in test.model.relation_forward.items() if 'Fir' in k}.items()):
1✔
110
            self.assertEqual(list_of_dimensions[ind],list(value.weights.shape))
1✔
111

112
    def test_network_building_tw_with_offest(self):
1✔
113
        Stream.reset_count()
1✔
114
        input2 = Input('in2')
1✔
115
        rel3 = Fir(input2.tw(0.05))
1✔
116
        rel4 = Fir(input2.tw([-0.04,0.02]))
1✔
117
        rel5 = Fir(input2.tw([-0.04,0.02],offset=0))
1✔
118
        rel6 = Fir(input2.tw([-0.04,0.02],offset=0.01))
1✔
119
        fun = Output('out',rel3+rel4+rel5+rel6)
1✔
120

121

122
        test = Modely(visualizer=None)
1✔
123
        test.addModel('fun',fun)
1✔
124
        test.neuralizeModel(0.01)
1✔
125

126
        list_of_dimensions = {'Fir2':[5,1], 'Fir5':[6,1], 'Fir8':[6,1], 'Fir11':[6,1]}
1✔
127
        for key, value in {k:v for k,v in test.model.relation_forward.items() if 'Fir' in k}.items():
1✔
128
            self.assertEqual(list_of_dimensions[key],list(value.weights.shape))
1✔
129

130
    def test_network_building_tw_negative(self):
1✔
131
        input2 = Input('in2')
1✔
132
        rel1 = Fir(input2.tw([-0.04,-0.01]))
1✔
133
        rel2 = Fir(input2.tw([-0.06,-0.03]))
1✔
134
        fun = Output('out',rel1+rel2)
1✔
135

136
        test = Modely(visualizer=None)
1✔
137
        test.addModel('fun',fun)
1✔
138
        test.neuralizeModel(0.01)
1✔
139

140
        list_of_dimensions = [[3,1], [3,1]]
1✔
141
        for ind, (key, value) in enumerate({k:v for k,v in test.model.relation_forward.items() if 'Fir' in k}.items()):
1✔
142
            self.assertEqual(list_of_dimensions[ind],list(value.weights.shape))
1✔
143

144
    def test_network_building_tw_positive(self):
1✔
145
        input2 = Input('in2')
1✔
146
        rel1 = Fir(input2.tw([0.01,0.04]))
1✔
147
        rel2 = Fir(input2.tw([0.03,0.06]))
1✔
148
        fun = Output('out',rel1+rel2)
1✔
149

150
        test = Modely(visualizer=None)
1✔
151
        test.addModel('fun',fun)
1✔
152
        test.neuralizeModel(0.01)
1✔
153

154
        list_of_dimensions = [[3,1], [3,1]]
1✔
155
        for ind, (key, value) in enumerate({k:v for k,v in test.model.relation_forward.items() if 'Fir' in k}.items()):
1✔
156
            self.assertEqual(list_of_dimensions[ind],list(value.weights.shape))
1✔
157

158
    def test_network_building_sw_with_offset(self):
1✔
159
        Stream.reset_count()
1✔
160
        input2 = Input('in2')
1✔
161
        rel3 = Fir(input2.sw(5))
1✔
162
        rel4 = Fir(input2.sw([-4,2]))
1✔
163
        rel5 = Fir(input2.sw([-4,2],offset=0))
1✔
164
        rel6 = Fir(input2.sw([-4,2],offset=1))
1✔
165
        fun = Output('out',rel3+rel4+rel5+rel6)
1✔
166

167
        test = Modely(visualizer=None, seed=1)
1✔
168
        test.addModel('fun',fun)
1✔
169
        test.neuralizeModel(0.01)
1✔
170

171
        list_of_dimensions = {'Fir2':[5,1], 'Fir5':[6,1], 'Fir8':[6,1], 'Fir11':[6,1]}
1✔
172
        for key, value in {k:v for k,v in test.model.relation_forward.items() if 'Fir' in k}.items():
1✔
173
            self.assertEqual(list_of_dimensions[key],list(value.weights.shape))
1✔
174

175
    def test_network_building_sw_and_tw(self):
1✔
176
        input2 = Input('in2')
1✔
177
        with self.assertRaises(ValueError):
1✔
178
            input2.sw(5)+input2.tw(0.05)
1✔
179

180
        rel1 = Fir(input2.sw([-4,2]))+Fir(input2.tw([-0.01,0]))
1✔
181
        fun = Output('out',rel1)
1✔
182

183
        test = Modely(visualizer=None)
1✔
184
        test.addModel('fun',fun)
1✔
185
        test.neuralizeModel(0.01)
1✔
186

187
        list_of_dimensions = [[6,1], [1,1]]
1✔
188
        for ind, (key, value) in enumerate({k:v for k,v in test.model.relation_forward.items() if 'Fir' in k}.items()):
1✔
189
            self.assertEqual(list_of_dimensions[ind],list(value.weights.shape))
1✔
190

191
    def test_network_linear(self):
1✔
192
        torch.manual_seed(1)
1✔
193
        input = Input('in1')
1✔
194
        rel1 = Linear(input.sw([-4,2]))
1✔
195
        rel2 = Linear(5)(input.sw([-1, 2]))
1✔
196
        fun1 = Output('out1',rel1)
1✔
197
        fun2 = Output('out2', rel2)
1✔
198

199
        input5 = Input('in5', dimensions=3)
1✔
200
        rel15 = Linear(input5.sw([-4,2]))
1✔
201
        rel25 = Linear(5)(input5.last())
1✔
202
        fun15 = Output('out51',rel15)
1✔
203
        fun25 = Output('out52', rel25)
1✔
204

205
        test = Modely(visualizer=None)
1✔
206
        test.addModel('fun',[fun1,fun2,fun15,fun25])
1✔
207
        test.neuralizeModel(0.01)
1✔
208

209
        list_of_dimensions = [[1,1,1],[1,1,5],[1,3,1],[1,3,5]]
1✔
210
        for ind, (key, value) in enumerate({k:v for k,v in test.model.relation_forward.items() if 'Linear' in k}.items()):
1✔
211
            self.assertEqual(list_of_dimensions[ind],list(value.weights.shape))
1✔
212

213
    def test_network_linear_interpolation_train(self):
1✔
214
        torch.manual_seed(1)
1✔
215
        x = Input('x')
1✔
216
        param = Parameter(name='a', sw=1)
1✔
217
        rel1 = Fir(parameter=param)(Interpolation(x_points=[1.0, 2.0, 3.0, 4.0],y_points=[2.0, 4.0, 6.0, 8.0], mode='linear')(x.last()))
1✔
218
        out = Output('out',rel1)
1✔
219

220
        test = Modely(visualizer=None)
1✔
221
        test.addModel('fun',[out])
1✔
222
        test.addMinimize('error', out, x.last())
1✔
223
        test.neuralizeModel(0.01)
1✔
224

225
        dataset = {'x':np.random.uniform(1,4,100)}
1✔
226
        test.loadData(name='dataset', source=dataset)
1✔
227
        test.trainModel(num_of_epochs=100, train_batch_size=10)
1✔
228
        self.assertAlmostEqual(test.model.all_parameters['a'].item(), 0.5, places=2)
1✔
229

230
    def test_network_linear_interpolation(self):
1✔
231
        torch.manual_seed(1)
1✔
232
        x = Input('x')
1✔
233
        rel1 = Interpolation(x_points=[1.0, 2.0, 3.0, 4.0],y_points=[1.0, 4.0, 9.0, 16.0], mode='linear')(x.last())
1✔
234
        out = Output('out',rel1)
1✔
235

236
        test = Modely(visualizer=None)
1✔
237
        test.addModel('fun',[out])
1✔
238
        test.neuralizeModel(0.01)
1✔
239

240
        inference = test(inputs={'x':[1.5,2.5,3.5]})
1✔
241
        self.assertEqual(inference['out'],[2.5,6.5,12.5])
1✔
242

243
        torch.manual_seed(1)
1✔
244
        x = Input('x')
1✔
245
        rel1 = Interpolation(x_points=[1.0, 4.0, 3.0, 2.0],y_points=[1.0, 16.0, 9.0, 4.0], mode='linear')(x.last())
1✔
246
        out = Output('out',rel1)
1✔
247

248
        test = Modely(visualizer=None)
1✔
249
        test.addModel('fun',[out])
1✔
250
        test.neuralizeModel(0.01)
1✔
251

252
        inference = test(inputs={'x':[1.5,2.5,3.5]})
1✔
253
        self.assertEqual(inference['out'],[2.5,6.5,12.5])
1✔
254

255
    def test_softmax_and_sigmoid(self):
1✔
256
        torch.manual_seed(1)
1✔
257
        x = Input('x')
1✔
258
        y = Input('y', dimensions=3)
1✔
259
        softmax = Softmax(y.last())
1✔
260
        sigmoid = Sigmoid(x.last())
1✔
261
        out = Output('softmax',softmax)
1✔
262
        out2 = Output('sigmoid',sigmoid)
1✔
263

264
        test = Modely(visualizer=None)
1✔
265
        test.addModel('model',[out,out2])
1✔
266
        test.neuralizeModel(0.01)
1✔
267

268
        inference = test(inputs={'x':[-1000.0, 0.0, 1000.0], 'y':[[-1.0,0.0,1.0],[-1000.0,0.0,1000.0],[1.0,2.0,3.0]]})
1✔
269
        self.assertEqual(inference['sigmoid'],[0.0, 0.5, 1.0])
1✔
270
        self.assertEqual(inference['softmax'],[[[0.09003057330846786, 0.2447284758090973, 0.6652409434318542]],
1✔
271
                                               [[0.0, 0.0, 1.0]],
272
                                               [[0.09003057330846786, 0.2447284758090973, 0.6652409434318542]]])
273

274
    def test_sech_cosh_function(self):
1✔
275
        torch.manual_seed(1)
1✔
276
        input = Input('in1')
1✔
277
        sech_rel = Sech(input.last())
1✔
278
        sech_rel_2 = Sech(input.sw(2))
1✔
279
        cosh_rel = Cosh(input.last())
1✔
280
        cosh_rel_2 = Cosh(input.sw(2))
1✔
281

282
        input5 = Input('in5', dimensions=5)
1✔
283
        sech_rel_5 = Sech(input5.last())
1✔
284
        cosh_rel_5 = Cosh(input5.last())
1✔
285

286
        out1 = Output('sech_out_1', sech_rel)
1✔
287
        out2 = Output('sech_out_2', sech_rel_2)
1✔
288
        out3 = Output('sech_out_3', sech_rel_5)
1✔
289
        out4 = Output('cosh_out_1', cosh_rel)
1✔
290
        out5 = Output('cosh_out_2', cosh_rel_2)
1✔
291
        out6 = Output('cosh_out_3', cosh_rel_5)
1✔
292

293
        test = Modely(visualizer=None)
1✔
294
        test.addModel('model',[out1,out2,out3,out4,out5,out6])
1✔
295
        test.neuralizeModel(0.01)
1✔
296

297
        result = test(inputs={'in1':[[3.0],[-2.0]], 'in5':[[4.0,1.0,0.0,-6.0,2.0]]})
1✔
298
        self.TestAlmostEqual([0.2658022344112396], result['sech_out_1'])
1✔
299
        self.TestAlmostEqual([[0.0993279218673706, 0.2658022344112396]], result['sech_out_2'])
1✔
300
        self.TestAlmostEqual([[[0.03661899268627167, 0.6480542421340942, 1.0, 0.004957473836839199, 0.2658022344112396]]], result['sech_out_3'])
1✔
301
        self.TestAlmostEqual([3.762195587158203], result['cosh_out_1'])
1✔
302
        self.TestAlmostEqual([[10.067662239074707, 3.762195587158203]], result['cosh_out_2'])
1✔
303
        self.TestAlmostEqual([[[27.3082332611084, 1.5430806875228882, 1.0, 201.71563720703125, 3.762195587158203]]], result['cosh_out_3'])
1✔
304

305
    def test_concatenate_time_concatenate(self):
1✔
306
        torch.manual_seed(1)
1✔
307
        input = Input('in1')
1✔
308
        input2 = Input('in2')
1✔
309
        concatenate_rel = Concatenate(input.last(),input2.last())
1✔
310
        timeconcatenate_rel = TimeConcatenate(input.last(),input2.last())
1✔
311
        concatenate_tw_rel = Concatenate(input.tw(3),input2.tw(3))
1✔
312
        timeconcatenate_tw_rel = TimeConcatenate(input.tw(3),input2.tw(3))
1✔
313

314
        input3 = Input('in3', dimensions=5)
1✔
315
        input4 = Input('in4', dimensions=5)
1✔
316

317
        concatenate_rel_5 = Concatenate(input3.last(),input4.last())
1✔
318
        timeconcatenate_rel_5 = TimeConcatenate(input3.last(),input4.last())
1✔
319
        concatenate_tw_rel_5 = Concatenate(input3.tw(3),input4.tw(3))
1✔
320
        timeconcatenate_tw_rel_5 = TimeConcatenate(input3.tw(3),input4.tw(3))
1✔
321

322
        out1 = Output('concatenate', concatenate_rel)
1✔
323
        out2 = Output('time_concatenate', timeconcatenate_rel)
1✔
324
        out3 = Output('concatenate_tw', concatenate_tw_rel)
1✔
325
        out4 = Output('time_concatenate_tw', timeconcatenate_tw_rel)
1✔
326
        out5 = Output('concatenate_5', concatenate_rel_5)
1✔
327
        out6 = Output('time_concatenate_5', timeconcatenate_rel_5)
1✔
328
        out7 = Output('concatenate_tw_5', concatenate_tw_rel_5)
1✔
329
        out8 = Output('time_concatenate_tw_5', timeconcatenate_tw_rel_5)
1✔
330

331
        test = Modely(visualizer=None)
1✔
332
        test.addModel('model',[out1,out2,out3,out4,out5,out6,out7,out8])
1✔
333
        test.neuralizeModel(1)
1✔
334

335
        result = test(inputs={'in1':[[1.0],[2.0],[3.0]], 'in2':[[4.0],[5.0],[6.0]],
1✔
336
                              'in3':[[7.0,8.0,9.0,10.0,11.0],[12.0,13.0,14.0,15.0,16.0],[17.0,18.0,19.0,20.0,21.0]],
337
                              'in4':[[22.0,23.0,24.0,25.0,26.0],[27.0,28.0,29.0,30.0,31.0],[32.0,33.0,34.0,35.0,36.0]]})
338
        self.assertEqual((1,1,2), np.array(result['concatenate']).shape)
1✔
339
        self.assertEqual([[[3.0, 6.0]]], result['concatenate'])
1✔
340
        self.assertEqual((1,2), np.array(result['time_concatenate']).shape)
1✔
341
        self.assertEqual([[3.0, 6.0]], result['time_concatenate'])
1✔
342
        self.assertEqual((1,3,2), np.array(result['concatenate_tw']).shape)
1✔
343
        self.assertEqual([[[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]]], result['concatenate_tw'])
1✔
344
        self.assertEqual((1,6), np.array(result['time_concatenate_tw']).shape)
1✔
345
        self.assertEqual([[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]], result['time_concatenate_tw'])
1✔
346
        self.assertEqual((1,1,10), np.array(result['concatenate_5']).shape)
1✔
347
        self.assertEqual([[[17.0, 18.0, 19.0, 20.0, 21.0, 32.0, 33.0, 34.0, 35.0, 36.0]]], result['concatenate_5'])
1✔
348
        self.assertEqual((1,2,5), np.array(result['time_concatenate_5']).shape)
1✔
349
        self.assertEqual([[[17.0, 18.0, 19.0, 20.0, 21.0], [32.0, 33.0, 34.0, 35.0, 36.0]]], result['time_concatenate_5'])
1✔
350
        self.assertEqual((1,3,10), np.array(result['concatenate_tw_5']).shape)
1✔
351
        self.assertEqual([[[7.0, 8.0, 9.0, 10.0, 11.0, 22.0, 23.0, 24.0, 25.0, 26.0],
1✔
352
                           [12.0, 13.0, 14.0, 15.0, 16.0, 27.0, 28.0, 29.0, 30.0, 31.0],
353
                           [17.0, 18.0, 19.0, 20.0, 21.0, 32.0, 33.0, 34.0, 35.0, 36.0]]], result['concatenate_tw_5'])
354
        self.assertEqual((1,6,5), np.array(result['time_concatenate_tw_5']).shape)
1✔
355
        self.assertEqual([[[7.0, 8.0, 9.0, 10.0, 11.0],
1✔
356
                           [12.0, 13.0, 14.0, 15.0, 16.0],
357
                           [17.0, 18.0, 19.0, 20.0, 21.0],
358
                           [22.0, 23.0, 24.0, 25.0, 26.0],
359
                           [27.0, 28.0, 29.0, 30.0, 31.0],
360
                           [32.0, 33.0, 34.0, 35.0, 36.0]]], result['time_concatenate_tw_5'])
361

362
    def test_equation_learner(self):
1✔
363
        x = Input('x')
1✔
364
        F = Input('F')
1✔
365

366
        def myFun(p1,p2,k1,k2):
1✔
367
            return k1*p1+k2*p2
1✔
368

369
        K1 = Parameter('k1', dimensions =  1, sw = 1,values=[[2.0]])
1✔
370
        K2 = Parameter('k2', dimensions =  1, sw = 1,values=[[3.0]])
1✔
371
        parfun = ParamFun(myFun, parameters=[K1,K2])
1✔
372
        parfun2 = ParamFun(myFun, parameters=[K1,K2])
1✔
373
        parfun3 = ParamFun(myFun, parameters=[K1,K2])
1✔
374
        fuzzi = Fuzzify(centers=[0,1,2,3])
1✔
375

376
        linear_layer_in = Linear(output_dimension=3, W_init=init_constant, W_init_params={'value':0}, b_init=init_constant, b_init_params={'value':0}, b=False)
1✔
377
        linear_layer_in_dim_2 = Linear(output_dimension=3, W_init=init_constant, W_init_params={'value':0}, b_init=init_constant, b_init_params={'value':0}, b=False)
1✔
378
        linear_layer_out = Linear(output_dimension=1, W_init=init_constant, W_init_params={'value':1}, b_init=init_constant, b_init_params={'value':0}, b=False)
1✔
379

380
        equation_learner = EquationLearner(functions=[Tan, Sin, Cos], linear_in=linear_layer_in)(x.last())
1✔
381
        equation_learner_out = EquationLearner(functions=[Tan, Sin, Cos], linear_in=linear_layer_in, linear_out=linear_layer_out)(x.last())
1✔
382
        equation_learner_tw = EquationLearner(functions=[Tan, Sin, Cos], linear_in=linear_layer_in)(x.sw(2))
1✔
383
        equation_learner_multi_tw = EquationLearner(functions=[Tan, Sin, Cos], linear_in=linear_layer_in_dim_2)((x.sw(2),F.sw(2)))
1✔
384

385
        linear_layer_in_2 = Linear(output_dimension=5, W_init=init_constant, W_init_params={'value':1})
1✔
386
        linear_layer_in_2_dim_2 = Linear(output_dimension=5, W_init=init_constant, W_init_params={'value':1})
1✔
387

388
        equation_learner_2 = EquationLearner(functions=[Add, Mul, Identity], linear_in=linear_layer_in_2)(x.last())
1✔
389
        equation_learner_2_tw = EquationLearner(functions=[Add, Mul, Identity], linear_in=linear_layer_in_2)(x.sw(2))
1✔
390
        equation_learner_2_multi_tw = EquationLearner(functions=[Add, Mul, Identity], linear_in=linear_layer_in_2_dim_2)((x.sw(2),F.sw(2)))
1✔
391

392
        linear_layer_in_3 = Linear(output_dimension=5, W_init=init_constant, W_init_params={'value':1}, b_init=init_constant, b_init_params={'value':0}, b=False)
1✔
393
        linear_layer_in_3_dim_2 = Linear(output_dimension=5, W_init=init_constant, W_init_params={'value':1}, b_init=init_constant, b_init_params={'value':0}, b=False)
1✔
394

395
        equation_learner_3 = EquationLearner(functions=[parfun, Add, fuzzi], linear_in=linear_layer_in_3)(x.last())
1✔
396
        equation_learner_3_tw = EquationLearner(functions=[parfun2, Add, fuzzi], linear_in=linear_layer_in_3)(x.sw(2))
1✔
397
        equation_learner_3_multi_tw = EquationLearner(functions=[parfun3, Add, fuzzi], linear_in=linear_layer_in_3_dim_2)((x.sw(2),F.sw(2)))
1✔
398

399
        out = Output('el',equation_learner)
1✔
400
        out2 = Output('el_out',equation_learner_out)
1✔
401
        out3 = Output('el_tw',equation_learner_tw)
1✔
402
        out4 = Output('el_multi_tw',equation_learner_multi_tw)
1✔
403
        out5 = Output('el2',equation_learner_2)
1✔
404
        out6 = Output('el2_tw',equation_learner_2_tw)
1✔
405
        out7 = Output('el2_multi_tw',equation_learner_2_multi_tw)
1✔
406
        out8 = Output('el3',equation_learner_3)
1✔
407
        out9 = Output('el3_tw',equation_learner_3_tw)
1✔
408
        out10 = Output('el3_multi_tw',equation_learner_3_multi_tw)
1✔
409
        example = Modely(visualizer=None)
1✔
410
        example.addModel('model',[out,out2,out3,out4,out5,out6,out7,out8,out9,out10])
1✔
411
        example.neuralizeModel()
1✔
412

413
        result = example({'x':[[1.0],[2.0]], 'F':[[3.0],[4.0]]})
1✔
414
        self.assertEqual(result['el'], [[[0.0, 0.0, 1.0]]])
1✔
415
        self.assertEqual(result['el_out'], [1.0])
1✔
416
        self.assertEqual(result['el_tw'], [[[0.0, 0.0, 1.0], [0.0, 0.0, 1.0]]])
1✔
417
        self.assertEqual(result['el_multi_tw'], [[[0.0, 0.0, 1.0], [0.0, 0.0, 1.0]]])
1✔
418
        self.assertEqual(result['el2'], [[[4.0, 4.0, 2.0]]])
1✔
419
        self.assertEqual(result['el2_tw'], [[[2.0, 1.0, 1.0], [4.0, 4.0, 2.0]]])
1✔
420
        self.assertEqual(result['el2_multi_tw'], [[[8.0, 16.0, 4.0], [12.0, 36.0, 6.0]]])
1✔
421
        self.assertEqual(result['el3'], [[[10.0, 4.0, 0.0, 0.0, 1.0, 0.0]]])
1✔
422
        self.assertEqual(result['el3_tw'], [[[5.0, 2.0, 0.0, 1.0, 0.0, 0.0], [10.0, 4.0, 0.0, 0.0, 1.0, 0.0]]])
1✔
423
        self.assertEqual(result['el3_multi_tw'], [[[20.0, 8.0, 0.0, 0.0, 0.0, 1.0], [30.0, 12.0, 0.0, 0.0, 0.0, 1.0]]])
1✔
424

425

426
if __name__ == '__main__':
1✔
NEW
427
    unittest.main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc