elephant.spade_src.fast_fca module — Elephant 0.5.0 documentation

# elephant.spade_src.fast_fca module

This module provides an implementation of the formal concept analysis (FCA) in pure Python. It is used by the SPADE analysis. The code builds on C. Lindig’s Fast Concept Analysis work (1999,2002).

Original code available at:

Copyright (C) 2008-2012 by Dominik Endres (dominik.endres@gmail.com). Relicensed for Elephant by permission.

## Usage example:

    >>> relation=[]
    >>> relation+=[('monkeyHand','neuron2')]
    >>> relation+=[('monkeyFace','neuron1')]
    >>> relation+=[('monkeyFace','neuron2')]
    >>> relation+=[('humanFace','neuron1')]
    >>> relation+=[('spider','neuron3')]
    >>> concepts=formalConcepts(relation)
    >>> concepts.computeLattice()
    >>> print(concepts)

If you generate publications based on this code, please cite the following paper:

Endres D., Adam R., Giese M.A. & Noppeney U.. (2012). Understanding the Semantic Structure of Human fMRI Brain Recordings with Formal Concept Analysis. Proceedings of the 10th International Conference on Formal Concept Analysis (ICFCA 2012) LNAI 7278, Springer,pp. 96-111.

class `elephant.spade_src.fast_fca.` `formalConcept`(extent=frozenset([]), intent=frozenset([]), intentIndexes=[])

  A formal concept is comprised of an extent and and intent. Furthermore, intentIndexes is an ordered list of attribute indexes for lectic ordering. Also contains sets of introduced attibutes and objects and lectically ordered lists of upper and lower neighbours.

  Methods

  `copy`()

    Copy construction.

class `elephant.spade_src.fast_fca.` `formalConcepts`(relation, objects=None, attributes=None)

  Computes set of concepts from a binary relation by an algorithm similar to C. Lindig’s Fast Concept Analysis (2002).

  Methods

  `checkDownset`(topConcept, nonMembers)

    Remove all elements from nonMembers which are in the downset of topConcept.

  `checkLowerNeighbours`(concept, nonMembers)

    Helper for checkDownset. Remove all elements from nonMembers which are in the downset of concept.

  `computeAttributeDownsets`()

    Iterate through all concepts and compute set of attributes which are introduced in the downset of each concept. Iteration is done in inverse lectic order, therefore each concept needs to check only its immediate subordinates.

  `computeClosestIntroducedAttributes`(num=5)

    Iterate through all concepts and find at most num introduced attributes of closest upper neighbours of. These attributes can then serve as concept name.

  `computeClosestIntroducedAttributesConcept`(con, num=5)
  `computeLattice`()

    Computes concepts and lattice. self.concepts contains lectically ordered list of concepts after completion.

  `computeLowerNeighbours`(concept, minsize=0)

    This dual version of upperNeighbours runs fast enough in Python to be useful. Based on a theorem from C. Lindig’s (1999) PhD thesis. Returns list of upper neighbours of concept. Ignores lower neighbours with less than minextent objects in extent.

  `computeMinExtentLattice`(minextent=0)

    Computes concepts and lattice. self.concepts contains lectically ordered list of concepts after completion.

  `computeStability`(extensional=True)

    Compute stability of concepts. After calling this method, each concept has a member variable ‘stability’ uses the algorithm described in roth,obiedkov,kourie (2008): on succinct representation of knowledge community taxonimies with FCA

  `computeUpperNeighbours`(concept)

    This version of upperNeighbours runs fast enough in Python to be useful. Based on a theorem from C. Lindig’s (1999) PhD thesis. Returns list of upper neighbours of concept.

  `delConceptFromDicts`(concept)
  `dotPrint`(outStream=<open file '<stdout>', mode 'w'>, extentView=None, title=None, showObjects='all', showAttributes='all', colorlist=None, withStability=False)

    Print ordered concept set in dot style. outStream: open, writeable stream to plot into. if extentView(extent,intent) is supplied, it needs to be a function that takes the extent and intent as an argument and returns an image filename for it, which will be plotted in the node. showObjects,showAttributes= show {all|none|introduced} objects/attributes in the concept nodes. colorlist: draw concept boundary in colors from that list, cycle.

  `enumerateConcepts`()

    Assigns numbers to concept based on lectic order.

  `findClosestIntroducedAttributes`(concept, num)

    Find at least num attributes that were introduced closest to concept in upward direction. This is useful for naming concepts which introduce no attributes by which they could be named.

  `findLargestConcept`(attribList, startConcept=None, nextLower=True)

    find the largest concept which has all the attributes in attribList, starting at startConcept. Return None if no such concept exists.

  `findLargestConcept_closure`(attribList, startConcept)

    find the largest concept which has all the attributes in attribList, starting at startConcept. Return None if no such concept exists.

  `getLowerNeighbours`(con)

    Get all lower neighbours of con. Concept must be in self.concepts!!!

  `getStableConcepts`(minStability=None, quantile=None, nmost=None)

    Return a formalConcept object with the most stable concepts. computeStability() needs to be called before this method. One of nmost,minStability,quantile must be supplied. minStability supersedes quantile supersedes nmost. nmost: return the n most stable concepts minStability: return all concepts with at least minStability quantile: return the most stable quantile <= 1.

  `getUpperNeighbours`(con)

    Get all upper neighbours of concept. Concept must be in self.concepts!!!

  `insertNewConcept`(attribList, numNames=5)

    Compute closure of attrib list and insert into graph if extent is not empty. Return new concept or None (if extent is empty). returns tuple (concept,isNew)

  `numberConceptsAndComputeIntroduced`()

    Numbers concepts and computes introduced objects and attributes

  `prune`(concept, renumber=True)

    Prune concept from lattice. Upper neighbours are connected to lower neighbours if no other path through the lattice connects them. Returns True on success.

  `pruneNoIntroduced`(noAttrib=True, noObject=True)

    Starting from the bottom, prune all concepts that do not introduce at least one attribute (if noAttrib) and/or at least one object (if noObject) Leaves top concept. Return number of pruned concepts

  `pruneSmallerExtents`(minNumObjects)

    Prune all concepts at the bottom of the lattice whose |extent|<=minNumObjects. This may lead to some attributes never being introduced! Return number of pruned concepts.

  `recomputeNeighbours`()

class `elephant.spade_src.fast_fca.` `formalContext`(relation, objects=None, attributes=None)

  The formal context. Builds dictionaries object=>attributes and vice versa for faster closure computation. Set of objects and attributes are kept in lists rather than sets for lectic ordering of concepts.

  Methods

  `attributesPrime`(attributeSet)

    return a set of all objects which have all attributes in attribute set.

  `indexList`(attributeSet)

    return ordered list of attribute indexes. For lectic ordering of concepts.

  `objectsPrime`(objectSet)

    return a frozenset of all attributes which are shared by members of objectSet.

  `updateExtent`(extent, attribute)

    return intersection of intent and all attributes of object.

  `updateIntent`(intent, object)

    return intersection of intent and all attributes of object.