Пример #1
0
        public void AreClose_Radius40_OpticalConst_DrudeLorentz()
        {
            // Arrange
            const double  DistanceMax  = 0.5;
            const double  DistanceStep = 0.1;
            List <double> distances    = getDistances(DistanceStep, DistanceMax);
            var           radius       = 40;

            string dirOpticalConst = "RadiusDistanceOutput_Azimuth45_EffectiveCrossExt";
            string dirDrudeLorentz = "RadiusDistanceDrudeLorentz_Azimuth45_EffectiveCrossExt";
            var    gp = new GnuPlot();

            setLineStyle(gp);
            gp.HoldOn();

            foreach (double distance in distances)
            {
                Dictionary <double, double> optical = SimpleFormatter.Read(
                    this.getFileFormat(dirOpticalConst, distance, radius));
                Dictionary <double, double> drudeLorentz = SimpleFormatter.Read(
                    this.getFileFormat(dirDrudeLorentz, distance, radius));

                gp.Plot(optical, @"title ""optical""");
                gp.Plot(drudeLorentz, @"title ""drude-lorentz""");

                //AssertHelper.DictionaryAreClose(optical, drudeLorentz, 0.1);
            }

            gp.Wait();
        }
        public void CalculateOpticalConstants_DrudeLorentz_Gnuplot()
        {
            // Arrange
            var optConst     = ParameterHelper.ReadOpticalConstants("opt_const.txt");
            var drudeLorentz = new DrudeLorentz();
            var dict         = new Dictionary <double, Complex>();

            foreach (var waveLength in optConst.WaveLengthList)
            {
                var freq = new SpectrumUnit(waveLength / OpticalConstants.WaveLengthMultiplier,
                                            SpectrumUnitType.WaveLength);
                dict.Add(waveLength, drudeLorentz.GetPermittivity(freq));
            }

            ParameterHelper.WriteOpticalConstants("opt_const_drudeLorentz.txt", dict);

            using (var gp = new GnuPlot())
            {
                gp.HoldOn();
                gp.Set("style data lines");

                gp.Plot(getPermitivittyFunc(optConst));
                gp.Plot(dict);

                gp.Wait();
            }
            // Act

            // Assert
        }
Пример #3
0
    // create or close gnuplot window
    void OnPlotActionActivated(object sender, System.EventArgs e)
    {
        try {
            // gnuplot process itself can be slow to startup
            // so this does not prevent closing it immediatly when pressed twice
            //plotExternalAction.Sensitive = false;

            switch (CurrentUI)
            {
            case ActiveUI.View2D:
                Table2D table2D = dataView2DGtk.Selected;
                if (table2D != null)
                {
                    GnuPlot.ToggleGnuPlot(table2D);
                }
                break;

            case ActiveUI.View3D:
                Table3D table3D = dataView3DGtk.Selected;
                if (table3D != null)
                {
                    GnuPlot.ToggleGnuPlot(table3D);
                }
                break;
            }
        } catch (GnuPlotProcessException ex) {
            Console.Error.WriteLine(ex);
            ErrorMsg("Error launching gnuplot!", ex.Message + "\n\nHave you installed gnuplot?" + "\nYou also may need to edit file '" + appName + ".exe.config'." + "\nCurrent platform-ID is '" + System.Environment.OSVersion.Platform.ToString() + "'." + "\nSee 'README.txt' for details.");
        } catch (GnuPlotException ex) {
            Console.Error.WriteLine(ex);
            ErrorMsg("Error launching gnuplot!", ex.Message);
        }
    }
