(compute, dataset,
        sample_size=None, batch_size=1, cachefile=None, **kwargs)
Computes conditional mean and variance for a large data sample that
    can be computed from a dataset.  The compute function should return a
    sequence of sample batch tuples (condition, (sample, unit)-tensor),
    one for each condition relevant to the batch.
Computes conditional mean and variance for a large data sample that
    can be computed from a dataset.  The compute function should return a
    sequence of sample batch tuples (condition, (sample, unit)-tensor),
    one for each condition relevant to the batch.
Computes conditional mean and variance for a large data sample that can be computed from a dataset . The compute function should return a sequence of sample batch tuples ( condition ( sample unit ) - tensor ) one for each condition relevant to the batch .
def tally_conditional_mean(compute, dataset,
        sample_size=None, batch_size=1, cachefile=None, **kwargs):
    '''
    Computes conditional mean and variance for a large data sample that
    can be computed from a dataset.  The compute function should return a
    sequence of sample batch tuples (condition, (sample, unit)-tensor),
    one for each condition relevant to the batch.
    '''
    with torch.no_grad():
        args = dict(sample_size=sample_size)
        cached_state = load_cached_state(cachefile, args)
        if cached_state is not None:
            return runningstats.RunningConditionalVariance(state=cached_state)
        loader = make_loader(dataset, sample_size, batch_size, **kwargs)
        cv = runningstats.RunningConditionalVariance()
        for i, batch in enumerate(pbar(loader)):
            sample_set = call_compute(compute, batch)
            for cond, sample in sample_set:
                # Move uncommon conditional data to the cpu before collating.
                cv.add(cond, sample)
        # At the end, move all to the CPU
        cv.to_('cpu')
        save_cached_state(cachefile, cv, args)
        return cv
def tally_conditional_mean ( compute , dataset , sample_size = None , batch_size = 1 , cachefile = None , * * kwargs ) : with torch . no_grad ( ) : args = dict ( sample_size = sample_size ) cached_state = load_cached_state ( cachefile , args ) if cached_state is not None : return runningstats . RunningConditionalVariance ( state = cached_state ) loader = make_loader ( dataset , sample_size , batch_size , * * kwargs ) cv = runningstats . RunningConditionalVariance ( ) for i , batch in enumerate ( pbar ( loader ) ) : sample_set = call_compute ( compute , batch ) for cond , sample in sample_set : # Move uncommon conditional data to the cpu before collating. cv . add ( cond , sample ) # At the end, move all to the CPU cv . to_ ( 'cpu' ) save_cached_state ( cachefile , cv , args ) return cv