DataSet Object Examples and Peaksigmoid: Difference between pages

From Eigenvector Research Documentation Wiki
(Difference between pages)
Jump to navigation Jump to search
imported>Scott
No edit summary
 
imported>Mathias
 
Line 1: Line 1:
__TOC__
===Purpose===
==DataSet Object Tour==
Outputs a sigmoid function.
Perhaps the best way to understand how DSOs work is to examine a couple of them. Several data sets are included with PLS_Toolbox, and all of them are in the form of DSOs. We will start with the smallest one, the Wine data set. Clear the MATLAB workspace (save anything important first!) and at the command line type:
<pre>>> load wine
>> whos
  Name      Size                  Bytes  Class


  wine      10x5                    6050  dataset object


Grand total is 920 elements using 6050 bytes</pre>
===Synopsis===
We have now loaded the Wine data set. When the <tt>whos</tt> command is used, we see that there is a single variable in the workspace, wine, of Class dataset object, with a data field that is 10 by 5. We can look at the contents of wine by typing:
<pre>>> wine
wine =  
      name: Wine
      type: data
    author: B.M. Wise
      date: 14-May-2001 13:47:54
    moddate: 06-Jun-2001 10:27:24
      data: 10x5 [double]
      label: {2x1} [array (char)]
              Mode 1  [Country: 10x6]
              Mode 2  [Variable: 5x6]
  axisscale: {2x1} [vector (real)]
              Mode 1  [: ]
              Mode 2  [: ]
      title: {2x1} [vector (char)]
              Mode 1  [: 'Country'] 
              Mode 2  [: 'Variable']
class: {2x1} [vector (integer)]
              Mode 1  [: ]
              Mode 2  [: ]
    include: {2x1} [vector (integer)]
              Mode 1  [: 1x10]
              Mode 2  [: 1x5] 
description: Wine, beer, and liquor consumption (gal/yr), life
            life expectancy (years), and heart disease rate 
            (cases/100,000/yr) for 10 countries.           
    history: {1x1 cell} [array (char)]
  userdata: </pre>
From this we see that the name of the data is Wine and that the type is “data.” Other types are also possible, such as “image” and “batch.” The author is listed, followed by the creation date and last-modified date. The next field, data, contains the actual data table. These data, or the data from any DSO field, can be extracted from the DSO just as they would be from a conventional structure array (type <tt>help struct</tt> or refer to the Examining a Structure Array section of Chapter 2 for help) using <tt>DSOname.fieldname</tt> syntax. For instance:
<pre>>> wine.data


ans =
:[y,y1,y2] = peaksigmoid(x,ax)


    2.5000  63.5000  40.1000  78.0000  61.1000
    0.9000  58.0000  25.1000  78.0000  94.1000
    1.7000  46.0000  65.0000  78.0000  106.4000
    1.2000  15.7000  102.1000  78.0000  173.0000
    1.5000  12.2000  100.0000  77.0000  199.7000
    2.0000    8.9000  87.8000  76.0000  176.0000
    3.8000    2.7000  17.1000  69.0000  373.6000
    1.0000    1.7000  140.0000  73.0000  283.7000
    2.1000    1.0000  55.0000  79.0000  34.7000
    0.8000    0.2000  50.4000  73.0000  36.4000</pre>
The labels can be extracted in a similar manner:
<pre>>> wine.label


ans =
===Inputs===


  [10x6] char
* '''x''' =  3 element vector where
  [ 5x6] char
:* x(1) = coefficient
</pre>
:* x(2) = offset
Note that <tt>ans</tt> is a cell array, i.e., the labels for each mode of the array are stored in a cell that is indexed to that mode. Thus, the labels for mode 1, the data set rows, can be extracted with:
:* x(3) = decay constant
<pre>>> wine.label{1}


ans =
===Outputs===


France
Italy
Switz
Austra
Brit 
U.S.A.
Russia
Czech
Japan
Mexico
</pre>
Note that curly brackets, {}, are used to index into cell arrays (type help cell for more information on cell arrays). In a similar way the labels for mode 2, the data set columns, can be extracted by executing:
<pre>>> wine.label{2}


ans =


Liquor
Wine 
Beer 
LifeEx
HeartD
</pre>
Other fields in the DSO include <tt>.axisscale</tt> (e.g., time or wavelength scale), <tt>.title</tt> (titles for the axes), and <tt>.class</tt> (e.g., class variables for samples). Note that a typical data set will not have all of the available fields filled. The Wine data set does not have axis scales, for instance, nor class variables.


