主要内容

本页采用了机器翻译。点击此处可查看英文原文。

处理多试验数据与模型合并

本示例演示了在使用 System Identification Toolbox™ 进行模型估计和优化时,如何处理多个试验并合并模型。

简介

System Identification Toolbox 中的分析和估计函数允许您处理多批数据。简而言之,如果您已经进行了多次试验并记录了多个输入-输出数据集,可以将它们归入一个 iddata 对象中,并将其用于任何估计程序。

在某些情况下,您可以将(单一)测量数据集“拆分”,以剔除数据质量不佳的部分。例如,部分数据可能因外部干扰或传感器故障而无法使用。在这种情况下,您可以将每部分有效数据分离出来,然后将其合并为一个包含多个试验的 iddata 对象。

例如,看看数据集 iddemo8data.mat

load iddemo8data

查看数据对象 dat

dat
dat =

Time domain data set with 1000 samples.
Sample time: 1 seconds                  
                                        
Outputs      Unit (if specified)        
   y1                                   
                                        
Inputs       Unit (if specified)        
   u1                                   
                                        
Data Properties
plot(dat)

Figure contains 2 axes objects. Axes object 1 with title y1 contains an object of type line. This object represents dat. Axes object 2 with title u1 contains an object of type line. This object represents dat.

您可以看到,在第 250 到 280 个采样点以及第 600 到 650 个采样点附近,输出结果存在一些问题。这可能是传感器故障。

因此,将数据分为三个独立的试验,并将其放入一个多试验数据对象中。

d1 = dat(1:250);
d2 = dat(281:600);
d3 = dat(651:1000);
d = merge(d1,d2,d3) % merge lets you create multi-exp iddata object
d =
Time domain data set containing 3 experiments.

Experiment   Samples      Sample Time          
   Exp1         250            1               
   Exp2         320            1               
   Exp3         350            1               
                                               
Outputs      Unit (if specified)               
   y1                                          
                                               
Inputs       Unit (if specified)               
   u1                                          
                                               
Data Properties

您可以为不同的试验赋予不同的名称。

d.ExperimentName = {'Period 1';'Day 2';'Phase 3'}
d =
Time domain data set containing 3 experiments.

Experiment     Samples      Sample Time        
   Period 1       250            1             
   Day 2          320            1             
   Phase 3        350            1             
                                               
Outputs        Unit (if specified)             
   y1                                          
                                               
Inputs         Unit (if specified)             
   u1                                          
                                               
Data Properties

要查看多试验数据对象,请使用 plot 命令 (plot(d))。

利用多试验数据进行估计

如前所述,所有模型估计程序均可处理多试验数据,并会考虑这些数据是在不同时期记录的这一情况。将前两个试验用于估计,将第三个试验用于验证。

de = getexp(d,[1,2]);      % subselection is done using the command getexp 
dv = getexp(d,'Phase 3');  % using numbers or names
m1 = arx(de,[2 2 1]);
m2 = n4sid(de,2);
m3 = armax(de,[2 2 2 1]);
compare(dv,m1,m2,m3)

Figure contains an axes object. The axes object with ylabel y1 contains 4 objects of type line. These objects represent Validation data (y1), m1: 73.05%, m2: 80.01%, m3: 80.09%.

compare 命令也支持多个试验。请使用右键点击菜单逐个选择要使用的试验。

compare(d,m1,m2,m3)

Figure contains an axes object. The axes object with ylabel y1 contains 4 objects of type line. These objects represent Validation data:Period 1 (y1), m1: 74.2%, m2: 80.41%, m3: 80.35%.

此外,对于多试验数据,spaetferesidpredictsim 的运行方式与处理单试验数据时相同。

使用矩阵和时间表表示多试验数据

除了使用 iddata 对象外,您还可以使用由数值矩阵和时间表组成的元胞数组来等效地表示多试验数据。

tt1 = timetable(seconds(d1.SamplingInstants),d1.u,d1.y);
tt2 = timetable(seconds(d2.SamplingInstants),d2.u,d2.y);
m1_mat = arx({d1.u,d2.u},{d1.y,d2.y},[2 2 1]);
m1_tt = arx({tt1,tt2},[2 2 1]);
compare(dv,m1,m1_mat,m1_tt)

Figure contains an axes object. The axes object with ylabel y1 contains 4 objects of type line. These objects represent Validation data (y1), m1: 73.05%, m1\_mat: 73.05%, m1\_tt: 73.05%.

估计后的模型合并

还有另一种处理独立数据集的方法。您可以为每个集合分别构建一个模型,然后将这些模型合并。

m4 = armax(getexp(de,1),[2 2 2 1]);
m5 = armax(getexp(de,2),[2 2 2 1]);
m6 = merge(m4,m5); % m4 and m5 are merged into m6

从概念上讲,这与从合并后的集合 de 中计算 m 是一样的,但在数值上并不相同。在处理 de 时,假设不同试验中的信噪比(大致)相同,而合并独立模型则会对噪声水平进行独立估计。如果不同试验的条件大致相同,那么直接基于多试验数据进行估计会更高效。

您可以查看模型 m3m6,这两个都是基于同一组数据、通过两种不同方法获得的 ARMAX 模型。

[m3.a;m6.a]
ans = 2×3

    1.0000    -1.5034    0.7008
    1.0000    -1.5022    0.7000

[m3.b;m6.b]
ans = 2×3

    0    1.0023    0.5029
    0    1.0035    0.5028

