The GX-TXT debugger · 10-module course

If a chart or statistics appear plausible, the defect can be hidden in the previous steps. Here we follow the data path: sampling, missing values, residues, scale and publication. The six examples help to choose an intermediate control that makes clear the point where the result changes.

Download the Python and GNU Octave examples (ZIP). Extract all the archive folders and keep the multifile examples files together.

D49 — A time series with a skipped sample

A border error can exclude a sample from a temporal window. With small and identifiable data we can verify which positions enter the calculation before applying it to a wider range.

The same window in two languages

Consider five synthetic [10, 20, 30, 40, 50] samples. We want to select the second, third and fourth: the expected result is [20, 30, 40].

In slices.py, samples[1:4] uses zero indexes and exclusive final limit. Stop the press debugger: in the window test it has 3 length.

Python debugger after slicing, with three elements in window.
Python window observed before printing.

In indexing.m, the same window is samples(2:4): Octave starts from 1 and the range includes 4. The test stops before printing after reading the first sample and window.

Octave debugger showing the first sample and the vector.
Sample reading in the Octave example.

The correct form depends on the convention of language. If the requirement also included the fifth sample, it would have to change both intervals and the expected result; the debugger helps to verify the choice, but the requirement comes before the code.

Exercise

What expressions select 30 and 40 respectively in Python and Octave?

Worked solution

Python: samples[2:4]. Octave: samples(3:4). Both select the third and fourth sample.

Course index · Previous lesson

D50 — Statistics with missing values

An absent measure is not equivalent to a measure equal to zero. To make the distinction explicit, we use a mask of validity separated from the values.

Follow the filter

Import and record missing_mean.m in Octave Scripts. The samples = [2, 0, 4, 6] vector contains a placeholder in the second position; is_valid = [1, 0, 1, 1] indicates which observations are valid. The choice to exclude that position is declared by the mask, not deducted from the zero value.

Open View → Debugger, set a breakpoint on the press and start Start Debug. Check in Locals / Globals valid, valid_count and mean_valid: the expected results are [2, 4, 6], 3 and 4 respectively. The second position does not contribute to the average. Complete the Job with Continue.

Octave debugger paused with the validity mask and the mean visible.
Debugger Octave on break with valid and average mask.

In the test the mask and the media are visible in Locals / Globals; scroll the panel to reach the other values. If your dataset uses another coding of missing values, build the mask according to its contract, without assuming that every zero is missing. Manage explicitly also the case where no element is valid.

Exercise

If all four positions were valid, what media would you get?

Worked solution

The average would be (2 + 0 + 4 + 6) / 4 = 3: including the placeholder changes both count and average.

Course index

D51 — Fitting and residuals

A simple regression offers different control points: input data, coefficients, forecasting and residues. A conclusive value alone does not explain where a possible deviation was born.

Follow a straight

Import and record linear_fit.m. The four synthetic points follow y = 2x + 1; the expected coefficients are 2 slope and intercept 1. Put a breakpoint on the print statement, start the debugger and observe coefficients, prediction, residuals and max_error in Locals / Globals. After Continue, the print shows the coefficients with two decimals and the maximum residual with six.

Octave debugger showing the column vector and its dimensions.
Octave panel to observe vector values and shape.

This screen, taken from the exercise on the forms, shows where to read type, shape and value of the vectors. In the fit also compares the dimensions of x, y and prediction before subtracting. The arrangement requires a maximum residual less than 1e-10: the arithmetic in mobile comma can leave very small differences, therefore it is not necessary to demand an exact zero.

Exercise

If the maximum residual is 1e-14, exceeds 1e-10 tolerance?

Worked solution

No. It is smaller than tolerance; the rounded six decimal print can show zero even when the internal value is not exactly zero.

Course index

D52 — Numerical integration and scale

Integration and unity must be consistent: a formula can be performed without errors and produce a result thousand times too large if time is expressed in the wrong drive.

Time, speed and distance

