def get(matches, used, Ps, get_P, Pa, ua): others = list(set(used) - set(matches)) extra = PosetProduct(tuple(map(get_P, others))) print('extra for Pa: %s' % extra) Pa_comp = PosetProduct(Pa.subs + extra.subs) print('Pa_comp: %s' % Pa_comp) extra_minimals = extra.get_minimal_elements() m_matches = matches + others s = set() R = set() for m1, m2 in itertools.product(ua.minimals, extra_minimals): m = m1 + m2 s.add(m) r = [None] * len(used) for i, a in enumerate(used): S1 = Pa_comp.subs[m_matches.index(a)] s1 = m[m_matches.index(a)] S2 = get_P(a) r[i] = express_value_in_isomorphic_space(S1, s1, S2) r = tuple(r) R.add(r) Pa_comp_lb = Pa_comp.Us(s) print('Pa_comp_lb: %s' % Pa_comp_lb) Ps_a = Ps.Us(R) return Ps_a
def add_extra(lb, P, v): P.belongs(v) P1 = lb.P if not isinstance(P1, PosetProduct): P1 = PosetProduct((P1, )) minimals = set((a, ) for a in lb.minimals) else: minimals = lb.minimals P1b = PosetProduct(P1.subs + (P, )) def mm(x): return x + (v, ) l1b = P1b.Us(map(mm, minimals)) return l1b
class PlotterUR2(Plotter): def check_plot_space(self, space): tu = get_types_universe() if not isinstance(space, UpperSets): msg = 'I can only plot upper sets of something isomorphic to R2.' raise_desc(NotPlottable, msg, space=space) P = space.P self.R2 = PosetProduct((Rcomp(), Rcomp())) if isinstance(space.P, PosetProduct) and len(space.P) == 2 and \ isinstance(space.P[0], RcompUnits) and isinstance(space.P[1], RcompUnits): self.P_to_S = lambda x: x else: #logger.debug('space = %s ; P = %s; R2 = %s' % (space,space.P,R2)) try: tu.check_leq(P, self.R2) except NotLeq as e: msg = ('cannot convert to R^2 from %s' % space) raise_wrapped(NotPlottable, e, msg, compact=True) self.P_to_S, _f2 = tu.get_embedding(P, self.R2) def get_xylabels(self, space): P = space.P return '%s' % P[0], '%s' % P[1] @contract(returns='seq[4]') def axis_for_sequence(self, space, seq): self.check_plot_space(space) R2 = PosetProduct((Rcomp(), Rcomp())) self.R2 = R2 # tu = get_types_universe() # P_TO_S, _ = tu.get_embedding(space.P, R2) maxx, maxy = 1000.0, 1000.0 def limit(p): x, y = p x = min(x, maxx) y = min(y, maxy) return x, y points2d = [[(limit(self.P_to_S(_))) for _ in s.minimals] for s in seq] axes = [get_bounds(_) for _ in points2d] merged = functools.reduce(reduce_bounds, axes) return merged def toR2(self, p): return self._get_screen_coords(p, self.axis) def _get_screen_coords(self, p, axis=None): x, y = p # XXX from mcdp_report.generic_report_utils import extra_space_top if axis is not None: dy = (axis[3] - axis[2]) * extra_space_top dx = (axis[1] - axis[0]) * extra_space_top top_x = axis[1] + dx top_y = axis[3] + dy if isinstance(x, (float, int)): x = min(axis[1], x) else: # top x = top_x if isinstance(y, (float, int)): y = min(axis[3], y) else: # top y = top_y p2 = x, y return p2 def plot(self, pylab, axis, space, value, params={}): params0 = dict(color_shadow=[1.0, 0.8, 0.8], markers='k.', markers_params={}) params0.update(params) color_shadow = params0.pop('color_shadow') markers = params0.pop('markers') markers_params = params0.pop('markers_params') if params0: msg = 'Extra parameters given.' raise_desc(ValueError, msg, params0=params0) self.axis = axis self.check_plot_space(space) # tu = get_types_universe() # P_TO_S, _ = tu.get_embedding(space.P, self.R2) minimals = [ self._get_screen_coords(self.P_to_S(_), axis) for _ in value.minimals ] minimals = poset_minima(minimals, self.R2.leq) v = self.R2.Us(minimals) from mcdp_report.generic_report_utils import extra_space_finite plot_upset_R2(pylab, v, axis, extra_space_shadow=extra_space_finite, color_shadow=color_shadow, markers=markers, marker_params=markers_params)