programmingzeal has asked for the wisdom of the Perl Monks concerning the following question:
My task is to plot Least Mean Squared Error (LSME) values from each iteration of a machine learning algorithm in a Graph of X and Y axes/coordinates. I decided to print special character (say *) on the console using loops. I do not want to use any libraries for graph plotting but to be simple by printing sequence of special character so that I may be able to print first quadrant of X-Y coordinates onto console.
I am familiar with NDC to view port mapping in graphics programming. But I am unable to implement such nested loops that print my required graph in first quadrant on console as same that we draw on paper.
On console, the origin (0,0) is top left corner of console. But on paper the origin is left bottom if we only plot first quadrant. For overcoming this problem I cracked an idea that I use a 2 D matrix structure and some transpose operation of it and use characters (BLANK SPACE and *) for plotting my graph. I developed following code which has two arrays, one with error values (LMSE) and the other one with the count of spaces.
I computed maximum value of my error values array and assigned the difference of Max value with original error value to another array. The logic which I am able to conceive is that I fill a matrix with spaces and * which when printed on console depict a X-Y first quadrant graph on console. Is my approach promising? Can somebody confirm my approach is correct and how to build such a matrix of " " and "*" characters?use strict; use warnings; use Data::Dumper; $|= 0; my @values = (7,9,2,0,1,2,4,3,9); my @values2; my $XAxis_LMSE = scalar @values; my ($minLMSE_Graph, $maxLMSE_Graph) = (sort {$a <=> $b} @values)[0, -1 +]; for (my $i = 0; $i < scalar @values; $i++) { my $rem = $maxLMSE_Graph - $values[$i]; push (@values2, $rem); } print Dumper @values2;
Y(x) values are given by array @values and X is number of Iterations. Iterations can go from 1 to say 100. While Y(x) also remains an Integer. Its a simple Column Bar Graph. It will be a vertical Bar Graph.
|
|---|