Пример #4
0
    // create or close gnuplot window
    void OnPlotActionActivated(object sender, System.EventArgs e)
    {
        var table = CurrentTable;

        if (table == null)
        {
            return;
        }

        try {
            // gnuplot process itself can be slow to startup
            // so this does not prevent closing it immediatly when pressed twice
            //plotExternalAction.Sensitive = false;
            GnuPlot.ToggleGnuPlot(table);
        } catch (GnuPlotProcessException ex) {
            Console.Error.WriteLine(ex);
            ErrorMsg("Error launching gnuplot!", ex.Message
                     + "\n\nHave you installed gnuplot?"
                     + "\nYou also may need to edit file '" + MainClass.AssemblyPath + ".exe.config'."
                     + "\nCurrent platform-ID is '" + System.Environment.OSVersion.Platform.ToString() + "'."
                     + "\nSee 'README.txt' for details.");
        } catch (GnuPlotException ex) {
            Console.Error.WriteLine(ex);
            ErrorMsg("Error launching gnuplot!", ex.Message);
        } catch (System.IO.FileNotFoundException ex) {
            Console.Error.WriteLine(ex);
            ErrorMsg("Error using gnuplot!", ex.Message + "\nFile: " + ex.FileName);
        }
    }
Пример #5
0
    private void PlotVector()
    {
        if (!Helper.Plot)
        {
            return;
        }

        if (!File.Exists(Helper.outputPath + "vectors.txt"))
        {
            using (var fs = File.Create(Helper.outputPath + "vectors.txt")) { }
        }

        foreach (var neuron in neurons)
        {
            if (neuron.PreviousWeights.Count == neuron.Weights.Count)
            {
                text +=
                    $"{neuron.PreviousWeights[0]} {neuron.PreviousWeights[1]} {neuron.Weights[0]} {neuron.Weights[1]}\r\n";
            }
        }

        using (var stream = File.CreateText(Helper.outputPath + "vectors.txt"))
        {
            stream.Write(text);
        }
        GnuPlot.Plot(Helper.outputPath + "vectors.txt", $" using 1:2:($3-$1):($4-$2) with vectors head filled lt 2 lc rgb 'red', '{Helper.outputPath + "shape.txt"}' using 1:2 title 'shape' with points pt '+' lc rgb 'black'");
    }
Пример #6
0
        public void TestMethod1()
        {
            Stopwatch watch = new Stopwatch();

            var gp = new GnuPlot();

            gp.HoldOn();
            for (int j = 0; j < 5; j++)
            {
                List <TimeSpan> list = new List <TimeSpan>();

                for (var i = 1; i <= 16; i++)
                {
                    watch.Start();
                    ParallelIterator.MaxDegreeOfParallelism = i;

                    FDTDProgram.Calculate();
                    watch.Stop();
                    list.Add(watch.Elapsed);
                    watch.Reset();
                }

                gp.Plot(list.Select(x => (double)x.Milliseconds));
            }
            gp.Wait();
        }
Пример #7
0
        public static void PlotData(Matrix <double> X, Vector <double> y)
        {
            List <(double x1, double x2)> pos = new List <(double x1, double x2)>();
            List <(double x1, double x2)> neg = new List <(double x1, double x2)>();

            for (int i = 0; i < y.Count; i++)
            {
                if (y[i] == 1)
                {
                    pos.Add((X[i, 0], X[i, 1]));
                }
                else
                {
                    neg.Add((X[i, 0], X[i, 1]));
                }
            }


            GnuPlot.HoldOn();
            GnuPlot.Set("title \"Data\"");
            //GnuPlot.Set("key bottom right");
            GnuPlot.Set("key outside noautotitle");
            //GnuPlot.Set("key title \"Legend\"");
            GnuPlot.Set("xlabel \"Exam 1 score\"");
            GnuPlot.Set("ylabel \"Exam 2 score\"");
            GnuPlot.Plot(pos.Select(p => p.x1).ToArray(), pos.Select(p => p.x2).ToArray(), "pt 1 ps 1 lc rgb \"black\" title \"Admitted\"");

            GnuPlot.Plot(neg.Select(p => p.x1).ToArray(), neg.Select(p => p.x2).ToArray(), "pt 7 ps 1 lc rgb \"yellow\" title \"Not admitted\"");
        }