DSOs also allow for multiple sets of many of these fields; for instance, you may store more than one set of labels for a particular mode. Most GUI tools including Analysis, PlotGUI and the DataSet Editor support multiple sets but there are some rare situations where their use has not yet been fully implemented. GUIs allow limited support of multiple sets; axis scales and titles are not yet completely supported in the main Analysis GUI.
<math>\sqrt{1-e^2}</math>


The user is encouraged to explore more of the DSOs included with PLS_Toolbox. For an example with axis scales, please see <tt>spec1</tt> in the <tt>nir_data.mat</tt> file. For an example with class variables, please see arch in the <tt>arch.mat</tt> file.
<math>f\left( {{a}_{i}},\mathbf{x} \right)={{x}_{1}}\left[ {{x}_{4}}{{\operatorname{e}}^{\frac{-4\ln \left( 2 \right){{\left( {{a}_{i}}-{{x}_{2}} \right)}^{2}}}{x_{3}^{2}}}}+\left( 1-{{x}_{4}} \right)\left[ \frac{x_{3}^{2}}{{{\left( {{a}_{i}}-{{x}_{2}} \right)}^{2}}+x_{3}^{2}} \right] \right]</math>




==Creating A DataSet Object==
<math>f\left( {{a}_{i}},\mathbf{x} \right)={{x}_{1}}\left[ {{x}_{4}}{{\operatorname{e}}^{\frac{-4\ln \left( 2 \right){{\left( {{a}_{i}}-{{x}_{2}} \right)}^{2}}}{x_{3}^{2}}}}+\left( 1-{{x}_{4}} \right)\left[ \frac{1-x_{3}^{2}}{{{\left( {1}+{{x}_{2}} \right)}^{2}}+x_{3}^{2}} \right] \right]</math>
The following shows an example using the 'wine' data set in the PLS_Toolbox. Other examples can be found in the <tt>datasetdemo.m</tt> script.


The first step in the example is to load the 'wine' data set and examine the variables. The MATLAB commands are:


<pre>
»load wine_raw
»whos
  Name  Size Bytes Class
  dat  10x5  400  double array
  names 10x6  120  char array
  vars  5x6  60  char array
</pre>


