@@ -501,77 +501,80 @@ def cohere_pairs( X, ij, NFFT=256, Fs=2, detrend=detrend_none,
501501 returnPxx = False ):
502502
503503 u"""
504- Cxy, Phase, freqs = cohere_pairs( X, ij, ...)
504+ Call signature::
505505
506- Compute the coherence and phase for all pairs ij, in X.
506+ Cxy, Phase, freqs = cohere_pairs( X, ij, ...)
507507
508- Parameters
509- ----------
510- X: array
511- a numSamples*numCols array
508+ Compute the coherence and phase for all pairs *ij*, in *X*.
512509
513- ij: list of tuples
514- Each tuple is a pair of indexes into the columns of X for which you want to
515- compute coherence. For example, if X has 64 columns, and you want to
516- compute all nonredundant pairs, define ij as
510+ *X* is a *numSamples* * *numCols* array
511+
512+ *ij* is a list of tuples. Each tuple is a pair of indexes into
513+ the columns of X for which you want to compute coherence. For
514+ example, if *X* has 64 columns, and you want to compute all
515+ nonredundant pairs, define *ij* as::
517516
518517 ij = []
519518 for i in range(64):
520519 for j in range(i+1,64):
521520 ij.append( (i,j) )
522521
523- preferSpeedOverMemory: optional, bool
522+ *preferSpeedOverMemory* is an optional bool. Defaults to true. If
523+ False, limits the caching by only making one, rather than two,
524+ complex cache arrays. This is useful if memory becomes critical.
525+ Even when *preferSpeedOverMemory* is False, :func:`cohere_pairs`
526+ will still give significant performace gains over calling
527+ :func:`cohere` for each pair, and will use subtantially less
528+ memory than if *preferSpeedOverMemory* is True. In my tests with
529+ a 43000,64 array over all nonredundant pairs,
530+ *preferSpeedOverMemory* = True delivered a 33% performance boost
531+ on a 1.7GHZ Athlon with 512MB RAM compared with
532+ *preferSpeedOverMemory* = False. But both solutions were more
533+ than 10x faster than naively crunching all possible pairs through
534+ :func:`cohere`.
535+
536+ Returns::
537+
538+ (Cxy, Phase, freqs)
524539
525- Defaults to true. If false, limits the caching by only making one, rather
526- than two, complex cache arrays. This is useful if memory becomes critical.
527- Even when preferSpeedOverMemory is false, cohere_pairs will still give
528- significant performace gains over calling cohere for each pair, and will
529- use subtantially less memory than if preferSpeedOverMemory is true. In my
530- tests with a 43000,64 array over all nonredundant pairs,
531- preferSpeedOverMemory=1 delivered a 33% performace boost on a 1.7GHZ Athlon
532- with 512MB RAM compared with preferSpeedOverMemory=0. But both solutions
533- were more than 10x faster than naievly crunching all possible pairs through
534- cohere.
535-
536- Returns
537- -------
540+ where:
538541
539- (Cxy, Phase, freqs), where:
540-
541- Cxy: dictionary of (i,j) tuples -> coherence vector for that
542- pair. Ie, Cxy[(i,j) = cohere(X[:,i], X[:,j]). Number of
543- dictionary keys is len(ij)
542+ - *Cxy*: dictionary of (*i*, *j*) tuples -> coherence vector for
543+ that pair. I.e., ``Cxy[(i,j) = cohere(X[:,i], X[:,j])``.
544+ Number of dictionary keys is ``len(ij)``.
544545
545- Phase: dictionary of phases of the cross spectral density at
546- each frequency for each pair. keys are (i,j ).
546+ - * Phase* : dictionary of phases of the cross spectral density at
547+ each frequency for each pair. Keys are (*i*, *j* ).
547548
548- freqs: vector of frequencies, equal in length to either the
549- coherence or phase vectors for any i,j key.
549+ - * freqs* : vector of frequencies, equal in length to either the
550+ coherence or phase vectors for any (*i*, *j*) key.
550551
551- Eg, to make a coherence Bode plot:
552+ Eg. , to make a coherence Bode plot: :
552553
553554 subplot(211)
554555 plot( freqs, Cxy[(12,19)])
555556 subplot(212)
556557 plot( freqs, Phase[(12,19)])
557558
558- For a large number of pairs, cohere_pairs can be much more
559- efficient than just calling cohere for each pair, because it
560- caches most of the intensive computations. If N is the number of
561- pairs, this function is O(N) for most of the heavy lifting,
562- whereas calling cohere for each pair is O(N^2). However, because
563- of the caching, it is also more memory intensive, making 2
564- additional complex arrays with approximately the same number of
565- elements as X.
566-
567- See test/cohere_pairs_test.py in the src tree for an example
568- script that shows that this cohere_pairs and cohere give the same
569- results for a given pair.
570-
571- See also
572- --------
573- :func: psd
574- """
559+ For a large number of pairs, :func:`cohere_pairs` can be much more
560+ efficient than just calling :func:`cohere` for each pair, because
561+ it caches most of the intensive computations. If :math:`N` is the
562+ number of pairs, this function is :math:`O(N)` for most of the
563+ heavy lifting, whereas calling cohere for each pair is
564+ :math:`O(N^2)`. However, because of the caching, it is also more
565+ memory intensive, making 2 additional complex arrays with
566+ approximately the same number of elements as *X*.
567+
568+ See :file:`test/cohere_pairs_test.py` in the src tree for an
569+ example script that shows that this :func:`cohere_pairs` and
570+ :func:`cohere` give the same results for a given pair.
571+
572+ .. sealso::
573+
574+ :func:`psd`
575+ For information about the methods used to compute
576+ :math:`P_{xy}`, :math:`P_{xx}` and :math:`P_{yy}`.
577+ """
575578 numRows , numCols = X .shape
576579
577580 # zero pad if X is too short
0 commit comments