Пример #8
0
        public void AreCloseDistance3_OpticalConst_DrudeLorentz()
        {
            // Arrange
            var distance = 2.9;
            var radiuses = new List <double> {
                4, 10, 20, 40, 70, 100, 200
            };

            string dirOpticalConst = "RadiusDistanceOutput_Azimuth45_EffectiveCrossExt";
            string dirDrudeLorentz = "RadiusDistanceDrudeLorentz_Azimuth45_EffectiveCrossExt";
            var    gp = new GnuPlot();

            setLineStyle(gp);
            gp.HoldOn();

            foreach (double radius in radiuses)
            {
                Dictionary <double, double> optical = SimpleFormatter.Read(
                    this.getFileFormat(dirOpticalConst, distance, radius));
                Dictionary <double, double> drudeLorentz = SimpleFormatter.Read(
                    this.getFileFormat(dirDrudeLorentz, distance, radius));

                gp.Plot(optical, @"title ""optical""");
                gp.Plot(drudeLorentz, @"title ""drude-lorentz""");

                //AssertHelper.DictionaryAreClose(optical, drudeLorentz, 0.1);
            }

            gp.Wait();
        }
Пример #9
0
        public static void PlotData(Matrix <double> X, Vector <double> y)
        {
            List <(double x1, double x2)> pos = new List <(double x1, double x2)>();
            List <(double x1, double x2)> neg = new List <(double x1, double x2)>();

            for (int i = 0; i < y.Count; i++)
            {
                if (y[i] == 1)
                {
                    pos.Add((X[i, 0], X[i, 1]));
                }
                else
                {
                    neg.Add((X[i, 0], X[i, 1]));
                }
            }


            GnuPlot.HoldOn();
            GnuPlot.Set("title \"\"");
            GnuPlot.Set("xlabel \"Microchip test 1\"");
            GnuPlot.Set("ylabel \"Microchip test 2\"");
            GnuPlot.Plot(pos.Select(p => p.x1).ToArray(), pos.Select(p => p.x2).ToArray(), "pt 1 ps 1 lc rgb \"black\" title \"y=1\"");

            GnuPlot.Plot(neg.Select(p => p.x1).ToArray(), neg.Select(p => p.x2).ToArray(), "pt 7 ps 1 lc rgb \"yellow\" title \"y=0\"");
        }
Пример #10
0
        private static void PlotFit(double min_x, double max_x, Vector <double> mu, Vector <double> sigma, Vector <double> theta, int p, double lambda)
        {
            // Plot training data and fit
            var x = Matrix <double> .Build.DenseOfColumnArrays(Generate.LinearRange(min_x - 15, .05, max_x + 25));

            Matrix <double> X_poly = MapPolyFeatures(x, p);

            for (int i = 0; i < X_poly.ColumnCount; i++)
            {
                Vector <double> v = X_poly.Column(i);
                v = v - mu[i];
                v = v / sigma[i];
                X_poly.SetColumn(i, v);
            }

            X_poly = X_poly.InsertColumn(0, Vector <double> .Build.Dense(X_poly.RowCount, 1));
            var hypothesis = X_poly * theta;

            GnuPlot.Set(string.Format("title \"Polynomial Regression Fit (lambda = {0:f6})\"", lambda));
            GnuPlot.Set("xlabel \"Change in water level (x)\"");
            GnuPlot.Set("ylabel \"Water flowing out of the dam (y)\"");
            GnuPlot.Set("autoscale xy");
            //GnuPlot.Set("xr[-100:100]");
            //GnuPlot.Set("yr[-200:400]");

            GnuPlot.Plot(x.Column(0).ToArray(), hypothesis.ToArray(), "with lines dashtype 2 lw 1 lc rgb \"blue\" notitle");
        }
