Example #1
0
        private void grad(IElementalAccessMatrix dy, IElementalAccessVector x)
        {
            IElementalAccessVector y0 = new DenseVector(x.Length);
            IElementalAccessVector y  = new DenseVector(x.Length);

            model(y0, x);
            for (int i = 0; i < x.Length; i++)
            {
                x.AddValue(i, 0.000001);
                model(y, x);
                for (int j = 0; j < x.Length; j++)
                {
                    dy.SetValue(j, i, (y.GetValue(j) - y0.GetValue(j)) / 0.000001);
                }
                x.AddValue(i, -0.000001);
            }
        }
Example #2
0
        /// <summary> Assembly using addValue</summary>
        /// <param name="nu">Maximum number of entries
        /// </param>
        /// <returns> Dense representation (not a direct copy)
        /// </returns>
        public static double[] addAssembleVector(IElementalAccessVector x, int nu)
        {
            int n = x.Length;

            double[]      data = new double[n];
            System.Random r    = new System.Random();

            for (int i = 0; i < nu; ++i)
            {
                int    ind   = TesterUtilities.getInt(n, r);
                double entry = r.NextDouble();
                data[ind] += entry;
                x.AddValue(ind, entry);
            }

            return(data);
        }