private LaplacianFourierSampler(IHostEnvironment env, ModelLoadContext ctx)
        {
            Contracts.AssertValue(env);
            _host = env.Register(RegistrationName);
            _host.AssertValue(ctx);

            // *** Binary format ***
            // int: sizeof(Float)
            // Float: a

            int cbFloat = ctx.Reader.ReadInt32();

            _host.CheckDecode(cbFloat == sizeof(float));

            _a = ctx.Reader.ReadFloat();
            _host.CheckDecode(FloatUtils.IsFinite(_a));
        }
            private Delegate DecodeInit <T>(object value)
            {
                _host.CheckDecode(value is VBuffer <T>);
                VBuffer <T> buffValue = (VBuffer <T>)value;
                ValueGetter <VBuffer <T> > buffGetter = (ref VBuffer <T> dst) => buffValue.CopyTo(ref dst);

                return(buffGetter);
            }
Пример #3
0
        internal static FixedSizeQueue <double> DeserializeFixedSizeQueueDouble(BinaryReader reader, IHost host)
        {
            int capacity = reader.ReadInt32();

            host.CheckDecode(capacity >= 0);

            var q     = new FixedSizeQueue <double>(capacity);
            int count = reader.ReadInt32();

            host.CheckDecode(0 <= count & count <= capacity);

            for (int index = 0; index < count; index++)
            {
                q.AddLast(reader.ReadDouble());
            }

            return(q);
        }
Пример #4
0
            private LabelNameBindableMapper(IHost host, ModelLoadContext ctx)
            {
                Contracts.AssertValue(host);
                _host = host;
                _host.AssertValue(ctx);

                ctx.LoadModel <ISchemaBindableMapper, SignatureLoadModel>(_host, out _bindable, _innerDir);
                BinarySaver saver = new BinarySaver(_host, new BinarySaver.Arguments());
                ColumnType  type;
                object      value;

                _host.CheckDecode(saver.TryLoadTypeAndValue(ctx.Reader.BaseStream, out type, out value));
                _host.CheckDecode(type.IsVector);
                _host.CheckDecode(value != null);
                _type         = type.AsVector;
                _getter       = Utils.MarshalInvoke(DecodeInit <int>, _type.ItemType.RawType, value);
                _metadataKind = ctx.Header.ModelVerReadable >= VersionAddedMetadataKind?
                                ctx.LoadNonEmptyString() : MetadataUtils.Kinds.SlotNames;
            }
Пример #5
0
        private Median(IHostEnvironment env, ModelLoadContext ctx)
        {
            Contracts.AssertValue(env);
            _host = env.Register(LoaderSignature);

            // *** Binary format ***
            // int: sizeof(Single)
            int cbFloat = ctx.Reader.ReadInt32();

            _host.CheckDecode(cbFloat == sizeof(Single));
        }
Пример #6
0
        protected BaseAverager(IHostEnvironment env, string name, ModelLoadContext ctx)
        {
            Contracts.AssertValue(env);
            env.AssertNonWhiteSpace(name);
            Host = env.Register(name);
            Host.CheckValue(ctx, nameof(ctx));

            // *** Binary format ***
            // int: sizeof(Single)
            int cbFloat = ctx.Reader.ReadInt32();

            Host.CheckDecode(cbFloat == sizeof(Single));
        }
Пример #7
0
        private ParquetPartitionedPathParser(IHost host, ModelLoadContext ctx)
        {
            Contracts.AssertValue(host);
            _host = host;
            _host.AssertValue(ctx);

            // ** Binary format **
            // int: number of columns
            // foreach column:
            //   string: column representation

            int numColumns = ctx.Reader.ReadInt32();

            _host.CheckDecode(numColumns >= 0);

            _columns = new PartitionedFileLoader.Column[numColumns];
            for (int i = 0; i < numColumns; i++)
            {
                var column = PartitionedFileLoader.Column.Parse(ctx.LoadString());
                _host.CheckDecode(column != null);
                _columns[i] = column;
            }
        }
