def consistency(self, coropa, dim, level): #numpy.random.seed(21) s = iisignature.prepare(dim,level,"coshx" if coropa else "cosx") myinfo = {"level":level, "dimension":dim, "methods": ("COSAX" if level <= 2 else "COSX"), "basis":("Standard Hall" if coropa else "Lyndon")} self.assertEqual(iisignature.info(s),myinfo) path = numpy.random.uniform(size=(10,dim)) basis = iisignature.basis(s) logsig = iisignature.logsig(path,s) sig = iisignature.sig(path,level) #check lengths self.assertEqual(len(basis),iisignature.logsiglength(dim,level)) self.assertEqual((len(basis),),logsig.shape) self.assertEqual(sig.shape,(iisignature.siglength(dim,level),)) #calculate a signature from logsig expanded_logsig = [numpy.zeros(dim ** m) for m in range(1,level + 1)] for coeff, expression in zip(logsig,basis): values, depth = valueOfBracket(expression,dim) expanded_logsig[depth - 1]+=values * coeff calculated_sig = numpy.concatenate(exponentiateTensor(expanded_logsig)) self.assertLess(diff(sig,calculated_sig),0.00001) #calculate a log signature from sig fullLogSig = numpy.concatenate(logTensor(splitConcatenatedTensor(sig,dim,level))) fullLogSigLib = iisignature.logsig(path,s,"x") diff1 = numpy.max(numpy.abs(fullLogSigLib - fullLogSig)) #print #(numpy.vstack([fullLogSig,fullLogSigLib,numpy.abs(fullLogSigLib-fullLogSig)]).transpose()) self.assertLess(diff1,0.00001) basisMatrix = [] zeros = [numpy.zeros(dim ** m) for m in range(1,level + 1)] for expression in basis: values, depth = valueOfBracket(expression, dim) temp = zeros[depth - 1] zeros[depth - 1] = values basisMatrix.append(numpy.concatenate(zeros)) zeros[depth - 1] = temp calculatedLogSig = lstsq(numpy.transpose(basisMatrix),fullLogSig)[0] diff2 = numpy.max(numpy.abs(logsig - calculatedLogSig)) self.assertLess(diff2,0.00001) #check consistency of methods slowLogSig = iisignature.logsig(path,s,"o") diffs = numpy.max(numpy.abs(slowLogSig - calculatedLogSig)) self.assertLess(diffs,0.00001) sigLogSig = iisignature.logsig(path,s,"s") diffs = numpy.max(numpy.abs(sigLogSig - calculatedLogSig)) self.assertLess(diffs,0.00001) if level < 3: areaLogSig = iisignature.logsig(path,s,"a") diffs = numpy.max(numpy.abs(areaLogSig - calculatedLogSig)) self.assertLess(diffs,0.00001)
def testLyndon(self): d=2 m=5 s=iisignature.prepare(d,m,"O") for expression in iisignature.basis(s): word = ''.join(c for c in expression if c not in '[,]') if len(word) > 1: for prefixLength in range(1,len(word)): self.assertLess(word[:prefixLength],word[prefixLength:])
def test_lyndon_brackets(): """Tests the lyndon_brackets function""" for channels in range(2, 11): # iisignature supports channels with unique symbols in the range 2 to 10 inclusive for depth in range(1, 6): iisignature_brackets = iisignature.basis(h.iisignature_prepare(channels, depth)) signatory_brackets = signatory.lyndon_brackets(channels, depth) for ii_elem, sig_elem in zip(iisignature_brackets, signatory_brackets): print('channels=' + str(channels)) print('depth=' + str(depth)) assert sig_elem == eval(_iisignature_convert(ii_elem))
def test_lyndon_words(): """Tests the lyndon_words function""" for channels in range(2, 11): # iisignature supports channels with unique symbols in the range 2 to 10 inclusive for depth in range(1, 6): iisignature_brackets = iisignature.basis(h.iisignature_prepare(channels, depth)) signatory_words = signatory.lyndon_words(channels, depth) for ii_elem, sig_elem in zip(iisignature_brackets, signatory_words): ii_elem_new = ii_elem.replace('[', '').replace(']', '').replace(',', '') ii_elem_new = _iisignature_convert(ii_elem_new) sig_elem_new = ''.join(str(i) for i in sig_elem) print('channels=' + str(channels)) print('depth=' + str(depth)) print('ii_elem' + str(ii_elem)) print('sig_elem' + str(sig_elem)) assert sig_elem_new == ii_elem_new
def getMatrices(s): info=iisignature.info(s) m=info["level"] d=info["dimension"] values=[[] for i in range(m)] for exp in iisignature.basis(s): vec,level = valueOfBracket(exp,d) values[level-1].append(vec) out=[] for v in values: def f(x,y): return numpy.inner(v[x],v[y]) out.append(numpy.fromfunction( numpy.vectorize(f),(len(v),len(v)),dtype=int)) # store=[] # for x1 in v: # store.append([]) # for x2 in v: # store[-1].append(numpy.inner(x1,x2)) # out.append(numpy.array(store)) return out
def log_sig_keys(self, dimension, depth): s = self.prepare(dimension, depth) return iisignature.basis(dimension, depth)
def logsigkeys(d, m): s = _getPrep(d, m) return " " + " ".join(iisignature.basis(s))
def logsigkeys(d,m): s=_getPrep(d,m) return " "+" ".join(iisignature.basis(s))