//--------------------------------------------------------------------------------------------- //Дисперсия private double GetPointsDispersion(Point3D[] points, Point3D pointsCentre) { double[] distancesFromPointsCentre = SpaceManager.GetDistances(points, pointsCentre); double dispersion = Statistician.GetDispersion(distancesFromPointsCentre); return(dispersion); }
public static Statistician AddStatisticians(Statistician s1, Statistician s2) { Statistician s3 = new Statistician(); int number = s2.number; s3.length = s1.length + s2.length; s3.lastNumber = s2.lastNumber; s3.numberSum = s1.numberSum + s2.numberSum; if (s1.smallestNumber < s2.smallestNumber) { s3.smallestNumber = s1.smallestNumber; } else { s3.smallestNumber = s2.smallestNumber; } if (s1.largestNumber > s2.largestNumber) { s3.largestNumber = s1.largestNumber; } else { s3.largestNumber = s2.largestNumber; } return(s3); }
//--------------------------------------------------------------------------------------------------------------------- //Индекс оптимального значения гаммы private int GetOptimalGammaValueIndex(double[] intensitiesByCyclingShift, double[] gammaValues) { Dictionary <int, double> rootMeanSquareErrors = new Dictionary <int, double>(); for (int index = 0; index < gammaValues.Length; index++) { double gamma = gammaValues[index]; double[] correctedIntensities = ArrayOperator.GetValuesInPower(intensitiesByCyclingShift, gamma); double rootMeanSquareError = Statistician.GetRootMeanSquareError(intensitiesByCyclingShift, correctedIntensities); rootMeanSquareErrors.Add(index, rootMeanSquareError); } int optimalIndex = 0; double optimalError = rootMeanSquareErrors[0]; foreach (KeyValuePair <int, double> pair in rootMeanSquareErrors) { if (pair.Value < optimalError) { optimalIndex = pair.Key; } } return(optimalIndex); }
public void SetUp() { _raceRepository = MockRepository.GenerateMock<IRaceRepository>(); _seasonRepository = MockRepository.GenerateMock<ISeasonRepository>(); _driverRepository = MockRepository.GenerateMock<IDriverRepository>(); _contractRepository = MockRepository.GenerateMock<IDriverContractRepository>(); _statistician = new Statistician(_raceRepository, _seasonRepository, _driverRepository, _contractRepository); }
//---------------------------------------------------------------------------------------------- //Средняя матрица public static RealMatrix GetAverageMatrix(params RealMatrix[] matrices) { int countMatrix = matrices.Length; int rowCount = matrices[0].RowCount; int columnCount = matrices[0].ColumnCount; RealMatrix meanMatrix = new RealMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnCount; column++) { double[] values = MatricesManager.GeValuesFromMatrices(row, column, matrices); double meanValue = Statistician.GetMeanValue(values); meanMatrix[row, column] = meanValue; } } return(meanMatrix); }
static void Main(string[] args) { Statistician stats1 = new Statistician(); Statistician stats2 = new Statistician(); stats1.NextNumber(1); stats1.NextNumber(2); stats1.NextNumber(3); stats2.NextNumber(4); stats2.NextNumber(5); stats2.NextNumber(6); var s3 = Statistician.AddStatisticians(stats1, stats2); Console.WriteLine("s3 length is " + s3.GetLength()); Console.WriteLine("s3 numbersum is " + s3.NumberSum()); Console.WriteLine("s3 mean is " + s3.GetMean()); Console.WriteLine("s3 smallest is " + s3.GetSmallest()); Console.WriteLine("s3 largest is " + s3.GetLargest()); }
//--------------------------------------------------------------------------------------------- public InterferogramDecodingResult DecodeInterferogram(RealMatrix[] interferograms, BitMask2D bitMask) { //Выбранные точки изображения Point[] selectedImagePoints = bitMask.GetTruePoints(); //Ортогональные векторы RealVector[] orthogonalVectors = this.GetOrthogonalVectors(interferograms, selectedImagePoints); RandomNumberGenerator randomNumberGenerator = new RandomNumberGenerator(); int indexVector1 = randomNumberGenerator.GetNextInteger(orthogonalVectors.Length - 1); int indexVector2 = randomNumberGenerator.GetNextInteger(orthogonalVectors.Length - 1); RealVector vector1 = orthogonalVectors[indexVector1]; RealVector vector2 = orthogonalVectors[indexVector2]; RealVector normalY; RealVector normalX; RealMatrix rotMatrixY; RealMatrix rotMatrixX; RealMatrix rotMatrix; double alfa; double beta; normalY = SpaceManager.GetVectorsCrossProduct(vector1, vector2); alfa = Math.Atan(-(normalY[0] / normalY[2])); rotMatrixY = SpaceManager.GetRotationMatrixAroundAxisY(alfa); normalX = SpaceManager.RotateVector(normalY, rotMatrixY); beta = Math.Atan(-(normalX[1] / normalX[2])); rotMatrixX = SpaceManager.GetRotationMatrixAroundAxisX(beta); rotMatrix = rotMatrixX * rotMatrixY; RealVector[] rotVectors = SpaceManager.RotateVectors(orthogonalVectors, rotMatrix); Point3D[] points3D = this.GetPoints3D(rotVectors); //this.OrthogonalVectorsPoints = points3D; Point2D[] points2D = SpaceManager.GetProjectionXY(points3D); this.PlaneXYPoints = points2D; RealMatrix covariationMatrix = Statistician.GetCovariationMatrix(points2D); double a11 = covariationMatrix[0, 0]; double a22 = covariationMatrix[1, 1]; double a12 = covariationMatrix[0, 1]; double[] eigenValues = MathHelper.GetEigenValuesMatrix2x2(covariationMatrix); double minEigenValue = eigenValues.Min(); double maxEigenValue = eigenValues.Max(); RealVector eigenVector1 = new RealVector ( 1, -((a11 + a12 - minEigenValue) / (a12 + a22 - minEigenValue)) ); RealVector eigenVector2 = new RealVector ( 1, -((a11 + a12 - maxEigenValue) / (a12 + a22 - maxEigenValue)) ); Complex complex = new Complex(eigenVector1[0], eigenVector1[1]); double omega = complex.Phase; double a = Math.Sqrt(minEigenValue); double b = Math.Sqrt(maxEigenValue); double h = a / Math.Sqrt(b * b - a * a); RealVector Nc = new RealVector(Math.Cos(omega), -Math.Sin(omega), h); Point3D[] circlePoints = this.GetCirclePoints(points3D, Nc); //this.OrthogonalVectorsPoints = circlePoints; RealVector[] circlePointsVectors = new RealVector[circlePoints.Length]; for (int index = 0; index < circlePoints.Length; index++) { circlePointsVectors[index] = new RealVector(circlePoints[index]); } indexVector1 = randomNumberGenerator.GetNextInteger(circlePointsVectors.Length - 1); indexVector2 = randomNumberGenerator.GetNextInteger(circlePointsVectors.Length - 1); vector1 = circlePointsVectors[indexVector1]; vector2 = circlePointsVectors[indexVector2]; normalY = SpaceManager.GetVectorsCrossProduct(vector1, vector2); alfa = Math.Atan(-(normalY[0] / normalY[2])); rotMatrixY = SpaceManager.GetRotationMatrixAroundAxisY(alfa); normalX = SpaceManager.RotateVector(normalY, rotMatrixY); beta = Math.Atan(-(normalX[1] / normalX[2])); rotMatrixX = SpaceManager.GetRotationMatrixAroundAxisX(beta); rotMatrix = rotMatrixX * rotMatrixY; rotVectors = SpaceManager.RotateVectors(circlePointsVectors, rotMatrix); points3D = this.GetPoints3D(rotVectors); points2D = SpaceManager.GetProjectionXY(points3D); this.OrthogonalVectorsPoints = points3D; RealMatrix phaseMatrix = new RealMatrix(interferograms[0].RowCount, interferograms[0].ColumnCount); for (int index = 0; index < selectedImagePoints.Length; index++) { Point2D circlePoint = points2D[index]; int x = selectedImagePoints[index].X; int y = selectedImagePoints[index].Y; phaseMatrix[y, x] = Math.PI + Math.Atan2(circlePoint.Y, circlePoint.X); } this.EigenVector1 = new RealVector(eigenVector1[0] / eigenVector1.Length, eigenVector1[1] / eigenVector1.Length); this.EigenVector2 = new RealVector(eigenVector2[0] / eigenVector2.Length, eigenVector2[1] / eigenVector2.Length); InterferogramDecodingResult decodingResult = new InterferogramDecodingResult(phaseMatrix); return(decodingResult); }
/// <summary> /// 定时任务。 /// </summary> /// <param name="state"></param> private static void TimerCallback(object state) { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); // 开始监视代码运行时间 #region 获取完整的统计数据 // Sql文件目录 string path = @"D:\StatisStaffService\SqlStatements"; var s = new Statistician(path); DataTable result = null; try { // 查询统计数据 result = s.GetResult() .AsEnumerable() .OrderBy(r => r.Field <string>(0)) .CopyToDataTable(); } catch (Exception e) { string msg = $"抛出异常:查询统计数据;异常消息:{ e.Message }。"; LogUtils.Logger.Error(msg); Console.WriteLine(msg); return; } // 获取统计时间 DateTime now = DateTime.Now; // 添加时间一列 var time = new DataColumn("statis_time", typeof(DateTime)) { DefaultValue = Convert.ToDateTime(now.ToString("yyyy-MM-dd HH:mm")) }; result.Columns.Add(time); time.SetOrdinal(0); // 校准定时器 bool changed = CalibrationTimer(timer, now); // 是否是整点 bool whether = (now.Minute == 0); try { // 保存统计结果 using (var command = new SqlCommand("insert_statis_worker") { CommandType = CommandType.StoredProcedure }) { command.Parameters.Add(new SqlParameter("@myTable", result)); command.Parameters.Add(new SqlParameter("@whetherCopy", whether)); DbHelperSQL.Exec(command); } } catch (Exception e) { string msg = $"抛出异常:保存统计结果;异常消息:{ e.Message }。"; LogUtils.Logger.Error(msg); Console.WriteLine(msg); } #endregion stopwatch.Stop(); // 停止监视 TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间 double hours = timespan.TotalHours; // 总小时 double minutes = timespan.TotalMinutes; // 总分钟 double seconds = timespan.TotalSeconds; // 总秒数 double milliseconds = timespan.TotalMilliseconds; // 总毫秒数 LogUtils.Logger.Info($"统计完成时间:{ now.ToString("yyyy-MM-dd HH:mm:ss") };统计耗费时间:{ seconds }秒;统计结果行数:{ result?.Rows.Count ?? 0 }。"); }