Esempio n. 1
0
        public void XYDataSetConstructorTest()
        {
            var ds = new XYDataSet();

            Assert.AreEqual(-1, ds.XMaxIndex);
            Assert.AreEqual(-1, ds.XMinIndex);
            Assert.AreEqual(-1, ds.YMaxIndex);
            Assert.AreEqual(-1, ds.YMinIndex);
            Assert.AreEqual(double.NaN, Math.Round(ds.Slope, 4));
            Assert.AreEqual(double.NaN, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(double.NaN, Math.Round(ds.XIntercept, 4));

            bool error = false;

            try { Assert.AreEqual(2000, ds.XMin); } catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.XMax); } catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.YMin); } catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.YMin); } catch { error = true; }
            Assert.IsTrue(error);
        }
Esempio n. 2
0
        public void XYDataSetConstructorTest2()
        {
            double[] X = { 2000, 2001, 2002, 2003, 2004 };
            double[] Y = { 9.34, 8.50, 7.62, 6.93, 6.60 };

            var ds = new XYDataSet(X, Y);

            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2004, ds.XMax);
            Assert.AreEqual(6.60, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(4, ds.XMaxIndex);
            Assert.AreEqual(0, ds.XMinIndex);
            Assert.AreEqual(0, ds.YMaxIndex);
            Assert.AreEqual(4, ds.YMinIndex);
            Assert.AreEqual(-0.705, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1419.208, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.061, Math.Round(ds.XIntercept, 4));

            X = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };

            ds = new XYDataSet(X, Y);
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2004, ds.XMax);
            Assert.AreEqual(6.60, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(2, ds.XMaxIndex);
            Assert.AreEqual(3, ds.XMinIndex);
            Assert.AreEqual(3, ds.YMaxIndex);
            Assert.AreEqual(2, ds.YMinIndex);
            Assert.AreEqual(-0.705, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1419.208, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.061, Math.Round(ds.XIntercept, 4));
        }
Esempio n. 3
0
        public void AddTest()
        {
            var X = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };

            var ds = new XYDataSet(X, Y);
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2004, ds.XMax);
            Assert.AreEqual(6.60, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(2, ds.XMaxIndex);
            Assert.AreEqual(3, ds.XMinIndex);
            Assert.AreEqual(3, ds.YMaxIndex);
            Assert.AreEqual(2, ds.YMinIndex);
            Assert.AreEqual(-0.705, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1419.208, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.061, Math.Round(ds.XIntercept, 4));
            Assert.AreEqual(2002, Math.Round(ds.XMean, 4));
            Assert.AreEqual(7.798, Math.Round(ds.YMean, 4));

            ds.Add(2005, 5.90);
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2005, ds.XMax);
            Assert.AreEqual(5.90, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(5, ds.XMaxIndex);
            Assert.AreEqual(3, ds.XMinIndex);
            Assert.AreEqual(3, ds.YMaxIndex);
            Assert.AreEqual(5, ds.YMinIndex);
            Assert.AreEqual(-0.674, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1357.1667, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.6004, Math.Round(ds.XIntercept, 4));
            Assert.AreEqual(2002.5, Math.Round(ds.XMean, 4));
            Assert.AreEqual(7.4817, Math.Round(ds.YMean, 4));
        }
Esempio n. 4
0
        private Results PerformFitting(Results rset)
        {
            List <Race> working = rset.Races.FindAll(x => x.SwimTime != null);

            double[] X     = working.Select(i => (double)i.RaceDate.Year).ToArray();
            double[] swimY = working.Select(i => i.SwimVelocity).ToArray();
            var      dswim = new XYDataSet(X, swimY);

            rset.SwimLine.Slope     = dswim.Slope;
            rset.SwimLine.Intercept = dswim.YIntercept;
            rset.SwimLine.RSqd      = dswim.ComputeRSquared();

            double[] bikeY = working.Select(i => i.BikeVelocity).ToArray();
            var      dbike = new XYDataSet(X, bikeY);

            rset.BikeLine.Slope     = dbike.Slope;
            rset.BikeLine.Intercept = dbike.YIntercept;
            rset.BikeLine.RSqd      = dbike.ComputeRSquared();

            double[] runY = working.Select(i => i.RunVelocity).ToArray();
            var      drun = new XYDataSet(X, runY);

            rset.RunLine.Slope     = drun.Slope;
            rset.RunLine.Intercept = drun.YIntercept;
            rset.RunLine.RSqd      = drun.ComputeRSquared();

            return(rset);
        }
