-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlottingHelper.cs
622 lines (569 loc) · 26.5 KB
/
PlottingHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
//
// PlottingHelpers.cs
//
// Author:
// Tom Diethe <[email protected]>
//
// Copyright (c) 2016 University of Bristol
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
namespace BayesianDictionaryLearning
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MicrosoftResearch.Infer.Distributions;
using PythonPlotter;
using InferHelpers;
using Vector = MathNet.Numerics.LinearAlgebra.Vector<double>;
using Matrix = MathNet.Numerics.LinearAlgebra.Matrix<double>;
public static class PlottingHelper
{
/// <summary>
/// Plots the results.
/// </summary>
/// <param name="x">The x values.</param>
/// <param name="y">The y values.</param>
/// <param name="title">The plot title.</param>
/// <param name="subTitle">Sub title.</param>
/// <param name="xlabel">x-axis label.</param>
/// <param name="ylabel">y-axis label.</param>
/// <param name="show">Whether to show the plot.</param>
public static void Plot(IEnumerable<double> x, IEnumerable<double> y, string title, string subTitle,
string xlabel, string ylabel, bool show = false)
{
var series = (ISeries) (new LineSeries { X = x, Y = y });
var plotter = new Plotter
{
Title = title + (string.IsNullOrEmpty(subTitle) ? string.Empty : " " + subTitle),
XLabel = xlabel,
YLabel = ylabel,
Series = new[] { series },
ScriptName = Path.Combine(MainClass.ScriptPath, title.Replace(" ", "_") + ".py"),
FigureName = Path.Combine(MainClass.FigurePath, title.Replace(" ", "_") + ".pdf"),
Python = MainClass.PythonPath,
Show = show,
Tight = true
};
plotter.Plot();
}
public static void TwinTwinPlot(
Dictionary<string, IEnumerable<double>> y1,
Dictionary<string, IEnumerable<double>> y2,
string title,
string xlabel,
string y1Label,
string y2Label,
bool show = false)
{
var series1 = y1.Select(ia => (ISeries) (new LineSeries {Label = ia.Key, X = ia.Value})).ToArray();
var series2 = y2.Select(ia => (ISeries) (new LineSeries {Label = ia.Key, X = ia.Value})).ToArray();
// Turn on color cycling for both series
series1[0].Color = "next(palette)";
series2[0].Color = "next(palette)";
// Here we build the plotting script for the second plot (without the pre/postamble),
// so we can append it to the script for the first plot
var plotter2 = new Plotter { XLabel = xlabel, YLabel = y2Label, Series = series2, TwinX = true };
plotter2.BuildScript();
// TODO: http://matplotlib.org/examples/api/two_scales.html
var plotter1 = new Plotter
{
Title = title,
XLabel = xlabel,
YLabel = y1Label,
Series = series1,
Python = MainClass.PythonPath,
Show = show,
Tight = true
};
plotter1.Plot(plotter2.Script);
}
/// <summary>
/// Plots the results.
/// </summary>
/// <param name="y">The values.</param>
/// <param name="filename">The file name.</param>
/// <param name="xlabel">x-axis label.</param>
/// <param name="ylabel">y-axis label.</param>
/// <param name="show">Whether to show the plot.</param>
public static void Plot(Dictionary<string, IEnumerable<double>> y, string filename, string xlabel,
string ylabel, bool show = false)
{
var series = y.Select(ia => (ISeries) (new LineSeries {Label = ia.Key, X = ia.Value})).ToArray();
var plotter = new Plotter
{
XLabel = xlabel,
YLabel = ylabel,
Series = series,
ScriptName = Path.Combine(MainClass.ScriptPath, filename.Replace(" ", "_") + ".py"),
FigureName = Path.Combine(MainClass.FigurePath, filename.Replace(" ", "_") + ".pdf"),
Python = MainClass.PythonPath,
Show = show,
Tight = true
};
plotter.Plot();
}
/// <summary>
/// Plots the results.
/// </summary>
/// <param name="y">The values.</param>
/// <param name="title">The plot title.</param>
/// <param name="subTitle">Sub title.</param>
/// <param name="xlabel">x-axis label.</param>
/// <param name="ylabel">y-axis label.</param>
/// <param name="show">Whether to show the plot.</param>
public static void Plot(Dictionary<string, IEnumerable<double>> y, string title, string subTitle, string xlabel,
string ylabel, bool show = false)
{
var series = y.Select(ia => (ISeries) (new LineSeries {Label = ia.Key, X = ia.Value})).ToArray();
var plotter = new Plotter
{
Title = title + (string.IsNullOrEmpty(subTitle) ? string.Empty : " " + subTitle),
XLabel = xlabel,
YLabel = ylabel,
Series = series,
ScriptName = Path.Combine(MainClass.ScriptPath, title.Replace(" ", "_") + ".py"),
FigureName = Path.Combine(MainClass.FigurePath, title.Replace(" ", "_") + ".pdf"),
Python = MainClass.PythonPath,
Show = show,
Tight = true
};
plotter.Plot();
}
public static void SparsityPlot(Gaussian[][] coefficients, string title, string filename, bool show = false)
{
var values = coefficients.GetMeans<Gaussian>(); // .To2D().Transpose().ToJagged();
var plotter = new Plotter
{
// Title = title,
XLabel = "bases",
YLabel = "signals",
ScriptName = Path.Combine(MainClass.ScriptPath, $"{filename.Replace(" ", "_")}.py"),
FigureName = Path.Combine(MainClass.FigurePath, $"{filename.Replace(" ", "_")}.pdf"),
Python = MainClass.PythonPath,
Series = new ISeries[] { new HintonSeries { Values = values } },
Grid = false,
Show = show,
Tight = true
};
plotter.Plot();
}
/// <summary>
/// Plots the functions.
/// </summary>
/// <param name="functions">The functions to plot.</param>
/// <param name="title">The plot title..</param>
/// <param name="subTitle">Sub title.</param>
/// <param name="numToShow">The number of functions to show.</param>
/// <param name="rows">The number of rows in the subplot.</param>
/// <param name="cols">The number of columns in the subplot.</param>
public static void PlotFunctions(double[][] functions, string title, string subTitle, int numToShow, int rows, int cols)
{
IList<ISeries> series = functions.Take(numToShow).Select(
(ia, i) => (ISeries)(new LineSeries
{
X = ia,
Row = i / cols,
Column = i % cols
})).ToArray();
var subplots = new Subplots { Rows = rows, Columns = cols, ShareX = true, ShareY = true };
var plotter = new Plotter
{
Title = title + (string.IsNullOrEmpty(subTitle) ? string.Empty : " " + subTitle),
XLabel = "x", YLabel = "y",
Series = series, Subplots = subplots,
ScriptName = Path.Combine(MainClass.ScriptPath, title + ".py"),
FigureName = Path.Combine(MainClass.FigurePath, title + ".pdf"),
Python = MainClass.PythonPath
};
plotter.Plot();
}
/// <summary>
/// Plots the results.
/// </summary>
/// <returns>The results.</returns>
/// <param name="numBases">Number bases.</param>
/// <param name="dictionary">Dictionary.</param>
/// <param name="coefficients">Coefficients.</param>
/// <param name="subTitle">Sub title.</param>
public static void PlotResults(int numBases, VectorGaussian[] dictionary, VectorGaussian[] coefficients, string subTitle = null)
{
PlotResults(
numBases,
dictionary.Select(DistributionHelpers.IndependentApproximation).ToArray(),
coefficients.Select(DistributionHelpers.IndependentApproximation).ToArray(),
subTitle);
}
/// <summary>
/// Plots the results.
/// </summary>
/// <returns>The results.</returns>
/// <param name="numBases">Number bases.</param>
/// <param name="dictionary">Dictionary.</param>
/// <param name="coefficients">Coefficients.</param>
/// <param name="subTitle">Sub title.</param>
public static void PlotResults(int numBases, Gaussian[][] dictionary, Gaussian[][] coefficients, string subTitle = null)
{
for (var i = 0; i < numBases / 16; i++)
{
PlotPosteriors(dictionary, "Dictionary", subTitle, i * 16, 16, 4, 4, PlotType.ErrorLine);
}
if (numBases <= 32)
{
PlotPosteriors(coefficients, "Coefficients", subTitle, 0, 16, 4, 4, PlotType.Bar);
}
else
{
PlotPosteriors(coefficients, "Coefficients", subTitle, 0, 16, 8, 2, PlotType.Bar);
}
}
public static void PlotResults(
int numBases, int signalWidth,
Gaussian[][] dictionary, Gaussian[][] coefficients,
string st, bool isImage, bool plotDictionary, bool plotCoefficients)
{
const PlotType plotTypeDict = PlotType.ErrorLine;
const PlotType plotTypeCoef = PlotType.ErrorBar;
// const PlotType plotTypeDict = PlotType.Line;
// const PlotType plotTypeCoef = PlotType.Bar;
if (numBases < 16)
{
if (isImage)
{
PlotImages(dictionary, signalWidth, "Dictionary", numBases, 1, plotDictionary);
}
else
{
PlotPosteriors(dictionary, "Dictionary", st, 0, numBases, numBases, 1, plotTypeDict, plotDictionary);
}
}
else
{
if (isImage)
{
PlotImages(dictionary, signalWidth, "Dictionary", 4, 4, plotDictionary);
}
else
{
PlotPosteriors(dictionary, "Dictionary", st, 0, 16, 4, 4, plotTypeDict, plotDictionary);
}
}
if (coefficients != null)
{
PlotPosteriors(coefficients, "Coefficients", st, 0, 6, 3, 2, plotTypeCoef, plotCoefficients);
}
}
/// <summary>
/// Plots the reconstructions.
/// </summary>
/// <returns>The reconstructions.</returns>
/// <param name="reconstructions">Reconstructions.</param>
/// <param name="averageError">The average reconstruction error.</param>
/// <param name="numToShow">Number to show.</param>
/// <param name="rows">Rows.</param>
/// <param name="cols">Cols.</param>
/// <param name="subTitle">Sub title.</param>
/// <param name="normalised">Whether these are normalised reconstructions.</param>
/// <param name="show">Whether to show the plot.</param>
public static void PlotReconstructions(Reconstruction[] reconstructions, double averageError, int numToShow,
int rows, int cols, string subTitle = null, bool normalised = false, bool show = false)
{
var series1 = reconstructions.Take(numToShow).Select(
(ia, i) => (ISeries)(new LineSeries
{
Label = "signal",
X = ia.Signal,
Row = i/cols,
Column = i%cols
})).ToArray();
var series2 = reconstructions.Take(numToShow).Select(
(ia, i) => (ISeries)(new ErrorLineSeries
{
Label = "reconstruction",
ErrorLabel = "$\\pm$s.d.",
X = ia.Estimate.GetMeans(),
ErrorValues = ia.Estimate.GetStandardDeviations(),
Row = i/cols,
Column = i%cols
})).ToArray();
IList<ISeries> series = series1.Concat(series2).ToArray();
string n = normalised ? " (normalised)" : string.Empty;
// var series = new[] { new LineSeries { X = x1, Row = 0 }, new LineSeries { X = x2, Row = 1 } };
var subplots = new Subplots {Rows = rows, Columns = cols, ShareX = true, ShareY = true};
string sub = string.IsNullOrEmpty(subTitle) ? string.Empty : $"_{subTitle.Replace(" ", "_")}";
var plotter = new Plotter
{
Title = $"Reconstructions{n}, RMSE={averageError:N4}",
XLabel = "x",
YLabel = "y",
Series = series,
Subplots = subplots,
ScriptName = Path.Combine(MainClass.ScriptPath, $"Reconstructions_{n}{sub}.py"),
FigureName = Path.Combine(MainClass.FigurePath, $"Reconstructions_{n}{sub}.pdf"),
Python = MainClass.PythonPath,
Show = show
};
plotter.Plot();
}
/// <summary>
/// Plots the image reconstructions. Note that we assume the images are square
/// </summary>
/// <returns>The reconstructions.</returns>
/// <param name="reconstructions">Reconstructions.</param>
/// <param name="averageError">The average reconstruction error.</param>
/// <param name="numToShow">Number to show.</param>
/// <param name="subTitle">Sub title.</param>
/// <param name="normalised">Whether these are normalised reconstructions.</param>
/// <param name="show">Whether to show the plot.</param>
public static void PlotImageReconstructions(Reconstruction[] reconstructions, double averageError, int numToShow,
string subTitle = null, bool normalised = false, bool show = false)
{
var series1 = reconstructions.Take(numToShow).Select(
(ia, i) => (ISeries) new HintonSeries
{
Label = "signal",
Values = Data.Reshape(Vector.Build.Dense(ia.Signal)),
Row = i,
Column = 0
}).ToArray();
var series2 = reconstructions.Take(numToShow).Select(
(ia, i) => (ISeries) new HintonSeries
{
Label = "reconstruction",
// ErrorLabel = "$\\pm$s.d.",
Values = Data.Reshape(Vector.Build.Dense(ia.Estimate.GetMeans())),
// ErrorValues = ia.Estimate.GetStandardDeviations(),
Row = i,
Column = 1
}).ToArray();
IList<ISeries> series = series1.Concat(series2).ToArray();
string n = normalised ? "(normalised)" : string.Empty;
var subplots = new Subplots {Rows = numToShow, Columns = 2, ShareX = false, ShareY = false};
string sub1 = string.IsNullOrEmpty(subTitle) ? string.Empty : $" {subTitle.Replace("_", " ")}";
string sub2 = string.IsNullOrEmpty(subTitle) ? string.Empty : $"_{subTitle.Replace(" ", "_")}";
string message = $"Reconstructions {n}{sub1}, avg. error={averageError:N4}";
Console.WriteLine(message);
var plotter = new Plotter
{
Title = message,
XLabel = "x",
YLabel = "y",
Grid = false,
Series = series,
Subplots = subplots,
ScriptName = Path.Combine(MainClass.ScriptPath, $"Reconstructions_{n}{sub2}.py"),
FigureName = Path.Combine(MainClass.FigurePath, $"Reconstructions_{n}{sub2}.pdf"),
Python = MainClass.PythonPath,
Show = show
};
plotter.Plot();
}
// /// <summary>
// /// Plots the reconstructions.
// /// </summary>
// /// <returns>The reconstructions.</returns>
// /// <param name="signals">Signals.</param>
// /// <param name="reconstructions">Reconstructions.</param>
// /// <param name="title">Title.</param>
// /// <param name="numToShow">Number to show.</param>
// /// <param name="rows">Rows.</param>
// /// <param name="cols">Cols.</param>
// /// <param name="subTitle">Sub title.</param>
// public static void PlotReconstructions(double[][] signals, double[][] reconstructions, string title, int numToShow, int rows, int cols, string subTitle = null)
// {
// var r = signals.Zip(reconstructions, (s, e) => new Reconstruction { Signal = s, Estimate = e.Select(Gaussian.PointMass).ToArray() }).ToArray();
// PlotReconstructions(r, averageError, title, numToShow, rows, cols, subTitle);
// }
/// <summary>
/// Plots the posteriors.
/// </summary>
/// <returns>The posteriors.</returns>
/// <param name="posteriors">Posteriors.</param>
/// <param name="title">Title.</param>
/// <param name="subTitle">Sub title.</param>
/// <param name="skip">Skip.</param>
/// <param name="numToShow">Number to show.</param>
/// <param name="rows">Rows.</param>
/// <param name="cols">Cols.</param>
/// <param name="plotType">Plot type.</param>
/// <param name="show">Whether to show the plot.</param>
public static void PlotPosteriors<T>(
T[][] posteriors,
string title,
string subTitle = null,
int skip = 0,
int numToShow = 16,
int rows = 4,
int cols = 4,
PlotType plotType = PlotType.ErrorLine,
bool show = true)
where T : IDistribution<double>, CanGetMean<double>, CanGetVariance<double>
{
ISeries[] series;
switch (plotType)
{
case PlotType.ErrorLine:
series = posteriors.Skip(skip).Take(numToShow).Select(
(ia, i) => (ISeries)(new ErrorLineSeries
{
// Label = i.ToString(),
X = ia.Select(x => x.GetMean()).ToArray(),
ErrorValues = ia.GetStandardDeviations(),
Row = i / cols,
Column = i % cols
})).ToArray();
break;
case PlotType.Bar:
series = posteriors.Skip(skip).Take(numToShow).Select(
(ia, i) => (ISeries)(new BarSeries<string>
{
// Label = i.ToString(),
DependentValues = ia.GetMeans(),
Row = i / cols,
Column = i % cols
})).ToArray();
break;
case PlotType.ErrorBar:
series = posteriors.Skip(skip).Take(numToShow).Select(
(ia, i) => (ISeries)(new BarSeries<string>
{
// Label = i.ToString(),
DependentValues = ia.GetMeans(),
ErrorValues = ia.GetStandardDeviations(),
Row = i / cols,
Column = i % cols
})).ToArray();
break;
case PlotType.Line:
series = posteriors.Skip(skip).Take(numToShow).Select(
(ia, i) => (ISeries)(new LineSeries
{
// Label = i.ToString(),
X = ia.GetMeans(),
Row = i / cols,
Column = i % cols
})).ToArray();
break;
default:
throw new ArgumentException("Unknonw plot type", nameof(plotType));
}
// var series = new[] { new LineSeries { X = x1, Row = 0 }, new LineSeries { X = x2, Row = 1 } };
var subplots = new Subplots { Rows = rows, Columns = cols, ShareX = true, ShareY = true };
string sub = string.IsNullOrEmpty(subTitle) ? string.Empty : $"_{subTitle.Replace(" ", "_")}";
string sel = $"{skip}-{skip + numToShow}";
var plotter = new Plotter
{
Title = $"{title} {sel}",
XLabel = "x", YLabel = "y", Series = series, Subplots = subplots,
Python = MainClass.PythonPath,
ScriptName = Path.Combine(MainClass.ScriptPath, $"{title}{sub}_{sel}.py"),
FigureName = Path.Combine(MainClass.FigurePath, $"{title}{sub}_{sel}.pdf"),
Show = show
};
plotter.Plot();
}
/// <summary>
/// Plot errors with evidence on twinx
/// </summary>
public static void PlotErrorsWithEvidence(Results results, bool show = false)
{
// Here we're going to customise the Plotter.TwinPlot function
var x = results.BasisCounts.Select(ia => (double)ia).ToArray();
var y1 = results.Errors;
var y2 = results.Evidence;
const string title = "Effect of number of bases";
const string xlabel = "#bases";
const string y1Label = "Reconstruction error";
const string y2Label = "Log Evidence";
var series1 = new ISeries[] { new LineSeries { X = x, Y = y1, Color = "next(palette)", Label = "Reconstruction error" } };
var series2 = new ISeries[] { new LineSeries { X = x, Y = y2, Color = "next(palette)", Label = "Evidence" } };
// Here we build the plotting script for the second plot (without the pre/postamble),
// so we can append it to the script for the first plot
var plotter2 = new Plotter { XLabel = xlabel, YLabel = y2Label, Series = series2, TwinX = true };
plotter2.BuildScript();
// TODO: http://matplotlib.org/examples/api/two_scales.html
var plotter1 = new Plotter
{
Title = title,
XLabel = xlabel,
YLabel = y1Label,
Series = series1,
Python = MainClass.PythonPath,
ScriptName = Path.Combine(MainClass.ScriptPath, "EffectOfBases"),
FigureName = Path.Combine(MainClass.FigurePath, "EffectOfBases"),
Show = show
};
plotter1.Plot(plotter2.Script);
}
/// <summary>
/// Plots the image.
/// </summary>
/// <param name="imageFlat">Image flat.</param>
/// <param name="show">Whether to show the plot.</param>
public static void PlotImage(Vector imageFlat, bool show = false)
{
// DenseOfColumnMajor(rows, columns, m.Row(0));
// Plotter.Hinton(image);
var plotter = new Plotter
{
Series = new ISeries[] { new MatrixSeries { Values = Data.Reshape(imageFlat) } },
Grid = false,
Python = MainClass.PythonPath,
ScriptName = Path.Combine(MainClass.ScriptPath, "EffectOfBases"),
FigureName = Path.Combine(MainClass.FigurePath, "EffectOfBases"),
Show = show
};
plotter.Plot();
}
/// <summary>
/// Plots the images.
/// </summary>
/// <param name="imagesFlat">Images.</param>
/// <param name="title">The title.</param>
/// <param name="rows">Number of rows.</param>
/// <param name="columns">Number of columns.</param>
/// <param name="show">Whether to show the plot</param>
public static void PlotImages(Matrix imagesFlat, string title, int rows, int columns, bool show = false)
{
var series =
(from t in imagesFlat.EnumerateRowsIndexed()
let index = t.Item1 let image = Data.Reshape(t.Item2)
select new MatrixSeries { Values = image, Row = index / columns, Column = index % columns }
).Cast<ISeries>().ToList();
var plotter = new Plotter
{
Title = title,
Series = series,
Grid = false,
Subplots = new Subplots { Rows = rows, Columns = columns },
Python = MainClass.PythonPath,
ScriptName = Path.Combine(MainClass.ScriptPath, "EffectOfBases"),
FigureName = Path.Combine(MainClass.FigurePath, "EffectOfBases"),
Show = show
};
plotter.Plot();
}
public static void PlotImages(Gaussian[][] images, int imageWidth, string title, int rows, int columns, bool show)
{
var dictionary = Matrix.Build.DenseOfRowArrays(images.GetMeans<Gaussian>());
PlotImages(dictionary.SubMatrix(0, rows * columns, 0, imageWidth), title, rows, columns, show);
}
}
}