| 1 | #cxx . . $ `<file>/dwtools/ICA.h`/ifndef _ICA_h_ |
| 2 | #define _ICA_h_cxx . . $ `dwtools/ICA.h:2:9`! |
| 3 | /* ICA.h |
| 4 | * |
| 5 | * Copyright (C) 2010-2020 David Weenink, 2015 Paul Boersma |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | djmw 20101202 Initial version |
| 23 | djmw 20120406 Latest modification. |
| 24 | */ |
| 25 | |
| 26 | #include "Covariance.h"cxx . . $ `<file>/dwtools/Covariance.h`/ |
| 27 | #include "Sound_and_MixingMatrix.h"cxx . . $ `<file>/dwtools/Sound_and_MixingMatrix.h`/ |
| 28 | |
| 29 | |
| 30 | Thing_definecxx . . $ Diagonalizer# (Diagonalizer, TableOfReal) { |
| 31 | }; |
| 32 | |
| 33 | Thing_definecxx . . $ classCrossCorrelationTable. (CrossCorrelationTable, SSCP) { |
| 34 | void v1_infocxx . . $ structCrossCorrelationTable#v1_info(49f6e7a06ebc5aa8). () |
| 35 | override; |
| 36 | }; |
| 37 | |
| 38 | Collection_definecxx . . $ autoCrossCorrelationTableList# (CrossCorrelationTableList, OrderedOf, CrossCorrelationTable) { |
| 39 | void v1_infocxx . . $ structCrossCorrelationTableList#v1_info(49f6e7a06ebc5aa8). () |
| 40 | override; |
| 41 | }; |
| 42 | |
| 43 | /* |
| 44 | Cell [i,j] of a CrossCorrelationTable contains the cross-correlation between signal i and signal j (for one particular lag time). |
| 45 | For example, the CrossCorrelation of an n-channel sound is a nxn table where cell [i,j] contains the |
| 46 | cross-correlation of channel i with channel j for a particlular lag time tau. |
| 47 | In the statistical literature sometimes the cross-correlation between signals is also called "covariance". |
| 48 | However, the only thing a Covariance has in common with a CrossCorrelationTable is that both are symmetric |
| 49 | matrices. Differences between a CrossCorrelationTable and a Covariance: |
| 50 | 1. a Covariance matrix is always positive definite, for a cross-correlation table this is only guaranteed for |
| 51 | lag time tau = 0. |
| 52 | 2. The elements c [i] [j] in a Covariance always satisfy |c [i] [j] / sqrt (c [i] [i] * c [j] [j])| <= 1, this is |
| 53 | in general not the case for cross-correlations. |
| 54 | */ |
| 55 | |
| 56 | autoCrossCorrelationTablecxx . . $ autoCrossCorrelationTable# CrossCorrelationTable_createcxx . . $ CrossCorrelationTable_create(a0a0e6978a83c325). (integercxx . . $ integer# dimension); |
| 57 | |
| 58 | autoCrossCorrelationTablecxx . . $ autoCrossCorrelationTable# CrossCorrelationTable_createSimplecxx . . $ CrossCorrelationTable_createSimple(74e9ee5100beae63). (conststring32cxx . . $ conststring32# covars, conststring32cxx . . $ conststring32# centroid, integercxx . . $ integer# numberOfSamples); |
| 59 | |
| 60 | /* (sum(i,j=1..dimension, i!=j; C [i] [j]^2)) / (dimension * (dimension - 1)) */ |
| 61 | double CrossCorrelationTable_getDiagonalityMeasurecxx . . $ CrossCorrelationTable_getDiagonalityMeasure(8c99c75a35ba248d). (CrossCorrelationTablecxx . . $ CrossCorrelationTable# me); |
| 62 | |
| 63 | autoCrossCorrelationTablecxx . . $ autoCrossCorrelationTable# CrossCorrelationTable_Diagonalizer_diagonalizecxx . . $ CrossCorrelationTable_Diagonalizer_diagonalize(3ae35290795ec2ec). (CrossCorrelationTablecxx . . $ CrossCorrelationTable# me, Diagonalizercxx . . $ Diagonalizer# thee); |
| 64 | |
| 65 | double CrossCorrelationTableList_getDiagonalityMeasurecxx . . $ CrossCorrelationTableList_getDiagonalityMeasure(62cdc31d9300723e). (CrossCorrelationTableListcxx . . $ CrossCorrelationTableList# me, double *w, integercxx . . $ integer# start, integercxx . . $ integer# end); |
| 66 | |
| 67 | double CrossCorrelationTableList_Diagonalizer_getDiagonalityMeasurecxx . . $ CrossCorrelationTableList_Diagonalizer_getDiagonalityMeasure(6a9c4959b1b5cfeb). (CrossCorrelationTableListcxx . . $ CrossCorrelationTableList# me, Diagonalizercxx . . $ Diagonalizer# thee, double *w, integercxx . . $ integer# start, integercxx . . $ integer# end); |
| 68 | |
| 69 | autoCrossCorrelationTableListcxx . . $ autoCrossCorrelationTableList# CrossCorrelationTableList_createTestSetcxx . . $ CrossCorrelationTableList_createTestSet(120e7a6e2e4da5dc). (integercxx . . $ integer# dimension, integercxx . . $ integer# n, int firstPositiveDefinite, double sigma); |
| 70 | |
| 71 | autoDiagonalizercxx . . $ autoDiagonalizer# Diagonalizer_createcxx . . $ Diagonalizer_create(bcab702e72ab5c32). (integercxx . . $ integer# dimension); |
| 72 | |
| 73 | autoSoundcxx . . $ autoSound# Sound_to_Sound_BSScxx . . $ Sound_to_Sound_BSS(df64cdc8834ccc78). (Soundcxx . . $ Sound# me, |
| 74 | double startTime, double endTime, integercxx . . $ integer# numberOfCrossCorrelations, double lagStep, |
| 75 | integercxx . . $ integer# maxNumberOfIterations, double delta_w, int method); |
| 76 | |
| 77 | autoSoundcxx . . $ autoSound# Sound_whitenChannelscxx . . $ Sound_whitenChannels(85b1946a04d271a2). (Soundcxx . . $ Sound# me, double varianceFraction); |
| 78 | autoSoundcxx . . $ autoSound# Sound_Covariance_whitenChannelscxx . . $ Sound_Covariance_whitenChannels(9a13f277389dca40). (Soundcxx . . $ Sound# me, Covariancecxx . . $ Covariance# thee, double varianceFraction); |
| 79 | |
| 80 | void MixingMatrix_CrossCorrelationTableList_improveUnmixingcxx . . $ MixingMatrix_CrossCorrelationTableList_improveUnmixing(7fdfc0c49b36abc9). (MixingMatrixcxx . . $ MixingMatrix# me, CrossCorrelationTableListcxx . . $ CrossCorrelationTableList# thee, integercxx . . $ integer# maxNumberOfIterations, double tol, int method); |
| 81 | |
| 82 | void MixingMatrix_Sound_improveUnmixingcxx . . $ MixingMatrix_Sound_improveUnmixing(663204965cf36aed). (MixingMatrixcxx . . $ MixingMatrix# me, Soundcxx . . $ Sound# thee, |
| 83 | double startTime, double endTime, integercxx . . $ integer# numberOfCrossCorrelations, double lagStep, |
| 84 | integercxx . . $ integer# maxNumberOfIterations, double tol, int method); |
| 85 | /* |
| 86 | Determine the matrix that diagonalizes a series of CrossCorrelationTables as well as possible. |
| 87 | */ |
| 88 | autoDiagonalizercxx . . $ autoDiagonalizer# CrossCorrelationTableList_to_Diagonalizercxx . . $ CrossCorrelationTableList_to_Diagonalizer(b0588e7d97db0065). (CrossCorrelationTableListcxx . . $ CrossCorrelationTableList# me, integercxx . . $ integer# maxNumberOfIterations, double tol, int method); |
| 89 | |
| 90 | void Diagonalizer_CrossCorrelationTableList_improveDiagonalitycxx . . $ Diagonalizer_CrossCorrelationTableList_improveDiagonality(3d48017db7220a58). (Diagonalizercxx . . $ Diagonalizer# me, CrossCorrelationTableListcxx . . $ CrossCorrelationTableList# thee, |
| 91 | integercxx . . $ integer# maxNumberOfIterations, double tol, int method); |
| 92 | |
| 93 | autoCrossCorrelationTableListcxx . . $ autoCrossCorrelationTableList# CrossCorrelationTables_to_CrossCorrelationTableListcxx . . $ CrossCorrelationTables_to_CrossCorrelationTableList(675f2f7e46154f5c). (OrderedOfcxx . . $ OrderedOf#<structCrossCorrelationTablecxx . . $ structCrossCorrelationTable#> *me); |
| 94 | /* |
| 95 | Determine V * C [k] * V' for k=1..n, where V is the diagonalizer matrix and C [k] the k-th CrossCorrelationTable. |
| 96 | */ |
| 97 | autoCrossCorrelationTableListcxx . . $ autoCrossCorrelationTableList# CrossCorrelationTableList_Diagonalizer_diagonalizecxx . . $ CrossCorrelationTableList_Diagonalizer_diagonalize(f379359ff980788e). (CrossCorrelationTableListcxx . . $ CrossCorrelationTableList# me, Diagonalizercxx . . $ Diagonalizer# thee); |
| 98 | |
| 99 | |
| 100 | autoDiagonalizercxx . . $ autoDiagonalizer# MixingMatrix_to_Diagonalizercxx . . $ MixingMatrix_to_Diagonalizer(473addad94a90b52). (MixingMatrixcxx . . $ MixingMatrix# me); |
| 101 | |
| 102 | autoMixingMatrixcxx . . $ autoMixingMatrix# Diagonalizer_to_MixingMatrixcxx . . $ Diagonalizer_to_MixingMatrix(bfcdf80a87879ec0). (Diagonalizercxx . . $ Diagonalizer# me); |
| 103 | |
| 104 | /* |
| 105 | For multi-channel "sounds" like EEG signals. |
| 106 | The cross-correlation between channel i and channel j is defined as |
| 107 | sum (k=1..nsamples; (z [i] [k] - mean [i]) (z [j] [k + lag] - mean [j])) / (nsamples - 1). |
| 108 | */ |
| 109 | autoCrossCorrelationTablecxx . . $ autoCrossCorrelationTable# Sound_to_CrossCorrelationTablecxx . . $ Sound_to_CrossCorrelationTable(365ea64c78210068). (Soundcxx . . $ Sound# me, |
| 110 | double startTime, double endTime, double lagStep); |
| 111 | |
| 112 | autoCrossCorrelationTablecxx . . $ autoCrossCorrelationTable# Sounds_to_CrossCorrelationTable_combinedcxx . . $ Sounds_to_CrossCorrelationTable_combined(ae6614b97b9e4a9d). (Soundcxx . . $ Sound# me, Soundcxx . . $ Sound# thee, |
| 113 | double relativeStartTime, double relativeEndTime, double lagStep); |
| 114 | |
| 115 | // The covariance is the cross-correlation with lag 0. |
| 116 | autoCovariancecxx . . $ autoCovariance# Sound_to_Covariance_channelscxx . . $ Sound_to_Covariance_channels(e0bd5cc471d84f37). (Soundcxx . . $ Sound# me, double startTime, double endTime); |
| 117 | /* |
| 118 | Determine a CrossCorrelationTable for lags (k-1)*lagStep, where k = 1...n. |
| 119 | */ |
| 120 | autoCrossCorrelationTableListcxx . . $ autoCrossCorrelationTableList# Sound_to_CrossCorrelationTableListcxx . . $ Sound_to_CrossCorrelationTableList(17b583310ad9ab5e). (Soundcxx . . $ Sound# me, |
| 121 | double startTime, double endTime, integercxx . . $ integer# numberOfCrossCorrelations, double lagStep); |
| 122 | |
| 123 | autoMixingMatrixcxx . . $ autoMixingMatrix# TableOfReal_to_MixingMatrixcxx . . $ TableOfReal_to_MixingMatrix(4b15bc7206a6818c). (TableOfRealcxx . . $ TableOfReal# me); |
| 124 | |
| 125 | autoMixingMatrixcxx . . $ autoMixingMatrix# Sound_to_MixingMatrixcxx . . $ Sound_to_MixingMatrix(d82867c4462d41ff). (Soundcxx . . $ Sound# me, |
| 126 | double startTime, double endTime, integercxx . . $ integer# numberOfCrossCorrelations, double lagStep, |
| 127 | integercxx . . $ integer# maxNumberOfIterations, double tol, int method); |
| 128 | |
| 129 | #endif /*_ICA_h_ */ |