Esempio n. 5
0
        public Hurst_Result Spocti_Hurstuv_Koeficient(List <double> vstupni_data)
        {
            Dictionary <char, List <double> > body = new Dictionary <char, List <double> >(); //slovník bodů

            body.Add('X', new List <double>());                                               //Xové souřadnice
            body.Add('Y', new List <double>());                                               //Yové souřadnice
            int max = 9;                                                                      //Velikost počáteční množiny bodů

            while (true)
            {
                var tmp_data = new List <double>(); //Ořezaná množina vstupních dat
                for (int i = 0; i < max; i++)
                {
                    tmp_data.Add(vstupni_data[i]);      //Naplnění Ořezané množiny vstupních dat
                }
                var res = Hurstuv_Koeficient(tmp_data); //Vypočet bodu, který je výsledkem R/S analýzy pro ořezanou množinu
                body['X'].Add(res.Item1);               //Přidání souřadnic bodu do slovníku bodů
                body['Y'].Add(res.Item2);               //Přidání souřadnic bodu do slovníku bodů
                if (max >= vstupni_data.Count)          //Pokud je velikost množiny větší než velikost vstupních dat, tak konec
                {
                    break;
                }
                max = max + 9 >= vstupni_data.Count ? vstupni_data.Count : max + 9; //Zvětšení velikosti ořezané mbnožiny
            }
            var ds = new XYDataSet(body['X'], body['Y']);

            return(new Hurst_Result
            {
                X = body['X'],
                Y = body['Y'],
                hurst = Math.Round(ds.Slope, 4),
                YIntercept = Math.Round(ds.YIntercept, 4)
            });
        }
Esempio n. 6
0
        public void IndexOfTest()
        {
            var X  = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y  = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };
            var ds = new XYDataSet(X, Y);

            Assert.AreEqual(-1, ds.IndexOf(new PointD(2022, 9.34)));
            Assert.AreEqual(3, ds.IndexOf(new PointD(2000, 9.34)));
        }
Esempio n. 7
0
        public void ContainsTest()
        {
            var X  = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y  = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };
            var ds = new XYDataSet(X, Y);

            Assert.IsFalse(ds.Contains(new PointD(2003, 10000.0)));
            Assert.IsTrue(ds.Contains(new PointD(2003, 6.93)));
        }
Esempio n. 8
0
        public void InsertTest()
        {
            var X  = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y  = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };
            var ds = new XYDataSet(X, Y);

            ds.Insert(1, new PointD(2005, 5.90));
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2005, ds.XMax);
            Assert.AreEqual(5.90, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(-0.674, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1357.1667, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.6004, Math.Round(ds.XIntercept, 4));
        }
Esempio n. 9
0
        public Star CalcBVEstimate(Star target, List <Star> comparables)
        {
            if (target.ValidColorIndex == true)
            {
                List <double> bvcat = new List <double>();
                List <double> bvins = new List <double>();

                foreach (Star otherstar in comparables.Where(x => x.ValidColorIndex == true))
                {
                    bvcat.Add((double)otherstar.ColorIndex);
                    bvins.Add((double)otherstar.InstrumentalColorIndex);
                }
                XYDataSet set = new XYDataSet(bvins, bvcat);
                target.CalculatedColorIndex = (decimal)set.Slope * target.InstrumentalColorIndex + (decimal)set.YIntercept;
            }
            return(target);
        }
Esempio n. 10
0
        public void ComputeRSquaredTest()
        {
            double[] X  = { 75.0, 83, 85, 85, 92, 97, 99 };
            double[] Y  = { 16.0, 20, 25, 27, 32, 48, 48 };
            var      ds = new XYDataSet(X, Y);

            var r2 = ds.ComputeRSquared();

            Assert.AreEqual(1.45, Math.Round(ds.Slope, 2));
            Assert.AreEqual(-96.85, Math.Round(ds.YIntercept, 2));
            Assert.AreEqual(0.927, Math.Round(r2, 3));

            Assert.AreEqual(0.927, Math.Round(ds.RSquare, 3));

            ds.Add(101, 51);

            Assert.AreEqual(double.NaN, Math.Round(ds.RSquare, 3));
        }
