Esempio n. 1
0
 public static CellVector operator -(CellVector A, Cell B)
 {
     CellVector C = new CellVector(A.Count, A.Affinity);
     for (int i = 0; i < A.Count; i++)
         C[i] = A[i] - B;
     return C;
 }
Esempio n. 2
0
 public static CellVector operator +(Cell B, CellVector A)
 {
     CellVector C = new CellVector(A.Count, A.Affinity);
     for (int i = 0; i < A.Count; i++)
         C[i] = B + A[i];
     return C;
 }
Esempio n. 3
0
        public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrix1DContext context)
        {

            string name = context.IDENTIFIER().GetText();
            CellAffinity type = GetAffinity(context.type());
            int rows = (int)Evaluator.ToNode(context.expression()).Evaluate().valueINT;
            CellMatrix mat = new CellVector(rows, type);
            Heap.Arrays.Reallocate(name, mat);

        }
        public static FNodeSet BindNodes(FNodeSet Gradients, CellVector Parameters, Dictionary<string, int> Map)
        {

            if (Gradients.Count != Parameters.Count)
                throw new ArgumentException("The node collection and parameter vector must be the same size");

            FNodeSet nodes = new FNodeSet();
            for (int i = 0; i < Gradients.Count; i++)
            {
                FNode t = NonlinearRegressionModel.BindNode(Gradients[i], Parameters, Map);
                nodes.Add(Gradients.Alias(i), t);
            }

            return nodes;

        }
        public static FNode BindNode(FNode Equation, CellVector Bindings, Dictionary<string, int> Map)
        {

            FNode t = Equation.CloneOfMe();
            foreach(KeyValuePair<string,int> kv in Map)
            {
                string name = kv.Key;
                int idx = kv.Value;
                FNode b = new FNodeValue(null, Bindings[idx]);
                t = FNodeCompacter.Bind(t, b, name);
            }

            return t;

        }
Esempio n. 6
0
        private void CalculateVariance()
        {

            if (this._means.Count != this._stats.Count)
                return;

            this._within_variance = new CellVector(this._count, CellValues.ZERO_DOUBLE);
            this._between_variance = new CellVector(this._count, CellValues.ZERO_DOUBLE);
            CellVector m = new CellVector(this._count, CellValues.ZERO_DOUBLE);
            CellVector n = new CellVector(this._count, CellValues.ZERO_DOUBLE);

            for (int i = 0; i < this._means.Count; i++)
            {

                for (int j = 2; j < this._means.Columns.Count; j++)
                {
                    this._within_variance[j - 2] += this._stats[i][j] * this._stats[i][1];
                    n[j - 2] += this._means[i][1];
                    m[j - 2] += this._means[i][j] * this._means[i][1];
                    this._between_variance[j - 2] += this._means[i][j] * this._means[i][j] * this._means[i][1];
                }

            }

            for (int i = 0; i < this._between_variance.Count; i++)
            {
                m[i] = m[i] / n[i];
                this._between_variance[i] = (this._between_variance[i] / n[i] - m[i] * m[i]) * n[i];
            }

            Console.WriteLine(this._within_variance);
        }
Esempio n. 7
0
 public CellVector(CellVector Value)
     : base(Value)
 {
 }
Esempio n. 8
0
        public static CellVector Parse(string Text, CellAffinity Affinity)
        {

            string[] values = Text.Split(',');
            CellVector v = new CellVector(values.Length, Affinity);
            for (int i = 0; i < values.Length; i++)
            {
                v[i] = Cell.Parse(values[i], Affinity);
            }

            return v;

        }
Esempio n. 9
0
        public static Cell DotProduct(CellVector A, CellVector B)
        {

            if (A.Count != B.Count)
                throw new ArgumentException("Both vectors passed must have the same lengh");

            Cell c = Cell.ZeroValue(A.Affinity);

            for (int i = 0; i < A.Count; i++)
                c += A[i] * B[i];

            return c;

        }
Esempio n. 10
0
        public static CellVector ForEach(CellVector A, Func<Cell, Cell> Delegate, CellAffinity ReturnType)
        {
            
            CellVector B = new CellVector(A.Count, ReturnType);
            for (int i = 0; i < A.Count; i++)
            {
                B[i] = Delegate(A[i]);
            }

            return B;

        }
Esempio n. 11
0
 public static CellVector CheckDivide(CellVector A, CellVector B)
 {
     CellVector C = new CellVector(A.Count, B.Affinity);
     Cell zero = new Cell(B.Affinity);
     for (int i = 0; i < A.Count; i++)
         C[i] = (B[i].IsZero ? A[i] / B[i] : zero);
     return C;
 }
Esempio n. 12
0
 public static CellVector CheckDivide(Cell B, CellVector A)
 {
     CellVector C = new CellVector(A.Count, B.Affinity);
     Cell zero = new Cell(B.AFFINITY);
     for (int i = 0; i < A.Count; i++)
         C[i] = (A[i].IsZero ? B / A[i] : zero);
     return C;
 }
Esempio n. 13
0
 public static CellVector CheckDivide(CellVector A, Cell B)
 {
     if (B.IsZero)
         return new CellVector(A.Count, Cell.ZeroValue(A.Affinity));
     return A / B;
 }
Esempio n. 14
0
 public static CellVector operator /(CellVector A, CellVector B)
 {
     CellVector C = new CellVector(A.Count, A.Affinity);
     for (int i = 0; i < A.Count; i++)
     {
         C[i] = A[i] / B[i];
     }
     return C;
 }