Exemple #1
0
        public new static DistArray <T> FromMatlabStruct(MatlabStruct s)
        {
//			s = struct();
//			s.className=class(this);
//			distCell = cell(1, length(this.distArray));
//			for i=1:length(this.distArray)
//					dist = this.distArray(i);
//					distCell{i} = dist.toStruct();
//			end
//			s.distArray = distCell;
//			s.mean = this.mean;
//			s.variance = this.variance;
//
            string className = s.GetString("className");

            if (!className.Equals("DistArray"))
            {
                throw new ArgumentException("The input does not represent a " + "DistArray");
            }
            object[,] distCell = s.GetCells("distArray");
            List <T> dists = new List <T>();

            for (int i = 0; i < distCell.Length; i++)
            {
                var          distDict   = (Dictionary <string, object>)distCell[0, i];
                MatlabStruct distStruct = new MatlabStruct(distDict);
                IKEPDist     disti      = KEPDist.FromMatlabStruct(distStruct);
                dists.Add((T)disti);
            }
            return(new DistArray <T>(dists));
        }
Exemple #2
0
        public static new StackVectorMapper FromMatlabStruct(MatlabStruct s)
        {
            //			s = struct();
            //			s.className=class(this);
            //			mapperCount = length(this.instancesMappers);
            //			mapperCell = cell(1, mapperCount);
            //			for i=1:mapperCount
            //					mapperCell{i} = this.instancesMappers{i}.toStruct();
            //			end
            //			s.instancesMappers = this.instancesMappers;

            string className = s.GetString("className");

            if (!className.Equals(MATLAB_CLASS))
            {
                throw new ArgumentException("The input does not represent a " + MATLAB_CLASS);
            }

            object[,] mappersCell = s.GetCells("instancesMappers");
            if (mappersCell.Length != 2)
            {
                throw new ArgumentException("instancesMappers should have length 2.");
            }
            int m    = mappersCell.GetLength(1);
            var maps = new VectorMapper[m];

            for (int i = 0; i < m; i++)
            {
                var          mapStruct = new MatlabStruct((Dictionary <string, object>)mappersCell[0, i]);
                VectorMapper map       = VectorMapper.FromMatlabStruct(mapStruct);
                maps[i] = map;
            }

            return(new StackVectorMapper(maps));
        }
Exemple #3
0
        public static TensorInstances <T1, T2> FromMatlabStruct(MatlabStruct s)
        {
//			s = struct();
//			s.className=class(this);
//			instancesCount = length(this.instancesCell);
//			cellStruct = cell(1, instancesCount);
//			for i=1:instancesCount
//					cellStruct = this.instancesCell{i}.toStruct();
//			end
//			s.instancesCell = cellStruct;

            string className = s.GetString("className");

            if (!className.Equals(MATLAB_CLASS))
            {
                throw new ArgumentException("The input does not represent a " +
                                            typeof(TensorInstances <T1, T2>));
            }
            int instancesCount = s.GetInt("instancesCount");

            if (instancesCount != 2)
            {
                throw new ArgumentException("expect instancesCount to be 2.");
            }
            object[,] instancesCell = s.GetCells("instancesCell");
            if (instancesCell.Length != 2)
            {
                throw new ArgumentException("instancesCell does not have length 2.");
            }
            var da1Dict = (Dictionary <string, object>)instancesCell[0, 0];
            var da2Dict = (Dictionary <string, object>)instancesCell[0, 1];

            // assume instancesCell contains DistArray's
            DistArray <T1> da1 = DistArray <T1> .FromMatlabStruct(
                new MatlabStruct(da1Dict));

            DistArray <T2> da2 = DistArray <T2> .FromMatlabStruct(
                new MatlabStruct(da2Dict));

            return(new TensorInstances <T1, T2>(da1.GetDists(), da2.GetDists()));
        }