Esempio n. 11
0
        public void XYDataSetConstructorTest3()
        {
            var X = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };

            var list = new List <PointD>();

            for (int i = 0; i < X.Length; ++i)
            {
                list.Add(new PointD(X[i], Y[i]));
            }

            var ds = new XYDataSet(list);

            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2004, ds.XMax);
            Assert.AreEqual(6.60, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(-0.705, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1419.208, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.061, Math.Round(ds.XIntercept, 4));
        }
Esempio n. 12
0
        public void ClearAndCountTest()
        {
            var X  = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y  = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };
            var ds = new XYDataSet(X, Y);

            Assert.AreEqual(5, ds.Count);
            ds.Clear();
            Assert.AreEqual(0, ds.Count);

            Assert.AreEqual(-1, ds.XMaxIndex);
            Assert.AreEqual(-1, ds.XMinIndex);
            Assert.AreEqual(-1, ds.YMaxIndex);
            Assert.AreEqual(-1, ds.YMinIndex);
            Assert.AreEqual(double.NaN, Math.Round(ds.Slope, 4));
            Assert.AreEqual(double.NaN, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(double.NaN, Math.Round(ds.XIntercept, 4));

            bool error = false;

            try { Assert.AreEqual(2000, ds.XMin); }
            catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.XMax); }
            catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.YMin); }
            catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.YMin); }
            catch { error = true; }
            Assert.IsTrue(error);
        }
Esempio n. 13
0
        public Star CalcVMagEstimate(Star target, List <Star> comparables)
        {
            //////////////////////////////
            // Do magnitude estimate.
            for (int i = 0; i < target.Samples.Count; i++)
            {
                List <double> bvcat = new List <double>();
                List <double> dcat  = new List <double>();

                foreach (Star otherstar in comparables)
                {
                    bvcat.Add((double)otherstar.ColorIndex);
                    dcat.Add((double)otherstar.CatalogEntry.Vmag - (double)otherstar.Samples[i].InstrumentalVMag);
                }
                XYDataSet set = new XYDataSet(bvcat, dcat);

                decimal calc = target.Samples[i].InstrumentalVMag + (decimal)set.YIntercept;

                // transform coefficient for filter differences if the target star's color index is known.
                // TODO: Fetch instrumental BMag for all stars in frame.
                if (target.ValidColorIndex == true)
                {
                    calc += (decimal)set.Slope * target.CalculatedColorIndex;
                }
                else if (target.ValidCatalogMag == true)
                {
                    calc += (decimal)set.Slope * target.ColorIndex;
                }


                target.Samples[i].ApparentVMag = calc;
                target.Samples[i].TFAVMag      = calc;
            }

            target.VMag   = target.Samples.Average(x => x.ApparentVMag);
            target.e_VMag = target.Samples.Select(x => x.ApparentVMag).StdDev();

            return(target);
        }
Esempio n. 14
0
        public void ClearAndCountTest()
        {
            var X = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };
            var ds = new XYDataSet(X, Y);

            Assert.AreEqual(5, ds.Count);
            ds.Clear();
            Assert.AreEqual(0, ds.Count);

            Assert.AreEqual(-1, ds.XMaxIndex);
            Assert.AreEqual(-1, ds.XMinIndex);
            Assert.AreEqual(-1, ds.YMaxIndex);
            Assert.AreEqual(-1, ds.YMinIndex);
            Assert.AreEqual(double.NaN, Math.Round(ds.Slope, 4));
            Assert.AreEqual(double.NaN, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(double.NaN, Math.Round(ds.XIntercept, 4));

            bool error = false;
            try { Assert.AreEqual(2000, ds.XMin); }
            catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.XMax); }
            catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.YMin); }
            catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.YMin); }
            catch { error = true; }
            Assert.IsTrue(error);
        }
Esempio n. 15
0
        public void ThisIndexTest()
        {
            var X  = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y  = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };
            var ds = new XYDataSet(X, Y);

            ds[3] = new PointD(2005, 5.90);
            Assert.AreEqual(2001, ds.XMin);
            Assert.AreEqual(2005, ds.XMax);
            Assert.AreEqual(5.90, ds.YMin);
            Assert.AreEqual(8.50, ds.YMax);
            Assert.AreEqual(-0.622, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1252.976, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2014.4309, Math.Round(ds.XIntercept, 4));

            ds.Add(2000, 9.34);
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2005, ds.XMax);
            Assert.AreEqual(5.90, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(-0.674, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1357.1667, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.6004, Math.Round(ds.XIntercept, 4));
        }
Esempio n. 16
0
        public void AddTest()
        {
            var X = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };

            var ds = new XYDataSet(X, Y);

            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2004, ds.XMax);
            Assert.AreEqual(6.60, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(2, ds.XMaxIndex);
            Assert.AreEqual(3, ds.XMinIndex);
            Assert.AreEqual(3, ds.YMaxIndex);
            Assert.AreEqual(2, ds.YMinIndex);
            Assert.AreEqual(-0.705, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1419.208, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.061, Math.Round(ds.XIntercept, 4));
            Assert.AreEqual(2002, Math.Round(ds.XMean, 4));
            Assert.AreEqual(7.798, Math.Round(ds.YMean, 4));

            ds.Add(2005, 5.90);
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2005, ds.XMax);
            Assert.AreEqual(5.90, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(5, ds.XMaxIndex);
            Assert.AreEqual(3, ds.XMinIndex);
            Assert.AreEqual(3, ds.YMaxIndex);
            Assert.AreEqual(5, ds.YMinIndex);
            Assert.AreEqual(-0.674, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1357.1667, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.6004, Math.Round(ds.XIntercept, 4));
            Assert.AreEqual(2002.5, Math.Round(ds.XMean, 4));
            Assert.AreEqual(7.4817, Math.Round(ds.YMean, 4));
        }
Esempio n. 17
0
        public void RemoveAtTest()
        {
            var X  = new[] { 2003.0, 2001, 2004, 2000, 2002, 2005 };
            var Y  = new[] { 6.93, 8.50, 6.60, 9.34, 7.62, 5.90 };
            var ds = new XYDataSet(X, Y);

            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2005, ds.XMax);
            Assert.AreEqual(5.90, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(-0.674, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1357.1667, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.6004, Math.Round(ds.XIntercept, 4));

            ds.RemoveAt(5);

            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2004, ds.XMax);
            Assert.AreEqual(6.60, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(-0.705, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1419.208, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.061, Math.Round(ds.XIntercept, 4));
        }
