示例#1
0
        public static FNode Generate(FNode Parent, Func<Cell[], Cell> Delegate, int Parameters, CellAffinity ReturnAffinity, string ToString)
        {

            CellFunction f = new CellFunction(ToString, Parameters, Delegate, ReturnAffinity, (x,y) => { return ToString; });
            return new FNodeResult(Parent, f);

        }
示例#2
0
 public FNodeDynamicRef(FNode Parent, FNode Index, CellAffinity Affinity, Register MemoryRef)
     : base(Parent, FNodeAffinity.FieldRefNode)
 {
     this._idx = Index;
     this._affinity = Affinity;
     this._memory = MemoryRef;
 }
示例#3
0
 public AggregateCount(FNode M, Predicate F)
     : base(CellAffinity.INT)
 {
     this._Map = M;
     this._F = F;
     this._Sig = 1;
 }
示例#4
0
 public AggregateFreq(FNode M, Predicate F, Predicate G)
     : base(CellAffinity.DOUBLE, F)
 {
     this._M = M;
     this._G = G;
     this._Sig = 2;
 }
示例#5
0
 public AggregateMin(FNode M, Predicate F)
     : base(M.ReturnAffinity())
 {
     this._Map = M;
     this._F = F;
     this._Sig = 1;
 }
示例#6
0
        // Compact all //
        public FNode Compact(FNode Node)
        {

            // Clone the current node //
            //FNode t = Node.CloneOfMe();

            this._Tocks = 1;
            while (this._Tocks != 0)
            {

                // Reset the tock variables //
                this._Tocks = 0;

                // Compact the leaf node; note that we may need to do this again //
                Node = CompactUnit(Node);

                // Accumulate the ticks //
                this._Ticks += this._Tocks;

                // Accumulate the cycles //
                this._Cycles++;

            }

            // return the compacted node //
            return Node;

        }
示例#7
0
        // A - A -> 0
        // A / A -> 1
        private FNode CompactCancleOut(FNode Node)
        {

            if (Node.Affinity != FNodeAffinity.ResultNode)
                return Node;

            FNodeResult x = (Node as FNodeResult);
            string name = x.InnerFunction.NameSig;

            // Check that the node is either - or / //
            if (name != FunctionNames.OP_SUB && name != FunctionNames.OP_DIV && name != FunctionNames.OP_DIV2)
                return Node;

            // Build an equality checker //
            IEqualityComparer<FNode> lne = new FNodeEquality();

            // Check if A == B //
            if (!lne.Equals(Node.Children[0], Node.Children[1]))
                return Node;

            // Check for A - A -> 0 //
            if (name == FunctionNames.OP_SUB)
                return new FNodeValue(Node.ParentNode, Cell.ZeroValue(CellAffinity.DOUBLE));

            // Check for A - A -> 0 //
            if (name == FunctionNames.OP_DIV || name == FunctionNames.OP_DIV2)
                return new FNodeValue(Node.ParentNode, Cell.OneValue(CellAffinity.DOUBLE));

            return Node;

        }
示例#8
0
 public static Predicate Equals(FNode Left, FNode Right)
 {
     FNodeResult node = new FNodeResult(null, CellFunctionFactory.LookUp("=="));
     node.AddChildNode(Left);
     node.AddChildNode(Right);
     return new Predicate(node);
 }
示例#9
0
 public HParameter(FNode Value)
 {
     this._affinity = HParameterAffinity.Expression;
     this._expression = Value;
     this._expression_set = new FNodeSet();
     this._expression_set.Add(Value); // in case a set of one was passed 
 }
示例#10
0
 public FNodeHeapRef(FNode Parent, MemoryStruct Heap, int DirectRef, CellAffinity ReturnType)
     : base(Parent, FNodeAffinity.HeapRefNode)
 {
     this._Pointer = DirectRef;
     this._Heap = Heap;
     this._ReturnType = ReturnType;
     this._name = Heap.Scalars.Name(DirectRef);
 }
示例#11
0
文件: Lambda.cs 项目: pwdlugosz/Horse
 // Constructor //
 public Lambda(string Name, FNode Expression, List<string> Parameters)
 {
     
     this._Expression = Expression;
     this._Name = Name;
     this._Pointers = Parameters;
     
 }
