Beispiel #1
0
 def _eval_laguerre_fxns(self):
     """
     Evaluate matrix B
      Rows: Memory size (self.M)
      Cols: Number of Laguerre Fxns (self.num_laguerres)
     """
     self.B = discrete_laguerre(self.alpha, self.num_laguerres, self.M)
Beispiel #2
0
    def fit(self, y=None, order=2, method='LS'):
        """
        Train method estimates the kernals of the system using orthogonal laguerre basis functions. Training is
         carried out with the following:

        * L basis functions are generated and evaluated - yields B matrix
        * Convolve each ith Laguerre function, b_i, with input data x(t).  - yields v_i(t) and V matrix
        * Solve Y = C*V, where C is the coefficient matrix of the Laguerre functions. Solve using `method`
        * Calculate kernels:
            * k_0 = c_0
            * k_1(m) = c_1* b(m)
            * k_2(m_1, m_2) = b(m)^T * c_2 * b(m)

        :param y: training output. If `None` it looks if self.y is array-like.
        :type y: array-like
        :param order: training output. If `None` it looks if self.y is array-like.
        :type order: array-like
        :param method: Method used to find the Laguerre coefficients, C
        :type method: _LS_, _(more to be added)_
        """

        try:
            self.y = y if y is not None else self.y
            assert len(self.y) == len(self.x)
        except TypeError():
            print "output y must be defined and of length len(x)"

        # setup volterra matrix: B
        self.B = discrete_laguerre(self.alpha, self.num_laguerres, self.M)
        # setup convolved Volterra matrix with data: conv(B,x)V
        self.V = np.array([np.convolve(self.B[:, l], self.x)[0:self.N] for l in range(self.num_laguerres)])
        # perform regression to estimate the coefficients C for each laguerre
        self._est_laguerre_coef()
        # calc kernels
        self._calculate_kernels()
Beispiel #3
0
def SISO_with_Laguerres(num_points=1024, memory=40, num_laguerres=3, laguerre_coef=(-0.5, 1., -1.5), alpha=0.5):
    """
    Function used to generate SISO time series data. Default parameters are based off 'test_LET1' in the Lysis7.2 MATLAB
    package.

    :param num_points: Number of data points to generate. len(x) & len(y)=num_points
    :type num_points: Integer, default _1024_
    :param memory: Number of lags in series
    :type memory: Integer, default _40_
    :param num_laguerres: Number of generalized Laguerre functions to use in generating output.
    :type laguerre_coef: Coefficients/weights in front each laguerre to formulate output
    :param alpha: Scaling factor of the generalized Laguerre function
    :type alpha: [-1, 1], default _0.5_

    Returns
    :param x: input data
    :type x: Numpy array
    :param y: output data
    :type y: Numpy array

    """
    #assert isinstance(num_points, (int, float))
    #assert isinstance(memory, (int, float))
    #assert isinstance(num_laguerres, (int, float))

    N = int(num_points)
    M = int(memory)
    L = int(num_laguerres)

    laguerre_coef = laguerre_coef[:num_laguerres] if len(laguerre_coef) >= num_laguerres else np.ones(num_laguerres)
    #lags = range(M)  # generate index memory

    # psuedo gaussian white noise
    x = randn(N)
    dlf = discrete_laguerre(alpha, L, M)
    h = (np.array(laguerre_coef) * dlf).sum(axis=1)  #
    v = np.convolve(x, h)
    y = v[:N] + np.power(v[:N], 2)

    return x,y