Пример #11
0
        public void DimmerVsOne_Azimuth45_EffectiveCrossExt()
        {
            // Arrange
            var radiuses = new List <double> {
                4, 10, 20, 40
            };
            var    distance     = 0;
            string dirAzimuth45 = "DimmerVsOne_Azimuth45_EffectiveCrossExt";
            string dirAzimOne   = "OneParticle_EffectiveCrossExt";

            foreach (double radius in radiuses)
            {
                var gp = new GnuPlot();
                setLineStyle(gp);
                gp.HoldOn();
                Dictionary <double, double> azim45 = SimpleFormatter.Read(
                    this.getFileFormat(dirAzimuth45, distance, radius))
                                                     .Where(x => x.Key <= 500)
                                                     .ToDictionary(x => x.Key * 1e9, x => x.Value * 2);
                gp.Plot(azim45, string.Format(@"title ""{0}""", distance));

                Dictionary <double, double> azimOne = SimpleFormatter.Read(
                    this.getFileFormatOneParticle(dirAzimOne, radius))
                                                      .Where(x => x.Key <= 500)
                                                      .ToDictionary(x => x.Key * 1e9, x => x.Value * 2);
                gp.Plot(azimOne, string.Format(@"title ""{0}""", 0));
            }
        }
Пример #12
0
        public void RadiusChangeOutput_InterparticleDistance_Spectrum()
        {
            // Arrange
            GnuPlot gp       = null;
            var     radius1  = 20;
            var     radiuses = new List <double> {
                4, 10, 15, 20
            };
            double distance     = 70;
            string dirAzimuth45 = "RadiusChangeOutput_InterparticleDistance_Spectrum";

            //foreach (var radius1 in radiuses)
            //{
            gp = new GnuPlot();
            setLineStyle(gp);
            gp.HoldOn();
            setColorPalette(gp);

            gp.Set(String.Format("title \"{0}\"", radius1));

            foreach (double radius in radiuses)
            {
                Dictionary <double, double> azim45 = SimpleFormatter.Read(
                    this.getFileFormatDiffRadiuses(dirAzimuth45, distance, radius1, radius))
                                                     .ToDictionary(x => x.Key * 1e9, x => x.Value);
                gp.Plot(azim45, string.Format(@"title ""{0}""", radius));

                //gp.Clear();
            }
            //}
            gp.Wait();
        }
Пример #13
0
        public void AreClose_Azimuth45_AzimuthSum()
        {
            // Arrange
            const int    DistanceMax  = 3;
            const double DistanceStep = 0.1;
            var          radiuses     = new List <double> {
                4, 10, 20, 40, 70, 100, 200
            };
            List <double> distances     = getDistances(DistanceStep, DistanceMax);
            string        dirAzimuthSum = "RadiusDistanceOutput_AzimuthSum";
            string        dirAzimuth45  = "RadiusDistanceOutput_Azimuth45";
            var           gp            = new GnuPlot();

            setLineStyle(gp);

            foreach (double radius in radiuses)
            {
                foreach (double distance in distances)
                {
                    Dictionary <double, double> azim45 = SimpleFormatter.Read(
                        this.getFileFormat(dirAzimuth45, distance, radius));
                    Dictionary <double, double> azimSum = SimpleFormatter.Read(
                        this.getFileFormat(dirAzimuthSum, distance, radius));
                    gp.HoldOn();

                    gp.Plot(azim45);
                    gp.Plot(azimSum);
                    gp.HoldOff();
                    AssertHelper.DictionaryAreClose(azim45, azimSum, 0.5);
                }
            }
        }
