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


C# Vector.CopyTo方法代码示例

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


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

示例1: ExplanotorySearch

        /// <summary>
        /// Передаются ссылки, point и delta будут изменены 
        /// </summary>
        /// <param name="delta"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        private Vector<double> ExplanotorySearch( Vector<double> point, Vector<double> delta)
        {
            var nvars = delta.Count;
            var prevbest = Fh.Y(point);
            var z = new DenseVector(nvars);

            point.CopyTo(z);

            int i;
            var minf = prevbest;

            for (i = 0; i < nvars; i++)
            {
                z[i] = point[i] + delta[i];
                var ftmp = Fh.Y(z);
                if (ftmp < minf)
                    minf = ftmp;
                else
                {
                    z[i] = point[i]  -delta[i];
                    ftmp = Fh.Y(z);
                    if (ftmp < minf)
                        minf = ftmp;
                    else
                    {
                        z[i] = point[i];
                    }
                }
            }

            return z;
        }
开发者ID:OlegFilimonov,项目名称:optimisation,代码行数:38,代码来源:HookeJeevesPS.cs

示例2: Solve

        /// <summary>
        /// Solves a system of linear equations, <b>Ax = b</b>, with A Cholesky factorized.
        /// </summary>
        /// <param name="input">The right hand side vector, <b>b</b>.</param>
        /// <param name="result">The left hand side <see cref="Matrix{T}"/>, <b>x</b>.</param>
        public override void Solve(Vector<Complex32> input, Vector<Complex32> result)
        {
            // Check for proper arguments.
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            // Check for proper dimensions.
            if (input.Count != result.Count)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            if (input.Count != CholeskyFactor.RowCount)
            {
                throw new ArgumentException(Resources.ArgumentMatrixDimensions);
            }

            input.CopyTo(result);
            var order = CholeskyFactor.RowCount;

            // Solve L*Y = B;
            Complex32 sum;
            for (var i = 0; i < order; i++)
            {
                sum = result[i];
                for (var k = i - 1; k >= 0; k--)
                {
                    sum -= CholeskyFactor.At(i, k) * result[k];
                }

                result[i] = sum / CholeskyFactor.At(i, i);
            }

            // Solve L'*X = Y;
            for (var i = order - 1; i >= 0; i--)
            {
                sum = result[i];
                for (var k = i + 1; k < order; k++)
                {
                    sum -= CholeskyFactor.At(k, i).Conjugate() * result[k];
                }

                result[i] = sum / CholeskyFactor.At(i, i);
            }
        }
开发者ID:jvangael,项目名称:mathnet-numerics,代码行数:57,代码来源:UserCholesky.cs

示例3: Solve

        /// <summary>
        /// Solves a system of linear equations, <b>Ax = b</b>, with A Cholesky factorized.
        /// </summary>
        /// <param name="input">The right hand side vector, <b>b</b>.</param>
        /// <param name="result">The left hand side <see cref="Matrix{T}"/>, <b>x</b>.</param>
        public override void Solve(Vector<float> input, Vector<float> result)
        {
            if (input.Count != result.Count)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            if (input.Count != Factor.RowCount)
            {
                throw Matrix.DimensionsDontMatch<ArgumentException>(input, Factor);
            }

            input.CopyTo(result);
            var order = Factor.RowCount;

            // Solve L*Y = B;
            float sum;
            for (var i = 0; i < order; i++)
            {
                sum = result[i];
                for (var k = i - 1; k >= 0; k--)
                {
                    sum -= Factor.At(i, k)*result[k];
                }

                result[i] = sum/Factor.At(i, i);
            }

            // Solve L'*X = Y;
            for (var i = order - 1; i >= 0; i--)
            {
                sum = result[i];
                for (var k = i + 1; k < order; k++)
                {
                    sum -= Factor.At(k, i)*result[k];
                }

                result[i] = sum/Factor.At(i, i);
            }
        }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:45,代码来源:UserCholesky.cs

