def setUp(self): self.objs_num = 60 self.atts_num = 12 self.cxt_random = fca.make_random_context(self.objs_num, self.atts_num, 0.3) self.cxt1 = fca.Context([[1, 1, 0], [0, 1, 1], [0, 0, 1]], ['g2', 'g1', 'g3'], ['m1', 'm3', 'm2']) self.cxt2 = fca.Context([(0, 1, 1), (1, 0, 1), (0, 1, 0)], ['g1', 'g2', 'g3'], ['m1', 'm2', 'm3'])
def setUp(self): self.objs_num = 60 self.atts_num = 12 self.cxt_random = fca.make_random_context(self.objs_num, self.atts_num, 0.3) self.cxt1 = fca.Context([[1,1,0], [0,1,1], [0,0,1]], ['g2', 'g1', 'g3'], ['m1', 'm3', 'm2']) self.cxt2 = fca.Context([(0,1,1), (1,0,1), (0,1,0)], ['g1', 'g2', 'g3'], ['m1', 'm2', 'm3'])
def test_random_cxt(self): atts_num = 20 objs_num = 1500 cxt_random = fca.make_random_context(objs_num, atts_num, 0.3) factors_iter = fca.algorithms.algorithm2_w_condition( cxt_random, fidelity=1, allow_repeatitions=False, min_atts_and_objs=3, objs_ge_atts=True) assert len(list(factors_iter)) > 1
def setUp(self): atts_num = 20 objs_num = 1500 self.cxt_random = fca.make_random_context(objs_num, atts_num, 0.3) self.cxt1 = fca.Context([(0, 1, 1), (1, 0, 1), (0, 1, 0)], ['g1', 'g2', 'g3'], ['m1', 'm2', 'm3']) self.cxt2 = fca.Context([(0, 1, 1), (1, 0, 1), (0, 1, 1)], ['g1', 'g2', 'g3'], ['m1', 'm2', 'm3']) self.cxt3 = fca.Context( [[1, 0, 1, 0, 1, 1], [0, 0, 1, 0, 0, 0], [1, 1, 0, 1, 1, 1], [0, 0, 1, 0, 0, 1], [0, 1, 1, 1, 0, 1]], ['g1', 'g2', 'g3', 'g4', 'g5'], ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'])
def setUp(self): atts_num = 20 objs_num = 1500 self.cxt_random = fca.make_random_context(objs_num, atts_num, 0.3) self.cxt1 = fca.Context([(0,1,1), (1,0,1), (0,1,0)], ['g1', 'g2', 'g3'], ['m1', 'm2', 'm3']) self.cxt2 = fca.Context([(0,1,1), (1,0,1), (0,1,1)], ['g1', 'g2', 'g3'], ['m1', 'm2', 'm3']) self.cxt3 = fca.Context([[1,0,1,0,1,1], [0,0,1,0,0,0], [1,1,0,1,1,1], [0,0,1,0,0,1], [0,1,1,1,0,1]], ['g1', 'g2', 'g3', 'g4', 'g5'], ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'])
def test_compare_aclosure_associative_aclosure(self): setup = '''import fca cxt_r = fca.make_random_context(2000, 200, 0.4) ''' stmt = ''' for att in cxt_r.attributes: cxt_r.aclosure([att]) ''' cxt_r = fca.make_random_context(1000, 100, 0.4) print(timeit.timeit(stmt, setup, number=10)) cProfile.runctx(stmt, globals(), locals()) stmt = ''' for att in cxt_r.attributes: cxt_r.associative_aclosure([att]) ''' print(timeit.timeit(stmt, setup, number=10)) cProfile.runctx(stmt, globals(), locals())
D = cxt.oprime(C) to_remove_U = set(itertools.product(C, D)) & U V = len(to_remove_U) if not allow_repeatitions: to_remove = (set(itertools.product(C, cxt.attributes)) | set(itertools.product(cxt.objects, D))) & U else: to_remove = to_remove_U elif good_factor(cpt=fca.Concept(C, D)): if len(to_remove) == 0: raise Exception( f'Algorithm stuck, something went wrong, pairs left ' f'{len(U)}') U -= to_remove # print(f'Factor out: {len(C)}, {len(D)}') yield fca.Concept(C, D), len(to_remove) / len_initial, (len_initial - len(U)) / len_initial break else: assert False if __name__ == '__main__': import cProfile import numpy.linalg as lalg from fca import make_random_context r_cxt = make_random_context(1200, 1000, .3) # r_cxt = r_cxt.reduce_attributes().reduce_objects() cProfile.run('print(lalg.svd(r_cxt.np_table))') cProfile.run('for x in algorithm2(r_cxt, .3): print(len(x[0].extent), len(x[0].intent), x[1])')
for j in set(cxt.attributes) - D ] if ls_measures: maxDj = max(ls_measures, key=lambda x: x[0]) else: maxDj = [0,] if maxDj[0] > V: j = maxDj[1] Dj = D | {j} C = cxt.aprime(Dj) D = cxt.oprime(C) to_remove = set(itertools.product(C, D)) & U V = len(to_remove) else: break if len(to_remove) == 0: print('Algorithm stuck, something went wrong, pairs left ', len(U)) assert False U -= to_remove yield fca.Concept(C, D), len(to_remove) / len_initial if __name__ == '__main__': import cProfile import numpy.linalg as lalg r_cxt = fca.make_random_context(1200, 1000, .3) # r_cxt = r_cxt.reduce_attributes().reduce_objects() cProfile.run('print(lalg.svd(r_cxt.np_table))') cProfile.run('for x in algorithm2(r_cxt, .3): print(len(x[0].extent), len(x[0].intent), x[1])')
def setUp(self): self.cxt_random = fca.make_random_context(60, 12, 0.3)
def test_random_dg_iter(): r_cxt = fca.make_random_context(40, 15, 0.3) dg_basis = r_cxt.get_attribute_implications() dg_basis_from_iter = [x for x in r_cxt.attribute_implications_iter()] assert len(dg_basis) == len(dg_basis_from_iter)