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); }
public FNodeDynamicRef(FNode Parent, FNode Index, CellAffinity Affinity, Register MemoryRef) : base(Parent, FNodeAffinity.FieldRefNode) { this._idx = Index; this._affinity = Affinity; this._memory = MemoryRef; }
public AggregateCount(FNode M, Predicate F) : base(CellAffinity.INT) { this._Map = M; this._F = F; this._Sig = 1; }
public AggregateFreq(FNode M, Predicate F, Predicate G) : base(CellAffinity.DOUBLE, F) { this._M = M; this._G = G; this._Sig = 2; }
public AggregateMin(FNode M, Predicate F) : base(M.ReturnAffinity()) { this._Map = M; this._F = F; this._Sig = 1; }
// 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; }
// 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; }
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); }
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 }
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); }
// Constructor // public Lambda(string Name, FNode Expression, List<string> Parameters) { this._Expression = Expression; this._Name = Name; this._Pointers = Parameters; }
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; }
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); }
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; }
public FNode(FNode Parent, FNodeAffinity Affinity) { this._ParentNode = Parent; this._Affinity = Affinity; this._Cache = new List<FNode>(); this._UID = Guid.NewGuid(); this._name = null; }
public AggregateStat(FNode X, FNode W, Predicate F) : base(X.ReturnAffinity()) { this._MapX = X; this._MapW = W; this._F = F; this._Sig = 3; }
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; }
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; }
private FNode CompactUnit(FNode Node) { for (int i = 0; i < Node.Children.Count; i++) Node.Children[i] = CompactUnit(Node.Children[i]); return CompactSingle(Node); }
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; }
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; }
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; }
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; }
public FNodeResult(FNode Parent, CellFunction Function) : base(Parent, FNodeAffinity.ResultNode) { this._Func = Function; }
/// <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; }
// Opperands // public static FNode CompactNode(FNode Node) { FNodeCompacter lnc = new FNodeCompacter(); return lnc.Compact(Node); }
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; }
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; }
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; }
public static bool IsStaticOne(FNode Node) { if (Node.Affinity == FNodeAffinity.ValueNode) return (Node as FNodeValue).InnerValue == Cell.OneValue(Node.ReturnAffinity()); return false; }