def starRegression(cache, dimensions, progressCallback=None, **args): if len(cache.contAttributes) == 1: return triangles1D(cache, True) if not cache.points: cache.points = orange.ExampleTable( orange.Domain(cache.contAttributes, cache.data.domain.classVar), cache.data).native(0) points = cache.points npoints = len(points) if not cache.tri: cache.tri = triangulate(cache, points) tri = cache.tri if not cache.stars: cache.stars = [star(x, tri) for x in xrange(npoints)] S = cache.stars points = cache.points if progressCallback: nPoints = 100.0 / len(points) for x, (S, p) in enumerate(zip(cache.stars, points)): if S == []: cache.deltas[x] = ['?' for i in dimensions] continue st = list(set(reduce(lambda x, y: x + y, S))) A = [points[i][:-1] for i in st] b = [[points[i][-1]] for i in st] cache.deltas[x] = [i[0] for i in numpy.linalg.lstsq(A, b)[0]] if progressCallback: progressCallback(x * nPoints)
def starRegression(cache, dimensions, progressCallback=None, **args): if len(cache.contAttributes) == 1: return triangles1D(cache, True) if not cache.points: cache.points = orange.ExampleTable( orange.Domain(cache.contAttributes, cache.data.domain.classVar), cache.data ).native(0) points = cache.points npoints = len(points) if not cache.tri: cache.tri = triangulate(cache, points) tri = cache.tri if not cache.stars: cache.stars = [star(x, tri) for x in xrange(npoints)] S = cache.stars points = cache.points if progressCallback: nPoints = 100.0 / len(points) for x, (S, p) in enumerate(zip(cache.stars, points)): if S == []: cache.deltas[x] = ["?" for i in dimensions] continue st = list(set(reduce(lambda x, y: x + y, S))) A = [points[i][:-1] for i in st] b = [[points[i][-1]] for i in st] cache.deltas[x] = [i[0] for i in numpy.linalg.lstsq(A, b)[0]] if progressCallback: progressCallback(x * nPoints)
def Dpca(self): self.pca() return if not self.deltas: self.deltas = [[None] * len(self.contAttributes) for x in xrange(len(self.data))] dimensions = [d for d in self.dimensions if not self.deltas[0][d]] if not dimensions: return if not self.points: self.points = orange.ExampleTable( orange.Domain(self.contAttributes, self.data.domain.classVar), self.data).native(0) points = self.points npoints = len(points) if not self.tri: print self.dimension self.tri = self.triangulate(points) tri = self.tri if not self.stars: self.stars = [star(x, tri) for x in xrange(npoints)] S = self.stars points = import85 nPoints = 100.0 / len(points) self.progressBarInit() for x, (S, p) in enumerate(zip(self.stars, points)): if S == []: self.deltas[x] = ['?' for i in dimensions] continue st = list(set(reduce(lambda x, y: x + y, S))) lenst = len(st) avgy = sum([points[i][-1] for i in st]) / lenst for di, d in enumerate(dimensions): avgx = sum([points[i][di] for i in st]) / lenst sxx2 = sum([(points[i][di] - avgx)**2 for i in st]) if sxx2: sxx = sum([(points[i][di] - avgx) * (points[i][-1] - avgy) for i in st]) b = sxx / sxx2 self.deltas[x][di] = b else: self.deltas[x][di] = '?' self.progressBarSet(x * nPoints) self.progressBarFinished()
def Dpca(self): self.pca() return if not self.deltas: self.deltas = [[None] * len(self.contAttributes) for x in xrange(len(self.data))] dimensions = [d for d in self.dimensions if not self.deltas[0][d]] if not dimensions: return if not self.points: self.points = orange.ExampleTable( orange.Domain(self.contAttributes, self.data.domain.classVar), self.data ).native(0) points = self.points npoints = len(points) if not self.tri: print self.dimension self.tri = self.triangulate(points) tri = self.tri if not self.stars: self.stars = [star(x, tri) for x in xrange(npoints)] S = self.stars points = import85 nPoints = 100.0 / len(points) self.progressBarInit() for x, (S, p) in enumerate(zip(self.stars, points)): if S == []: self.deltas[x] = ["?" for i in dimensions] continue st = list(set(reduce(lambda x, y: x + y, S))) lenst = len(st) avgy = sum([points[i][-1] for i in st]) / lenst for di, d in enumerate(dimensions): avgx = sum([points[i][di] for i in st]) / lenst sxx2 = sum([(points[i][di] - avgx) ** 2 for i in st]) if sxx2: sxx = sum([(points[i][di] - avgx) * (points[i][-1] - avgy) for i in st]) b = sxx / sxx2 self.deltas[x][di] = b else: self.deltas[x][di] = "?" self.progressBarSet(x * nPoints) self.progressBarFinished()
def starUnivariateRegression(cache, dimensions, progressCallback=None, **args): if len(cache.contAttributes) == 1: return triangles1D(cache, True) if not cache.points: cache.points = orange.ExampleTable( orange.Domain(cache.contAttributes, cache.data.domain.classVar), cache.data).native(0) points = cache.points npoints = len(points) if not cache.tri: cache.tri = triangulate(cache, points) tri = cache.tri if not cache.stars: cache.stars = [star(x, tri) for x in xrange(npoints)] S = cache.stars points = cache.points if progressCallback: nPoints = 100.0 / len(points) for x, (S, p) in enumerate(zip(cache.stars, points)): if S == []: cache.deltas[x] = ['?' for i in dimensions] continue st = list(set(reduce(lambda x, y: x + y, S))) lenst = len(st) avgy = sum([points[i][-1] for i in st]) / lenst for d in dimensions: avgx = sum([points[i][d] for i in st]) / lenst sxx2 = sum([(points[i][d] - avgx)**2 for i in st]) if sxx2: sxx = sum([(points[i][d] - avgx) * (points[i][-1] - avgy) for i in st]) b = sxx / sxx2 cache.deltas[x][d] = b else: cache.deltas[x][d] = '?' if progressCallback: progressCallback(x * nPoints)
def starUnivariateRegression(cache, dimensions, progressCallback=None, **args): if len(cache.contAttributes) == 1: return triangles1D(cache, True) if not cache.points: cache.points = orange.ExampleTable( orange.Domain(cache.contAttributes, cache.data.domain.classVar), cache.data ).native(0) points = cache.points npoints = len(points) if not cache.tri: cache.tri = triangulate(cache, points) tri = cache.tri if not cache.stars: cache.stars = [star(x, tri) for x in xrange(npoints)] S = cache.stars points = cache.points if progressCallback: nPoints = 100.0 / len(points) for x, (S, p) in enumerate(zip(cache.stars, points)): if S == []: cache.deltas[x] = ["?" for i in dimensions] continue st = list(set(reduce(lambda x, y: x + y, S))) lenst = len(st) avgy = sum([points[i][-1] for i in st]) / lenst for d in dimensions: avgx = sum([points[i][d] for i in st]) / lenst sxx2 = sum([(points[i][d] - avgx) ** 2 for i in st]) if sxx2: sxx = sum([(points[i][d] - avgx) * (points[i][-1] - avgy) for i in st]) b = sxx / sxx2 cache.deltas[x][d] = b else: cache.deltas[x][d] = "?" if progressCallback: progressCallback(x * nPoints)
def firstTriangle(cache, dimensions, progressCallback=None, **args): if len(cache.contAttributes) == 1: return triangles1D(cache, False) if not cache.points: cache.points = orange.ExampleTable( orange.Domain(cache.contAttributes, cache.data.domain.classVar), cache.data).native(0) points = cache.points npoints = len(points) if not cache.tri: cache.tri = triangulate(cache, points) tri = cache.tri if not cache.stars: cache.stars = [star(x, tri) for x in xrange(npoints)] S = cache.stars if not cache.dts: cache.dts = [ min([ min([ dist(points[x][:-1], points[v][:-1]) for v in simplex if v != x ]) for simplex in S[x] ]) * .1 for x in xrange(npoints) ] if progressCallback: nPoints = 100.0 / npoints for x, (S, xp, dt, deltas) in enumerate( zip(cache.stars, points, cache.dts, cache.deltas)): for d in dimensions: xn = xp[:-1] DBG = 0 # if xn[0]>16 and xn[1]<44.5 and xn[1]>43: # #if xn[0]>4.7 and xn[0]<4.9 and xn[1]<24.5 and xn[1]>23.5: # DBG=1 # #print "DBG" O = numpy.array(xp[:-1]) xn[d] += dt swx = simplex_with_xn(cache, xn, S) if swx: # if DBG: # print "iskanje cudnih trikotnikov" # print swx # print [points[k] for k in swx] obrni = 1 # if DBG: # print xp # print swx # print [points[k][-1] for k in swx] # vecs = numpy.array([numpy.array(points[p][:-1])-O for p in swx if p!=x]) # vecs = vecs.transpose() # XN = numpy.array(xn)-O # coef = numpy.linalg.solve(vecs,XN) # xnz = sum(coef*[numpy.array(points[p][-1]-xp[-1])for p in swx if p!=x])+xp[-1] # dd = obrni * (xnz-xp[-1]) / dt # print "xnz= ",xnz,"\tdd=",dd,"\trazlika (xnz-xp[-1])=",(xnz-xp[-1]) # print "-----------------" else: xn[d] = xp[d] - dt swx = simplex_with_xn(cache, xn, S) if swx: obrni = -1 # if DBG: # print xp # print swx # print "v levo\t",[points[k] for k in swx] # print "----------------" else: # if DBG: # print xp # do = simplex_with_xnDBG(cache, xp, S, d) # print do do = simplex_with_xnDBG(cache, xp, S, d) if do: deltas[d] = do else: deltas[d] = "?" continue vecs = numpy.array( [numpy.array(points[p][:-1]) - O for p in swx if p != x]) vecs = vecs.transpose() XN = numpy.array(xn) - O coef = numpy.linalg.solve(vecs, XN) xnz = sum( coef * [numpy.array(points[p][-1] - xp[-1]) for p in swx if p != x]) + xp[-1] deltas[d] = obrni * (xnz - xp[-1]) / dt #print "DELTAS = ",deltas[d] if progressCallback: progressCallback(x * nPoints)
def firstTriangle(cache, dimensions, progressCallback=None, **args): if len(cache.contAttributes) == 1: return triangles1D(cache, False) if not cache.points: cache.points = orange.ExampleTable( orange.Domain(cache.contAttributes, cache.data.domain.classVar), cache.data ).native(0) points = cache.points npoints = len(points) if not cache.tri: cache.tri = triangulate(cache, points) tri = cache.tri if not cache.stars: cache.stars = [star(x, tri) for x in xrange(npoints)] S = cache.stars if not cache.dts: cache.dts = [ min([min([dist(points[x][:-1], points[v][:-1]) for v in simplex if v != x]) for simplex in S[x]]) * 0.1 for x in xrange(npoints) ] if progressCallback: nPoints = 100.0 / npoints for x, (S, xp, dt, deltas) in enumerate(zip(cache.stars, points, cache.dts, cache.deltas)): for d in dimensions: xn = xp[:-1] DBG = 0 # if xn[0]>16 and xn[1]<44.5 and xn[1]>43: # #if xn[0]>4.7 and xn[0]<4.9 and xn[1]<24.5 and xn[1]>23.5: # DBG=1 # #print "DBG" O = numpy.array(xp[:-1]) xn[d] += dt swx = simplex_with_xn(cache, xn, S) if swx: # if DBG: # print "iskanje cudnih trikotnikov" # print swx # print [points[k] for k in swx] obrni = 1 # if DBG: # print xp # print swx # print [points[k][-1] for k in swx] # vecs = numpy.array([numpy.array(points[p][:-1])-O for p in swx if p!=x]) # vecs = vecs.transpose() # XN = numpy.array(xn)-O # coef = numpy.linalg.solve(vecs,XN) # xnz = sum(coef*[numpy.array(points[p][-1]-xp[-1])for p in swx if p!=x])+xp[-1] # dd = obrni * (xnz-xp[-1]) / dt # print "xnz= ",xnz,"\tdd=",dd,"\trazlika (xnz-xp[-1])=",(xnz-xp[-1]) # print "-----------------" else: xn[d] = xp[d] - dt swx = simplex_with_xn(cache, xn, S) if swx: obrni = -1 # if DBG: # print xp # print swx # print "v levo\t",[points[k] for k in swx] # print "----------------" else: # if DBG: # print xp # do = simplex_with_xnDBG(cache, xp, S, d) # print do do = simplex_with_xnDBG(cache, xp, S, d) if do: deltas[d] = do else: deltas[d] = "?" continue vecs = numpy.array([numpy.array(points[p][:-1]) - O for p in swx if p != x]) vecs = vecs.transpose() XN = numpy.array(xn) - O coef = numpy.linalg.solve(vecs, XN) xnz = sum(coef * [numpy.array(points[p][-1] - xp[-1]) for p in swx if p != x]) + xp[-1] deltas[d] = obrni * (xnz - xp[-1]) / dt # print "DELTAS = ",deltas[d] if progressCallback: progressCallback(x * nPoints)