[m3.c;m6.c]
ans = 2×3

    1.0000    -0.9744    0.1578
    1.0000    -0.9751    0.1584

compare(dv,m3,m6)

Figure contains an axes object. The axes object with ylabel y1 contains 3 objects of type line. These objects represent Validation data (y1), m3: 80.09%, m6: 80.09%.

案例研究:独立数据集的串联与合并

现在考虑由系统 m0 生成的两个数据集。

m0
m0 =
  Discrete-time identified state-space model:
    x(t+Ts) = A x(t) + B u(t) + K e(t)
       y(t) = C x(t) + D u(t) + e(t)
 
  A = 
             x1        x2        x3
   x1    0.5296    -0.476    0.1238
   x2    -0.476  -0.09743    0.1354
   x3    0.1238    0.1354   -0.8233
 
  B = 
             u1        u2
   x1    -1.146  -0.03763
   x2     1.191    0.3273
   x3         0         0
 
  C = 
            x1       x2       x3
   y1  -0.1867  -0.5883  -0.1364
   y2   0.7258        0   0.1139
 
  D = 
          u1     u2
   y1  1.067      0
   y2      0      0
 
  K = 
       y1  y2
   x1   0   0
   x2   0   0
   x3   0   0
 
Sample time: 1 seconds

Parameterization:
   STRUCTURED form (some fixed coefficients in  A, B, C).
   Feedthrough: on some input channels
   Disturbance component: none
   Number of free coefficients: 23
   Use "idssdata", "getpvec", "getcov" for parameters and their uncertainties.

Status:                                                         
Created by direct construction or transformation. Not estimated.
 
Model Properties

您收集了数据集 z1z2,它们是从 m0 通过不同的输入、噪声和初始条件生成的。这些数据集是从之前加载的 iddemo8data.mat 中获取的。

绘制第一个数据集。

plot(z1) 

Figure contains 4 axes objects. Axes object 1 with title y1 contains an object of type line. This object represents z1. Axes object 2 with title y2 contains an object of type line. This object represents z1. Axes object 3 with title u1 contains an object of type line. This object represents z1. Axes object 4 with title u2 contains an object of type line. This object represents z1.

绘制第二个数据集。

plot(z2)

Figure contains 4 axes objects. Axes object 1 with title y1 contains an object of type line. This object represents z2. Axes object 2 with title y2 contains an object of type line. This object represents z2. Axes object 3 with title u1 contains an object of type line. This object represents z2. Axes object 4 with title u2 contains an object of type line. This object represents z2.

将获得的数据拼接起来并绘制绘图。

zzl = [z1;z2]
zzl =

Time domain data set with 400 samples.
Sample time: 1 seconds                 
                                       
Outputs      Unit (if specified)       
   y1                                  
   y2                                  
                                       
Inputs       Unit (if specified)       
   u1                                  
   u2                                  
                                       
Data Properties
plot(zzl)

Figure contains 4 axes objects. Axes object 1 with title y1 contains an object of type line. This object represents zzl. Axes object 2 with title y2 contains an object of type line. This object represents zzl. Axes object 3 with title u1 contains an object of type line. This object represents zzl. Axes object 4 with title u2 contains an object of type line. This object represents zzl.

您可以使用 ssest 获得一个离散时间状态空间模型。

ml = ssest(zzl,3,'Ts',1,'Feedthrough', [true, false]);

比较模型 m0ml 的波德响应。

clf
bode(m0,ml)
legend('show')

MATLAB figure

从上面的四个波德图可以看出,这是一个不太理想的模型。

现在,将这两个数据集视为不同的试验。

zzm = merge(z1,z2)
zzm =
Time domain data set containing 2 experiments.

Experiment   Samples      Sample Time          
   Exp1         200            1               
   Exp2         200            1               
                                               
Outputs      Unit (if specified)               
   y1                                          
   y2                                          
                                               
Inputs       Unit (if specified)               
   u1                                          
   u2                                          
                                               
Data Properties
% The model for this data can be estimated as before (watching progress this time)
mm = ssest(zzm,3,'Ts',1,'Feedthrough',[true, false], ssestOptions('Display', 'on'));

比较真实系统(蓝色)、基于拼接数据的模型(绿色)以及基于合并数据集的模型(红色)的波德图。

clf
bode(m0,'b',ml,'g',mm,'r')
legend('show')

MATLAB figure

如上图所示,合并后的数据集得出的模型效果更好。

利用多试验数据辨识线性模型

在使用多试验数据拟合线性模型时,需针对每个试验分别估计初始条件。您可以在报告中找到这些信息。

mm.Report.Parameters.X0
ans = 3×2

     1.4243    -1.4165
    -0.0138     0.0607
    -0.8412     0.8619

结论

本示例分析了如何将多个数据集结合起来用于估计一个模型。当您拥有来自独立试验运行的多个数据集,或者将数据划分为多个子集以剔除不良数据段时,此技术非常有用。您可以将多个试验打包到一个 iddata 对象、一个数值矩阵的元胞数组或一个时间表的元胞数组中,该对象随后可用于满足所有估计和分析需求。该技术既适用于时域数据,也适用于频域数据。

您也可以在估计完成后合并模型。您可以使用这种方法对独立估计的模型进行“平均处理”。如果多个数据集的噪声特性不同,那么在估计之后合并模型,比在估计之前合并数据集本身效果更好。

另请参阅

主题