Esempio n. 18
0
		private async void UserPrompt_OnKeyDown(object sender, KeyRoutedEventArgs e)
		{

			//OPERATOR, <EMPLOYMENT/SOC>, <AS>, <GRAPH>, <BETWEEN>, <start:end>, <filter> <filtertype>
			//show programming as line
			if (e.Key == VirtualKey.Enter)
			{
				try
				{
					var commands = UserPrompt.Text.ToLower().Split(new char[] {' ', ','});

					switch (commands[0])
					{
						case "show":
							switch (commands[1])
							{
								case "testdata":
									var testData = new List<testDataTemplate>
									{
										new testDataTemplate {year = "2011", value = 14},
										new testDataTemplate {year = "2012", value = 15},
										new testDataTemplate {year = "2013", value = 16},
										new testDataTemplate {year = "2014", value = 20},
										new testDataTemplate {year = "2015", value = 18},

										new testDataTemplate {year = "2016", value = 20},
										new testDataTemplate {year = "2017", value = 24},
										new testDataTemplate {year = "2018", value = 27},
										new testDataTemplate {year = "2019", value = 29},
										new testDataTemplate {year = "2020", value = 24},

										new testDataTemplate {year = "2021", value = 31},
										new testDataTemplate {year = "2022", value = 32},
										new testDataTemplate {year = "2023", value = 33},
										new testDataTemplate {year = "2024", value = 39},
										new testDataTemplate {year = "2025", value = 37},

										new testDataTemplate {year = "2026", value = 42},
										new testDataTemplate {year = "2027", value = 43},
										new testDataTemplate {year = "2028", value = 44},
										new testDataTemplate {year = "2029", value = 45},
										new testDataTemplate {year = "2030", value = 41},
									};
									dataBuilder = testData;
									break;

								default:
									dataBuilder = await GetYearEmploymentDataSmart(commands);

									break;
							}

							ShowChart(commands.Length > 2 ? commands[3] : "line", dataBuilder); //default to line if <AS> not given
							break;
						case "map": //MEEEEEH, someone give me a polygon map
							dynGrid.Visibility = Visibility.Collapsed;
							mappletGrid.Visibility = Visibility.Visible;
							BINGIT.MapType = MapType.HighContrast;

							var loc = new Location(53.136954, -1.392331);
							BINGIT.SetView(loc, 7.00);

							var pushpin = new Pushpin()
							{
								Text = "pins yo'"
							};
							MapLayer.SetPosition(pushpin, new Location
							{

							});
							BINGIT.Children.Add(pushpin);


							Debug.WriteLine(await dataGrabber.LMI.essRegionJason(1, "2136"));
							break;
						case "analyse": //check degree from the normal
							switch (commands[2])
							{
								case "regression":

									switch (commands[3])
									{
										case "auto":

											if (commands[1] == "all")
											{
												var socs = new List<double>
												{
													2136,
													2213,
													2413,
													2311,
													2213,
													2451,
													4162,
													4216,
													3131,
													3213,
													8212,
													1190,
													1225,
													1241,
													1251,
													2111


												};

												var regressionsToPlot = new List<testDataTemplate>();

												foreach (var soc in socs) //waaa, this code is so un-refactored.
												{
													var y = await dataGrabber.LMI.wfpredict(soc.ToString(), "2013", "2020");
													var d = y.predictedEmployment.Select(
														data => new testDataTemplate {year = data.year.ToString(), value = data.employment}).ToList();

													var years = d.Select(year => Convert.ToDouble(year.year)).ToList();
													var values = d.Select(year => Convert.ToDouble(year.value)).ToList();
													var ds = new XYDataSet(years, values);

													double smallestYear = years.Min();
													double smallestValue = values.Min();

													for (int i = 0; i < years.Count; i++) //normalise
													{
														years[i] -= smallestYear;
													}
													for (int i = 0; i < values.Count; i++)
													{
														values[i] -= smallestValue;
													}
													OutputGrid.Visibility = Visibility.Visible;

													var gradient = ds.ComputeRSquared();

													var deviation = d.Select(data => data.value - (Convert.ToDouble(data.year)*(gradient))).ToList();

													double deviationAverage = deviation.Sum();

													deviationAverage = deviationAverage/deviation.Count;

													regressionsToPlot.Add(new testDataTemplate
													{
														year = soc.ToString(), //crap names is for graphing stuff, needs recode
														value = deviationAverage
													});

													ShowChart("column", regressionsToPlot);
												}
												regressionsToPlot = regressionsToPlot.OrderBy(x => x.value).ToList();
												ShowChart("column", regressionsToPlot);

												foreach (var reg in regressionsToPlot)
												{
													reg.year = await dataGrabber.LMI.reverseSOC(reg.year);
												}

												ShowChart("column", regressionsToPlot);


											}
											else //do all
											{
												var d = await GetYearEmploymentDataSmart(commands);

												var years = d.Select(year => Convert.ToDouble(year.year)).ToList();
												var values = d.Select(year => Convert.ToDouble(year.value)).ToList();
												var ds = new XYDataSet(years, values);

												double smallestYear = years.Min();
												double smallestValue = values.Min();

												for (int i = 0; i < years.Count; i++) //normalise
												{
													years[i] -= smallestYear;
												}
												for (int i = 0; i < values.Count; i++)
												{
													values[i] -= smallestValue;
												}
												OutputGrid.Visibility = Visibility.Visible;

												var gradient = ds.ComputeRSquared();

												var deviation = d.Select(data => data.value - (Convert.ToDouble(data.year)*(gradient))).ToList();

												double deviationAverage = deviation.Sum();

												deviationAverage = deviationAverage/deviation.Count;

												OutputGrid.Visibility = Visibility.Visible;
												Output.Visibility = Visibility.Visible;

												Output.Text = "Average Deviation: " + deviationAverage + "\n";
												Output.Text += "Slope: " + Math.Round(ds.Slope, 2) + "\n";
												Output.Text += "YIntercept: " + Math.Round(ds.YIntercept, 2) + "\n";
												Output.Text += "Rsquared: " + Math.Round(ds.ComputeRSquared(), 3) + "\n";
											}

											break;
									}

									break;
							}
							break;
							//case "analyse":
							//	var year = commands[1];
							//	var detailBuilder = new Templates.DetailedYear();
							//	dynGrid.Visibility = Visibility.Collapsed;
							//	detailView.Visibility = Visibility.Visible;

							//	for (int i = 0; i < 8000; i++)
							//	{
							//		try
							//		{
							//			var x = await dataGrabber.LMI.wfpredict(i.ToString(), year, year);
							//			if detailBuilder[x.soc]
							//		}
							//		catch (Exception ex)
							//		{

							//		}

							//	}

							//(DetailChart1.Series[0] as ColumnSeries).ItemsSource = detailBuilder.employments;
							//break;

						case ":":
							switch (commands[1])
							{
								case "reset":
									ClearGraph();
									break;
								case "layer":
									layer = true;
									break;
								case "unlayer":
									layer = false;
									break;
								case "regression":

									if (dataBuilder.Count > 0) //compare to normal reg line
									{
										//var d = await GetYearEmploymentDataSmart(commands);

										var d = dataBuilder;

										var years = d.Select(year => Convert.ToDouble(year.year)).ToList();
										var values = d.Select(year => Convert.ToDouble(year.value)).ToList();
										var ds = new XYDataSet(years, values);

										double smallestYear = years.Min();
										double smallestValue = values.Min();

										//var yearsReg = new List<double>();
										//var valuesReg = new List<double>();

										var y = new List<testDataTemplate>();

										const double reg = 2000;

										for (int i = 0; i < years.Count; i++)
										{
											y.Add(new testDataTemplate
											{
												year = (smallestYear + i).ToString(), //fine
												value = smallestValue + (i*reg)
											});

											//yearsReg.Add(smallestYear + i);
											//valuesReg.Add(smallestValue + (smallestYear + i)*reg);
										}

										ShowChartReg(y);


										//OutputGrid.Visibility = Visibility.Visible;

										//Output.Text = "Slope: " + Math.Round(ds.Slope, 2) + "\n";
										//Output.Text += "YIntercept: " + Math.Round(ds.YIntercept, 2) + "\n";
										//Output.Text += "Rsquared: " + Math.Round(ds.ComputeRSquared(), 3) + "\n";
									}
									break;
							}
							break;
					}

				}
				catch (Exception)
				{
					
				}
			 }

		}
