public void TestLambdaColumnPassThroughTransform()
        {
            /*using (*/
            var host = EnvHelper.NewTestEnvironment();
            {
                var inputs = new InputOutputU[] {
                    new InputOutputU()
                    {
                        X = new float[] { 0.1f, 1.1f }, Y = 0
                    },
                    new InputOutputU()
                    {
                        X = new float[] { 0.2f, 1.2f }, Y = 1
                    },
                    new InputOutputU()
                    {
                        X = new float[] { 0.3f, 1.3f }, Y = 2
                    }
                };

                var data       = DataViewConstructionUtils.CreateFromEnumerable(host, inputs);
                var lambdaView = LambdaColumnHelper.Create <VBuffer <float>, VBuffer <float> >(host,
                                                                                               "Lambda", data, "X", "XX", new VectorDataViewType(NumberDataViewType.Single, 2),
                                                                                               new VectorDataViewType(NumberDataViewType.Single, 2),
                                                                                               (in VBuffer <float> src, ref VBuffer <float> dst) =>
                {
                    dst           = new VBuffer <float>(2, new float[2]);
                    dst.Values[0] = src.Values[0] + 1f;
                    dst.Values[1] = src.Values[1] + 1f;
                });
예제 #2
0
        public void TestLambdaColumnPassThroughTransform()
        {
            using (var host = EnvHelper.NewTestEnvironment())
            {
                var inputs = new InputOutputU[] {
                    new InputOutputU()
                    {
                        X = new float[] { 0.1f, 1.1f }, Y = 0
                    },
                    new InputOutputU()
                    {
                        X = new float[] { 0.2f, 1.2f }, Y = 1
                    },
                    new InputOutputU()
                    {
                        X = new float[] { 0.3f, 1.3f }, Y = 2
                    }
                };

                var data       = host.CreateStreamingDataView(inputs);
                var lambdaView = LambdaColumnHelper.Create <VBuffer <float>, VBuffer <float> >(host,
                                                                                               "Lambda", data, "X", "XX", new VectorType(NumberType.R4, 2),
                                                                                               new VectorType(NumberType.R4, 2),
                                                                                               (in VBuffer <float> src, ref VBuffer <float> dst) =>
                {
                    dst           = new VBuffer <float>(2, new float[2]);
                    dst.Values[0] = src.Values[0] + 1f;
                    dst.Values[1] = src.Values[1] + 1f;
                });
예제 #3
0
        /// <summary>
        /// Converts all vector columns into string by add CSharp transform.
        /// </summary>
        public static IDataTransform AddFlatteningTransform(IHostEnvironment env, IDataView view)
        {
            IDataTransform res    = null;
            var            schema = view.Schema;

            for (int i = 0; i < schema.Count; ++i)
            {
                var ty = schema[i].Type;
                if (ty.IsVector())
                {
                    var name = schema[i].Name;
                    view = LambdaColumnHelper.Create(env,
                                                     "Lambda", view, name, name, new VectorType(NumberType.R4),
                                                     TextType.Instance,
                                                     (in VBuffer <float> src, ref ReadOnlyMemory <char> dst) =>
                    {
                        var st = string.Join(";", src.Values.Select(c => c.ToString()));
                        dst    = new ReadOnlyMemory <char>(st.ToCharArray());
                    });
예제 #4
0
        private RoleMappedData BuildViewBeforeTraining(out string slotName, out string slotTime, bool train)
        {
            int        index, indexTime;
            ColumnType type, typeTime;

            ValidateInputs(out index, out indexTime, out type, out typeTime);
            IDataView input = Source;

            slotName = _args.columns[0].Source;

            if (train && type.IsVector())
            {
                slotName = input.Schema.GetTempColumnName() + "in";
                input    = LambdaColumnHelper.Create(Host, "takeslot", input, _args.columns[0].Source, slotName,
                                                     new VectorType(NumberType.R4), NumberType.R4,
                                                     (in VBuffer <float> src, ref float dst) =>
                {
                    dst = src.GetItemOrDefault(0);
                });