Here are the examples of the python api numpy.less_equal taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
7 Examples
3
Example 1
Project: ndgrutedb Source File: lcc.py
def get_coords_for_lccs(self, ncc):
"""Computes coordinates for each voxel in the top ncc connected components"""
inlcc = (np.less_equal(self.vertexCC,ncc)*np.greater(self.vertexCC,0)).nonzero()[0]
coord = np.array([zindex.MortonXYZ(v) for v in inlcc])
return np.concatenate((coord,self.vertexCC[inlcc][np.newaxis].T),axis=1)
3
Example 2
def __call__(self, X, axis=-1):
''' Compute kernel from points
Parameters
----------
X : array
array of points
axis : int, optional
axis containing coordinates. Default -1
'''
_normsq = self._normsq(X, axis) / 2.
t = np.less_equal(_normsq, 15)
return np.exp(-np.minimum(_normsq, 15)) * t
0
Example 3
Project: discomll Source File: decision_tree.py
def fit(x, y, t, randomized, max_tree_nodes, min_samples_leaf, min_samples_split, class_majority, measure, accuracy,
separate_max):
"""
Function builds a binary decision tree with given dataset and it expand tree nodes in priority order. Tree model is
stored in a dictionary and it has following structure:
{parent_identifier: [(child_identifier, highest_estimated_feature_index , split_value, distribution_of_labels,
depth, feature_type)]}
x: numpy array - dataset with features
y: numpy array - dataset with labels
t: list - features types
randomized: boolean - if True, algorithm estimates sqrt(num_of_features)+1 randomly selected features each
iteration.
If False, it estimates all features in each iteration.
max_tree_nodes: integer - number of tree nodes to expand.
min_samples_leaf: float - minimal number of samples in leafs.
class_majority: float - purity of the classes in leafs.
measure: measure function - information gain or mdl.
split_fun: split function - discretization of continuous features can be made randomly or with equal label frequency.
"""
depth = 0 # depth of the tree
node_id = 1 # node identifier
# conditions of continuous and discrete features.
operation = {"c": (np.less_equal, np.greater), "d": (np.in1d, np.in1d)}
tree = {0: [(node_id, -1, "", dict(Counter(y)), depth, "")]} # initialize tree model
mapping = range(len(x[0])) # global features indices
# sqrt(num_of_features) is estimated if randomized == True.
# If randomized == False, all indices are estimated at each node.
rand_attr = int(np.ceil(np.sqrt(len(x[0]))))
recalculate = True
while recalculate:
recalculate = False
est_indices = rand_indices(x, rand_attr) if randomized else range(len(x[0]))
# estimate indices with given measure
est = [measure(x[:, i], y, t[i], accuracy, separate_max) for i in est_indices]
try:
max_est, split = max(est) # find highest estimated split
except:
recalculate = True
best = est_indices[est.index((max_est, split))] # select feature index with highest estimate
queue = Queue.PriorityQueue() # initialize priority queue
# put datasets in the queue
queue.put((max_est, (node_id, x, y, mapping, best, split, depth)))
while not queue.empty() and len(tree) * 2 < max_tree_nodes:
_, (parent_id, x, y, mapping, best, split, depth) = queue.get()
# features indices are mapped due to constantly changing subsets of data
best_map = mapping[best]
for j in range(2): # for left and right branch of the tree
selection = range(len(x[0])) # select all indices for the new subset
new_mapping = [i for i in mapping] # create a mapping of indices for a new subset
if t[best_map] == "d" and len(split[j]) == 1:
# if feature is discrete with one value in split, we cannot split it further.
selection.remove(best) # remove feature from new dataset
new_mapping.remove(best_map) # remove mapping of feature
# select rows of new dataset that satisfy condition (less than, greater than or in)
indices = operation[t[best_map]][j](x[:, best], split[j]).nonzero()[0]
# create new subsets of data
sub_x, sub_y = x[indices.reshape(len(indices), 1), selection], y[indices]
if j == 0 and (len(sub_y) < min_samples_leaf or len(x) - len(sub_y) < min_samples_leaf):
break
node_id += 1 # increase node identifier
y_dist = Counter(sub_y) # distribution of labels in the new node
# connect child node with its parent and update tree model
tree[parent_id] = tree.get(parent_id, []) + [(node_id, best_map,
set(split[j]) if t[best_map] == "d" else split[j],
dict(y_dist), depth + 1, t[best_map])]
# select new indices for estimation
est_indices = rand_indices(sub_x, rand_attr) if randomized and len(sub_x[0]) > rand_attr else range(
len(sub_x[0]))
# check label majority
current_majority = y_dist[max(y_dist, key=y_dist.get)] / float(len(sub_y))
# if new node satisfies following conditions it can be further split
if current_majority < class_majority and len(sub_y) > min_samples_split and est_indices != -1:
# estimate selected indices
est = [measure(sub_x[:, i], sub_y, t[new_mapping[i]], accuracy, separate_max) for i in est_indices]
try:
max_est, new_split = max(est) # find highest estimated split
except:
continue
# select feature index with highest estimate
new_best = est_indices[est.index((max_est, new_split))]
# put new datasets in the queue with inverse value of estimate (priority order)
queue.put(
(max_est * -1 * len(sub_y), (node_id, sub_x, sub_y, new_mapping, new_best, new_split, depth + 1)))
return tree
0
Example 4
Project: scikit-learn Source File: gaussian_mixture.py
def _check_precision_positivity(precision, covariance_type):
"""Check a precision vector is positive-definite."""
if np.any(np.less_equal(precision, 0.0)):
raise ValueError("'%s precision' should be "
"positive" % covariance_type)
0
Example 5
def assert_allclose(x, y, rtol=1.e-5, atol=1.e-5):
assert np.all(np.less_equal(abs(x-y), atol + rtol * abs(y)))
0
Example 6
def _f(self, a, b): return np.less_equal(a,b)
class equal(BinaryElemwiseNoDrv):
0
Example 7
Project: nupic Source File: lines.py
def contains(self, mouseevent):
"""
Test whether the mouse event occurred on the line. The pick
radius determines the precision of the location test (usually
within five points of the value). Use
:meth:`~matplotlib.lines.Line2D.get_pickradius` or
:meth:`~matplotlib.lines.Line2D.set_pickradius` to view or
modify it.
Returns *True* if any values are within the radius along with
``{'ind': pointlist}``, where *pointlist* is the set of points
within the radius.
TODO: sort returned indices by distance
"""
if callable(self._contains): return self._contains(self,mouseevent)
if not is_numlike(self.pickradius):
raise ValueError,"pick radius should be a distance"
# Make sure we have data to plot
if self._invalid:
self.recache()
if len(self._xy)==0: return False,{}
# Convert points to pixels
path, affine = self._transformed_path.get_transformed_path_and_affine()
path = affine.transform_path(path)
xy = path.vertices
xt = xy[:, 0]
yt = xy[:, 1]
# Convert pick radius from points to pixels
if self.figure == None:
warning.warn('no figure set when check if mouse is on line')
pixels = self.pickradius
else:
pixels = self.figure.dpi/72. * self.pickradius
# Check for collision
if self._linestyle in ['None',None]:
# If no line, return the nearby point(s)
d = (xt-mouseevent.x)**2 + (yt-mouseevent.y)**2
ind, = np.nonzero(np.less_equal(d, pixels**2))
else:
# If line, return the nearby segment(s)
ind = segment_hits(mouseevent.x,mouseevent.y,xt,yt,pixels)
# Debugging message
if False and self._label != u'':
print "Checking line",self._label,"at",mouseevent.x,mouseevent.y
print 'xt', xt
print 'yt', yt
#print 'dx,dy', (xt-mouseevent.x)**2., (yt-mouseevent.y)**2.
print 'ind',ind
# Return the point(s) within radius
return len(ind)>0,dict(ind=ind)