Example #1
0
        /// <summary>
        /// Performs iteration step
        /// </summary>
        /// <returns>Sogma0</returns>
        public double Iterate()
        {
            MeasuresNames   = measurementsNames;
            SelectionsNames = selectionNames;
            Init();
            int n = Dimension;
            int l = selection.DataDimension;

            if (x == null)
            {
                x = new double[n];
            }
            else if (x.Length != n)
            {
                x = new double[n];
            }
            if (y == null)
            {
                y  = new double?[l];
                y1 = new double?[l];
            }
            else if (y.Length != l)
            {
                y  = new double?[l];
                y1 = new double?[l];
            }
            if (h == null)
            {
                h = new double?[n, l];
            }
            else if ((h.GetLength(0) != n) | (h.GetLength(1) != l))
            {
                h = new double?[n, l];
            }
            for (int i = 0; i < x.Length; i++)
            {
                IAliasName al = aliases[i];
                x[i] = (double)al.Value;

                /*!!! ====  Test of test ===========
                 * x[i] = (double) al.Value + 0.000001;
                 * //*///==============================
            }
            if (delta.Length != x.Length)
            {
                double[] d = new double[x.Length];
                for (int i = 0; (i < x.Length) & (i < delta.Length); i++)
                {
                    d[i] = delta[i];
                }
                delta = d;
            }
            method.Iterate(x, delta, dispersions, y, y1, h);
            for (int i = 0; i < x.Length; i++)
            {
                IAliasName al = aliases[i];
                al.Value = x[i];
            }
            return(standardDeviation);
        }
Example #2
0
 /// <summary>
 /// Sets aliases
 /// </summary>
 public void SetAliases()
 {
     for (int i = 0; i < x.Length; i++)
     {
         IAliasName al = aliases[i];
         al.Value = x[i];
     }
 }
Example #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="symbol">Formula symbol</param>
 /// <param name="alias">Alias object</param>
 /// <param name="name">Alias name</param>
 public AliasNameVariable(string symbol, IAlias alias, string name)
 {
     this.alias  = alias;
     this.name   = name;
     this.symbol = symbol;
     tree        = new ObjectFormulaTree(this, new List <ObjectFormulaTree>());
     aliasName   = new AliasName(alias, name);
 }
 private static IAliasName ToAnonymousName(IAliasName alias)
 {
     return(Names.Alias(alias.Identifier.ToHash()));
 }
Example #5
0
 double GetValue(IAliasName a)
 {
     return((double)a.Value);
 }
Example #6
0
 void SetDelta(IAliasName a, double delta)
 {
     a.Value = (double)a.Value + delta;
 }
