The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.
Example 1
def prim(self):
'''
Returns Prim's minimum spanninng tree
'''
big_f = set([])
costs = np.empty((self.n), dtype=object)
costs[:] = np.max(self.costs) + 1
big_e = np.empty((self.n), dtype=object)
big_q = set(range(self.n))
tree_edges = np.array([], dtype=object)
while len(big_q) > 0:
v = np.argmin(costs)
big_q.remove(v)
costs[v] = np.Infinity
big_f.add(v)
if big_e[v] is not None:
tree_edges = np.append(tree_edges, None)
tree_edges[-1] = (big_e[v], v)
for i, w in zip(range(len(self.FSs[v])), self.FSs[v]):
if w in big_q and self.FS_costs[v][i] < costs[w]:
costs[w] = self.FS_costs[v][i]
big_e[w] = v
return tree_edges
Example 2
def prim(self):
'''
Returns Prim's minimum spanninng tree
'''
big_f = set([])
costs = np.empty((self.n), dtype=object)
costs[:] = np.max(self.costs) + 1
big_e = np.empty((self.n), dtype=object)
big_q = set(range(self.n))
tree_edges = np.array([], dtype=object)
while len(big_q) > 0:
v = np.argmin(costs)
big_q.remove(v)
costs[v] = np.Infinity
big_f.add(v)
if big_e[v] is not None:
tree_edges = np.append(tree_edges, None)
tree_edges[-1] = (big_e[v], v)
for i, w in zip(range(len(self.FSs[v])), self.FSs[v]):
if w in big_q and self.FS_costs[v][i] < costs[w]:
costs[w] = self.FS_costs[v][i]
big_e[w] = v
return tree_edges
Example 3
def fitness(self, x, limit=np.Infinity):
"""
Wraps the fitness-function of the actual problem, whose results
are logged if the fitness is an improvement.
"""
# Calculate fitness of the actual problem.
new_fitness = self.problem.fitness(x=x, limit=limit)
# If log is desired.
if self.capacity > 0:
# If the new fitness is an improvement over the worst-known fitness in the log.
if new_fitness < self.solutions[-1].fitness:
# Update the worst solution in the log with the new solution.
self.solutions[-1] = _LogElement(x=x, fitness=new_fitness)
# Sort the logged solutions.
self.solutions = sorted(self.solutions, key=lambda solution: solution.fitness)
return new_fitness
########################################################################
Example 4
def fitness(self, x, limit=np.Infinity):
"""
This is the fitness function that must be implemented for an
optimization problem.
It is also sometimes called the cost- or error-function.
:param x:
Calculate the fitness value for these parameters in the search-space.
:param limit:
Calculation of the fitness can be aborted if the value is greater than this limit.
This is used for so-called Pre-Emptive Fitness Evaluation in the MetaFitness-class.
You can ignore this value.
:return:
Fitness-value of x.
"""
# Raise an exception if the child-class has not implemented this function.
raise NotImplementedError
########################################################################
Example 5
def get_k(df, groupby, unknown=None):
"""
Return the k-anonymity level of a df, grouped by the specified columns.
:param df: The dataframe to get k from
:param groupby: The columns to group by
:typ