当前位置: 首页>>代码示例>>C#>>正文


C# Vector.ToArray方法代码示例

本文整理汇总了C#中Vector.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.ToArray方法的具体用法?C# Vector.ToArray怎么用?C# Vector.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector的用法示例。


在下文中一共展示了Vector.ToArray方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: uploadFromVector

		public void uploadFromVector(Vector<uint> data, int startOffset, int count) {
			GL.BindBuffer(BufferTarget.ElementArrayBuffer, mId);
#if PLATFORM_MONOMAC
		    GL.BufferData<uint>(BufferTarget.ElementArrayBuffer, 
		        (IntPtr)(count * sizeof(uint)), 
		        data.ToArray(), 
		        BufferUsageHint.StaticDraw);
#elif PLATFORM_MONOTOUCH
			GL.BufferData<uint>(BufferTarget.ElementArrayBuffer, 
                (IntPtr)(count * sizeof(uint)), 
                data.ToArray(), 
                BufferUsage.StaticDraw);
#endif
		}
开发者ID:bbqchickenrobot,项目名称:playscript-mono,代码行数:14,代码来源:IndexBuffer3D.cs

示例2: CalibrateWavelengthForPosition

 public static void CalibrateWavelengthForPosition(Vector<double> z, Vector<double> w)
 {
     double[] fit = Fit.Polynomial(z.ToArray(), w.ToArray(), 2);
     var model = z.PointwiseMultiply(z)*fit[2] + z * fit[1] + fit[0];
     var dif = model - w;
     double rms = Math.Sqrt(dif.DotProduct(dif) / (calibration_points + 1));
     WebApiApplication.calibration.K0 = fit[0];
     WebApiApplication.calibration.K1 = fit[1];
     WebApiApplication.calibration.K2 = fit[2];
     WebApiApplication.calibration.State = MbrCalibration.Calibrated;
     WebApiApplication.calibration.RmsError = rms;
 }
开发者ID:willtalmadge,项目名称:MbrControl,代码行数:12,代码来源:WavelengthController.cs

示例3: DualNumber

        /// <summary>
        /// A new <see cref="DualNumber" /> with the specified value and first and second partial derivatives.
        /// </summary>
        public DualNumber(double value, Vector gradient, Matrix hessian)
        {
            this.value = value;
            this.gradient = gradient;
            this.hessian = hessian;

            if (gradient != null)
            {
                n = gradient.Length;
                gradientArray = gradient.ToArray();
            }

            if (hessian != null)
            {
                if (gradient == null)
                {
                    throw new ArgumentException("The gradient must be specified if the Hessian is specified.");
                }

                if (hessian.Rows != n || hessian.Columns != n)
                {
                    throw new ArgumentException("Inconsistent number of derivatives.");
                }

                // Since the Hessian is symmetric we only need to store the upper triangular part of it. Use a
                // one dimensional array until the matrix is requested (if ever). Doing it this way is almost
                // a factor of 10 faster than using naive matrix operations.

                hessianArray = new double[HessianSize(n)];

                for (int i = 0, k = 0; i < n; i++)
                {
                    for (int j = i; j < n; j++, k++)
                    {
                        if (hessian[i, j] != hessian[j, i] && !(double.IsNaN(hessian[i, j]) && double.IsNaN(hessian[j, i])) && !(double.IsPositiveInfinity(hessian[i, j]) && double.IsPositiveInfinity(hessian[j, i])) && !(double.IsNegativeInfinity(hessian[i, j]) && double.IsNegativeInfinity(hessian[j, i])))
                        {
                            throw new ArgumentException("The Hessian must be symmetric.");
                        }

                        hessianArray[k] = hessian[i, j];
                    }
                }
            }
        }
开发者ID:mortenbakkedal,项目名称:SharpMath,代码行数:47,代码来源:DualNumber.cs