Пример #14
0
        public void RadiusChangeOutput_Azimuth_Spectrum()
        {
            // Arrange
            const int    DistanceMax  = 3;
            const double DistanceStep = 0.1;

            var radius1  = 4;
            var radiuses = new List <double> {
                4, 10, 20, 40, 70, 100, 200
            };
            List <double> distances    = getDistances(DistanceStep, DistanceMax);
            string        dirAzimuth45 = "RadiusChangeOutput_Azimuth45";

            var gp = new GnuPlot();

            gp.Set("style data lines");
            gp.HoldOn();
            foreach (double radius in radiuses)
            {
                Dictionary <decimal, List <double> > spectrum = this.zipToDictionaryDiffRadiuses(distances, dirAzimuth45, radius1, radius);
                string filename = Path.Combine(BasePath, this.TestContext.TestName, "Azim45.txt");
                SimpleFormatter.WriteDictionary(filename, spectrum, distances);

                foreach (double distance in distances.Take(5))
                {
                    Dictionary <double, double> azim45 = SimpleFormatter.Read(
                        this.getFileFormatDiffRadiuses(dirAzimuth45, distance, radius1, radius));
                    gp.Plot(azim45, string.Format(@"title ""{0}""", radius));
                }
                gp.Clear();
            }


            gp.Wait();
        }
Пример #15
0
        public void Peaks_Azimuth0_Azimuth90()
        {
            // Arrange
            const int    DistanceMax  = 3;
            const double DistanceStep = 0.1;
            var          radiuses     = new List <double> {
                4, 10, 20, 40
            };
            List <double> distances    = getDistances(DistanceStep, DistanceMax);
            string        dirAzimuth0  = "RadiusDistanceOutput_Azimuth0";
            string        dirAzimuth90 = "RadiusDistanceOutput_Azimuth90";
            var           gp           = new GnuPlot();

            gp.Set("style data lines");
            gp.Set("xtics 0.5");
            gp.Set("grid xtics ytics");
            gp.Set("size square");
            gp.HoldOn();
            radiuses.Reverse();
            foreach (double radius in radiuses)
            {
                Dictionary <double, double> peaks0  = this.getPeaks0(distances, radius, dirAzimuth0);
                Dictionary <double, double> peaks90 = this.getPeaks90(distances, radius, dirAzimuth90);

                //gp.HoldOn();
                // gp.Set(string.Format("terminal win {0}", radius));
                gp.Plot(peaks0);
                gp.Plot(peaks90);
                // gp.HoldOff();
            }
            gp.Wait();
        }
Пример #16
0
        public void Calculate_PerformanceMetrics()
        {
            var           serialTicks = 192769194.79518071;
            List <double> all         = new List <double>();
            var           gp          = new GnuPlot();

            gp.Set("style data linespoints");
            gp.HoldOn();

            for (int i = 256; i <= 1024; i = i * 2)
            {
                List <long> list = new List <long>();
                for (int j = 0; j < 20; j++)
                {
                    Stopwatch watch = Stopwatch.StartNew();
                    //ArrayExtensions.MaxDegreeOfParallelism = i;

                    FDTDProgram.Calculate();
                    watch.Stop();
                    list.Add(watch.ElapsedTicks);
                }
                all.Add(list.Average());
            }

            gp.Plot(all.Select(x => serialTicks / x));

            gp.Wait();
        }
Пример #17
0
    static void Main(string[] args)
    {
        System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
        customCulture.NumberFormat.NumberDecimalSeparator = ".";

        System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;

        ParseArgs(args);

        foreach (var shape in shapes)
        {
            Helper.SetShape(shape.shape, shape.args);
        }

        if (Helper.Plot)
        {
            GnuPlot.Set("", "xrange[-10:10]", "yrange[-10:10]", "size square" /*, "terminal gif animate delay 5"*/,
                        $"output '{Helper.outputPath}{Helper.outputFilename.Replace(".txt", ".gif")}'");
            Helper.PlotPoints(Helper.ShapePoints, "with points pt '+' lc rgb 'black'", Helper.outputPath + "shape.txt");
        }

        Network network = new Network(Helper.ShapePoints, epochs, neurons, learningRate, sigma0, method);

        network.Learn();
    }
