• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SCIInstitute / UncertainSCI / 4659511182

pending completion
4659511182

Pull #108

github

GitHub
Merge 3320693ee into 52de2ab68
Pull Request #108: Sphinx build

1589 of 3151 relevant lines covered (50.43%)

4.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.57
/UncertainSCI/sampling.py
1
import numpy as np
8✔
2
from numpy import random
8✔
3

4
from UncertainSCI.indexing import MultiIndexSet
8✔
5

6
def mixture_tensor_discrete_sampling(M, grids, weights, iset):
8✔
7
    """
8
    Constructs M random samples from a mixture of tensorial discrete measures.
9
    The measure is a uniform mixture of measures, each supported on the tensor
10
    product of grids (a list of arrays).
11

12
    The input weights define a collection of tensorial measures on the discrete
13
    support.
14

15
    The MultiIndexSet iset defines which measures are used in the mixture.
16

17
    weights is a list of arrays, where weights[j][:,i] corresponds to the
18
    i'th distribution on dimension j.
19
    """
20

21
    assert len(grids) == len(weights) == iset.dim
×
22

23
    N = [grids[j].size for j in range(iset.dim)]
×
24

25
    x = np.zeros([M, iset.dim])
×
26
    indices = iset.choice(M)
×
27

28
    max_indices = iset.maximum_unvivariate_degree()
×
29

30
    # Loop over possible values for the indices for each dimension.
31
    # This should be faster than looping over samples.
32

33
    for d in range(iset.dim):
×
34
        for k in range(max_indices[d]):
×
35
            mask = indices[:,d] == k
×
36
            x[mask,d] = random.choice(grids[d], probabilities=weights[d][:,k])
×
37

38
    return x
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc