@@ -844,6 +844,22 @@ def thin_indices(self, factor, weights=None):
844
844
"""
845
845
if weights is None :
846
846
weights = self .weights
847
+ return WeightedSamples .thin_indices_single_samples (factor , weights )
848
+
849
+ @staticmethod
850
+ def thin_indices_and_weights (factor , weights ):
851
+ """
852
+ Returns indices and new weights for use when thinning samples.
853
+
854
+ :param factor: thin factor
855
+ :param weights: initial weight (counts) per sample point
856
+ :return: (unique index, counts) tuple of sample index values to keep and new weights
857
+ """
858
+ thin_ix = WeightedSamples .thin_indices_single_samples (factor , weights )
859
+ return np .unique (thin_ix , return_counts = True )
860
+
861
+ @staticmethod
862
+ def thin_indices_single_samples (factor , weights ):
847
863
numrows = len (weights )
848
864
norm1 = np .sum (weights )
849
865
weights = weights .astype (int )
@@ -914,8 +930,7 @@ def weighted_thin(self, factor):
914
930
This function also preserves separate chains.
915
931
:param factor: The (integer) factor to thin by
916
932
"""
917
- thin_ix = self .thin_indices (factor )
918
- unique , counts = np .unique (thin_ix , return_counts = True )
933
+ unique , counts = self .thin_indices_and_weights (factor , self .weights )
919
934
self .setSamples (self .samples [unique , :],
920
935
loglikes = None if self .loglikes is None
921
936
else self .loglikes [unique ],
@@ -1137,7 +1152,8 @@ def _getParamIndices(self):
1137
1152
:return: A dict mapping the param name to the parameter index.
1138
1153
"""
1139
1154
if self .samples is not None and len (self .paramNames .names ) != self .n :
1140
- raise WeightedSampleError ("paramNames size does not match number of parameters in samples" )
1155
+ raise WeightedSampleError ("paramNames size (%s) does not match number of "
1156
+ "parameters in samples (%s)" % (len (self .paramNames .names ), self .n ))
1141
1157
index = dict ()
1142
1158
for i , name in enumerate (self .paramNames .names ):
1143
1159
index [name .name ] = i
0 commit comments