Esempio n. 19
0
        public void XYDataSetConstructorTest3()
        {
            var X = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };

            var list = new List<PointD>();
            for (int i = 0; i < X.Length; ++i)
                list.Add(new PointD(X[i], Y[i]));

            var ds = new XYDataSet(list);
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2004, ds.XMax);
            Assert.AreEqual(6.60, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(-0.705, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1419.208, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.061, Math.Round(ds.XIntercept, 4));
        }
Esempio n. 20
0
        public void XYDataSetConstructorTest2()
        {
            double[] X = {2000, 2001, 2002, 2003, 2004};
            double[] Y = {9.34, 8.50, 7.62, 6.93, 6.60};

            var ds = new XYDataSet(X, Y);
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2004, ds.XMax);
            Assert.AreEqual(6.60, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(4, ds.XMaxIndex);
            Assert.AreEqual(0, ds.XMinIndex);
            Assert.AreEqual(0, ds.YMaxIndex);
            Assert.AreEqual(4, ds.YMinIndex);
            Assert.AreEqual(-0.705, Math.Round(ds.Slope,4));
            Assert.AreEqual(1419.208, Math.Round(ds.YIntercept,4));
            Assert.AreEqual(2013.061, Math.Round(ds.XIntercept, 4));

            X = new[]{ 2003.0, 2001, 2004, 2000, 2002 };
            Y = new[]{ 6.93, 8.50, 6.60, 9.34, 7.62 };

            ds = new XYDataSet(X, Y);
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2004, ds.XMax);
            Assert.AreEqual(6.60, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(2, ds.XMaxIndex);
            Assert.AreEqual(3, ds.XMinIndex);
            Assert.AreEqual(3, ds.YMaxIndex);
            Assert.AreEqual(2, ds.YMinIndex);
            Assert.AreEqual(-0.705, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1419.208, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.061, Math.Round(ds.XIntercept, 4));
        }