Пример #18
0
        public void MakePlot(double[] xBound, double[] yBound)
        {
            string xr = "xr[" + xBound[0] + ":" + xBound[1] + "]";
            string yr = "yr[" + yBound[0] + ":" + yBound[1] + "]";

            GnuPlot.Set("cntrparam levels 30", "isosamples 40", xr, yr, "decimalsign locale");
            GnuPlot.SPlot(filename, "with pm3d");
        }
Пример #19
0
 public static void PlotData(double[] x, double[] y)
 {
     GnuPlot.Set("title \"Water flowing\"");
     GnuPlot.Set("key bottom right");
     GnuPlot.Set("xlabel \"Change in water level (x)\"");
     GnuPlot.Set("ylabel \"Water flowing out of the dam (y)\"");
     GnuPlot.Plot(x, y, "pt 2 ps 1 lc rgb \"red\" notitle");
 }
Пример #20
0
 // plot the data
 public static void PlotData(double[] x, double[] y)
 {
     GnuPlot.Set("title \"Linear Regression\"");
     GnuPlot.Set("key bottom right");
     //GnuPlot.Set("key title \"Legend\"");
     GnuPlot.Set("xlabel \"Population of City in 10,000s\"");
     GnuPlot.Set("ylabel \"Profit in $10,000s\"");
     GnuPlot.Plot(x, y, "pt 2 ps 1 lc rgb \"red\" title \"Training data\"");
 }
Пример #21
0
        private static void PlotJ(Matrix <double> j_history, string title, string color)
        {
            double[] x = MathNet.Numerics.Generate.LinearRange(1, 1, j_history.RowCount);
            double[] y = j_history.Column(0).ToArray();

            GnuPlot.Set("xlabel \"Number of iteration\"");
            GnuPlot.Set("ylabel \"Cost J\"");
            GnuPlot.Plot(x, y, "with lines linestyle 1 lc rgb \"" + color + "\" linewidth 2 title \"" + title + "\" ");
        }
Пример #22
0
        private void button1_Click(object sender, EventArgs e)
        {
            GnuPlot gp = new GnuPlot();

            gp.HoldOn();
            gp.Unset("key");
            gp.Plot(NoisySine(1000, 1));
            gp.Plot(NoisySine(1000, 1.5));
            gp.Plot(NoisySine(1000, 2));
        }
Пример #23
0
 public static void PlotPoints(List <Point> points, string options, string saveFileName = "")
 {
     double[] X = points.Select(p => p.x).ToArray();
     double[] Y = points.Select(p => p.y).ToArray();
     GnuPlot.Plot(X, Y, options);
     if (saveFileName != "")
     {
         GnuPlot.SaveData(X, Y, saveFileName);
     }
 }
Пример #24
0
        private void button2_Click(object sender, EventArgs e)
        {
            GnuPlot gp = new GnuPlot();

            gp.HoldOn();
            gp.Set("title 'Phase-Locked Signals'");
            gp.Set("samples 2000");
            gp.Unset("key");
            gp.Plot("sin(x)");
            gp.Plot("cos(x)");
        }
