Exemplo n.º 1
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         if (Rows != null)
         {
             hashCode = hashCode * 59 + Rows.GetHashCode();
         }
         if (RowOrder != null)
         {
             hashCode = hashCode * 59 + RowOrder.GetHashCode();
         }
         if (Columns != null)
         {
             hashCode = hashCode * 59 + Columns.GetHashCode();
         }
         if (Subplots != null)
         {
             hashCode = hashCode * 59 + Subplots.GetHashCode();
         }
         if (XAxes != null)
         {
             hashCode = hashCode * 59 + XAxes.GetHashCode();
         }
         if (YAxes != null)
         {
             hashCode = hashCode * 59 + YAxes.GetHashCode();
         }
         if (Pattern != null)
         {
             hashCode = hashCode * 59 + Pattern.GetHashCode();
         }
         if (XGap != null)
         {
             hashCode = hashCode * 59 + XGap.GetHashCode();
         }
         if (YGap != null)
         {
             hashCode = hashCode * 59 + YGap.GetHashCode();
         }
         if (Domain != null)
         {
             hashCode = hashCode * 59 + Domain.GetHashCode();
         }
         if (XSide != null)
         {
             hashCode = hashCode * 59 + XSide.GetHashCode();
         }
         if (YSide != null)
         {
             hashCode = hashCode * 59 + YSide.GetHashCode();
         }
         return(hashCode);
     }
 }
        /// <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="subTitle">Sub title.</param>
        /// <param name="normalised">Whether these are normalised reconstructions.</param>
        /// <param name="plotOptions">Plotting options.</param>
        public static void PlotImageReconstructions(Reconstruction[] reconstructions, double averageError,
                                                    string subTitle, bool normalised, PlotOptions plotOptions)
        {
            var series1 = reconstructions.Take(plotOptions.Reconstructions.NumToShow).Select(
                (ia, i) => (ISeries) new HintonSeries
            {
                Label  = "signal",
                Values = Reshape(Vector.Build.Dense(ia.Signal)),
                Row    = i,
                Column = 0
            }).ToArray();
            var series2 = reconstructions.Take(plotOptions.Reconstructions.NumToShow).Select(
                (ia, i) => (ISeries) new HintonSeries
            {
                Label = "reconstruction",
                // ErrorLabel = "$\\pm$s.d.",
                Values = 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 = plotOptions.Reconstructions.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(ScriptPath, $"Reconstructions_{n}{sub2}.py"),
                FigureName = Path.Combine(FigurePath, $"Reconstructions_{n}{sub2}.pdf"),
                Python     = PythonPath,
                Show       = plotOptions.Reconstructions.Show
            };

            plotter.Plot();
        }
        /// <summary>
        /// Plots the results.
        /// </summary>
        /// <returns>The results.</returns>
        /// <param name="numBases">Number of bases.</param>
        /// <param name="signalWidth">The signal width.</param>
        /// <param name="dictionary">Dictionary.</param>
        /// <param name="coefficients">Coefficients.</param>
        /// <param name="st">Sub title.</param>
        /// <param name="plotOptions">The plotting options.</param>
        /// <param name="labels">Class labels.</param>
        public static void PlotResults(
            int numBases, int signalWidth,
            Gaussian[][][] dictionary, Gaussian[][][] coefficients,
            string st, PlotOptions plotOptions, IList <string> labels)
        {
            var subplots = new Subplots
            {
                ShareX  = true,
                ShareY  = true,
                Rows    = numBases < 16 ? numBases : 4,
                Columns = numBases < 16 ? 1 : 4,
            };

            plotOptions.Dictionary.Subplots  = subplots;
            plotOptions.Dictionary.NumToShow = plotOptions.IsImage ? 1 : Math.Min(numBases, 16);

            for (var i = 0; i < dictionary.Length; i++)
            {
                string label = "Dictionary_class=" + (labels == null ? $"{i}" : labels[i]);
                if (plotOptions.IsImage)
                {
                    PlotImages(dictionary[i], signalWidth, label, plotOptions.Dictionary);
                }
                else
                {
                    PlotPosteriors(dictionary[i], label, st, plotOptions.Dictionary);
                }
            }

            if (coefficients == null)
            {
                return;
            }

            subplots.Rows    = 3;
            subplots.Columns = 2;
            plotOptions.Coefficients.NumToShow = 6;
            plotOptions.Coefficients.Subplots  = subplots;

            for (var i = 0; i < coefficients.Length; i++)
            {
                var    coefficient = coefficients[i];
                string label       = "Coefficients_class={label}" + (labels == null ? $"{i}" : labels[i]);
                PlotPosteriors(coefficient, label, st, plotOptions.Coefficients);
            }
        }
        /// <summary>
        /// Plots the results.
        /// </summary>
        /// <returns>The results.</returns>
        /// <param name="numBases">Number of bases.</param>
        /// <param name="signalWidth">The signal width.</param>
        /// <param name="dictionary">Dictionary.</param>
        /// <param name="coefficients">Coefficients.</param>
        /// <param name="st">Sub title.</param>
        /// <param name="plotOptions">The plotting options.</param>
        public static void PlotResults(
            int numBases, int signalWidth,
            Gaussian[][] dictionary, Gaussian[][] coefficients,
            string st, PlotOptions plotOptions)
        {
            var subplots = new Subplots
            {
                ShareX  = true,
                ShareY  = true,
                Rows    = numBases < 16 ? numBases : 4,
                Columns = numBases < 16 ? 1 : 4
            };

            plotOptions.Dictionary.Subplots  = subplots;
            plotOptions.Dictionary.NumToShow = plotOptions.IsImage ? 1 : Math.Min(numBases, 16);

            if (plotOptions.IsImage)
            {
                PlotImages(dictionary, signalWidth, "Dictionary", plotOptions.Dictionary);
            }
            else
            {
                PlotPosteriors(dictionary, "Dictionary", st, plotOptions.Dictionary);
            }

            if (coefficients == null)
            {
                return;
            }

            subplots.Rows    = 3;
            subplots.Columns = 2;
            plotOptions.Coefficients.NumToShow = 6;
            plotOptions.Coefficients.Subplots  = subplots;
            PlotPosteriors(coefficients, "Coefficients", st, plotOptions.Coefficients);
        }
Exemplo n.º 5
0
        public bool Equals([AllowNull] Grid other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return((Rows == other.Rows && Rows != null && other.Rows != null && Rows.Equals(other.Rows)) &&
                   (RowOrder == other.RowOrder && RowOrder != null && other.RowOrder != null && RowOrder.Equals(other.RowOrder)) &&
                   (Columns == other.Columns && Columns != null && other.Columns != null && Columns.Equals(other.Columns)) &&
                   (Equals(Subplots, other.Subplots) || Subplots != null && other.Subplots != null && Subplots.SequenceEqual(other.Subplots)) &&
                   (Equals(XAxes, other.XAxes) || XAxes != null && other.XAxes != null && XAxes.SequenceEqual(other.XAxes)) &&
                   (Equals(YAxes, other.YAxes) || YAxes != null && other.YAxes != null && YAxes.SequenceEqual(other.YAxes)) &&
                   (Pattern == other.Pattern && Pattern != null && other.Pattern != null && Pattern.Equals(other.Pattern)) &&
                   (XGap == other.XGap && XGap != null && other.XGap != null && XGap.Equals(other.XGap)) &&
                   (YGap == other.YGap && YGap != null && other.YGap != null && YGap.Equals(other.YGap)) &&
                   (Domain == other.Domain && Domain != null && other.Domain != null && Domain.Equals(other.Domain)) &&
                   (XSide == other.XSide && XSide != null && other.XSide != null && XSide.Equals(other.XSide)) &&
                   (YSide == other.YSide && YSide != null && other.YSide != null && YSide.Equals(other.YSide)));
        }