示例4: Approximate

        /// <summary>
        /// Approximates the solution to the matrix equation <b>Ax = b</b>.
        /// </summary>
        /// <param name="rhs">The right hand side vector.</param>
        /// <param name="lhs">The left hand side vector. Also known as the result vector.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="rhs"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="lhs"/> is <see langword="null"/>. </exception>
        /// <exception cref="ArgumentException">
        ///   <para>
        ///     If <paramref name="rhs"/> and <paramref name="lhs"/> do not have the same size.
        ///   </para>
        ///   <para>
        ///     - or -
        ///   </para>
        ///   <para>
        ///     If the size of <paramref name="rhs"/> is different the number of rows of the coefficient matrix.
        ///   </para>
        /// </exception>
        public void Approximate(Vector rhs, Vector lhs)
        {
            if (rhs == null)
            {
                throw new ArgumentNullException("rhs");
            }

            if (lhs == null)
            {
                throw new ArgumentNullException("lhs");
            }

            if ((lhs.Count != rhs.Count) || (lhs.Count != _size))
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            rhs.CopyTo(lhs);
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:37,代码来源:UnitPreconditioner.cs

示例5: Solve

        /// <summary>
        /// Solves a system of linear equations, <c>Ax = b</c>, with A LU factorized.
        /// </summary>
        /// <param name="input">The right hand side vector, <c>b</c>.</param>
        /// <param name="result">The left hand side <see cref="Matrix{T}"/>, <c>x</c>.</param>
        public override void Solve(Vector<double> input, Vector<double> result)
        {
            // Check for proper arguments.
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            // Check for proper dimensions.
            if (input.Count != result.Count)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            if (input.Count != Factors.RowCount)
            {
                throw new ArgumentException(Resources.ArgumentMatrixDimensions);
            }

            // Copy the contents of input to result.
            input.CopyTo(result);
            for (var i = 0; i < Pivots.Length; i++)
            {
                if (Pivots[i] == i)
                {
                    continue;
                }

                var p = Pivots[i];
                var temp = result[p];
                result[p] = result[i];
                result[i] = temp;
            }
            
            var order = Factors.RowCount;

            // Solve L*Y = P*B
            for (var k = 0; k < order; k++)
            {
                for (var i = k + 1; i < order; i++)
                {
                    result[i] -= result[k] * Factors.At(i, k);
                }
            }

            // Solve U*X = Y;
            for (var k = order - 1; k >= 0; k--)
            {
                result[k] /= Factors.At(k, k);
                for (var i = 0; i < k; i++)
                {
                    result[i] -= result[k] * Factors.At(i, k);
                }
            }
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:65,代码来源:UserLU.cs

示例6: learnBptt

        private void learnBptt()
        {
            for (int step = 0; step < bptt + bptt_block - 2; step++)
            {
                if (null == bptt_inputs[step] && null == bptt_fea[step])
                    break;

                var sparse = bptt_inputs[step];
                var bptt_fea_step = bptt_fea[step];
                var last_bptt_hidden = bptt_hidden[step + 1];
                var last_last_bptt_hidden = bptt_hidden[step + 2];
                Parallel.For(0, LayerSize, parallelOption, a =>
                {
                    // compute hidden layer gradient
                    er[a] *= cellOutput[a] * (1 - cellOutput[a]);

                    //dense weight update fea->0
                    double[] vector_a = null;
                    double er2 = er[a];
                    Vector<double> vecErr = new Vector<double>(er2);

                    int i = 0;
                    if (DenseFeatureSize > 0)
                    {
                        vector_a = DenseWeightsDelta[a];
                        i = 0;
                        while (i < DenseFeatureSize - Vector<double>.Count)
                        {
                            Vector<double> v1 = new Vector<double>(bptt_fea_step, i);
                            Vector<double> v2 = new Vector<double>(vector_a, i);
                            v2 += vecErr * v1;
                            v2.CopyTo(vector_a, i);

                            i += Vector<double>.Count;
                        }

                        while (i < DenseFeatureSize)
                        {
                            vector_a[i] += er2 * bptt_fea_step[i];
                            i++;
                        }
                    }

                    if (SparseFeatureSize > 0)
                    {
                        //sparse weight update hidden->input
                        vector_a = SparseWeightsDelta[a];
                        for (i = 0; i < sparse.Count; i++)
                        {
                            var entry = sparse.GetEntry(i);
                            vector_a[entry.Key] += er2 * entry.Value;
                        }
                    }

                    //bptt weight update
                    vector_a = BpttWeightsDelta[a];
                    i = 0;
                    while (i < LayerSize - Vector<double>.Count)
                    {
                        Vector<double> v1 = new Vector<double>(previousCellOutput, i);
                        Vector<double> v2 = new Vector<double>(vector_a, i);
                        v2 += vecErr * v1;
                        v2.CopyTo(vector_a, i);

                        i += Vector<double>.Count;
                    }

                    while (i < LayerSize)
                    {
                        vector_a[i] += er2 * previousCellOutput[i];
                        i++;
                    }

                });

                //propagates errors hidden->input to the recurrent part
                double[] previousHiddenErr = new double[LayerSize];
                RNNHelper.matrixXvectorADDErr(previousHiddenErr, er, BpttWeights, LayerSize, LayerSize);

                for (int a = 0; a < LayerSize; a++)
                {
                    //propagate error from time T-n to T-n-1
                    er[a] = previousHiddenErr[a] + last_bptt_hidden.er[a];
                }
                if (step < bptt + bptt_block - 3)
                {
                    for (int a = 0; a < LayerSize; a++)
                    {
                        cellOutput[a] = last_bptt_hidden.cellOutput[a];
                        previousCellOutput[a] = last_last_bptt_hidden.cellOutput[a];
                    }
                }
            }

            //restore hidden layer after bptt
            bptt_hidden[0].cellOutput.CopyTo(cellOutput, 0);

            Parallel.For(0, LayerSize, parallelOption, b =>
            {
                double[] vector_b = null;
//.........这里部分代码省略.........
开发者ID:dmit25,项目名称:RNNSharp,代码行数:101,代码来源:BPTTLayer.cs

示例7: UpdateBigramTransition

        public void UpdateBigramTransition(Sequence seq)
        {
            int OutputLayerSize = OutputLayer.LayerSize;
            int numStates = seq.States.Length;
            Matrix<double> m_DeltaBigramLM = new Matrix<double>(OutputLayerSize, OutputLayerSize);

            for (int timeat = 1; timeat < numStates; timeat++)
            {
                double[] CRFSeqOutput_timeat = CRFSeqOutput[timeat];
                double[] CRFSeqOutput_pre_timeat = CRFSeqOutput[timeat - 1];
                for (int i = 0; i < OutputLayerSize; i++)
                {
                    double CRFSeqOutput_timeat_i = CRFSeqOutput_timeat[i];
                    double[] CRFTagTransWeights_i = CRFTagTransWeights[i];
                    double[] m_DeltaBigramLM_i = m_DeltaBigramLM[i];
                    int j = 0;

                    Vector<double> vecCRFSeqOutput_timeat_i = new Vector<double>(CRFSeqOutput_timeat_i);
                    while (j < OutputLayerSize - Vector<double>.Count)
                    {
                        Vector<double> v1 = new Vector<double>(CRFTagTransWeights_i, j);
                        Vector<double> v2 = new Vector<double>(CRFSeqOutput_pre_timeat, j);
                        Vector<double> v = new Vector<double>(m_DeltaBigramLM_i, j);

                        v -= (v1 * vecCRFSeqOutput_timeat_i * v2);
                        v.CopyTo(m_DeltaBigramLM_i, j);

                        j += Vector<double>.Count;
                    }

                    while (j < OutputLayerSize)
                    {
                        m_DeltaBigramLM_i[j] -= (CRFTagTransWeights_i[j] * CRFSeqOutput_timeat_i * CRFSeqOutput_pre_timeat[j]);
                        j++;
                    }
                }

                int iTagId = seq.States[timeat].Label;
                int iLastTagId = seq.States[timeat - 1].Label;
                m_DeltaBigramLM[iTagId][iLastTagId] += 1;
            }

            //Update tag Bigram LM
            for (int b = 0; b < OutputLayerSize; b++)
            {
                double[] vector_b = CRFTagTransWeights[b];
                double[] vector_delta_b = m_DeltaBigramLM[b];
                int a = 0;

                while (a < OutputLayerSize - Vector<double>.Count)
                {
                    Vector<double> v1 = new Vector<double>(vector_delta_b, a);
                    Vector<double> v = new Vector<double>(vector_b, a);

                    //Normalize delta
                    v1 = RNNHelper.NormalizeGradient(v1);

                    //Update weights
                    v += RNNHelper.vecNormalLearningRate * v1;
                    v.CopyTo(vector_b, a);

                    a += Vector<double>.Count;
                }

                while (a < OutputLayerSize)
                {
                    vector_b[a] += RNNHelper.LearningRate * RNNHelper.NormalizeGradient(vector_delta_b[a]);
                    a++;
                }
            }
        }
开发者ID:dmit25,项目名称:RNNSharp,代码行数:71,代码来源:RNN.cs

示例8: Softmax

        public void Softmax(SimpleLayer outputLayer)
        {
            double sum = 0;
            for (int c = 0; c < outputLayer.LayerSize; c++)
            {
                double cellOutput = outputLayer.cellOutput[c];
                if (cellOutput > 50) cellOutput = 50;
                if (cellOutput < -50) cellOutput = -50;
                double val = Math.Exp(cellOutput);
                sum += val;
                outputLayer.cellOutput[c] = val;
            }
            int i = 0;
            Vector<double> vecSum = new Vector<double>(sum);
            while (i < outputLayer.LayerSize - Vector<double>.Count)
            {
                Vector<double> v = new Vector<double>(outputLayer.cellOutput, i);
                v /= vecSum;
                v.CopyTo(outputLayer.cellOutput, i);
                i += Vector<double>.Count;
            }

            while (i < outputLayer.LayerSize)
            {
                outputLayer.cellOutput[i] /= sum;
                i++;
            }
        }
开发者ID:dmit25,项目名称:RNNSharp,代码行数:28,代码来源:RNN.cs


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