Esempio n. 21
0
        public void XYDataSetConstructorTest()
        {
            var ds = new XYDataSet();

            Assert.AreEqual(-1, ds.XMaxIndex);
            Assert.AreEqual(-1, ds.XMinIndex);
            Assert.AreEqual(-1, ds.YMaxIndex);
            Assert.AreEqual(-1, ds.YMinIndex);
            Assert.AreEqual(double.NaN, Math.Round(ds.Slope, 4));
            Assert.AreEqual(double.NaN, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(double.NaN, Math.Round(ds.XIntercept, 4));

            bool error = false;
            try { Assert.AreEqual(2000, ds.XMin); } catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.XMax); } catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.YMin); } catch { error = true; }
            Assert.IsTrue(error);

            error = false;
            try { Assert.AreEqual(2000, ds.YMin); } catch { error = true; }
            Assert.IsTrue(error);
        }
Esempio n. 22
0
        public void ThisIndexTest()
        {
            var X = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };
            var ds = new XYDataSet(X, Y);

            ds[3] = new PointD(2005, 5.90);
            Assert.AreEqual(2001, ds.XMin);
            Assert.AreEqual(2005, ds.XMax);
            Assert.AreEqual(5.90, ds.YMin);
            Assert.AreEqual(8.50, ds.YMax);
            Assert.AreEqual(-0.622, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1252.976, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2014.4309, Math.Round(ds.XIntercept, 4));

            ds.Add(2000, 9.34);
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2005, ds.XMax);
            Assert.AreEqual(5.90, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(-0.674, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1357.1667, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.6004, Math.Round(ds.XIntercept, 4));
        }
Esempio n. 23
0
        public void RemoveTest()
        {
            var X = new[] { 2003.0, 2001, 2004, 2000, 2002, 2005 };
            var Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62, 5.90 };
            var ds = new XYDataSet(X, Y);

            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2005, ds.XMax);
            Assert.AreEqual(5.90, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(-0.674, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1357.1667, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.6004, Math.Round(ds.XIntercept, 4));

            ds.Remove(new PointD(2005, 5.90));

            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2004, ds.XMax);
            Assert.AreEqual(6.60, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(-0.705, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1419.208, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.061, Math.Round(ds.XIntercept, 4));
        }
Esempio n. 24
0
        public void InsertTest()
        {
            var X = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };
            var ds = new XYDataSet(X, Y);

            ds.Insert(1, new PointD(2005, 5.90));
            Assert.AreEqual(2000, ds.XMin);
            Assert.AreEqual(2005, ds.XMax);
            Assert.AreEqual(5.90, ds.YMin);
            Assert.AreEqual(9.34, ds.YMax);
            Assert.AreEqual(-0.674, Math.Round(ds.Slope, 4));
            Assert.AreEqual(1357.1667, Math.Round(ds.YIntercept, 4));
            Assert.AreEqual(2013.6004, Math.Round(ds.XIntercept, 4));
        }
Esempio n. 25
0
        public void IndexOfTest()
        {
            var X = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };
            var ds = new XYDataSet(X, Y);

            Assert.AreEqual(-1, ds.IndexOf(new PointD(2022, 9.34)));
            Assert.AreEqual(3, ds.IndexOf(new PointD(2000, 9.34)));
        }
Esempio n. 26
0
        public void ContainsTest()
        {
            var X = new[] { 2003.0, 2001, 2004, 2000, 2002 };
            var Y = new[] { 6.93, 8.50, 6.60, 9.34, 7.62 };
            var ds = new XYDataSet(X, Y);

            Assert.IsFalse(ds.Contains(new PointD(2003, 10000.0)));
            Assert.IsTrue(ds.Contains(new PointD(2003, 6.93)));
        }
Esempio n. 27
0
        public void ComputeRSquaredTest()
        {
            double[] X = { 75.0, 83, 85, 85, 92, 97, 99 };
            double[] Y = { 16.0, 20, 25, 27, 32, 48, 48 };
            var ds = new XYDataSet(X, Y);

            var r2 = ds.ComputeRSquared();
            Assert.AreEqual(1.45, Math.Round(ds.Slope,2));
            Assert.AreEqual(-96.85, Math.Round(ds.YIntercept,2));
            Assert.AreEqual(0.927, Math.Round(r2, 3));

            Assert.AreEqual(0.927, Math.Round(ds.RSquare, 3));

            ds.Add(101, 51);

            Assert.AreEqual(double.NaN, Math.Round(ds.RSquare, 3));
        }