Skip to content

Commit

Permalink
fix silliness
Browse files Browse the repository at this point in the history
  • Loading branch information
SHoltzen committed Aug 22, 2019
1 parent cc2db5c commit cc4a04e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 43 deletions.
1 change: 0 additions & 1 deletion .#markov.py

This file was deleted.

39 changes: 7 additions & 32 deletions factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,6 @@ def fast_random_element(g):


class FactorGraph:
### Given a group g, strips the factor generators from that group
### necessary for the correctness of automorphism group order
def strip_factors(self, g):
stripped_gens = []
for gen in g.gens():
sgen = []
for cycle in gen.cycle_tuples(singletons=False):
# print "checking cycle " + str(cycle)
# check this cycle contains a factor
contains_factor = False
for factor in self.factors:
for e in factor:
# print "checking if " + str(e) + " in " + str(cycle)
if e in cycle:
contains_factor = True
if not contains_factor:
# print "no factor in " + str(cycle)
sgen.append(cycle)
stripped_gens.append(tuple(sgen))
print stripped_gens
return PermutationGroup(stripped_gens)


### graph: a sage graph
### variables: a list of graph vertices which correspond to variables in the factor graph
### factors: a list of list of factors; each list is a single color
Expand All @@ -59,14 +36,11 @@ def strip_factors(self, g):
def __init__(self, graph, variables, factors, potential):
self.graph = graph
self.variables = variables
print "variables: " + str(variables)
print "factors: " + str(factors)
self.factors = factors
self.potential = potential
g = graph.automorphism_group(partition=[variables] + factors)
print g
self.graph_aut = self.strip_factors(g)
print self.graph_aut
self.graph_aut = g
# print self.graph_aut
self.graph_aut_order = self.graph_aut.order()

### converts a variable state into a variable partition
Expand Down Expand Up @@ -131,7 +105,6 @@ def partition(self):
c = queue.popleft()
# TODO: turn this into a single GI call by having it return both the
# automorphism group and the canonical form
print c + self.factors
gcanon, cert = my_bliss.canonical_form(self.graph,
partition=c + self.factors,
certificate=True,
Expand All @@ -153,7 +126,7 @@ def partition(self):
A, orbits = self.graph.automorphism_group(partition=c+self.factors,
orbits=True,
algorithm="bliss")
orbitsz = g_order / (self.strip_factors(A)).order()
orbitsz = g_order / A.order()
A = None

states = self.partition_to_state(c)
Expand Down Expand Up @@ -195,10 +168,12 @@ def potential(state):
if v:
p += 1
return p
return FactorGraph(g, v, [factors[:len(factors)/2],factors[len(factors)/2:]], potential)
# make half the factors different colors
# return FactorGraph(g, v, [factors[:len(factors)/2],factors[len(factors)/2:]], potential)
return FactorGraph(g, v, [factors], potential)


if __name__ == "__main__":
fg = gen_complete_pairwise_factorgraph(8)
fg = gen_complete_pairwise_factorgraph(10)
print fg.partition()
print fg.brute_force_partition()
12 changes: 2 additions & 10 deletions markov.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def fast_random_element(g):

class MarkovModel:
### graph: a sage graph
### variables: a list of graph vertices which correspond to variables in the factor graph
### variables: a list of graph vertices which correspond to variables
### potential: state -> real: a function which evaluates the potential on a particular state
### a state is a dictionary assigning variables to Boolean values
def __init__(self, graph, variables, potential, order=True):
Expand Down Expand Up @@ -543,15 +543,7 @@ def trivial_query(state):
return supp_explored


def gen_complete_pairwise_factorgraph(n):
(g, (v, factors)) = gen_complete_pairwise_factor(n)
def potential(state):
p = 0.0
for v in state.itervalues():
if v:
p += 1
return p
return FactorGraph(g, v, [factors], potential)


def run_burnside():
cur_state = dict()
Expand Down

0 comments on commit cc4a04e

Please sign in to comment.