Example #7
0
        /// <summary>
        /// Performs iteration
        /// </summary>
        /// <returns>Residue</returns>
        public double Iterate()
        {
            PrepareIteration();
            double           sigma = 0;
            List <IIterator> iterators;

            if (ownIterators.Count != 0)
            {
                iterators = ownIterators;
            }
            else
            {
                iterators = this.iterators;
            }
            if (iterators.Count == 0)
            {
                return(1);
            }
            foreach (IIterator it in iterators)
            {
                it.Reset();
            }
            for (int i = 0; i < a.GetLength(0); i++)
            {
                for (int j = 0; j < a.GetLength(1); j++)
                {
                    a[i, j] = d[i, j];
                }
            }
            for (int i = 0; i < z.Length; i++)
            {
                z[i] = 0;
            }
            while (true)
            {
                consumer.Reset();
                try
                {
                    consumer.UpdateChildrenData();
                }
                catch (Exception ex)
                {
                    ex.ShowError(10);
                    goto cycle;
                }
                for (int i = 0; i < y.Length; i++)
                {
                    object o = left[i].Parameter();
                    if (o == null)
                    {
                        goto cycle;
                    }
                    y[i] = (double)o;
                    o    = right[i].Parameter();
                    if (o == null | o is DBNull)
                    {
                        goto cycle;
                    }
                    double res = (double)o - y[i];
                    yr[i]  = res;
                    sigma += res * res;
                }
                for (int i = 0; i < aliases.Length; i++)
                {
                    IAliasName a     = aliases[i];
                    double     delta = dx[i];
                    SetDelta(a, delta);
                    consumer.Reset();
                    consumer.UpdateChildrenData();
                    for (int j = 0; j < y.Length; j++)
                    {
                        object obj = left[j].Parameter();
                        if (obj == null)
                        {
                            SetDelta(a, -delta);
                            goto cycle;
                        }
                        ht[i, j] = ((double)obj - y[j]) / delta;
                    }
                    SetDelta(a, -delta);
                }
                for (int i = 0; i < y.Length; i++)
                {
                    for (int j = 0; j <= i; j++)
                    {
                        mr[i, j] = (double)r[i, j].Parameter();
                        mr[j, i] = mr[i, j];
                    }
                }
                RealMatrix.Invert(mr, mr1);
                RealMatrix.Multiply(ht, mr1, htr);
                for (int i = 0; i < a.GetLength(0); i++)
                {
                    for (int k = 0; k < htr.GetLength(1); k++)
                    {
                        z[i] += htr[i, k] * yr[k];
                        for (int j = 0; j < a.GetLength(1); j++)
                        {
                            a[i, j] += htr[i, k] * ht[j, k];
                        }
                    }
                }
cycle:
                foreach (IIterator it in iterators)
                {
                    if (!it.Next())
                    {
                        goto m;
                    }
                }
            }
m:
            RealMatrix.Solve(a, z, indxa);
            for (int i = 0; i < z.Length; i++)
            {
                SetDelta(aliases[i], z[i]);
            }
            return(sigma);
        }
Example #8
0
        /// <summary>
        /// Performs full iteration
        /// </summary>
        /// <returns>Residue</returns>
        public double FullIterate()
        {
            PrepareIteration();
            for (int i = 0; i < a.GetLength(0); i++)
            {
                for (int j = 0; j < a.GetLength(1); j++)
                {
                    a[i, j] = d[i, j];
                }
            }
            for (int i = 0; i < z.Length; i++)
            {
                z[i] = 0;
            }
            currentSigma = 0;
            List <double[]> c = Calculate();
            double          s = currentSigma;

            List <double[]>[] ll = new List <double[]> [aliases.Length];
            double[,] h = new double[aliases.Length, c.Count];
            for (int i = 0; i < aliases.Length; i++)
            {
                IAliasName alias = aliases[i];
                double     delta = dx[i];
                SetDelta(alias, delta);
                ll[i] = Calculate();
                SetDelta(alias, -delta);
            }
            for (int i = 0; i < y.Length; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    mr[i, j] = (double)r[i, j].Parameter();
                    mr[j, i] = mr[i, j];
                }
            }
            RealMatrix.Invert(mr, mr1);
            for (int im = 0; im < c.Count; im++)
            {
                double[] y0 = c[im];
                for (int i = 0; i < aliases.Length; i++)
                {
                    double[] y = ll[i][im];
                    for (int j = 0; j < y.Length; j++)
                    {
                        ht[i, j] = (y[j] - y0[j]) / dx[i];
                    }
                }
                RealMatrix.Multiply(ht, mr1, htr);
                for (int i = 0; i < a.GetLength(0); i++)
                {
                    for (int k = 0; k < htr.GetLength(1); k++)
                    {
                        z[i] -= htr[i, k] * y0[k];
                        for (int j = 0; j < a.GetLength(1); j++)
                        {
                            a[i, j] += htr[i, k] * ht[j, k];
                        }
                    }
                }
            }
            RealMatrix.Solve(a, z, indxa);
            for (int i = 0; i < z.Length; i++)
            {
                SetDelta(aliases[i], z[i]);
            }
            return(s);
        }