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

tonegas / nnodely / 20074796492

09 Dec 2025 06:47PM UTC coverage: 96.807% (-1.0%) from 97.767%
20074796492

Pull #109

github

tonegas
Fixes of tests
Pull Request #109: New version of nnodely

867 of 887 new or added lines in 37 files covered. (97.75%)

157 existing lines in 5 files now uncovered.

13066 of 13497 relevant lines covered (96.81%)

0.97 hits per line

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

97.18
/nnodely/visualizer/mplnotebookvisualizer.py
1
import matplotlib.pyplot as plt
1✔
2
import numpy as np
1✔
3

4
from nnodely.visualizer.textvisualizer import TextVisualizer
1✔
5
from nnodely.layers.fuzzify import return_fuzzify
1✔
6
from nnodely.layers.parametricfunction import return_standard_inputs, return_function
1✔
7
from nnodely.support.utils import check
1✔
8
from mplplots import plots
1✔
9

10
class MPLNotebookVisualizer(TextVisualizer):
1✔
11
    def __init__(self, verbose = 1, *, test = False):
1✔
12
        super().__init__(verbose)
1✔
13
        self.test = test
1✔
14
        if self.test:
1✔
15
            plt.ion()
1✔
16

17
    def showEndTraining(self, epoch, train_losses, val_losses):
1✔
18
        train_tag = self.modely.running_parameters['train_tag']
1✔
19
        val_tag = self.modely.running_parameters['val_tag']
1✔
20
        for key in self.modely.json['Minimizers'].keys():
1✔
21
            fig = plt.figure()
1✔
22
            ax = fig.add_subplot(111)
1✔
23
            if val_losses:
1✔
24
                plots.plot_training(ax, f"Training on {train_tag} and {val_tag}", key, train_losses[key], val_losses[key])
1✔
25
            else:
NEW
26
                plots.plot_training(ax, f"Training on {train_tag}", key, train_losses[key])
×
27
        plt.show()
1✔
28

29
    def showResult(self, name_data):
1✔
30
        super().showResult(name_data)
1✔
31
        for key in self.modely.json['Minimizers'].keys():
1✔
32
            fig = plt.figure()
1✔
33
            ax = fig.add_subplot(111)
1✔
34
            np_data_A = np.array(self.modely.prediction[name_data][key]['A'])
1✔
35
            if len(np_data_A.shape) > 3 and np_data_A.shape[1] > 30:
1✔
36
                np_data_B = np.array(self.modely.prediction[name_data][key]['B'])
1✔
37
                indices = np.linspace(0, np_data_A.shape[1] - 1, 30, dtype=int)
1✔
38
                data_A = np_data_A[:, indices, :, :].tolist()
1✔
39
                data_B = np_data_B[:, indices, :, :].tolist()
1✔
40
                data_idxs = np.array(self.modely.prediction[name_data]['idxs'])[:,indices].tolist()
1✔
41
            else:
42
                data_A = self.modely.prediction[name_data][key]['A']
1✔
43
                data_B = self.modely.prediction[name_data][key]['B']
1✔
44
                data_idxs = self.modely.prediction[name_data]['idxs'] if len(np_data_A.shape) > 3 else None
1✔
45

46
            plots.plot_results(ax, name_data, key, data_A,
1✔
47
                               data_B, data_idxs, self.modely._model_def['Info']["SampleTime"])
48
        plt.show()
1✔
49

50
    def showWeights(self, weights = None):
1✔
51
        pass
×
52

53
    def showFunctions(self, functions = None, xlim = None, num_points = 1000):
1✔
54
        check(self.modely.neuralized, ValueError, "The model has not been neuralized.")
1✔
55
        for fun, value in self.modely._model_def['Functions'].items():
1✔
56
            if fun in functions:
1✔
57
                if 'functions' in self.modely._model_def['Functions'][fun]:
1✔
58
                    x, activ_fun = return_fuzzify(value, xlim, num_points)
1✔
59
                    fig = plt.figure()
1✔
60
                    ax = fig.add_subplot(111)
1✔
61
                    plots.plot_fuzzy(ax, fun, x, activ_fun, value['centers'])
1✔
62
                elif 'code':
1✔
63
                    function_inputs = return_standard_inputs(value, self.modely._model_def, xlim, num_points)
1✔
64
                    function_output, function_input_list = return_function(value, function_inputs)
1✔
65
                    if value['n_input'] == 2:
1✔
66
                        x0 = function_inputs[0].reshape(num_points, num_points).tolist()
1✔
67
                        x1 = function_inputs[1].reshape(num_points, num_points).tolist()
1✔
68
                        output = function_output.reshape(num_points, num_points).tolist()
1✔
69
                        params = []
1✔
70
                        for i, key in enumerate(value['params_and_consts']):
1✔
71
                            params += [function_inputs[i + value['n_input']].tolist()]
1✔
72
                        plots.plot_3d_function(plt, fun, x0, x1, params, output, function_input_list)
1✔
73
                    else:
74
                        x = function_inputs[0].reshape(num_points).tolist()
1✔
75
                        output = function_output.reshape(num_points).tolist()
1✔
76
                        params = []
1✔
77
                        for i, key in enumerate(value['params_and_consts']):
1✔
78
                            params += [function_inputs[i + value['n_input']].tolist()]
1✔
79
                        plots.plot_2d_function(plt, fun, x, params, output, function_input_list)
1✔
80
        plt.show()
1✔
81

82
    def closePlots(self):
1✔
83
        plt.close()
1✔
84

85

86

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