Пример #25
0
        public void RadiusChangeOutputPeaks_Azimuth0_Azimuth90()
        {
            // Arrange
            const int    DistanceMax  = 3;
            const double DistanceStep = 0.1;
            var          radiuses     = new List <double> {
                4, 10, 20, 40, 70, 100, 200
            };
            var           radius1      = 4;
            List <double> distances    = getDistances(DistanceStep, DistanceMax);
            string        dirAzimuth0  = "RadiusChangeOutput_Azimuth0";
            string        dirAzimuth90 = "RadiusChangeOutput_Azimuth90";
            var           gp           = new GnuPlot();

            gp.Set("style data lines");
            gp.HoldOn();
            radiuses.Reverse();
            foreach (double radius in radiuses)
            {
                var peaks0 = new Dictionary <double, double>();

                var peaks90 = new Dictionary <double, double>();

                foreach (double distance in distances)
                {
                    Dictionary <double, double> azim0 = SimpleFormatter.Read(
                        this.getFileFormatDiffRadiuses(dirAzimuth0, distance, radius1, radius));
                    Dictionary <double, double> azim90 = SimpleFormatter.Read(
                        this.getFileFormatDiffRadiuses(dirAzimuth90, distance, radius1, radius));

                    peaks0.Add(distance, azim0.MaxPair().Key);

                    peaks90.Add(distance, azim0.MaxPair().Key);
                }
                // gp.HoldOn();
                // gp.Set(string.Format("terminal win {0}", radius));
                gp.Plot(peaks0);
                gp.Plot(peaks90);
                // gp.HoldOff();

                string basepath  = Path.Combine(BasePath, this.TestContext.TestName);
                string filename0 = Path.Combine(
                    basepath,
                    string.Format("peaks_0deg_{0}.txt", radius));
                SimpleFormatter.Write(filename0, peaks0);
                string filename90 = Path.Combine(
                    basepath,
                    string.Format("peaks_90deg_{0}.txt", radius));
                SimpleFormatter.Write(filename90, peaks90);
            }
            gp.Wait();
        }
Пример #26
0
        // Plot J cost function
        private static void PlotJ(Matrix <double> X, Matrix <double> y, Matrix <double> theta)
        {
            // Grid over which we will calculate J
            double[] theta0_vals = MathNet.Numerics.Generate.LinearSpaced(100, -10, 10);
            double[] theta1_vals = MathNet.Numerics.Generate.LinearSpaced(100, -1, 4);

            // initialize J_vals to a matrix of 0's
            int size = theta0_vals.Length * theta1_vals.Length;

            double[] sx = new double[size];
            double[] sy = new double[size];
            double[] sz = new double[size];


            // Fill out J_vals
            int idx = 0;

            for (int i = 0; i < theta0_vals.Length; i++)
            {
                for (int k = 0; k < theta1_vals.Length; k++)
                {
                    Matrix <double> t = Matrix <double> .Build.Dense(2, 1);

                    t[0, 0] = theta0_vals[i];
                    t[1, 0] = theta1_vals[k];

                    sx[idx] = theta0_vals[i];
                    sy[idx] = theta1_vals[k];
                    sz[idx] = ComputeCost(X, y, t);
                    idx++;
                }
            }

            GnuPlot.HoldOn();
            GnuPlot.Set("terminal wxt 1");
            GnuPlot.Set("title \"Cost function J\"");
            GnuPlot.Set("key bottom right");
            GnuPlot.Set("xlabel \"{/Symbol q}_0\"");
            GnuPlot.Set("ylabel \"{/Symbol q}_1\"");

            // surface plot
            GnuPlot.SPlot(sx, sy, sz, "palette title \"J({/Symbol q}_0,{/Symbol q}_1)\"");

            // Contour plot
            GnuPlot.Set("terminal wxt 2");
            GnuPlot.Set("cntrparam levels auto 10", "logscale z", "xr[-10:10]", "yr[-1:4]");
            GnuPlot.Unset("key", "label");
            GnuPlot.Contour(sx, sy, sz);

            GnuPlot.Plot(new double[] { theta[0, 0] }, new double[] { theta[1, 0] }, "pt 2 ps 1 lc rgb \"red\"");
        }
