static void Main(string[] args) { // ScalarFunction x = "x"; ScalarFunction y = "y"; ScalarFunction a = "a"; ScalarFunction b = "b"; ScalarFunction c = "c"; ScalarFunction d = "d"; ScalarFunction i = "i"; ScalarFunction j = "j"; MatrixFunction m = NewMatrix(new Matrix <ScalarFunction>( new[] { new ScalarFunction[] { a, b }, new ScalarFunction[] { c, d } })); VectorFunction v = NewColumnVector(new ScalarFunction[] { x, y }); VectorFunction r = NewColumnVector(new ScalarFunction[] { i, j }); BinaryFunction k = MatrixMethods.RotationMethod(m, v, r); k = k.Calculate(); //Console.WriteLine(((a * i + c * j) / (a * a + c * c)).Calculate()); //var sqrt = op_Exponentiation(op_Exponentiation(a, 2) + op_Exponentiation(c, 2), 0.5); //var d_y = ((a * j - c * i) / (a * d - c * b)) * (a * b + c * d); //var gg = ((x * (a * a + c * c)) + y) / sqrt == (a * i + c * j) / sqrt; //var gg2 = NewScalarFind(x, gg).Calculate(); //var gg3 = gg2.Calculate(NewScalarFind(y, y == d_y)); Console.ReadKey(); }
/// <summary> /// Apply smooth filter to bitmap /// </summary> public void ApplyFilter(Bitmap b, int nWeight) { ConvMatrix m = new ConvMatrix(); m.SetAll(1); m.Pixel = nWeight; m.Factor = nWeight + 8; b = MatrixFunction.Conv3X3(b, m); }
/// <summary> /// Applying Emboss filter to the bitmap /// </summary> public void ApplyFilter(Bitmap b) { ConvMatrix m = new ConvMatrix(); m.SetAll(-1); m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 0; m.Pixel = 4; m.Offset = 127; b = MatrixFunction.Conv3X3(b, m); }
public void RotateMethod() { MatrixFunction m = NewMatrix(new Matrix <ScalarFunction>( new[] { new ScalarFunction[] { "a", "b" }, new ScalarFunction[] { "c", "d" } })); VectorFunction v = NewColumnVector(new ScalarFunction[] { "x", "y" }); VectorFunction r = NewColumnVector(new ScalarFunction[] { "i", "j" }); BinaryFunction b = MatrixMethods.RotationMethod(m, v, r); }
/// <summary> /// Apply sphere effect to bitmap /// </summary> public void ApplyFilter(Bitmap b) { int nWidth = b.Width; int nHeight = b.Height; Point[,] fp = new Point[nWidth, nHeight]; Point mid = new Point(); mid.X = nWidth / 2; mid.Y = nHeight / 2; double theta, radius; double newX, newY; for (int x = 0; x < nWidth; ++x) { for (int y = 0; y < nHeight; ++y) { int trueX = x - mid.X; int trueY = y - mid.Y; theta = Math.Atan2((trueY), (trueX)); radius = Math.Sqrt(trueX * trueX + trueY * trueY); double newRadius = radius * radius / (Math.Max(mid.X, mid.Y)); newX = mid.X + (newRadius * Math.Cos(theta)); if (newX > 0 && newX < nWidth) { fp[x, y].X = (int)newX; } else { fp[x, y].X = fp[x, y].Y = (int)0.0; } newY = mid.Y + (newRadius * Math.Sin(theta)); if (newY > 0 && newY < nHeight && newX > 0 && newX < nWidth) { fp[x, y].Y = (int)newY; } else { fp[x, y].X = fp[x, y].Y = (int)0.0; } } } MatrixFunction.OffsetFilterAbs(b, fp); }
/// <summary> /// Set transperenty to bitmap /// </summary> static public Bitmap ApplyFilter(Bitmap sourceImage, byte alphaComponent = 100) { ColorMatrix colorMatrix = new ColorMatrix(new float[][] { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 0.3f, 0 }, new float[] { 0, 0, 0, 0, 1 } }); return(MatrixFunction.ApplyColorMatrix(sourceImage, colorMatrix)); }
public DemoStats(double[][] dataMatrix) { var transpMatrix = MatrixFunction.TransposeMatrix(dataMatrix); Correlations = new CorrelationsAnalysis(transpMatrix, dataMatrix[0].Length - 1); Regressions = new RegressionAnalysis(dataMatrix, dataMatrix[0].Length - 1); Descriptive = new DescriptiveStatistics[transpMatrix.Length]; for (int i = 0; i < Descriptive.Length; ++i) { Descriptive[i] = new DescriptiveStatistics(transpMatrix[i]); } Forecast = new Forecast(dataMatrix, transpMatrix.Length - 1); }
/// <summary> /// Apply water effect to bitmap /// </summary> public void ApplyFilter(Bitmap b, short nWave) { int nWidth = b.Width; int nHeight = b.Height; Point[,] pt = new Point[nWidth, nHeight]; Point mid = new Point(); mid.X = nWidth / 2; mid.Y = nHeight / 2; double newX, newY; double xo, yo; for (int x = 0; x < nWidth; ++x) { for (int y = 0; y < nHeight; ++y) { xo = ((double)nWave * Math.Sin(2.0 * 3.1415 * (float)y / 128.0)); yo = ((double)nWave * Math.Cos(2.0 * 3.1415 * (float)x / 128.0)); newX = (x + xo); newY = (y + yo); if (newX > 0 && newX < nWidth) { pt[x, y].X = (int)newX; } else { pt[x, y].X = 0; } if (newY > 0 && newY < nHeight) { pt[x, y].Y = (int)newY; } else { pt[x, y].Y = 0; } } } MatrixFunction.OffsetFilterAbs(b, pt); }
/// <summary> /// Apply swiirl effect to bitmap /// </summary> public void ApplyFilter(Bitmap b, double fDegree) { int nWidth = b.Width; int nHeight = b.Height; Point[,] pt = new Point[nWidth, nHeight]; Point mid = new Point(); mid.X = nWidth / 2; mid.Y = nHeight / 2; double theta, radius; double newX, newY; for (int x = 0; x < nWidth; ++x) { for (int y = 0; y < nHeight; ++y) { int trueX = x - mid.X; int trueY = y - mid.Y; theta = Math.Atan2((trueY), (trueX)); radius = Math.Sqrt(trueX * trueX + trueY * trueY); newX = mid.X + (radius * Math.Cos(theta + fDegree * radius)); if (newX > 0 && newX < nWidth) { pt[x, y].X = (int)newX; } newY = mid.Y + (radius * Math.Sin(theta + fDegree * radius)); if (newY > 0 && newY < nHeight) { pt[x, y].Y = (int)newY; } } } MatrixFunction.OffsetFilterAbs(b, pt); }
private static void Main(string[] args) { int n = 629, m = 10; var matrix = ReadDataMatrix(@"D:\Универ\3 курс\2 семестр\Тер вер и мат стат\movie_metadata_1.csv"); var transpMatrix = MatrixFunction.TransposeMatrix(matrix); Dictionary <double, double> laplasMatrix = ReadLaplasMatrix("2.txt"); Console.WriteLine("Описательная статистика"); for (int k = 0; k < m; ++k) { PearsonConsentCriterion pcc = new PearsonConsentCriterion(transpMatrix[k].Take(n).ToArray(), laplasMatrix); KolmogorovConsentCriterion kcc = new KolmogorovConsentCriterion(transpMatrix[k]); DescriptiveStatistics ds = new DescriptiveStatistics(transpMatrix[k]); Console.WriteLine(); Console.WriteLine("Среднее арифметическое = {0}", ds.ArithmeticalMean); Console.WriteLine("Мода = {0}", ds.Mode); Console.WriteLine("Медиана = {0}", ds.Median); Console.WriteLine("Дисперсия = {0}", ds.Dispersion); Console.WriteLine("Асимметрия = {0}", ds.Assimmetry); Console.WriteLine("Эксцесс = {0}", ds.Excess); Console.WriteLine("Стандартное отклонение = {0}", ds.StandardDeviation); Console.WriteLine("Коэффициент вариации = {0}", ds.VariationCoefficient); Console.WriteLine("Размах вариации = {0}", ds.VariationRange); Console.WriteLine("Среднее значение x: " + pcc.AverageValueX); Console.WriteLine("Среднее квадратичное отклонение: " + pcc.MeanSquareDeviation); Console.WriteLine("Критерий Пирсона: " + pcc.PearsonCriterionValue); Console.WriteLine("Табличный критерий Пирсона = " + 63.6567); Console.WriteLine("Критерий Колмогорова = " + kcc.KolmogorovCriterionValue); Console.WriteLine("Табличный критерий Колмогорова = 1,950\n\n"); Console.WriteLine(); } Console.WriteLine("Нажмите, чтобы увидеть далее..."); Console.ReadLine(); Console.WriteLine("Корреляционный анализ"); CorrelationsAnalysis correlationsAnalyses = new CorrelationsAnalysis(transpMatrix, m - 1); Console.WriteLine("Матрица корреляции"); foreach (double[] correlationCoef in correlationsAnalyses.PairCorrelationsMatrix) { for (int j = 0; j < correlationCoef.Length; j++) { Console.Write("{0} ", Math.Round(correlationCoef[j], 5)); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Коэффициенты значимости для матрицы парных корреляций: "); foreach (double[] t in correlationsAnalyses.MatrixSignificanceFactors) { for (int j = 0; j < t.Length; j++) { Console.Write("{0} ", Math.Round(t[j], 5)); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Коэффициенты значимости:"); foreach (double t in correlationsAnalyses.ParametersSignificanceFactors) { Console.WriteLine(t); } Console.WriteLine(); var multipleCoefficientY = correlationsAnalyses.SelectiveMultipleCoefficient; var determinationCoefficientY = correlationsAnalyses.DeterminationCoefficient; Console.WriteLine("Выборочный множественный коэффициент Y: " + multipleCoefficientY); Console.WriteLine("Коэффициент детерминации: " + determinationCoefficientY); if (determinationCoefficientY > 0.8) { Console.WriteLine("Модель адекватна"); } Console.WriteLine(); Console.WriteLine("Матрица частной корреляции"); foreach (double[] t in correlationsAnalyses.PartialCorrelationsMatrix) { for (int j = 0; j < correlationsAnalyses.PartialCorrelationsMatrix.Length; j++) { Console.Write("{0,6} ", Math.Round(t[j], 4)); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Нажмите, чтобы увидеть далее..."); Console.ReadLine(); Console.WriteLine("Регрессионный анализ"); RegressionAnalysis ra = new RegressionAnalysis(matrix, m - 1); Console.WriteLine("Коэффициенты регрессии:"); for (int i = 0; i < ra.RegressionCoefficients.Length; i++) { if (i == 0) { Console.WriteLine("a = {0}", ra.RegressionCoefficients[i]); } else { Console.WriteLine("b{0} = {1}", i, ra.RegressionCoefficients[i]); } } Console.WriteLine("Значимость коэффициентов регрессии:"); for (int i = 0; i < m; i++) { Console.WriteLine("b{0} = {1}", (i + 1), ra.RegressionCoefficientsSignificance[i]); } Console.WriteLine("Доверительные интервалы коэффициентов регрессии:"); for (int i = 0; i < m; i++) { Console.WriteLine("{0} <= b{1} <= {2}", ra.ConfidenceIntervalsOfCoefficients[i].Item1, (i + 1), ra.ConfidenceIntervalsOfCoefficients[i].Item2); } Console.WriteLine("Коэффициент значимости уравнения регрессии:"); Console.WriteLine(ra.RegressionEquationSignificance); Console.WriteLine(); Console.WriteLine("Коэффициенты эластичности"); double[] elast = ra.ElasticityCoefficients; for (int u = 0; u < m; u++) { Console.WriteLine("x{0} = {1}", (u + 1), elast[u]); } Forecast f = new Forecast(matrix, m - 1); Console.WriteLine("Прогнозирование"); Console.WriteLine(f.Value[0] + " < y < " + f.Value[1]); Console.WriteLine(); }