示例4: CalculateConstraint

        private void CalculateConstraint()
        {
            //three possible cases, both finites, owner finite/external infnite and viceversa

            if (!Owner.Infinity && !external.Infinity)
            {
                double[] ownerPoint = Owner.Coordinates;
                double[] foreignPoint = external.Coordinates;

                double[] coefficents = new Vector(ownerPoint.Length + 1);
                coefficents[coefficents.Length - 1] = 0;

                //calculating coefficents except the independent coefficent
                for (int i = 0; i < ownerPoint.Length; i++)
                {
                    coefficents[i] = ownerPoint[i] - foreignPoint[i];
                    //calculating the independent coefficent
                    coefficents[coefficents.Length - 1] -= coefficents[i] * ((foreignPoint[i] + ownerPoint[i]) / 2f);
                }
                this.constraint = new HyperPlaneConstraint(coefficents);
            }
            else if (External.Infinity && Owner.Infinity)
            {
                INuclei[] n = External.Simplice.Nucleis.Intersect(Owner.Simplice.Nucleis).ToArray();
                if (n.Length != 2)
                    throw new NotSupportedException();

                IVoronoiFacet vf = n[0].VoronoiHyperRegion.Facets.Single(f => f.External == n[1]);
                double[] coefficents = new Vector(Owner.Coordinates.Length + 1);
                for (int i = 0; i < Owner.Coordinates.Length; i++)
                {
                    coefficents[i] = vf[i];
                }
                this.constraint = new HyperPlaneConstraint(coefficents);

            }
            else if (External.Infinity)
            {
                if (Owner.Simplice.Nucleis.Length > 2)
                {
                    double[] middlePoint = new double[Nucleis[0].Coordinates.Length];
                    Helpers.CalculateSimpliceCentroidFromFacets(this.Nucleis,this.Rank, ref middlePoint);

                    Vector normal = new Vector(Nucleis[0].Coordinates.Length + 1);
                    double independentTerm = 0;
                    for (int i = 0; i < Nucleis[0].Coordinates.Length; i++)
                    {
                        normal[i] = Owner.Coordinates[i] - middlePoint[i];
                        independentTerm -= normal[i] * middlePoint[i];
                    }
                    normal[normal.Length - 1] = independentTerm;
                    this.constraint = new HyperPlaneConstraint(normal.ToArray());
                }
                else
                {
                    //only two nucleis...is this enough general for n-dimensions?
                    //hope this is only the case base, where a voronoiVertex overlaps a voronoiFacet
                    INuclei n = External.Simplice.Nucleis.Intersect(Owner.Simplice.Nucleis).Single();

                    Vector normal = new Vector(Nucleis[0].Coordinates.Length + 1);
                    double independentTerm = 0;
                    for (int i = 0; i < Nucleis[0].Coordinates.Length; i++)
                    {
                        normal[i] = Owner.Coordinates[i] - n.Coordinates[i];
                        independentTerm -= normal[i] * n.Coordinates[i];
                    }
                    normal[normal.Length - 1] = independentTerm;
                    this.constraint = new HyperPlaneConstraint(normal.ToArray());
                }
            }
            else if (Owner.Infinity)
            {
                if (External.Simplice.Nucleis.Length > 2)
                {
                    double[] middlePoint = new double[Nucleis[0].Coordinates.Length];
                    Helpers.CalculateSimpliceCentroidFromFacets(Nucleis, this.Rank, ref middlePoint);

                    Vector normal = new Vector(Nucleis[0].Coordinates.Length + 1);
                    double independentTerm = 0;
                    for (int i = 0; i < Nucleis[0].Coordinates.Length; i++)
                    {
                        normal[i] = middlePoint[i] - External.Coordinates[i];
                        independentTerm -= normal[i] * middlePoint[i];
                    }
                    normal[normal.Length - 1] = independentTerm;
                    this.constraint = new HyperPlaneConstraint(normal.ToArray());
                }
                else
                {
                    //only two nucleis...is this enough general for n-dimensions?
                    //hope this is only the case base, where a voronoiVertex overlaps a voronoiFacet
                    INuclei n = External.Simplice.Nucleis.Intersect(Owner.Simplice.Nucleis).Single();

                    Vector normal = new Vector(Nucleis[0].Coordinates.Length + 1);
                    double independentTerm = 0;
                    for (int i = 0; i < Nucleis[0].Coordinates.Length; i++)
                    {
                        normal[i] = n.Coordinates[i] - External.Coordinates[i];
                        independentTerm -= normal[i] * n.Coordinates[i];
                    }
//.........这里部分代码省略.........
开发者ID:pabloinigoblasco,项目名称:nd-voronoi-sharp,代码行数:101,代码来源:BowyerSimpliceFacet.cs

示例5: FitInternal

        private void FitInternal(Matrix<double> x, Vector<double> y)
        {
            if (this.Kernel.KernelFunction != null)
            {
                // you must store a reference to X to compute the kernel in predict
                // TODO: add keyword copy to copy on demand
                this.xFit = x;
                x = this.ComputeKernel(x);

                if (x.RowCount != x.ColumnCount)
                {
                    throw new ArgumentException("X.RowCount should be equal to X.ColumnCount");
                }
            }

            var problem = new svm_problem();
            problem.l = x.RowCount;
            problem.x = new svm_node[x.RowCount][];
            foreach (var row in x.RowEnumerator())
            {
                if (Kernel.LibSvmKernel == LibSvmKernel.Precomputed)
                {
                    var svmNodes =
                        row.Item2.GetIndexedEnumerator().Select(i =>
                            new svm_node
                            {
                                index = i.Item1 + 1,
                                value = i.Item2
                            });

                    problem.x[row.Item1] =
                        new[]
                            {
                                new svm_node
                                {
                                    index = 0,
                                    value = row.Item1 + 1
                                }
                            }.Concat(svmNodes).ToArray();
                }
                else
                {
                    var svmNodes =
                        row.Item2.GetIndexedEnumerator().Select(
                        i => new svm_node { index = i.Item1, value = i.Item2 });

                    problem.x[row.Item1] = svmNodes.ToArray();
                }
            }

            problem.y = y.ToArray();

            this.Param.kernel_type = (int)this.Kernel.LibSvmKernel;
            if (new[] { LibSvmKernel.Poly, LibSvmKernel.Rbf }.Contains(this.Kernel.LibSvmKernel) &&
                    this.Gamma == 0)
            {
                // if custom gamma is not provided ...
                this.Param.gamma = 1.0 / x.ColumnCount;
            }
            else
            {
                this.Param.gamma = this.Gamma;
            }

            this.Model = svm.svm_train(problem, this.Param);
        }
开发者ID:geoparsYoti,项目名称:Sharpkit.Learn,代码行数:66,代码来源:LibSvmBase.cs

示例6: UpdateModel

        /// <summary>
        /// Updates the underlying interpolation mode, if needed.
        /// </summary>
        private void UpdateModel()
        {
            switch (this.interpolationType)
            {
                // Right now only the Least Squares requires this operation to be done.
                case EInterpolationType.LEAST_SQUARES:
                    this.quadraticModel = new Fairmat.Optimization.QuadraticModel();

                    // Unroll matrix and coordinate vectors in order to make it suitable
                    // for the Quadratic model implementation.
                    int n = this.values.R * this.values.C;
                    Matrix xy = new Matrix(n, 2);
                    Vector z = new Vector(n);
                    int count = 0;
                    for (int x = 0; x < this.coordinatesX.Length; x++)
                    {
                        for (int y = 0; y < this.coordinatesY.Length; y++)
                        {
                            xy[count, Range.All] = ((Matrix)new Vector() { this[x, -1], this[-1, y] }).T;
                            z[count] = this[x, y];
                            count++;
                        }
                    }

                    this.quadraticModel.Estimate(xy.ToArray() as double[,], z.ToArray() as double[]);
                    break;
                default:
                    break;
            }
        }
开发者ID:GaikovM,项目名称:ModelingTools,代码行数:33,代码来源:CPointFunction2D.cs

示例7: PathFromStencil


//.........这里部分代码省略.........
            Vector<Point> pts = new Vector<Point>();
            int count = 0;

            // find all islands
            while (true) 
            {
                bool startFound = false;

                while (true)
                {
                    if (stencil[start])
                    {
                        startFound = true;
                        break;
                    }

                    ++start.X;

                    if (start.X >= bounds.Right)
                    {
                        ++start.Y;
                        start.X = bounds.Left;

                        if (start.Y >= bounds.Bottom)
                        {
                            break;
                        }
                    }
                }
            
                if (!startFound)
                {
                    break;
                }

                pts.Clear();
                Point last = new Point(start.X, start.Y + 1);
                Point curr = new Point(start.X, start.Y);
                Point next = curr;
                Point left = Point.Empty;
                Point right = Point.Empty;
            
                // trace island outline
                while (true)
                {
                    left.X = ((curr.X - last.X) + (curr.Y - last.Y) + 2) / 2 + curr.X - 1;
                    left.Y = ((curr.Y - last.Y) - (curr.X - last.X) + 2) / 2 + curr.Y - 1;

                    right.X = ((curr.X - last.X) - (curr.Y - last.Y) + 2) / 2 + curr.X - 1;
                    right.Y = ((curr.Y - last.Y) + (curr.X - last.X) + 2) / 2 + curr.Y - 1;

                    if (bounds.Contains(left) && stencil[left])
                    {
                        // go left
                        next.X += curr.Y - last.Y;
                        next.Y -= curr.X - last.X;
                    }
                    else if (bounds.Contains(right) && stencil[right])
                    {
                        // go straight
                        next.X += curr.X - last.X;
                        next.Y += curr.Y - last.Y;
                    }
                    else
                    {
                        // turn right
                        next.X -= curr.Y - last.Y;
                        next.Y += curr.X - last.X;
                    }

                    if (Math.Sign(next.X - curr.X) != Math.Sign(curr.X - last.X) ||
                        Math.Sign(next.Y - curr.Y) != Math.Sign(curr.Y - last.Y))
                    {
                        pts.Add(curr);
                        ++count;
                    }

                    last = curr;
                    curr = next;

                    if (next.X == start.X && next.Y == start.Y)
                    {
                        break;
                    }
                }

                Point[] points = pts.ToArray();
                Scanline[] scans = Utility.GetScans(points);

                foreach (Scanline scan in scans)
                {
                    stencil.Invert(scan);
                }

                ret.AddLines(points);
                ret.CloseFigure();
            }

            return ret;
        }
开发者ID:herbqiao,项目名称:paint.net,代码行数:101,代码来源:PdnGraphicsPath.cs

示例8: solve

        public static Vector<double> solve(
            List<double[]> Vertices,
            List<int[]> TrianglesVertices,
            List<double[]> FacetNormals,
            Vector<double> X, Point3D oRoot,
            UnitVector3D vDir1,
            UnitVector3D vDir2, Mesh M)
        {
            //Method from article -Wang,Smith. Surface flattening based on energy model. Computer-Aided Design (2002) 823-833	

            //PseudoCode
            //Input: P - Set of nodes, in the initial position and N is the number of nodes
            //Output: the final positions of P with E(o) minimized

            //  FOR i = 1 TO n
            //        mi = p / 3 Sum(Ak), where Ak is the area

            //  WHILE (Relative Area difference Es > Permissible accuracy or Relative edge length difference Ec > Permissible accuracy)
            //  AND Variation of E(o) > Permissible percentage €
            //  AND the number of iterations < Permissible number N
            //        FOR i = 1 TO n
            //                Compute Tensile force of Node Pi: Fi = Sum(C * (Dist(PiPj) - Dist(QiQj)))nij where(P - 2D - Q - 3D nij - Vector Pi to Pj)
            //                Compute new position of Pi  qi = qi + dtqi. + dt ^ 2 / 2 qi..where qi.= qi.+ dtqi..and qi..= Fi / mi
            //                Compute Penalty force and aplly to Fpi
            //                Compute new position of Pi  qi = qi + dtqi. + dt ^ 2 / 2 qi..where qi.= qi.+ dtqi..and qi..= Fpi / mi
            //        Compute new Es= Sum(TotalAreaNow - TotalAreaBefore) / TotalAreaNow
            //        Compute new Ec= Sum(TotalLenghtNow - TotalLenghtBefore) / TotalLenghtNow
            //        Compute new E(o)Sum(E(pi)) where E(pi) = 0.5 * Sum(C * (Dist(PiPj) - Dist(QiQj))) ^ 2

            double[] Mass = new double [Vertices.Count];
            int[] MassCounter = new int[Vertices.Count];
            double Permissible = 0.00000001;
            Vector<double> Fi = Vector<double>.Build.Dense(2);
            List<Vector<double>> dqi = new List<Vector<double>>();
            List<Vector<double>> qi = new List<Vector<double>>();
            double LastEc = 0, Ec = 0;
            double LastEs = 0, Es = 0;
            double LastEo = 0, Eo = 0;
            double C = 0.5;
            double ro = 1;
            double t = 0.01;
            int N = 100;
            int Iteration = 0;
            double Total = 0;
            double LastTotal = 0;
            foreach (int[] tri in TrianglesVertices) {
                double A = getArea(Vertices[tri[0]], Vertices[tri[1]], Vertices[tri[2]]);
                double P = getPerimeter(Vertices[tri[0]], Vertices[tri[1]], Vertices[tri[2]]);
                Mass[tri[0]] += ((double)1 / (double)3) * A * ro;
                Mass[tri[1]] += ((double)1 / (double)3) * A * ro;
                Mass[tri[2]] += ((double)1 / (double)3) * A * ro;
                MassCounter[tri[0]] += 1;
                MassCounter[tri[1]] += 1;
                MassCounter[tri[2]] += 1;
                LastEc += A;
                LastEs += P;
            }
            for (int i = 0; i < Vertices.Count; i++) {
                Mass[i] = Mass[i] / MassCounter[i];
                qi.Add(Vector<double>.Build.DenseOfArray(new double[] { X[i * 2], X[i * 2 + 1], 0 }));
                dqi.Add(Vector<double>.Build.DenseOfArray(new double[] { 0, 0, 0 }));
            }
            do {
                Iteration += 1;
                LastEo = Eo;
                Eo = 0;
                Total = 0;
                for (int i = 0; i < Vertices.Count; i++) {
                    Point3D Pi = new Point3D(qi[i][0], qi[i][1], qi[i][2]);
                    Point3D Qi = new Point3D(Vertices[i][0], Vertices[i][1], Vertices[i][2]);
                    Fi = Vector<double>.Build.Dense(3);
                    for (int j = i+1; j < Vertices.Count; j++) {
                        if (i == j) continue;
                        Point3D Pj = new Point3D(qi[j][0], qi[j][1], qi[j][2]);
                        Point3D Qj = new Point3D(Vertices[j][0], Vertices[j][1], Vertices[j][2]);
                        UnitVector3D nij = new UnitVector3D((Pi.ToVector()- Pj.ToVector()).ToArray());
                        Fi += C * ((Pi.DistanceTo(Pj) - Qi.DistanceTo(Qj)) * nij).ToVector();
                        Eo += Math.Pow(C * ((Pi.DistanceTo(Pj) - Qi.DistanceTo(Qj))), 2);
                    }
                    Vector<double> ddqi = Fi / Mass[i];
                    Console.WriteLine(Fi);
                    dqi[i] += t * ddqi;
                    qi[i] += dqi[i] * t + 0.5 * Math.Pow(t, 2) * ddqi;

                    Total += Math.Abs(qi[i][0] - X[i * 2]);
                    Total += Math.Abs(qi[i][1] - X[i * 2] + 1);
                }
                Console.WriteLine(Total- LastTotal);
                LastTotal = Total;
                LastEc = Ec;
                Ec = 0;
                LastEs = Es;
                Es = 0;
                foreach (int[] tri in TrianglesVertices) {
                    double A = getArea(Vertices[tri[0]], Vertices[tri[1]], Vertices[tri[2]]);
                    double P = getPerimeter(Vertices[tri[0]], Vertices[tri[1]], Vertices[tri[2]]);
                    Ec += A;
                    Es += P;
                }
                if (((Ec - LastEc) / Ec < Permissible || (Es - LastEs) / Es < Permissible)
//.........这里部分代码省略.........
开发者ID:JGEsteves89,项目名称:BlankCalculator,代码行数:101,代码来源:EnergyModelFiniteSolver.cs

示例9: InferMixture

        private static double InferMixture(Vector[] observedData, int dimensions, int clusters)
        {
            var evidence = Variable.Bernoulli(0.5).Named("evidence");

            var evidenceBlock = Variable.If(evidence);
            var k = new Range(clusters).Named("k");

            // Mixture component means
            var means = Variable.Array<Vector>(k).Named("means");
            means[k] = Variable.VectorGaussianFromMeanAndPrecision(
                Vector.Zero(dimensions),
                PositiveDefiniteMatrix.IdentityScaledBy(dimensions, 0.01)).ForEach(k);

            // Mixture component precisions
            var precs = Variable.Array<PositiveDefiniteMatrix>(k).Named("precs");
            precs[k] = Variable.WishartFromShapeAndRate(100.0, PositiveDefiniteMatrix.IdentityScaledBy(dimensions, 0.01)).ForEach(k);

            // Mixture weights
            var weights = Variable.Dirichlet(k, Enumerable.Range(0, clusters).Select(_ => 1.0).ToArray()).Named("weights");

            // Create a variable array which will hold the data
            var n = new Range(observedData.Length).Named("n");
            var data = Variable.Array<Vector>(n).Named("x");

            // Create latent indicator variable for each data point
            var z = Variable.Array<int>(n).Named("z");

            // The mixture of Gaussians model
            using (Variable.ForEach(n))
            {
                z[n] = Variable.Discrete(weights);
                using (Variable.Switch(z[n]))
                {
                    data[n] = Variable.VectorGaussianFromMeanAndPrecision(means[z[n]], precs[z[n]]);
                }
            }

            // Initialise messages randomly so as to break symmetry
            var zinit = new Discrete[n.SizeAsInt];
            for (int i = 0; i < zinit.Length; i++)
                zinit[i] = Discrete.PointMass(Rand.Int(k.SizeAsInt), k.SizeAsInt);
            z.InitialiseTo(Distribution<int>.Array(zinit));

            evidenceBlock.CloseBlock();

            // Attach some generated data
            data.ObservedValue = observedData.ToArray();

            // The inference
            var ie = new InferenceEngine(new VariationalMessagePassing());
            ie.ShowProgress = false;
            Console.WriteLine("Dist over pi=" + ie.Infer(weights));
            Console.WriteLine("Dist over means=\n" + ie.Infer(means));
            Console.WriteLine("Dist over precs=\n" + ie.Infer(precs));
            var logEvidence = ie.Infer<Bernoulli>(evidence);
            Console.WriteLine("The model log evidence is {0}", logEvidence.LogOdds);
            return logEvidence.LogOdds;
        }
开发者ID:adamgoral,项目名称:infernethol,代码行数:58,代码来源:GaussianMixture.cs

示例10: Test_Others

        public void Test_Others()
        {
            Vector v1 = new Vector(1, 2, 3, 4, 5);
            // �o��
            Assert.That(v1.ToArray(), Is.EqualTo(new[] { 1.0, 2, 3, 4, 5 }));
            string s = v1.ToString();
            string csv = Vectors.ToCsv(v1);

            v1 = Vector.Fill(10, 1);
            Assert.AreEqual(10, v1.Size);
            Assert.AreEqual(new Vector(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), v1);

            v1.Flip();          // �������]
            v1.Zero();          // �S�Ă̗v�f��0
            Assert.AreEqual(new Vector(new Size(10)).Zero(), v1);
        }
开发者ID:krdlab,项目名称:lisys,代码行数:16,代码来源:VectorTest.cs

示例11: PFunction2D

        /// <summary>
        /// Constructor to initialize the function with the specified data.
        /// </summary>
        /// <param name="coordinatesX">
        /// A <see cref="Vector"/> of coordinates, which must go from the
        /// lowest to the highest and represents the x parameter of the function.
        /// </param>
        /// <param name="coordinatesY">
        /// A <see cref="Vector"/> of coordinates, which must go from the lowest
        /// to the highest and represents the y parameter of the function.
        /// </param>
        /// <param name="values">
        /// A <see cref="Matrix"/> containing the defined data points for
        /// all the coordinates specified by coordinatesX and coordinatesY.
        /// </param>
        public PFunction2D(Vector coordinatesX, Vector coordinatesY, Matrix values)
            : this(null)
        {
            SetSizes(coordinatesX.Count, coordinatesY.Count);
            this.coordinatesX = Array.ConvertAll((double[])coordinatesX.ToArray(), element => RightValue.ConvertFrom(element, true));
            this.coordinatesY = Array.ConvertAll((double[])coordinatesY.ToArray(), element => RightValue.ConvertFrom(element, true));

            for (int x = 0; x < values.R; x++)
            {
                for (int y = 0; y < values.C; y++)
                {
                    this.values[x, y] = RightValue.ConvertFrom(values[x, y], true);
                }
            }
        }
开发者ID:GaikovM,项目名称:ModelingTools,代码行数:30,代码来源:PFunction2D.cs

示例12: findAlternans

        private int[] findAlternans(Vector<int> t_end_Vec, Vector<double> ecg, uint fs)
        {
            int[] t_end = t_end_Vec.ToArray();

            // t-wave length calculation
            // assuming t-wave length of 150ms
            // 360Hz*0,15s=54
            double t_length1 = fs*0.15;
            int t_length = Convert.ToInt32(t_length1);

            // creating a matrix containing all detected t-waves
            var M = Matrix<double>.Build;

            var t_waves = M.Dense(t_end.Length, t_length);

            for (var i = 0; i < t_end.Length; i++)
            {
                var j = 0;
                for (int v = t_end[i] - t_length; v < t_end[i]; v++)
                {
                    t_waves[i, j] = ecg[v];
                    j += 1;
                }
            }

            // creating a vector containg the medians of corresponding
            // t-waves samples
            var V = Vector<double>.Build;

            var t_mdn = V.Dense(t_length);
            var temp = V.Dense(t_end.Length);

            for (var i = 0; i < t_length; i++)
            {
                t_waves.Column(i, 0, t_end.Length, temp);
                var mdn = temp.ToArray();
                Array.Sort(mdn);

                int mid = t_end.Length / 2;
                t_mdn[i] = mdn[mid];
            }

            // calculating ACI values for each t-wave vector
            var aci = V.Dense(t_end.Length);

            for (var m = 0; m < t_end.Length; m++)
            {
                var aci_aux_nom = V.Dense(t_length);
                var aci_aux_denom = V.Dense(t_length);

                for (var n = 0; n < t_length; n++)
                {
                    aci_aux_nom[n] = t_waves[m, n] * t_mdn[n];
                    aci_aux_denom[n] = t_mdn[n] * t_mdn[n];
                }

                aci[m] = aci_aux_nom.Sum() / aci_aux_denom.Sum();
            }

            // finding fluctuations around 1
            // 1 - value changed around 1
            // 0 - value hasn't changed
            var fluct = V.Dense(t_end.Length);

            for (int k = 0; k < t_end.Length; k++)
            {
                if (((aci[k] > 1) && (aci[k + 1] < 1)) || ((aci[k] < 1) && (aci[k + 1] > 1)))
                {
                    fluct[k] = 1;
                }
                else
                {
                    fluct[k] = 0;

                }
            }

            // determining whether the fluctuations have occured in
            // 7 or more consecutive heartbeats
            var alt_tresh = 7;
            var V1 = Vector<int>.Build;
            var alternans = V1.Dense(t_end.Length);
            var counter = 0;
            var first_el = 0;
            var last_el = 0;

            for (var o = 0; o < t_end.Length; o++)
            {
                if (counter == 0)
                {
                    if (fluct[o]==1)
                    {
                        first_el = o;
                        counter++;
                    }
                }

                else if ((counter > 0) && (counter < alt_tresh))
                {
                    if (fluct[o] == 1)
//.........这里部分代码省略.........
开发者ID:Nefarin,项目名称:DadmProject,代码行数:101,代码来源:T_Wave_Alt_Alg.cs

示例13: PanTompkins

        public Vector<double> PanTompkins(Vector<double> signalECG, uint samplingFrequency)
        {
            //Init
            double fd = 5;
            double fg = 15;
            Delay = 0;

            //PROCESS
            //filtering
            double[] arr_f = Filtering(Convert.ToDouble(samplingFrequency), fd, fg, signalECG.ToArray());   //plus convert vector to array

            //differentiation
            double[] arr_d = Derivative(arr_f);

            //squaring
            double[] arr_2 = Squaring(arr_d);

            //moving-window integration
            double[] arr_i = Integrating(arr_2, samplingFrequency);

            //adaptive thresholding
            Vector<double> locsR = findRs(arr_i, signalECG, samplingFrequency);

            return locsR;
        }
开发者ID:Nefarin,项目名称:DadmProject,代码行数:25,代码来源:R_Peaks_Alg.cs

示例14: Hilbert

        public Vector<double> Hilbert(Vector<double> signalECG, uint samplingFrequency)
        {
            //Init
            double fd = 5;
            double fg = 15;
            Delay = 0;

            //PROCESS
            //filtering
            double[] h_arr_f = Filtering(Convert.ToDouble(samplingFrequency), fd, fg, signalECG.ToArray());   //plus convert vector to array
            Vector<double> h_sig_f = Vector<double>.Build.DenseOfArray(h_arr_f);

            //Hilbert Transform
            double[] h_arr_ht = HilbertTransform(h_arr_f);

            //moving-window integration
            double[] h_arr_i = Integration(h_arr_ht, samplingFrequency);

            //adaptive thresholding
            double[] loc_R = FindPeak(h_arr_i, signalECG);
            Vector<double> locsR = Vector<double>.Build.DenseOfArray(loc_R);

            return locsR;
        }
开发者ID:Nefarin,项目名称:DadmProject,代码行数:24,代码来源:R_Peaks_Alg.cs


注:本文中的Vector.ToArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。