Пример #27
0
        private static void DisplayData(Vector <double>[] X)
        {
            int w         = 20;
            int h         = 20;
            int row       = 0;
            int col       = 0;
            int offsetRow = 0;
            int offsetCol = 0;
            int dim       = (int)Math.Sqrt(X.Length);

            double[,] d = new double[h * dim, w *dim];


            for (int i = 0; i < X.Length; i++)
            {
                for (int k = 0; k < (w * h); k++)
                {
                    d[row + offsetRow, col + offsetCol] = X[i][k];
                    offsetCol++;

                    if (offsetCol % w == 0)
                    {
                        offsetRow++;
                        offsetCol = 0;
                    }
                }

                col += w;
                if (col >= (w * dim))
                {
                    row += h;
                    col  = 0;
                }

                offsetRow = 0;
                offsetCol = 0;
            }

            //d = RotateRight(d);

            //GnuPlot.Unset("key");
            GnuPlot.Unset("colorbox");
            //GnuPlot.Unset("tics");
            GnuPlot.Set("grid");
            GnuPlot.Set("palette grey");
            //GnuPlot.Set("xrange [0:200]");
            //GnuPlot.Set("yrange [0:200]");
            GnuPlot.Set("pm3d map");
            GnuPlot.SPlot(d, "with image");
        }
Пример #28
0
        private static void PlotValidationCurve(double[] x, double[] jtrain, double[] jvc)
        {
            GnuPlot.HoldOn();
            GnuPlot.Set("title \"Validation curve\"");
            GnuPlot.Set("xlabel \"Lamda\"");
            GnuPlot.Set("key top right box");
            GnuPlot.Set("ylabel \"Error\"");
            GnuPlot.Set("autoscale xy");

            GnuPlot.Plot(x, jtrain, "with lines ls 1 lw 2 lc rgb \"cyan\" title \"Train\" ");
            GnuPlot.Plot(x, jvc, "with lines ls 1 lw 2 lc rgb \"orange\" title \"Cross Validation\" ");

            GnuPlot.HoldOff();
        }
Пример #29
0
        private static void PlotLinearLearningCurve(double[] x, double[] jtrain, double[] jvc)
        {
            GnuPlot.HoldOn();
            GnuPlot.Set("title \"Learning curve for linear regression\"");
            GnuPlot.Set("xlabel \"Number of training examples\"");
            GnuPlot.Set("key top right box");
            GnuPlot.Set("ylabel \"Error\"");
            GnuPlot.Set("xr[0:13]");
            GnuPlot.Set("yr[0:150]");

            GnuPlot.Plot(x, jtrain, "with lines ls 1 lw 2 lc rgb \"cyan\" title \"Train\" ");
            GnuPlot.Plot(x, jvc, "with lines ls 1 lw 2 lc rgb \"orange\" title \"Cross Validation\" ");

            GnuPlot.HoldOff();
        }
Пример #30
0
    protected void muestraVisualizacion(object sender, EventArgs e)
    {
        HttpClient client = new HttpClient();

        client.BaseAddress = new Uri(URLGET);

        // Add an Accept header for JSON format.
        client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

        string dataObjects = "";
        // List data response.
        HttpResponseMessage response = client.GetAsync(urlParametersGET).Result;

        if (response.IsSuccessStatusCode)
        {
            // Parse the response body.
            dataObjects = response.Content.ReadAsStringAsync().Result;
            Console.WriteLine("{0}", dataObjects);

            var serializer = new JavaScriptSerializer();
            var obj        = serializer.DeserializeObject(dataObjects);
            Dictionary <string, object> dString = obj as Dictionary <string, object>;
            //Console.WriteLine ("Ahora serializado: {0}", feedObj);

            IList feeds = dString["feeds"] as IList;
            int   i     = 0;
            Date  = new double[feeds.Count];
            Light = new double[feeds.Count];
            foreach (var feed in feeds)
            {
                Dictionary <string, object> f = feed as Dictionary <string, object>;
                DateTime dateTime             = Convert.ToDateTime(f ["created_at"]);
                var      dateUNIX             = (TimeZoneInfo.ConvertTimeToUtc(dateTime) - new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc)).TotalSeconds;
                Date [i] = Convert.ToDouble(dateUNIX);
                //(string)f ["created_at"];
                Light[i] = Convert.ToDouble(f ["field4"]);
                i++;
            }

            //GnuPlot.HoldOn();
            GnuPlot.Plot(Date, Light, "with points pt 2");
        }
        else
        {
            Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
        }
    }