private void PlotBreakEvenPoint() { plot4.Clear(); Finances finances = GameController.instance.player.finances; List <int> priceData = new List <int>(); priceData.AddRange(finances.revenue); priceData.Sort(); List <int> quantityData = finances.GetQuantityData(); Regression regression = new Regression(); float a = 0; float b = 0; float rSq = 0; //regression.LinearRegression(quantityData.ToArray(), finances.revenue.ToArray(),out a, out b, out rSq); List <float> regressionData = new List <float>(); float xSize = (quantityData.Max() - quantityData.Min()) / quantityData.Count; List <float> quantityNormalizedData = new List <float>() { 0 }; for (int i = 0; i < quantityData.Count; i++) { quantityNormalizedData.Add(quantityNormalizedData.LastOrDefault() + xSize); } float ySize = (priceData.Max() - priceData.Min()) / priceData.Count; List <float> regressionDataNormalized = new List <float>() { 0 }; for (int i = 0; i < priceData.Count; i++) { regressionDataNormalized.Add(regressionDataNormalized.LastOrDefault() + ySize); } regressionDataNormalized.Remove(regressionDataNormalized.LastOrDefault()); // regressionData.AddRange(regression.Function(quantityNormalizedData, a, b)); List <int> x = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; LineGraphVisual originalVisual = new LineGraphVisual(containers[3], dotSprite, 12, false, new Color(1, 1, 1, 0.0f), Color.white); LineGraphVisual revenueVisual = new LineGraphVisual(containers[3], dotSprite, 12, false, Color.cyan, Color.white); LineGraphVisual regressionVisual = new LineGraphVisual(containers[3], dotSprite, 12, false, Color.yellow, Color.white); LineGraphVisual expencesRegressionVisual = new LineGraphVisual(containers[3], dotSprite, 12, false, Color.red, Color.red); List <float> extrems = new List <float>(); List <float> expencesRegression = new List <float>(); if (finances.revenue.Max() >= finances.staticExpences.Max()) { extrems = plot4.ShowPlot(finances.revenue, originalVisual, 14, containers[3], 0, 0, null, displayGrid: false); } else { extrems = plot4.ShowPlot(finances.staticExpences, originalVisual, -1, containers[3], 0, 0, displayGrid: false); } plot4.ShowPlot(regressionDataNormalized, revenueVisual, 14, containers[3], extrems[0], extrems[1], (int i) => Mathf.RoundToInt(quantityNormalizedData[i]).ToString(), (float f) => String.Format("{0:n0} $", Mathf.RoundToInt(f)), displayGrid: true); List <int> yearExpences = finances.GetOverYearExpences(); if (yearExpences.Count < x.Count) { for (int i = yearExpences.Count; i < x.Count; i++) { yearExpences.Add(yearExpences.LastOrDefault()); } } regression.LinearRegression(x.ToArray(), yearExpences.ToArray(), out a, out b, out rSq); // take last 12 elements and delete the last one in order to make regression. Adjust x accordingly expencesRegression = regression.Function(x.ConvertAll(p => (float)p), a, b); Debug.Log("-----Linear Regression-----"); Debug.Log("A: " + a + " B: " + b + "Rsquare: " + rSq); plot4.ShowPlot(expencesRegression, expencesRegressionVisual, -1, containers[3], extrems[0], extrems[1], displayGrid: false); }