private static void AppendSet(ExpressionVisitor Evaluator, FNodeSet Fields, HScriptParser.EOW_tables_starContext context) { if (Evaluator.Columns.Count == 0) return; // no need to toss an exception string alias = Evaluator.Columns.Keys.First(); FNodeSet nodes = new FNodeSet(Evaluator.Columns[alias]); nodes.AssignRegister(Evaluator.Registers[alias]); string suffix = (context.K_AS() == null) ? null : context.IDENTIFIER().GetText(); for (int i = 0; i < nodes.Count; i++) { Fields.Add((suffix == null) ? nodes.Alias(i) : suffix + nodes.Alias(i), nodes[i]); } }
private static void AppendSet(ExpressionVisitor Evaluator, FNodeSet Fields, HScriptParser.EOW_table_starContext context) { string alias = context.IDENTIFIER()[0].GetText(); if (!Evaluator.Columns.ContainsKey(alias)) throw new Exception(string.Format("Alias '{0}' does not exist", alias)); FNodeSet nodes = new FNodeSet(Evaluator.Columns[alias]); nodes.AssignRegister(Evaluator.Registers[alias]); string suffix = (context.K_AS() == null) ? null : context.IDENTIFIER()[1].GetText(); for (int i = 0; i < nodes.Count; i++) { Fields.Add((suffix == null) ? nodes.Alias(i) : suffix + nodes.Alias(i), nodes[i]); } }
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 override RecordSet Initialize(DataSet Data, Predicate Where, FNodeSet Fields, int Clusters) { // Get the min of each field // AggregateSet set1 = new AggregateSet(); for (int i = 0; i < Fields.Count; i++) { set1.Add(new AggregateMin(Fields[i].CloneOfMe()), Fields.Alias(i)); } // Get the max of each field // AggregateSet set2 = new AggregateSet(); for (int i = 0; i < Fields.Count; i++) { set2.Add(new AggregateMax(Fields[i].CloneOfMe()), Fields.Alias(i)); } // Render the min and max // RecordSet rs1 = AggregatePlan.Render(Data, Where, new FNodeSet(), set1); RecordSet rs2 = AggregatePlan.Render(Data, Where, new FNodeSet(), set2); // Create the output means table // RecordSet rs = new RecordSet(Schema.Join(new Schema("key int, count double"), rs1.Columns)); // Fill in the gaps // for (int i = 0; i < Clusters; i++) { if (i == 0) { RecordBuilder rb = new RecordBuilder(); rb.Add(0); rb.Add(0D); rb.Add(rs1[0]); rs.Add(rb.ToRecord()); } else if (i == Clusters - 1) { RecordBuilder rb = new RecordBuilder(); rb.Add(Clusters - 1); rb.Add(0D); rb.Add(rs2[0]); rs.Add(rb.ToRecord()); } else { RecordBuilder rb = new RecordBuilder(); rb.Add(i); rb.Add(0D); for (int j = 0; j < rs1.Columns.Count; j++) { double clus = (double)Clusters; double jay = (double)j; rb.Add(rs1[0][j].DOUBLE + (rs2[0][j].DOUBLE - rs1[0][j].DOUBLE) / clus * jay); } rs.Add(rb.ToRecord()); } } return rs; }
public override RecordSet Initialize(DataSet Data, Predicate Where, FNodeSet Fields, int Clusters) { AggregateSet set = new AggregateSet(); set.Add(new AggregateSum(FNodeFactory.Value(1D)), "CLUSTER_ELEMENT_COUNT"); for (int i = 0; i < Fields.Count; i++) { set.Add(new AggregateAverage(Fields[i].CloneOfMe()), Fields.Alias(i)); } FNode rnd = new FNodeResult(null, new CellRandomInt()); rnd.AddChildNode(new FNodeValue(rnd, new Cell(this.Seed))); rnd.AddChildNode(new FNodeValue(rnd, new Cell(0))); rnd.AddChildNode(new FNodeValue(rnd, new Cell(Clusters))); FNodeSet keys = new FNodeSet(); keys.Add(rnd); RecordSet rs = AggregatePlan.Render(Data, Where, keys, set); return rs; }
private void Render(DataSet Data, FNodeSet X_Values, FNodeSet Y_Values, Predicate Where) { FNodeSet outputs = new FNodeSet(); for (int i = 0; i < Y_Values.Count; i++) { outputs.Add("Y_" + Y_Values.Alias(i), Y_Values[i].CloneOfMe()); } // Build the reader fnode-set // FNodeSet nodes = FNodeSet.Union(X_Values, outputs); // Construct the keys // this.InputKey = Key.Build(X_Values.Count); this.OutputKey = Key.Build(X_Values.Count, Y_Values.Count); // Build the data // DataSet rs = QuarterHorse.FastReadPlan.Render(Data, Where, nodes, this._max_record_count); this.ScrubbedData = Matrix.ToMatrix(rs.ToRecordSet); }