The variable '<tt>dat</tt>' contains the data array corresponding to the 5 variables wine, beer, and liquor consumption, life expectancy, and heart disease for 10 samples (countries).
<math>f\left( {{a}_{i}},\mathbf{x} \right)={{x}_{1}}\left[ {}+\left( 1-{{x}_{4}} \right)\left[ \frac{1-x_{3}^{2}}{{{\left( \right)}+x_{3}^{2}} \right] \right]</math>


The country names are contained in the variable '<tt>names</tt>' and the variable names are contained in '<tt>vars</tt>'. The next step creates a <tt>DataSet</tt> object, gives it a name, authorship, and description.
* '''y(1) ''' =


<pre>»wined = dataset(dat);
* '''y(2) ''' = <math>{\operatorname{d}\!y\over\operatorname{d}\!{x}_{i}}</math>
»wined.name = 'Wine';
»wined.author = 'A.E. Newman';
»wined.description= ...
{'Wine, beer, and liquor consumption (gal/yr)',...
'life expectancy (years), and heart disease rate', ...
'(cases/100,/yr) for 10 countries.'};
»wined.label{1} = names;
»wined.label{2} = vars;</pre>


Additional assignments can also be made. Here the label for the first mode (rows) is shown explicitly next to the data array (like sample labels). Also, titles, axis, and titles are assigned.
* ''' y(3) ''' = <math>{\operatorname{d^2}\!y\over\operatorname{d}\!{{x}_{i}}^{2}}</math>
 
<pre>»wined.labelname{1} = 'Countries';
»wined.label{1} = ...
{'France' ...
'Italy', ...
'Switz', ...
'Austra', ...
...
'Mexico'};
»wined.title{1} = 'Country';
»wined.class{1} = [1 1 1 2 3];
»wined.classname{1} = 'Continent';
»wined.axisscale{1} = 1:5;
»wined.axisscalename{1} = 'Country Number';</pre>
Additional assignments can also be made for mode 2. Here the label for the second mode (columns) is shown explicitly above the data array (like column headings). Also, titles, axis, and titles are assigned.
 
<pre>»wined.labelname{2} = 'Variables';
»wined.label{2} = ...
{'Liquor','Wine','Beer','LifeExp','HeartD'};</pre>
 
If the data matrix is N-way the assignment process can be extended to Mode 3, Mode 4, ... Mode N. It can also be extended to using multiple sets of labels and axis scales ''e.g.''
<pre>»wined.labelname{2,2} = 'Alcohol Content and Quality';
»wined.label{2,2} = {'high','medium','low','good','bad'};</pre>
An individual label can be replaced by further indexing into a given label set using curly braces followed by the string replacement:
 
<pre>»wined.label{2,2}{4} = 'excellent';</pre>
 
Sub-portions of the <tt>DataSet</tt> can be retrieved by indexing into the main <tt>DataSet</tt> object. For example, here the first three columns ('Liquor', 'Wine', and 'Beer') are extracted into a new <tt>DataSet</tt> named "alcohol":
 
<pre>»alcohol = wined(:,1:3);</pre>
 
Similarly, a shortcut to extract a single variable or sample out of the <tt>DataSet</tt> is to index into the main <tt>DataSet</tt> object using the label for the requested item. For example, to extract a DataSet containing only the Liquor values, you could use:
 
<pre>»alcohol = wined.liquor;</pre>
 
Note that the upper-case characters in the label do not matter. If there are any spaces or mathematical symbols in the label, you must enclose the label in parenthesis and quotes:
 
<pre>»alcohol = wined.('liquor');</pre>
 
Additionally, any field in the <tt>DataSet</tt> can also be indexed into directly. Here the second country name is pulled out of the labels by extracting the entire second row of the mode 1 labels:
 
<pre>»country2 = wined.label{1}(2,:);</pre>
 
==Using the Class Lookup Table==
Classes in a <tt>DataSet</tt> are stored as numeric values (in the '''.class''' field). Each numeric value and be associated with a text value using the '''classlookup''' field. This field contains a simple nx2 table with numeric values in the first column and string values in the second. For example, the ''arch'' dataset has a classlookkup table for elements:
 
<pre>>> load arch
>> arch.classlookup{1,1}
ans =  
    [0]    'Class 0'
    [1]    'K'     
    [2]    'BL'   
    [3]    'SH'   
    [4]    'AN'  </pre>
 
 
There are two basic ways to alter a classlookup table, by extracting the table or directly accessing the table.
 
===Extracting the Table===
Extracting the table can be useful if you need to perform several changes:
 
<pre>a  = arch.classlookup{1};
a{3,2} = 'YYY';
a{4,2} = 'ZZZ';
arch.classlookup{1} = a;
arch.classlookup{1}
ans =
  [0]    'Class 0'
  [1]    'K'
  [2]    'YYY'
  [3]    'ZZZ'
  [4]    'AN'
</pre>
 
 
===Direct Access===
If you just need to change a single value (or a small number of values) you can directly access the lookup table using '''.assignstr''' and '''.assignval''' fields. For example, the change class 0 of <tt>arch</tt> from "Class 0" to "Unknown":
 
<pre>
arch.classlookup{1}.assignstr = {0 'Unknown'}
>> arch.classlookup{1}
 
ans =
 
  [0]    'Unknown'
  [1]    'K'
  [2]    'BL'
  [3]    'SH'
  [4]    'AN'
</pre>
 
Then, to change the numeric value of "Unknown" from 0 to 6:
 
<pre>
>> arch.classlookup{1}
arch.classlookup{1}.assignval = {6 'Unknown'}
ans =
 
  [0]    'Class 0'
  [1]    'K'
  [2]    'BL'
  [3]    'SH'
  [4]    'AN'
  [6]    'Unknown'</pre>

Revision as of 11:37, 4 August 2016

Purpose

Outputs a sigmoid function.


Synopsis

[y,y1,y2] = peaksigmoid(x,ax)


Inputs

  • x = 3 element vector where
  • x(1) = coefficient
  • x(2) = offset
  • x(3) = decay constant

Outputs



Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f\left( {{a}_{i}},\mathbf{x} \right)={{x}_{1}}\left[ {}+\left( 1-{{x}_{4}} \right)\left[ \frac{1-x_{3}^{2}}{{{\left( \right)}+x_{3}^{2}} \right] \right]}

  • y(1) =
  • y(2) =
  • y(3) =