def memoryFunctionZapprox(self, den_order): """ @param den_order: @type den_order: C{int} @returns: an approximation to the M{z}-transform of the process' memory function that correponds to an expansion of the denominator up to order den_order @rtype: L{Scientific.Function.Rational.RationalFunction} """ poles = self.poles() cpoles = N.conjugate(poles) coeff0 = N.conjugate(self.coeff[0]) beta = N.zeros((self.order, ), N.Complex) for i in range(self.order): pole = poles[i] beta[i] = -(self.sigsq*pole**(self.order-1)/coeff0) / \ (N.multiply.reduce((pole-poles)[:i]) * N.multiply.reduce((pole-poles)[i+1:]) * N.multiply.reduce(pole-1./cpoles) * self.variance) beta = beta / N.sum(beta) den_coeff = [] for i in range(den_order): sum = 0. for j in range(self.order): sum += beta[j] * poles[j]**i den_coeff.append(sum) den_coeff.reverse() mz = (RationalFunction(den_order * [0.] + [1.], den_coeff) + RationalFunction([1., -1.], [1.])) / self.delta_t**2 if not _isComplex(self.coeff): mz.numerator.coeff = _realPart(mz.numerator.coeff) mz.denominator.coeff = _realPart(mz.denominator.coeff) return mz
def __coerce__(self, other): if hasattr(other, 'is_rational_function'): return (self, other) elif hasattr(other, 'is_polynomial'): return (self, RationalFunction(other, [1.])) else: return (self, RationalFunction([other], [1.]))
def memoryFunctionZ(self): """ @returns: the M{z}-transform of the process' memory function @rtype: L{Scientific.Function.Rational.RationalFunction} """ poles = self.poles() cpoles = N.conjugate(poles) coeff0 = N.conjugate(self.coeff[0]) beta = N.zeros((self.order, ), N.Complex) for i in range(self.order): pole = poles[i] beta[i] = -(self.sigsq*pole**(self.order-1)/coeff0) / \ (N.multiply.reduce((pole-poles)[:i]) * N.multiply.reduce((pole-poles)[i+1:]) * N.multiply.reduce(pole-1./cpoles) * self.variance) beta = beta / N.sum(beta) sum = 0. for i in range(self.order): sum = sum + RationalFunction([beta[i]], [-poles[i], 1.]) mz = (1. / sum + Polynomial([1., -1.])) / self.delta_t**2 if not _isComplex(self.coeff): mz.numerator.coeff = _realPart(mz.numerator.coeff) mz.denominator.coeff = _realPart(mz.denominator.coeff) return mz
def memoryFunctionZ(self): poles = self.poles() cpoles = [p.conjugate() for p in poles] coeff0 = conjugate(self.coeff[0]) beta = self.order * [0] sum = 0. for i in range(self.order): pole = poles[i] prod = N.Complex(self.variance, 0.) for j in range(i): prod *= (pole - poles[j]) for j in range(i + 1, self.order): prod *= (pole - poles[j]) for j in range(self.order): prod *= (pole - N.Complex(1., 0.) / cpoles[j]) beta[i] = -((pole**(self.order - 1)) * self.sigsq / coeff0) / prod sum += beta[i] for i in range(self.order): beta[i] /= sum sum = 0. for i in range(self.order): sum += RationalFunction([beta[i]], [-poles[i], 1.]) mz = (1. / sum + Polynomial([1., -1.])) / self.delta_t**2 if not isComplex(self.coeff[0]): mz.numerator.coeff = [c.real for c in mz.numerator.coeff] mz.denominator.coeff = [c.real for c in mz.denominator.coeff] return mz
def memoryFunctionZapprox(self, den_order): poles = self.poles() cpoles = N.conjugate(poles) coeff0 = N.conjugate(self.coeff[0]) beta = N.zeros((self.order, ), N.Complex) for i in range(self.order): pole = poles[i] beta[i] = -(self.sigsq*pole**(self.order-1)/coeff0) / \ (N.multiply.reduce((pole-poles)[:i]) * N.multiply.reduce((pole-poles)[i+1:]) * N.multiply.reduce(pole-1./cpoles) * self.variance) beta = beta / N.sum(beta) den_coeff = [] for i in range(den_order): sum = 0. for j in range(self.order): sum += beta[j] * poles[j]**i den_coeff.append(sum) den_coeff.reverse() mz = (RationalFunction(den_order * [0.] + [1.], den_coeff) + Polynomial([1., -1.])) / self.delta_t**2 if not isComplex(self.coeff): mz.numerator.coeff = realPart(mz.numerator.coeff) mz.denominator.coeff = realPart(mz.denominator.coeff) return mz
def divide(self, shift=0): num = self.numerator.coeff[:] if shift > 0: num = shift * [0.] + num den = self.denominator.coeff den_order = len(den) coeff = [] while len(num) >= den_order: q = num[-1] / den[-1] coeff.append(q) for i in range(den_order): num[len(num) - den_order + i] -= q * den[i] num = num[:-1] if not coeff: coeff = [0] coeff.reverse() if not num: num = [0] return Polynomial(coeff), RationalFunction(num, den)
def __rsub__(self, other): return RationalFunction( other.numerator * self.denominator - other.denominator * self.numerator, self.denominator * other.denominator)
def __add__(self, other): return RationalFunction( self.numerator * other.denominator + self.denominator * other.numerator, self.denominator * other.denominator)
def __rdiv__(self, other): return RationalFunction(other.numerator * self.denominator, other.denominator * self.numerator)
def __rdiv__(self, other): return RationalFunction(other, self)
def __div__(self, other): if self.dim != 1 or other.dim != 1: raise ValueError, "not implemented" return RationalFunction(self, other)