@@ -96,7 +96,7 @@ def pdescs(rdms, descriptor):
96
96
)
97
97
98
98
99
- def rescale (rdms , method : str = 'evidence' ):
99
+ def rescale (rdms , method : str = 'evidence' , threshold = 1e-8 ):
100
100
"""Bring RDMs closer together
101
101
102
102
Iteratively scales RDMs based on pairs in-common.
@@ -105,11 +105,15 @@ def rescale(rdms, method: str = 'evidence'):
105
105
Args:
106
106
method (str, optional): One of 'evidence', 'setsize' or
107
107
'simple'. Defaults to 'evidence'.
108
+ threshold (float): Stop iterating when the sum of squares
109
+ difference between iterations is smaller than this value.
110
+ A smaller value means more iterations, but the algorithm
111
+ may not always converge.
108
112
109
113
Returns:
110
114
RDMs: RDMs object with the aligned RDMs
111
115
"""
112
- aligned , weights = _rescale (rdms .dissimilarities , method )
116
+ aligned , weights = _rescale (rdms .dissimilarities , method , threshold )
113
117
rdm_descriptors = deepcopy (rdms .rdm_descriptors )
114
118
if weights is not None :
115
119
rdm_descriptors ['rescalingWeights' ] = weights
@@ -166,7 +170,7 @@ def _scale(vectors: ndarray) -> ndarray:
166
170
return vectors / sqrt (_ss (vectors ))
167
171
168
172
169
- def _rescale (dissim : ndarray , method : str ) -> Tuple [ndarray , ndarray ]:
173
+ def _rescale (dissim : ndarray , method : str , threshold = 1e-8 ) -> Tuple [ndarray , ndarray ]:
170
174
"""Rescale RDM vectors
171
175
172
176
See :meth:`rsatoolbox.rdm.combine.rescale`
@@ -191,7 +195,7 @@ def _rescale(dissim: ndarray, method: str) -> Tuple[ndarray, ndarray]:
191
195
192
196
current_estimate = _scale (_mean (dissim ))
193
197
prev_estimate = np .full ([n_conds , ], - inf )
194
- while _ss (current_estimate - prev_estimate ) > 1e-8 :
198
+ while _ss (current_estimate - prev_estimate ) > threshold :
195
199
prev_estimate = current_estimate .copy ()
196
200
tiled_estimate = np .tile (current_estimate , [n_rdms , 1 ])
197
201
tiled_estimate [np .isnan (dissim )] = nan
0 commit comments