/// <summary> /// �����U���̌����s���D /// </summary> /// <param name="set1">����ΏۂƂȂ鐔�l�Q</param> /// <param name="set2">����ΏۂƂȂ鐔�l�Q</param> /// <param name="level">�L�Ӑ���</param> /// <param name="p">p�l���i�[�����iout�j</param> /// <param name="f">���蓝�v�ʁi��Βl�j���i�[�����iout�j</param> /// <returns>true�̏ꍇ�́u�L�Ӎ�����v�Cfalse�̏ꍇ�́u�L�Ӎ������v��Ӗ�����</returns> public static bool Test(IVector set1, IVector set2, double level, out double p, out double f) { int size1 = set1.Size; int size2 = set2.Size; if (size1 < 2 || size2 < 2) { throw new Exception.IllegalArgumentException(); } // ���v�� double u1 = set1.Variance; double u2 = set2.Variance; int dof1, dof2; if (u1 > u2) { f = u1 / u2; dof1 = size1 - 1; dof2 = size2 - 1; } else { f = u2 / u1; dof1 = size2 - 1; dof2 = size1 - 1; } p = GSL.Functions.cdf_fdist_Q(f, dof1, dof2); return p <= level; }
public static bool LinearlyIndependentOf(this IVector v, params IVector[] vecs) { IVector[] temp = new IVector[vecs.Length + 1]; Array.Copy(vecs, temp, vecs.Length); temp[vecs.Length] = v; return VecOps.LinearlyIndependent(temp); }
public static Vector Cross(IVector v1, IVector v2) { return new Vector( v1.Y * v2.Z - v1.Z * v2.Y, v1.Z * v2.X - v1.X * v2.Z, v1.X * v2.Y - v1.Y * v2.X); }
public IArcEntity ArcByCenterPointStartPointSweepAngle(IPointEntity centerPoint, IPointEntity startPoint, double sweepAngle, IVector normal) { DSGeometryApplication.Check(); double radius = startPoint.DistanceTo(centerPoint); double startAngle = 30; return new ArcEntity(centerPoint, normal, radius, startAngle, sweepAngle); }
//here we have _gradient as sum of gradients, should make step in this direction protected override bool LearnBatch(INet net, double currentLearningCycleError) { if (_prevStep != null) { var y = _gradient.Negate().Sum(_prevGradient); //yk //_gradientDiffNorm = y.Norm; //Console.WriteLine("Gradient diff norm: {0}", _gradientDiffNorm.GetMod().X); //Console.WriteLine(); //if (IsNetLearned(currentLearningCycleError)) // return; //its time to calculate b(k + 1) _b = CalculateInvertedPseudoGaussian(_b, _prevStep, y); } var direction = CalculateMinimizeDirection(_b, _gradient); //pk - direction of next step var step = MakeStep(direction, net, currentLearningCycleError); //step = alpha*pk //var step = MakeStepGoldstein(direction, net, currentLearningCycleError, _gradient); //step = alpha*pk if (step == null) { } //Save step and grad _prevStep = step; _prevGradient = _gradient; //clear gradient vector _gradient = null; return true; }
/// <summary> /// �����Ɏw�肳�ꂽ�x�N�g���̃T�C�Y��0�łȂ����Ƃׂ�D /// </summary> /// <param name="v"></param> /// <exception cref="Exception.ZeroSizeException"> /// �x�N�g���T�C�Y��0�̏ꍇ��throw�����D /// </exception> public static void ZeroSize(IVector v) { if (v.Size == 0) { throw new Exception.ZeroSizeException(); } }
public Item(XElement ItemNode) { this.nestedItems = new List<IMenuable>(); typeOfTheItem = (new ItemType()).GetItemType(ItemNode.Attribute("type").Value ?? ""); name = ItemNode.Attribute("name").Value ?? ""; position = new Vector(ItemNode.Attribute("position").Value ?? ""); }
protected override void InternalCompute(IVector array, bool periodic) { int len = array.Length; int N = periodic ? len : len - 1; for (int i = 0; i < len; ++i) array[i] = 1 - RMath.Pow2((2 * i - N) / (double)N); }
/// <summary> /// �����Ɏw�肳�ꂽ�x�N�g���̃T�C�Y����v���邱�Ƃׂ�D /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> /// <exception cref="Exception.MismatchSizeException"> /// �x�N�g���̃T�C�Y����v���Ȃ��Ƃ���throw�����D /// </exception> public static void MismatchSize(IVector v1, IVector v2) { if (v1.Size != v2.Size) { throw new Exception.MismatchSizeException(); } }
public RVector(IVector source) { if (source != null) { Position = source.Position; Direction = source.Direction; } }
internal ArcEntity(IPointEntity center, IVector normal, double radius, double startAngle, double sweepAngle) { this.CenterPoint = center; this.Normal = normal; this.Radius = radius; this.StartAngle = startAngle; this.SweepAngle = sweepAngle; }
protected override void InternalCompute(IVector array, bool periodic) { int len = array.Length; int N = periodic ? len : len - 1; double scale = 2 * Math.PI / N; for (int i = 0; i < len; ++i) array[i] = 0.54 - 0.46 * Math.Cos(i * scale); }
/// <summary> /// �ꕽ�ςɑ��镽�ϒl�̌����s���D /// </summary> /// <param name="set">����ΏۂƂȂ鐔�l�Q</param> /// <param name="population">�ꕽ��</param> /// <param name="level">�L�Ӑ���</param> /// <param name="p">p�l���i�[�����iout�j</param> /// <param name="t">t�l���i�[�����iout�j</param> /// <returns>true�̏ꍇ�́u�L�Ӎ�����v�Cfalse�̏ꍇ�́u�L�Ӎ������v��Ӗ�����</returns> public static bool Test(IVector set, double population, double level, out double p, out double t) { VectorChecker.ZeroSize(set); t = (set.Average - population) / Math.Sqrt(set.Variance); p = GSL.Functions.cdf_tdist_Q(Math.Abs(t), set.Size - 1); return p <= level; }
public static Vector Multiply(IVector v, double c) { double[] components = new double[v.Count]; for (int i = 0; i < components.Length; i++) { components[i] = v[i] * c; } return new Vector(components); }
public IFuzzyNumber Mul(IVector x) { var res = this[0].Mul(x[0]); for (int i = 1; i < _values.Length; i++) { res.Set(res.Sum(this[i].Mul(x[i]))); } return res; }
protected override void InternalCompute(IVector array, bool periodic) { int len = array.Length; int N = periodic ? len : len - 1; double scale = 2 * Math.PI / N; double N2 = N / 2.0; for (int i = 0; i < len; ++i) array[i] = 0.5 * (1 + Math.Cos((i - N2) * scale)); }
private SquareMatrix(bool check, IVector[] rows) : base(false, rows) { if (check) { for (int i = 0; i < rows.Length; i++) if (rows[i].Count != rows.Length) throw new ArgumentException(); } }
public static Vector Subtract(IVector a, IVector b) { if (a.Count != b.Count) throw new ArgumentException(); double[] components = new double[a.Count]; for (int i = 0; i < components.Length; i++) { components[i] = a[i] - b[i]; } return new Vector(components); }
public static void DebugSolver(int iteration, double residual, IVector x) { string message = "i: " + Convert.ToString(iteration) + "\t" + "r:" + Convert.ToString(residual) + "\t"; //message += "x:"; //for (int i = 0; i < x.Size; i++ ) // message += " " + Convert.ToString(x[i]); message += "\n\r"; File.AppendAllText(logFile,message); }
public static double Dot(this IVector a, IVector b) { if (a.Count != b.Count) throw new ArgumentException(); double sum = 0; for (int i = 0; i < a.Count; i++) { sum += a[i] * b[i]; } return sum; }
public static SquareMatrix Identity(int dimension) { IVector[] rows = new IVector[dimension]; for (int i = 0; i < dimension; i++) { double[] temp = new double[dimension]; temp[i] = 1; rows[i] = new Vector(temp); } return new SquareMatrix(false, rows); }
protected override void InternalCompute(IVector array, bool periodic) { int len = array.Length; int N = periodic ? len : len - 1; double N2 = N / 2.0; for (int i = 0; i < len; ++i) { double arg = _alpha * (i - N2) / N2; array[i] = Math.Exp(-0.5 * arg * arg); } }
protected override void InternalCompute(IVector array, bool periodic) { int len = array.Length; int N = periodic ? len : len - 1; double scale1 = 2 * Math.PI / N; double scale2 = 4 * Math.PI / N; double scale3 = 6 * Math.PI / N; double scale4 = 8 * Math.PI / N; for (int i = 0; i < len; ++i) array[i] = 0.2156 - 0.4160 * Math.Cos(i * scale1) + 0.2781 * Math.Cos(i * scale2) - 0.0836 * Math.Cos(i * scale3) + 0.0069 * Math.Cos(i * scale4); }
public static double DistanceSquared(this IVector a, IVector b) { if (a.Count != b.Count) throw new ArgumentException(); double sum = 0; for (int i = 0; i < a.Count; i++) { sum += (a[i] - b[i]) * (a[i] - b[i]); } return sum; //return a.Subtract(b).LengthSquared(); }
public CrossValidationResult(int numberOfPoints, int numberOfY, int numberOfFactors, bool multipleSpectralResiduals) { _predictedY = new IMatrix[numberOfFactors+1]; _spectralResidual = new IMatrix[numberOfFactors+1]; _crossPRESS = VectorMath.CreateExtensibleVector(numberOfFactors+1); for(int i=0;i<=numberOfFactors;i++) { _predictedY[i] = new MatrixMath.BEMatrix(numberOfPoints,numberOfY); _spectralResidual[i] = new MatrixMath.BEMatrix(numberOfPoints,multipleSpectralResiduals ? numberOfY : 1); } }
protected override void InternalCompute(IVector array, bool periodic) { int len = array.Length; int N = periodic ? len : len - 1; double scale1 = 2 * Math.PI / N; double scale2 = 4 * Math.PI / N; double scale3 = 6 * Math.PI / N; double ic; int i; for (i = 0, ic = -N / 2.0; i < len; ++i, ic += 1) array[i] = 0.35875 + 0.48829 * Math.Cos(ic * scale1) + 0.14128 * Math.Cos(ic * scale2) + 0.01168 * Math.Cos(ic * scale3); }
Matrix MatrixA() { IVector[] temp = new IVector[Height]; for (int i = 0; i < Height; i++) { double[] vec = new double[w1]; for (int j = 0; j < w1; j++) vec[j] = this[i][j]; temp[i] = new Vector(vec); } return FromRows(temp); }
public IVector MemberviseMul(IVector x) { if(Length != x.Length) throw new ArgumentException("Vectors dimensions differ."); var values = new IFuzzyNumber[Length]; for (int i = 0; i < _values.Length; i++) { values[i] = _values[i].Mul(x[i]); } return new Vector(values); }
/// <summary> /// 2�̃x�N�g���̑��ւ���߂�D /// </summary> /// <param name="vx">�x�N�g��</param> /// <param name="vy">�x�N�g��</param> /// <returns>����</returns> /// <exception cref="Exception.MismatchSizeException"> /// �x�N�g���̃T�C�Y����v���Ȃ��Ƃ���throw�����D /// </exception> public static double Correl(IVector vx, IVector vy) { VectorChecker.MismatchSize(vx, vy); double sxy = 0.0; double avg_x = vx.Average; double avg_y = vy.Average; for (int i = 0; i < vx.Size; ++i) { sxy += ((vx[i] - avg_x) * (vy[i] - avg_y)); } return sxy / Math.Sqrt(vx.Scatter * vy.Scatter); }
Matrix MatrixB() { int w2 = Width - w1; IVector[] temp = new IVector[Height]; for (int i = 0; i < Height; i++) { double[] vec = new double[w2]; for (int j = 0; j < w2; j++) vec[j] = this[i][w1 + j]; temp[i] = new Vector(vec); } return FromRows(temp); }
/// <summary> /// See <see cref="IPcgBetaParameterCalculation.Initialize(IVectorView)"/>. /// </summary> public void Initialize(PcgAlgorithmBase pcg) => residualOld = pcg.Residual.Copy();
public override IVector ApplyTransposed(IVector vector) { return(new Vector(_data.TransposeThisAndMultiply(((Vector)vector).Data))); }
public static IMatrix <double> AU(IMatrix <double> A, DoubleVector u, int r1, int r2, int c1, int c2, IVector <double> v) { if (r2 < r1 || c2 < c1) { return(A); } if (c2 - c1 + 1 > u.Length) { throw new ArgumentException("Householder vector too short.", "u"); } if (r2 - r1 + 1 > v.Length) { throw new ArgumentException("Work vector too short.", "v"); } for (int i = r1; i <= r2; i++) { v[i - r1] = 0.0; for (int j = c1; j <= c2; j++) { v[i - r1] = v[i - r1] + A[i, j] * u[j - c1]; } } for (int i = r1; i <= r2; i++) { for (int j = c1; j <= c2; j++) { A[i, j] = A[i, j] - v[i - r1] * u[j - c1]; } } return(A); }
/// <summary> /// Solves the linear system A * x = b, where A = <paramref name="matrix"/> and b = <paramref name="rhs"/>. /// Initially x = <paramref name="initialGuess"/> and then it converges to the solution. /// </summary> /// <param name="matrix">The matrix A of the linear system A * x = b. It must be symmetric positive definite.</param> /// <param name="rhs"> /// The right hand side vector b of the linear system A * x = b. Constraints: /// <paramref name="rhs"/>.<see cref="IIndexable1D.Length"/> /// == <paramref name="matrix"/>.<see cref="IIndexable2D.NumRows"/>. /// </param> /// <param name="solution"> /// The vector from which to start refining the solution vector x. Constraints: /// <paramref name="solution"/>.<see cref="IIndexable1D.Length"/> /// == <paramref name="matrix"/>.<see cref="IIndexable2D.NumColumns"/>. /// </param> /// <param name="initialGuessIsZero"> /// If <paramref name="solution"/> is 0, then set <paramref name="initialGuessIsZero"/> to true to avoid performing the /// operation b-A*0 before starting. /// </param> /// <exception cref="NonMatchingDimensionsException"> /// Thrown if <paramref name="rhs"/> or <paramref name="solution"/> violate the described constraints. /// </exception> public IterativeStatistics Solve(IMatrixView matrix, IVectorView rhs, IVector solution, bool initialGuessIsZero) //TODO: find a better way to handle the case x0=0 => Solve(new ExplicitMatrixTransformation(matrix), rhs, solution, initialGuessIsZero);
/// <summary> /// Solves the linear system A * x = b, where A = <paramref name="matrix"/> and b = <paramref name="rhs"/>. /// Initially x = <paramref name="initialGuess"/> and then it converges to the solution. /// </summary> /// <param name="matrix"> /// Represents the matrix A of the linear system A * x = b, which must be symmetric positive definite. /// </param> /// <param name="rhs"> /// The right hand side vector b of the linear system A * x = b. Constraints: /// <paramref name="rhs"/>.<see cref="IIndexable1D.Length"/> /// == <paramref name="matrix"/>.<see cref="IIndexable2D.NumRows"/>. /// </param> /// <param name="solution"> /// The vector from which to start refining the solution vector x. Constraints: /// <paramref name="solution"/>.<see cref="IIndexable1D.Length"/> /// == <paramref name="matrix"/>.<see cref="IIndexable2D.NumColumns"/>. /// </param> /// <param name="initialGuessIsZero"> /// If <paramref name="solution"/> is 0, then set <paramref name="initialGuessIsZero"/> to true to avoid performing the /// operation b-A*0 before starting. /// </param> /// <exception cref="NonMatchingDimensionsException"> /// Thrown if <paramref name="rhs"/> or <paramref name="solution"/> violate the described constraints. /// </exception> public IterativeStatistics Solve(ILinearTransformation matrix, IVectorView rhs, IVector solution, bool initialGuessIsZero) //TODO: find a better way to handle the case x0=0 { //TODO: these will also be checked by the matrix vector multiplication. Preconditions.CheckMultiplicationDimensions(matrix.NumColumns, solution.Length); Preconditions.CheckSystemSolutionDimensions(matrix.NumRows, rhs.Length); this.Matrix = matrix; this.Rhs = rhs; this.solution = solution; // r = b - A * x if (initialGuessIsZero) { residual = rhs.Copy(); } else { residual = ExactResidual.Calculate(matrix, rhs, solution); } return(SolveInternal(maxIterationsProvider.GetMaxIterations(matrix.NumColumns))); }
public bool InitializeStartingVectorFromSearchVectors(IVector <double> x, IVector <double> b) { return(SearchVectors.InitializeStartingVectorFromReorthogonalizedSearchVectors( (Vector <double>)x, (Vector <double>)b, p, q)); }
public void subscribe(string host, int port, string tableName, string actionName, MessageHandler handler, long offset, IVector filter) { subscribe(host, port, tableName, actionName, handler, offset, false, filter); }
public virtual IVector TransMult(IMatrix A, IVector x, IVector y) { return(TransMultAdd(1.0, A, x, 0.0, y, y)); }
private static void checkTransMultAddArguments(IMatrix A, IVector x, IVector y, IVector z) { if (A.RowCount != x.Length) { throw new IndexOutOfRangeException("A.numRows() != x.size()"); } if (A.ColumnCount != y.Length) { throw new IndexOutOfRangeException("A.numColumns() != y.size()"); } if (y.Length != z.Length) { throw new IndexOutOfRangeException("y.size() != z.size()"); } if (x == y) { throw new ArgumentException("x == y"); } if (x == z) { throw new ArgumentException("x == z"); } }
protected internal abstract IVector TransMultAddI(double alpha, IMatrix A, IVector x, double beta, IVector y, IVector z);
public virtual IVector TransMultAdd(double alpha, IMatrix A, IVector x, double beta, IVector y, IVector z) { checkTransMultAddArguments(A, x, y, z); // Quick return if possible if (alpha == 0.0 && beta == 0.0) { SetVector(0.0, z); } else if (alpha == 0.0) { ScaleCopy(beta, y, z); } else { TransMultAddI(alpha, A, x, beta, y, z); } return(z); }
public virtual IVector Mult(double alpha, IMatrix A, IVector x, IVector y) { return(MultAdd(alpha, A, x, 0.0, y, y)); }
public virtual IVector MultAdd(IMatrix A, IVector x, IVector y) { return(MultAdd(1.0, A, x, 1.0, y, y)); }
/// <inheritdoc /> protected override IMatrix <double> MultiplySafe(IVector <double> vector) { return(MultiplyInternal(this, vector)); }
public void subscribe(string host, int port, string tableName, MessageHandler handler, long offset, IVector filter) { subscribe(host, port, tableName, DEFAULT_ACTION_NAME, handler, offset, false, filter); }
public virtual IVector TransMultAdd(double alpha, IMatrix A, IVector x, double beta, IVector y) { return(TransMultAdd(alpha, A, x, beta, y, y)); }
public void subscribe(string host, int port, string tableName, string actionName, MessageHandler handler, long offset, bool reconnect, IVector filter) { BlockingCollection <List <IMessage> > queue = subscribeInternal(host, port, tableName, actionName, handler, offset, reconnect, filter); lock (queueHandlers) { queueHandlers.Add(tableNameToTopic[host + ":" + port + ":" + tableName], new QueueHandlerBinder(queue, handler)); } }
public virtual IVector TransMultAdd(double alpha, IMatrix A, IVector x, IVector y, IVector z) { return(TransMultAdd(alpha, A, x, 1.0, y, z)); }
private IterativeStatistics SolveInternal(int maxIterations) { // δnew = δ0 = r * r resDotRes = residual.DotProduct(residual); // The convergence criterion must be initialized immediately after the first r and r*r are computed. residualConvergence.Initialize(this); // This is also used as output double residualNormRatio = double.NaN; // d = r direction = residual.Copy(); // Allocate memory for other vectors, which will be reused during each iteration matrixTimesDirection = Rhs.CreateZeroVectorWithSameFormat(); for (Iteration = 0; Iteration < maxIterations; ++Iteration) { // q = A * d Matrix.Multiply(direction, matrixTimesDirection); // α = δnew / (d * q) StepSize = ResDotRes / (direction.DotProduct(matrixTimesDirection)); // x = x + α * d solution.AxpyIntoThis(direction, StepSize); // δold = δnew double resDotResOld = ResDotRes; // Normally the residual vector is updated as: r = r - α * q and δnew = r * r. // However corrections might need to be applied. residualUpdater.UpdateResidual(this, residual, out resDotRes); // At this point we can check if CG has converged and exit, thus avoiding the uneccesary operations that follow. residualNormRatio = residualConvergence.EstimateResidualNormRatio(this); if (residualNormRatio <= residualTolerance) { return(new IterativeStatistics { AlgorithmName = name, HasConverged = true, NumIterationsRequired = Iteration + 1, ResidualNormRatioEstimation = residualNormRatio }); } // β = δnew / δold ParamBeta = ResDotRes / resDotResOld; // d = r + β * d //TODO: benchmark the two options to find out which is faster //direction = residual.Axpy(direction, beta); //This allocates a new vector d, copies r and GCs the existing d. direction.LinearCombinationIntoThis(ParamBeta, residual, 1.0); //This performs additions instead of copying and needless multiplications. } // We reached the max iterations before CG converged return(new IterativeStatistics { AlgorithmName = name, HasConverged = false, NumIterationsRequired = maxIterations, ResidualNormRatioEstimation = residualNormRatio }); }
/// <inheritdoc /> protected override void DivideSafe(IVector <double> vector) { DivideInternal(this, vector); }
/// <inheritdoc /> protected override void AddSafe(IVector <double> vector) { CheckDimensionsEqual(this, vector); AddInternal(this, vector); }
public void WriteObject(IVector vector) { WriteDouble("X", vector.X); WriteDouble("Y", vector.Y); WriteDouble("Z", vector.Z); }
public override void append(IVector value) { values.AddRange(((BasicStringVector)value).getdataArray()); }
public MainWindowViewmodel(IPingTimer pingTimer, IPingService pingService, IPingCollectionVectorFactory pingCollectionVectorFactory, IPingVectorFactory pingVectorFactory, IVectorComparer vectorComparer, IIpAddressService ipAddressService, IDispatcherAccessor dispatcherAccessor, PingStatsUtil pingStatsUtil, IPingResponseUtil pingResponseUtil) { _pingTimer = pingTimer; _pingService = pingService; _pingCollectionVectorFactory = pingCollectionVectorFactory; _pingVectorFactory = pingVectorFactory; _vectorComparer = vectorComparer; _pingStatsUtil = pingStatsUtil; _pingResponseUtil = pingResponseUtil; IObservable <long> pingTimerObservable = _pingTimer.Start(() => false); IDisposable pingResponseSubscription = null; _targetDatamodels = new ConcurrentDictionary <IPAddress, PingState>(); _stats = new ConcurrentDictionary <IPAddress, PingStats>(); System.Windows.Threading.Dispatcher d = dispatcherAccessor.GetDispatcher(); Subject <int> resortSubject = new Subject <int>(); ResortObservable = resortSubject; ipAddressService.IpAddressObservable.Subscribe(ipAddresses => { pingResponseSubscription?.Dispose(); IObservable <IEnumerable <Task <IPingResponse> > > pingResponseObservable = pingTimerObservable.Select(l => _pingService.Ping(ipAddresses)); pingResponseSubscription = pingResponseObservable.Subscribe(async pingResponseTasks => { IPingResponse[] responses = await Task.WhenAll(pingResponseTasks); IVector[] vectors = responses.Select(pingResponse => { IPingStats stats = GetUpdatedStats(pingResponse); IVector pingVector = _pingVectorFactory.GetVector(pingResponse, stats); if (_targetDatamodels.TryGetValue(pingResponse.TargetIpAddress, out PingState pingState)) { TargetDatamodel targetDatamodelX = pingState.TargetDatamodel; targetDatamodelX.RoundTripTime = pingResponse.RoundTripTime; targetDatamodelX.StatusSuccess = GetStatusSuccess(pingResponse.Status); IVector boring = _pingVectorFactory.GetVector(new PingResponse(IPAddress.Loopback, TimeSpan.Zero, IPStatus.DestinationHostUnreachable, IPAddress.Loopback), new PingStats(DateTime.Now.AddDays(-1), DateTime.Now) { Average25 = 0, Average25Count = 25, StatusHistory = new bool[PingStatsUtil.MaxHistoryCount] }); double change = _vectorComparer.Compare(boring, pingVector); targetDatamodelX.Change = change; if (targetDatamodelX.Change > 0.008) { targetDatamodelX.ShowUntil = DateTime.Now.Add(TimeToShowOddTargets); } if (targetDatamodelX.ShowUntil <= DateTime.Now) { targetDatamodelX.ShowUntil = null; } pingState.Previous = pingVector; } else { TargetDatamodel targetDatamodel = new TargetDatamodel(address: pingResponse.TargetIpAddress, statusSuccess: GetStatusSuccess(pingResponse.Status), roundTripTime: pingResponse.RoundTripTime); _targetDatamodels.Add(pingResponse.TargetIpAddress, new PingState { TargetDatamodel = targetDatamodel, Previous = pingVector }); d.Invoke(() => TargetDatamodels.Add(targetDatamodel)); } return(pingVector); }).ToArray(); resortSubject.OnNext(0); }); }); TargetDatamodels = new ObservableCollection <TargetDatamodel>(); }
public static IMatrix <double> UA(IReadOnlyList <double> u, IMatrix <double> A, int r1, int r2, int c1, int c2, IVector <double> v) { if (r2 < r1 || c2 < c1) { return(A); } if (r2 - r1 + 1 > u.Count) { throw new ArgumentException("Householder vector too short.", "u"); } if (c2 - c1 + 1 > v.Length) { throw new ArgumentException("Work vector too short.", "v"); } for (int j = c1; j <= c2; j++) { v[j - c1] = 0.0; } for (int i = r1; i <= r2; i++) { for (int j = c1; j <= c2; j++) { v[j - c1] = v[j - c1] + u[i - r1] * A[i, j]; } } for (int i = r1; i <= r2; i++) { for (int j = c1; j <= c2; j++) { A[i, j] = A[i, j] - u[i - r1] * v[j - c1]; } } return(A); }
public override IElement Evaluate(IElement[] Arguments, Variables Variables) { double[] Coefficients = null; Complex[] CoefficientsZ = null; ILambdaExpression f = null; ScriptNode fDef = null; double rc, ic; double dr; Complex R; int N; int dimx, dimy; int c = Arguments.Length; int i = 0; object Obj; Complex z; Obj = Arguments[i++].AssociatedObjectValue; if (Obj is Complex) { z = (Complex)Obj; rc = z.Real; ic = z.Imaginary; } else { rc = Expression.ToDouble(Obj); ic = Expression.ToDouble(Arguments[i++].AssociatedObjectValue); } if (i >= c) { throw new ScriptRuntimeException("Insufficient parameters in call to NewtonBasinFractal().", this); } dr = Expression.ToDouble(Arguments[i++].AssociatedObjectValue); if (i < c && (Arguments[i] is DoubleNumber || Arguments[i] is ComplexNumber)) { R = Expression.ToComplex(Arguments[i++].AssociatedObjectValue); } else { R = Complex.One; if (i < c && this.Arguments[i] == null) { i++; } } if (i < c) { if (Arguments[i] is DoubleVector) { Coefficients = (double[])Arguments[i++].AssociatedObjectValue; } else if (Arguments[i] is ComplexVector) { CoefficientsZ = (Complex[])Arguments[i++].AssociatedObjectValue; } /*else if (Parameters[i] is RealPolynomial) * Coefficients = ((RealPolynomial)Arguments[i++].AssociatedObjectValue).Coefficients; * else if (Parameters[i] is ComplexPolynomial) * CoefficientsZ = ((ComplexPolynomial)Arguments[i++].AssociatedObjectValue).Coefficients;*/ else if (Arguments[i] is IVector) { IVector Vector = (IVector)Arguments[i++]; int j, d = Vector.Dimension; CoefficientsZ = new Complex[d]; for (j = 0; j < d; j++) { CoefficientsZ[j] = Expression.ToComplex(Vector.GetElement(j).AssociatedObjectValue); } } else if (Arguments[i].AssociatedObjectValue is ILambdaExpression) { f = (ILambdaExpression)Arguments[i]; if (f.NrArguments != 1) { throw new ScriptRuntimeException("Lambda expression in calls to NewtonBasinFractal() must be of one variable.", this); } fDef = this.Arguments[i++]; } else { throw new ScriptRuntimeException("Parameter " + (i + 1).ToString() + " in call to NewtonBasinFractal has to be a vector of numbers, containing coefficients " + "of the polynomial to use. Now it was of type " + Arguments[i].GetType().FullName, this); } } else { throw new ScriptRuntimeException("Missing coefficients or lambda expression.", this); } if (i < c) { N = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue); } else { N = 32; } if (i < c) { dimx = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue); } else { dimx = 320; } if (i < c) { dimy = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue); } else { dimy = 200; } if (i < c) { throw new ScriptRuntimeException("Parameter mismatch in call to NewtonBasinFractal(r,c,dr,Coefficients[,Palette][,dimx[,dimy]]).", this); } if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000) { throw new ScriptRuntimeException("Image size must be within 1x1 to 5000x5000", this); } if (f != null) { return(CalcNewton(rc, ic, dr, R, f, fDef, Variables, N, dimx, dimy, this, this.FractalZoomScript, new object[] { dimx, dimy, N, R, fDef })); } else if (CoefficientsZ != null) { return(CalcNewton(rc, ic, dr, R, CoefficientsZ, N, dimx, dimy, this, this.FractalZoomScript, new object[] { dimx, dimy, N, R, CoefficientsZ })); } else { return(CalcNewton(rc, ic, dr, R, Coefficients, N, dimx, dimy, this, this.FractalZoomScript, new object[] { dimx, dimy, N, R, Coefficients })); } }
public void MultiplyWithMatrix(IVector <double> vIn, IVector <double> vOut) { ((SkylineMatrix2D <double>)solver.SubdomainsDictionary.Values.First().Matrix).Multiply(vIn, ((Vector <double>)vOut).Data, 1.0, 0, 0, true); }
public void Update() { lock (update_lock) { switch (state) { case 1: if (r < OrbR) { color = Color.Red; } v.L -= Math.Sqrt(Math.Max(0, v.L)) / 26d; if (v.L < 0.125) { v.L = 0; } break; case 3: this.bulletTime++; v.L = PHI * speed + speed * 2 / Math.Max(1, Math.Sqrt(this.bulletTime)); if (bulletTime >= 9 && Map.OutOfBounds(pos, OrbR)) { if (YeetMode && !HEADS[Owner].Died) { HEADS[Owner].Eat(ID); } else { color = Color.White; state = (byte)OrbStates.WHITE; bulletTime = 0; Owner = Keys.None; window.DrawWhite += Draw; } bulletTime = 0; killstreak = 0; window.DrawBullet -= Draw; } break; default: return; } //collisions if (pos.X < OrbR) { v.X = Math.Abs(v.X); pos.X = 2d * OrbR - pos.X; } else if (pos.X > W - OrbR) { v.X = -Math.Abs(v.X); pos.X = 2d * (W - OrbR) - pos.X; } else if (pos.Y < OrbR) { v.Y = Math.Abs(v.Y); pos.Y = 2 * OrbR - pos.Y; } else if (pos.Y > W / 2d - OrbR) { v.Y = -Math.Abs(v.Y); pos.Y = 2 * (W / 2d - OrbR) - pos.Y; } if (pos.X + pos.Y < C + OrbR * sqrt2 && v * new IVector(-1, -1) >= 0) { d = Math.Sqrt(Math.Abs(pos.X + pos.Y - C - OrbR * sqrt2) / sqrt2); n = ~new IVector(-1, -1); pos -= 2 * d * n; v -= 2 * (v * n) * n; } else if (W - pos.X + pos.Y < C + OrbR * sqrt2 && v * new IVector(1, -1) >= 0) { d = Math.Sqrt(Math.Abs(W - pos.X + pos.Y - C - OrbR * sqrt2) / sqrt2); n = ~new IVector(1, -1); pos -= 2 * d * n; v -= 2 * (v * n) * n; } else if (W / 2 + pos.X - pos.Y < C + OrbR * sqrt2 && v * new IVector(-1, 1) >= 0) { d = Math.Sqrt(Math.Abs(W / 2 + pos.X - pos.Y - C - OrbR * sqrt2) / sqrt2); n = ~new IVector(-1, 1); pos -= 2 * d * n; v -= 2 * (v * n) * n; } else if (W + W / 2f - pos.X - pos.Y < C + OrbR * sqrt2 && v * new IVector(1, 1) >= 0) { d = Math.Sqrt(Math.Abs(W + W / 2 - pos.X - pos.Y - C - OrbR * sqrt2) / sqrt2); n = ~new IVector(1, 1); pos -= 2 * d * n; v -= 2 * (v * n) * n; } //update pos += v; } }
public virtual IVector MultAdd(IMatrix A, IVector x, double beta, IVector y) { return(MultAdd(1.0, A, x, beta, y, y)); }
/// <inheritdoc /> protected override void SubtractSafe(IVector <double> vector) { SubtractInternal(this, vector); }