Package schrodinger :: Package application :: Package combiglide :: Package packages :: Module hierarchy :: Class Partition
[hide private]
[frames] | no frames]

Class Partition

A Partition in the hierarchy. Meant to be called only by Partitioning in this module. N.B.: The term "item" is a synonym for a Partition object at the lowest level of the hierarchy.

Instance Methods [hide private]
 
__init__(self, partitioning, name, data=None)
Create a new partition with the given name in the given partitioning.
 
addOrderedPartitiones(self, ordered_partitions)
Add the ordered partition list to its item.
 
addChild(self, child)
Add a child to the current partition.
 
addParent(self, parent)
Add a parent to the current partition.
 
getItems(self, add_pop=False)
Get the set of items contained in the current partition.
set of items
getRandomItems(self, nwanted)
Get (up to) nwanted random items from the current partition.
set of items
_getDiverseRandomItemsRecurs(self, nwanted, fill)
Worker function to implement the recursive part of the method invoked by getDiverseRandomItems.
set of items
getDiverseRandomItems(self, nwanted, fill=1)
Get (up to) nwanted random items from a Partition, selecting more or less equally from Partition children, recursively, at each level down to the items themselves.
 
__str__(self)
Class Variables [hide private]
int NO_FILL = 0
Do not diverge from equal child sampling in an attempt to return nwanted items; see getDiverseRandomItems().
int PART_FILL = 1
Mildly diverge from equal child sampling in an attempt to return nwanted items; see getDiverseRandomItems().
int FULL_FILL = 2
Strongly diverge from equal child sampling in an attempt to return nwanted items; see getDiverseRandomItems().
Instance Variables [hide private]
set of Partition children
Children of the current Partition (set by Hierarchy.registerItem())
Any object data
Arbitrary data associated with an item (set by Hierarchy.registerItem())
str name
Name of the current Partition (set by Hierarchy.registerItem())
int nitems
Number of items contained by the current Partition (set by Hierarchy.setPartitionPopulations())
list of Partition ordered_partitions
for the lowest-level Partitioning, only, the full ordered partition list for an item.
set of Partition parents
Parents of the current Partition (set by Hierarchy.registerItem())
Partitioning partitioning
Partitioning to which the current Partition belongs (set by Hierarchy.registerItem())
Method Details [hide private]

__init__(self, partitioning, name, data=None)
(Constructor)

 

Create a new partition with the given name in the given partitioning. It is assumed that the name has already been checked for uniqueness within the partitioning.

Parameters:
  • partitioning (Partitioning) - Partitioning to which the partition is added.
  • name (str) - Partition name.
  • data (anything) - Any object the user wishes to store with the item for later retrieval.

addOrderedPartitiones(self, ordered_partitions)

 

Add the ordered partition list to its item. This permits certain search optimizations.

Parameters:
  • ordered_partitions (list of Partition) - The item's ordered partition list for all partitionings

addChild(self, child)

 

Add a child to the current partition.

Parameters:
  • child (Partition) - The child partition to be added to the current partition's children.

addParent(self, parent)

 

Add a parent to the current partition.

Parameters:
  • parent (Partition) - The parent partition to be added to the current partition's parents.

getItems(self, add_pop=False)

 

Get the set of items contained in the current partition.

Parameters:
  • add_pop (bool) - If True, set the partition attribute "nitems" to the number of items in each partition encountered.

getRandomItems(self, nwanted)

 

Get (up to) nwanted random items from the current partition. If there are nwanted or fewer items in the partition, return them all.

Parameters:
  • nwanted (int) - Maximum number of items to return.
Returns: set of items
Items constituting the sample

_getDiverseRandomItemsRecurs(self, nwanted, fill)

 

Worker function to implement the recursive part of the method invoked by getDiverseRandomItems. See that method's description for details.

Parameters:
  • nwanted (int) - Maximum number of items to return
  • fill (Partition constant) - One of FULL_FILL, PART_FILL, or NO_FILL, which enforce successively stronger diversity criteria
Returns: set of items
Items constituting the sample

getDiverseRandomItems(self, nwanted, fill=1)

 

Get (up to) nwanted random items from a Partition, selecting more or less equally from Partition children, recursively, at each level down to the items themselves. This avoids unbalanced random sampling in situations where some child partitions contain many more items than others.

Parameters:
  • nwanted (int) - Maximum number of items to be requrned
  • fill (Partition constant) - One of FULL_FILL, PART_FILL, or NO_FILL, which enforce successively stronger diversity criteria and lead to successively lower likelihood that a full complement of nwanted structures will be returned. PART_FILL is the default. With FULL_FILL, the method will always return a full complement of nwanted items, if that many exist.
Returns: set of items
Items constituting the sample