示例#1
0
        public static Record MonoChromeBitmapToRecord(Bitmap Map)
        {

            RecordBuilder factory = new RecordBuilder();
            for (int x = 0; x < Map.Height; x++)
            {

                for (int y = 0; y < Map.Width; y++)
                {

                    if (Map.GetPixel(x, y).ToArgb() == Color.Black.ToArgb())
                    {
                        factory.Add(1D);
                    }
                    else
                    {
                        factory.Add(0D);
                    }

                }

            }
            return factory.ToRecord();

        }
示例#2
0
        // Records //
        public static Record ToRecord(string Text, Schema Columns, char[] Delims, char Escape)
        {

            // Split the data //
            string[] t = Splitter.Split(Text, Delims, Escape, false, Cell.NULL_STRING_TEXT);

            // Check the length //
            if (t.Length != Columns.Count)
                throw new Exception(string.Format("Text has {0} fields, but schema has {1} fields", t.Length, Columns.Count));

            // Build the record //
            RecordBuilder rb = new RecordBuilder();
            for (int i = 0; i < t.Length; i++)
                rb.Add(Cell.Parse(t[i], Columns.ColumnAffinity(i)));
            
            return rb.ToRecord();

        }
示例#3
0
        public void ImportFromInterim(RecordSet InterimData)
        {

            int MapperCount = this.BaseMappers.Count;
            int[] Signiture = this.BaseReducers.Signiture;
            int TotalCellCount = MapperCount + Signiture.Sum();

            // Check that this is the correct size //
            if (InterimData.Columns.Count != TotalCellCount)
                throw new Exception(string.Format("RecordSet passed [{0}] has few columns than required by deserializer [{1}]", InterimData.Columns.Count, TotalCellCount));

            // Import the data //
            for (int i = 0; i < InterimData.Count; i++)
            {

                // Build map key //
                RecordBuilder KeyBuilder = new RecordBuilder();
                for (int j = 0; j < MapperCount; j++)
                {
                    KeyBuilder.Add(InterimData[i][j]);
                }

                // Build compound record //
                RecordBuilder ValueBuilder = new RecordBuilder();
                for (int j = MapperCount; j < TotalCellCount; j++)
                {
                    ValueBuilder.Add(InterimData[i][j]);
                }

                // Add to dictionary //
                this._cache.Add(KeyBuilder.ToRecord(), CompoundRecord.FromRecord(ValueBuilder.ToRecord(), Signiture));

            }

        }
示例#4
0
        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;

        }
示例#5
0
        private void HandleNullCluster(RecordSet Means)
        {

            // Increment the fail itterations //
            this._zero_fail_itterations++;

            // Find which nodes are missing //
            List<int> MissingKeys = new List<int>();
            for (int i = 0; i < this._count; i++)
            {
                if (Means.Seek(new Cell(i), 0) == -1)
                {
                    this._zero_fail_counts++;
                    MissingKeys.Add(i);
                }
            }

            // Add back the missing nodes from the current itteration //
            foreach (int x in MissingKeys)
            {
                RecordBuilder rb = new RecordBuilder();
                rb.Add(x);
                rb.Add(Record.Subrecord(this._means[x], 1, this._means.Columns.Count - 1));
                Means.Add(rb.ToRecord());
            }

        }
示例#6
0
        public static Record GetSquareRecord(string FilePath)
        {

            Bitmap map = new Bitmap((FilePath));
            Record r = Lipizzan.Exchange.MonoChromeBitmapToRecord(map);
            RecordBuilder rb = new RecordBuilder();
            rb.Add(FilePath);
            rb.Add(0D);
            rb.Add(0D);
            rb.Add(1D);
            rb.Add(r);

            return rb.ToRecord();

        }