示例#12
0
 public FNodeFieldRef(FNode Parent, int Index, CellAffinity Affinity, int FSize, Register MemoryRef)
     : base(Parent, FNodeAffinity.FieldRefNode)
 {
     this._idx = Index;
     this._affinity = Affinity;
     this._memory = MemoryRef;
     this._size = FSize;
 }
示例#13
0
 public FNodePointer(FNode Parent, string RefName, CellAffinity Type, int Size)
     : base(Parent, FNodeAffinity.PointerNode)
 {
     this._Type = Type;
     this._NameID = RefName;
     this._name = RefName;
     this._Size = Schema.FixSize(Type, Size);
 }
示例#14
0
 public FNodeArrayDynamicRef(FNode Parent, FNode Row, FNode Col, MemoryStruct Heap, int DirectRef)
     : base(Parent, FNodeAffinity.MatrixRefNode)
 {
     this._RowIndex = Row;
     this._ColIndex = Col;
     this._DirectRef = DirectRef;
     this._Heap = Heap;
 }
示例#15
0
文件: FNode.cs 项目: pwdlugosz/Horse
 public FNode(FNode Parent, FNodeAffinity Affinity)
 {
     this._ParentNode = Parent;
     this._Affinity = Affinity;
     this._Cache = new List<FNode>();
     this._UID = Guid.NewGuid();
     this._name = null;
 }
示例#16
0
 public AggregateStat(FNode X, FNode W, Predicate F)
     : base(X.ReturnAffinity())
 {
     this._MapX = X;
     this._MapW = W;
     this._F = F;
     this._Sig = 3;
 }
示例#17
0
        private int _AssignID; // 0 == assign, 1 == increment, 2 == decrement, 3 == auto increment, 4 == auto decrement

        /// <summary>
        /// Create an assignment action
        /// </summary>
        /// <param name="Parent">Parent node</param>
        /// <param name="Heap">The memory heap to work off of</param>
        /// <param name="Index">The direct location of the variable in the heap</param>
        /// <param name="Map">The expression to assign to</param>
        /// <param name="AssignID">0 == assign, 1 == increment, 2 == decrement, 3 == auto increment, 4 == auto decrement</param>
        public TNodeAssignScalar(TNode Parent, MemoryStruct Heap, int Index, FNode Map, int AssignID)
            : base(Parent)
        {
            this._Heap = Heap;
            this._Mapping = Map;
            this._Index = Index;
            this._AssignID = AssignID;
        }
示例#18
0
        private int _AssignID; // 0 == assign, 1 == increment, 2 == decrement, 3 == auto increment, 4 == auto decrement

        public TNodeMatrixUnitAssign(TNode Parent, CellMatrix Data, FNode Node, FNode RowID, FNode ColumnID, int AssignID)
            : base(Parent)
        {
            this._matrix = Data;
            this._Node = Node;
            this._AssignID = AssignID;
            this._row_id = RowID;
            this._col_id = ColumnID;
        }
示例#19
0
        private FNode CompactUnit(FNode Node)
        {

            for (int i = 0; i < Node.Children.Count; i++)
                Node.Children[i] = CompactUnit(Node.Children[i]);

            return CompactSingle(Node);

        }
示例#20
0
        public GeneralizedLinearModel(string Name, DataSet Data, Predicate Where, FNode Expected, FNodeSet Actual, FNode Weight, Lambda LinkFunction)
            : base(Name, Data, Where, Expected, Actual, Weight)
        {

            int val = IsCorrectLink(LinkFunction);
            if (val == -1)
                throw new Exception("Link function must have exactly one argument");
            else if (val == -2)
                throw new Exception("Link function is not differentiable");
            this._Link = LinkFunction;
 
        }
示例#21
0
 public RowCluster(string Name, DataSet Data, Predicate Where, FNodeSet Fields, FNode Weight, int Count)
 {
     this._data = Data;
     this._where = Where;
     this._fields = Fields;
     this._count = Count;
     this._rule = new RowClusterRuleEuclid();
     this._initializer = new RowClusterInitializerSpectrum();
     this._means = this._initializer.Initialize(Data, Where, Fields, Count);
     this._weight = Weight;
     this.Name = Name;
 }