In integral.m, time_s = [0, 1, 2, 3] is expressed in seconds and speed_m_per_s = [2, 2, 2, 2] in meters per second. The area under the curve is 2 × 3 = 6 meters. Import and record the script in Octave Scripts, put a breakpoint on the print and start the debugger. Check the vectors and distance_m, then continue: the press is DISTANCE 6.0 m.

Octave debugger showing source, stack and variables after resizing the panels.
Debugger Octave during a control of the units of a transformation.

The image resumes the conversion of the D40: the debugger shows numbers, while the names and context clarify the units. If time came as [0, 1000, 2000, 3000] milliseconds, convert it into seconds by splitting to 1000 before trapz. Pass it directly to the formula with speed in m/s would produce 6000, without correctly representing meters.

Exercise

What distance runs through a constant speed of 2 m/s in 3 s?

Worked solution

6 m. The product between seconds and meters per second leaves meters.

Course index

D53 — From Dataset to plot

A correct chart requires both correct values and the right association between sizes and axes. Before you build it, stop by reading the Dataset.

From Session to Axes

Follow the D41 to create a debug_sensor_series test session, then the D39 to read time_s and voltage_v. The data are [0, 1, 2] s and [1, 2, 3] V respectively. The Dataset is created-only: to repeat the publication choose a new session or a new ID and update it also in the reading script.

Values and shapes of the vectors read from the Dataset.
Dataset beds in the Octave debugger.

In the D39 screen, we control values and shapes after read_range. To prepare an XY chart combines time with horizontal axis and vertical tension; the expected pairs are (0, 1), (1, 2), (2, 3). Reverse the variables preserves three numerical pairs but changes the meaning of the chart. It carries units and names on the axes and checks a known point before drawing conclusions.

The sensor_plot.m script builds the chart through Plot Dataset API. Import it to the same Session, save it and start the debug; after the eventual initial break, press Continue. In the test the Job is finished with COMPLETED and produced the following chart with the native renderingr. The file is the result exported by GX-TXT, not a viewer screen.

GX-TXT XY plot showing voltage rising from 1 to 3 as time goes from 0 to 2.
XY chart produced by GX-TXT: the voltage grows from 1 to 3 while the time goes from 0 to 2.

The graph uses the Time and Voltage names; in the documentation it explicitly associates the s and V units. The availability of the API and the renderr depends on the installed configuration.

Exercise

What do you get with 1 s time and 2 V voltage?

Worked solution

With time on X and voltage on Y the point is (1, 2); reverse the axes would give (2, 1) and a different interpretation.

Course index

D54 — A multifile project with a propagated error

When a data crosses multiple functions and files, the point where an unexpected result appears does not necessarily coincide with its origin. We follow the value from the caller to the support function.

A reproducible base

Prepare the main.py and helpers.py project, as in the D18. The caller passes 4 and expects adjust to return 5. Save both files and stop the debugger on the calculation line in the helper.

Debugger paused in helpers.py with the adjust frame and a value of 4.
Helper and caller function in the Python project stack.

The test shows value = 4 in the function and caller in the stack. If a copy of the helper incorrectly added 2, the symptom in the caller would be 6, but the point to be corrected would be the operation in the helper. To practice, change a copy of the project, save and restart: first check the incoming argument, then the operation and finally the returned value. Update or temporarily remove the intentionally unsatisfied statement during diagnosis and restore it to check the correction.

Exercise

If the helper already receives 5 instead of 4, is it enough to correct his addition?

Worked solution

Not necessarily: you first need to go back to the caller and check why he provided 5. The value observed at the entrance distinguishes a problem upstream from one in the function.

Course index

These cases prepare the final project, in which it is necessary to document the defect, correction and verification so that another person can repeat them.

Previous: Module 08 · 10-module course contents · Next: Module 10

#debugger #GNU Octave #GX-TXT #Python

Other steps of this project

Leave a Reply

Your email address will not be published. Required fields are marked *