ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
DataFrame.m
Go to the documentation of this file.
1%> \brief
2%> This is the abstract class for generating instances of objects
3%> that can contain basic attributes required for tabular read-only
4%> access to a MATLAB ``table``-compatible data stored externally.<br>
5%>
6%> \details
7%> This class is merely a convenience read-only wrapper
8%> to reference external tabular data as table.<br>
9%> This class primarily exist to facilitate bypassing
10%> the lack of references and pointers in MATLAB.<br>
11%>
12%> \remark
13%> See the constructor documentation for example usage.<br>
14%>
15%> \see
16%> [DataRef](@ref DataRef)<br>
17%>
18%> \final
19%>
20%> \author
21%> \JoshuaOsborne, May 21 2024, 4:45 PM, University of Texas at Arlington<br>
22%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
23%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
24classdef DataFrame < pm.container.DataRef
25
26 methods(Access = public)
27
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29
30 %> \brief
31 %> Generate an return an object of class [pm.container.DataFrame](@ref DataFrame)
32 %> from the input dataframe or its specified input reference.<br>
33 %>
34 %> \details
35 %> This is the constructor of the class [pm.container.DataFrame](@ref DataFrame).<br>
36 %>
37 %> \param[in] dfref : The input MATLAB 2D matrix or table containing the target dataset
38 %> or function handle that takes no arguments and returns the dataset.<br>
39 %> Specifying a function handle is superior to specifying the dataset
40 %> directly, because the function handle will always allow the use of
41 %> the most updated version of the user table or matrix.<br>
42 %> (**optional**. default = ``table(zeros(0, 0))``)
43 %>
44 %> \return
45 %> ``self`` : The output scalar object of class [pm.container.DataFrame](@ref DataFrame).<br>
46 %>
47 %> \interface{DataFrame}
48 %> \code{.m}
49 %>
50 %> dfref = pm.container.DataFrame(dfref);
51 %>
52 %> \endcode
53 %>
54 %> \example{DataFrame}
55 %> \include{lineno} example/container/DataFrame/main.m
56 %> \output{DataFrame}
57 %> \include{lineno} example/container/DataFrame/main.out.m
58 %>
59 %> \final{DataFrame}
60 %>
61 %> \author
62 %> \JoshuaOsborne, May 21 2024, 4:54 PM, University of Texas at Arlington<br>
63 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
64 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
65 function self = DataFrame(dfref)
66 if nargin < 1
67 dfref = [];
68 end
69 if isempty(dfref)
70 dfref = table(zeros(0, 0));
71 end
72 self = self@pm.container.DataRef(dfref);
73 end
74
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
77 %> \brief
78 %> Generate and return a table copy of the dataframe contained in the
79 %> user-specified input ``dfref`` to the constructor of the parent object.<br>
80 %>
81 %> \details
82 %> This class method offers the only way to access the user-specified dataframe.<br>
83 %> The underlying logic behind the use of function to access the dataframe
84 %> originates from the lack of the concept of references (pointers)
85 %> in the MATLAB computing language.<br>
86 %>
87 %> \param[inout] self : The **implicitly-passed** input argument representing the parent object of the method.<br>
88 %>
89 %> \return
90 %> ``df`` : The output scalar MATLAB ``table`` a full copy of the dataframe
91 %> contained in the user-specified input ``dfref`` passed
92 %> to the constructor of the parent object.<br>
93 %>
94 %> \interface{copy}
95 %> \code{.m}
96 %>
97 %>
98 %> df = pm.container.DataFrame.copy()
99 %>
100 %> \endcode
101 %>
102 %> \remark
103 %> See the constructor documentation for example usage.<br>
104 %>
105 %> \final{copy}
106 %>
107 %> \author
108 %> \JoshuaOsborne, May 21 2024, 4:54 PM, University of Texas at Arlington<br>
109 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
110 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
111 function df = copy(self)
112 df = copy@pm.container.DataRef(self);
113 if ~istable(df)
114 df = array2table(df);
115 end
116 end
117
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119
120 %> \brief
121 %> Generate and return the number of columns in the user-specified
122 %> dataframe ``dfref`` at the time of constructing the parent object.<br>
123 %>
124 %> \details
125 %> This class method is a handy shorthand for ``size(self.dfref, 2)``, particularly
126 %> useful for specifying a range of indices of columns in visualization tasks.<br>
127 %>
128 %> \param[inout] self : The **implicitly-passed** input argument representing the parent object of the method.<br>
129 %>
130 %> \return
131 %> ``count`` : The output scalar MATLAB whole-number representing the number
132 %> of columns in the ``dfref`` component of the parent object.
133 %>
134 %> \interface{ncol}
135 %> \code{.m}
136 %>
137 %>
138 %> count = pm.container.DataFrame.ncol()
139 %>
140 %> \endcode
141 %>
142 %> \remark
143 %> See the constructor documentation for example usage.<br>
144 %>
145 %> \final{ncol}
146 %>
147 %> \author
148 %> \JoshuaOsborne, May 21 2024, 5:00 PM, University of Texas at Arlington<br>
149 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
150 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
151 function count = ncol(self)
152 count = size(self.copy(), 2);
153 end
154
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 %> \brief
158 %> Generate and return the number of rows in the user-specified
159 %> dataframe ``dfref`` at the time of constructing the parent object.<br>
160 %>
161 %> \details
162 %> This class method is a handy shorthand for ``size(self.dfref, 2)``,
163 %> particularly useful for specifying a range of indices of rows to visualize.<br>
164 %>
165 %> \param[inout] self : The **implicitly-passed** input argument representing the parent object of the method.<br>
166 %>
167 %> \return
168 %> ``count`` : The output scalar MATLAB whole-number representing the number
169 %> of rows in the ``dfref`` component of the parent object.<br>
170 %>
171 %> \interface{nrow}
172 %> \code{.m}
173 %>
174 %> count = pm.container.DataFrame.nrow()
175 %>
176 %> \endcode
177 %>
178 %> \remark
179 %> See the constructor documentation for example usage.<br>
180 %>
181 %> \final{nrow}
182 %>
183 %> \author
184 %> \JoshuaOsborne, May 21 2024, 5:04 PM, University of Texas at Arlington<br>
185 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
186 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
187 function count = nrow(self)
188 count = size(self.copy(), 1);
189 end
190
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192
193 %> \brief
194 %> Generate and return a natural logarithmically-spaced
195 %> range of indices from the row indices of the input
196 %> dataframe ``dfref`` to the parent object.<br>
197 %>
198 %> \details
199 %> This method is a convenience wrapper
200 %> around function [pm.array.logrange](@ref logrange).<br>
201 %>
202 %> \warning
203 %> Beware of the different order of the input arguments
204 %> between this method and [pm.array.logrange](@ref logrange).<br>
205 %>
206 %> \param[inout] self : The **implicitly-passed** input/output argument representing the parent object of the method.<br>
207 %> \param[in] count : The input scalar MATLAB whole-number (integer)
208 %> representing the maximum size of the output range.<br>
209 %> Due to rounding operation involved in creating the
210 %> output range, it is impossible to prespecify the
211 %> output range size, only the maximum.<br>
212 %> (**optional**, default = ``1000``)
213 %>
214 %> \param[in] start : The input scalar MATLAB whole-number (integer)
215 %> representing the starting point of the output range.<br>
216 %> It must be a number in the range ``[1, size(self.dfref, 1)]``.
217 %> Otherwise, the value ``max(1, min(start, self.nrow()))`` will be used.<br>
218 %> (**optional**, default = ``1``)
219 %>
220 %> \param[in] stop : The input scalar MATLAB whole-number (integer)
221 %> representing the stopping point of the output range.<br>
222 %> It must be a number in the range ``[1, size(self.dfref, 1)]``.
223 %> Otherwise, the value ``max(start, min(stop, self.nrow()))`` will be used.<br>
224 %> (**optional**, default = ``1``)
225 %>
226 %> \return
227 %> ``indices`` : The output vector of MATLAB real values containing
228 %> the set of naturally logarithmically-spaced integer
229 %> values in the specified input range.<br>
230 %>
231 %> \interface{rowslog}
232 %> \code{.m}
233 %>
234 %> indices = pm.container.DataFrame()
235 %> indices = pm.container.DataFrame([])
236 %>
237 %> indices = pm.container.DataFrame([], [])
238 %> indices = pm.container.DataFrame([], start)
239 %> indices = pm.container.DataFrame(count, [])
240 %> indices = pm.container.DataFrame(count, start)
241 %>
242 %> indices = pm.container.DataFrame([], [], [])
243 %> indices = pm.container.DataFrame(count, [], [])
244 %> indices = pm.container.DataFrame([], start, [])
245 %> indices = pm.container.DataFrame([], [], stop)
246 %> indices = pm.container.DataFrame([], start, stop)
247 %> indices = pm.container.DataFrame(count, [], stop)
248 %> indices = pm.container.DataFrame(count, start, [])
249 %> indices = pm.container.DataFrame(count, start, stop)
250 %>
251 %> \endcode
252 %>
253 %> \remark
254 %> See the constructor documentation for example usage.<br>
255 %>
256 %> \final{rowslog}
257 %>
258 %> \author
259 %> \JoshuaOsborne, May 21 2024, 5:10 PM, University of Texas at Arlington<br>
260 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
261 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
262 function indices = rowslog(self, count, start, stop)
263 if nargin < 4
264 stop = [];
265 end
266 if nargin < 3
267 start = [];
268 end
269 if nargin < 2
270 count = [];
271 end
272 if isempty(stop)
273 stop = self.nrow();
274 end
275 if isempty(start)
276 start = 1;
277 end
278 if isempty(count)
279 count = 1000;
280 end
281 indices = pm.array.logrange(max(1, min(start, self.nrow())), max(start, min(stop, self.nrow())), count);
282 end
283
284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285
286 end
287
288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289
290end
function version(in silent)
Return a scalar MATLAB string containing the latest available ParaMonte MATLAB version newer than the...
This is the abstract class for generating instances of objects that can contain basic attributes requ...
Definition: DataFrame.m:25
function copy(in self)
Generate and return a table copy of the dataframe contained in the user-specified input dfref to the ...
function DataFrame(in dfref)
Generate an return an object of class pm.container.DataFrame from the input dataframe or its specifie...
function nrow(in self)
Generate and return the number of rows in the user-specified dataframe dfref at the time of construct...
function rowslog(in self, in count, in start, in stop)
Generate and return a natural logarithmically-spaced range of indices from the row indices of the inp...
function ncol(in self)
Generate and return the number of columns in the user-specified dataframe dfref at the time of constr...
This is the abstract class for generating instances of objects that can contain basic attributes requ...
Definition: DataRef.m:27
function copy(in from, in to, in field, in exclude)
Copy the contents of the struct/object from to the struct/object to recursively and without destroyin...
function logrange(in start, in stop, in sizemax)
Return a set of maximum sizemax unique integer spacings almost linearly spaced in the natural logarit...