示例#22
0
        private FNode CompactSingle(FNode Node)
        {

            // The order we do these is optimized to reduce the number of tock loops //
            Node = CompactPower(Node);
            Node = CompactMultDivMod(Node);
            Node = CompactAddSub(Node);
            Node = CompactUni(Node);
            Node = CompactCancleOut(Node);
            Node = CompactStaticArguments(Node);

            return Node;

        }
示例#23
0
        public NonlinearRegressionModel(string Name, DataSet Data, Predicate Where, FNode YValue, FNode Equation, FNode Weight)
            : base(Name, Data, Where, YValue, null, Weight)
        {
            
            // Save the equation //
            this._equation = Equation;

            // Create the parameter map //
            this._map = NonlinearRegressionModel.MapParameters(this._equation);

            // Set the X nodes equal to the partial gradients //
            this._XValue = NonlinearRegressionModel.Gradients(this._equation, this._map);

            // Need to initialize the matricies and vectors since the base ctor would not because XValues were passed as null //
            this.InitializeMatricies(this._XValue.Count);

            // Set the model to not strict //
            this.IsStrict = false;

            // Allow for more itterations //
            this._MaximumIterations = 20;

        }
示例#24
0
 public FNodeResult(FNode Parent, CellFunction Function)
     : base(Parent, FNodeAffinity.ResultNode)
 {
     this._Func = Function;
 }
示例#25
0
        /// <summary>
        /// Binds a leaf node to another node
        /// </summary>
        /// <param name="MainNode">The node containing a pointer node that will be bound</param>
        /// <param name="ParameterNode">The node that will be bound to the MainNode</param>
        /// <param name="PointerNodeName">The name of the pointer the ParameterNode will be replacing</param>
        /// <returns></returns>
        public static FNode Bind(FNode MainNode, FNode ParameterNode, string PointerNodeName)
        {

            // Clone the main node //
            FNode t = MainNode.CloneOfMe();

            // Decompile t //
            List<FNodePointer> refs = FNodeAnalysis.AllPointers(t);

            // Replace the pointer node with the parameter node //
            foreach (FNodePointer x in refs)
            {
                if (x.PointerName == PointerNodeName)
                    FNodeAnalysis.ReplaceNode(x, ParameterNode);
            }

            return t;

        }
示例#26
0
 // Opperands //
 public static FNode CompactNode(FNode Node)
 {
     FNodeCompacter lnc = new FNodeCompacter();
     return lnc.Compact(Node);
 }
示例#27
0
        public static bool ChildrenAreAllStatic(FNode Node)
        {

            if (Node.IsTerminal)
                return false;

            foreach (FNode n in Node.Children)
            {
                if (n.Affinity != FNodeAffinity.ValueNode)
                    return false;
            }
            return true;

        }
示例#28
0
 public static bool IsUniNegative(FNode Node)
 {
     if (Node.Affinity == FNodeAffinity.ResultNode)
     {
         FNodeResult x = (Node as FNodeResult);
         return x.InnerFunction.NameSig == FunctionNames.UNI_MINUS;
     }
     return false;
 }
示例#29
0
 public static bool IsStaticMinusOne(FNode Node)
 {
     if (Node.Affinity == FNodeAffinity.ValueNode)
         return (Node as FNodeValue).InnerValue == -Cell.OneValue(Node.ReturnAffinity());
     if (Node.Affinity == FNodeAffinity.ResultNode)
     {
         FNodeResult x = (Node as FNodeResult);
         if (x.InnerFunction.NameSig == FunctionNames.UNI_MINUS && IsStaticOne(x.Children[0]))
             return true;
     }
     return false;
 }
示例#30
0
 public static bool IsStaticOne(FNode Node)
 {
     if (Node.Affinity == FNodeAffinity.ValueNode)
         return (Node as FNodeValue).InnerValue == Cell.OneValue(Node.ReturnAffinity());
     return false;
 }