Пример #8
0
        protected SchemaBindablePipelineEnsembleBase(IHostEnvironment env, ModelLoadContext ctx, string scoreColumnKind)
        {
            Host = env.Register(LoaderSignature);
            Host.AssertNonEmpty(scoreColumnKind);

            _scoreColumnKind = scoreColumnKind;

            // *** Binary format ***
            // int: id of _scoreColumnKind (loaded in the Create method)
            // int: number of predictors
            // The predictor models
            // int: the number of input columns
            // for each input column:
            //   int: id of the column name

            var length = ctx.Reader.ReadInt32();

            Host.CheckDecode(length > 0);
            PredictorModels = new IPredictorModel[length];
            for (int i = 0; i < PredictorModels.Length; i++)
            {
                string dir =
                    ctx.Header.ModelVerWritten == 0x00010001
                        ? "PredictorModels"
                        : Path.Combine(ctx.Directory, "PredictorModels");
                using (var ent = ctx.Repository.OpenEntry(dir, $"PredictorModel_{i:000}"))
                    PredictorModels[i] = new PredictorModel(Host, ent.Stream);
            }

            length = ctx.Reader.ReadInt32();
            Host.CheckDecode(length >= 0);
            _inputCols = new string[length];
            for (int i = 0; i < length; i++)
            {
                _inputCols[i] = ctx.LoadNonEmptyString();
            }
        }
        internal BaseMultiCombiner(IHostEnvironment env, string name, ModelLoadContext ctx)
        {
            Contracts.AssertValue(env);
            env.AssertNonWhiteSpace(name);
            Host = env.Register(name);
            Host.AssertValue(ctx);

            // *** Binary format ***
            // int: sizeof(Single)
            // bool: _normalize
            int cbFloat = ctx.Reader.ReadInt32();

            Host.CheckDecode(cbFloat == sizeof(Single));
            Normalize = ctx.Reader.ReadBoolByte();
        }
Пример #10
0
        protected PredictorBase(IHostEnvironment env, string name, ModelLoadContext ctx)
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckNonWhiteSpace(name, nameof(name));
            Host = env.Register(name);

            // *** Binary format ***
            // int: sizeof(Float)

            // Verify that the Float type matches.
            int cbFloat = ctx.Reader.ReadInt32();
#pragma warning disable TLC_NoMessagesForLoadContext // This one is actually useful.
            Host.CheckDecode(cbFloat == sizeof(Float), "This file was saved by an incompatible version");
#pragma warning restore TLC_NoMessagesForLoadContext
        }
Пример #11
0
        // Factory for SignatureLoadModel.
        public TransformWrapper(IHostEnvironment env, ModelLoadContext ctx)
        {
            Contracts.CheckValue(env, nameof(env));
            _host = env.Register(nameof(TransformWrapper));
            _host.CheckValue(ctx, nameof(ctx));

            ctx.CheckAtModel(GetVersionInfo());
            int n = ctx.Reader.ReadInt32();

            _host.CheckDecode(n >= 0);

            ctx.LoadModel <IDataLoader, SignatureLoadDataLoader>(env, out var loader, "Loader", new MultiFileSource(null));

            IDataView data = loader;

            for (int i = 0; i < n; i++)
            {
                var dirName = string.Format(TransformDirTemplate, i);
                ctx.LoadModel <IDataTransform, SignatureLoadDataTransform>(env, out var xf, dirName, data);
                data = xf;
            }

            _xf = data;
        }
Пример #12
0
        private MatrixFactorizationPredictor(IHostEnvironment env, ModelLoadContext ctx)
        {
            Contracts.CheckValue(env, nameof(env));
            _host = env.Register(RegistrationName);
            // *** Binary format ***
            // int: number of rows (m), the limit on row
            // int: number of columns (n), the limit on column
            // int: rank of factor matrices (k)
            // float[m * k]: the left factor matrix
            // float[k * n]: the right factor matrix

            _numberOfRows = ctx.Reader.ReadInt32();
            _host.CheckDecode(_numberOfRows > 0);
            if (ctx.Header.ModelVerWritten < VersionNoMinCount)
            {
                ulong mMin = ctx.Reader.ReadUInt64();
                // We no longer support non zero Min for KeyType.
                _host.CheckDecode(mMin == 0);
                _host.CheckDecode((ulong)_numberOfRows <= ulong.MaxValue - mMin);
            }
            _numberofColumns = ctx.Reader.ReadInt32();
            _host.CheckDecode(_numberofColumns > 0);
            if (ctx.Header.ModelVerWritten < VersionNoMinCount)
            {
                ulong nMin = ctx.Reader.ReadUInt64();
                // We no longer support non zero Min for KeyType.
                _host.CheckDecode(nMin == 0);
                _host.CheckDecode((ulong)_numberofColumns <= ulong.MaxValue - nMin);
            }
            _approximationRank = ctx.Reader.ReadInt32();
            _host.CheckDecode(_approximationRank > 0);

            _leftFactorMatrix  = Utils.ReadSingleArray(ctx.Reader, checked (_numberOfRows * _approximationRank));
            _rightFactorMatrix = Utils.ReadSingleArray(ctx.Reader, checked (_numberofColumns * _approximationRank));

            MatrixColumnIndexType = new KeyType(typeof(uint), _numberofColumns);
            MatrixRowIndexType    = new KeyType(typeof(uint), _numberOfRows);
        }