#### PYMC3: How to use math.switch for high dimensional random variables

By Chaow Wu

I am currently trying to implement change point detection using this guide: http://nbviewer.jupyter.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter1_Introduction/Ch1_Introduction_PyMC3.ipynb

It uses a switch statement to decide between the parameters of distributions for before and after the change point.

``````lambda_ = pm.math.switch(tau > idx, lambda_1, lambda_2)
``````

I am also trying to find a changepoint, but using data that is assumed to come from a multivariate distribution.

Here is my code:

``````tau = pm.Uniform("tau_", lower = x_data[0], upper = x_data[-1])
mus_1 = pm.Uniform("mus1", lower = min(y_data[0]), upper = max(y_data[0]), shape = 10)
mus_2 = pm.Uniform("mus2", lower = min(y_data[0]), upper = max(y_data[0]), shape = 10)
mus_ = pm.math.switch(tau > x_data, mus_1, mus_2)
``````

I put shape as 10 for the distribution assumed is a multivariate normal distribution with 10 variables.

I assumed that the switch statement would assign the shape 10 random variable element wise to the x_data (7919 points)

However, I get the following error:

``````ValueError: Input dimension mis-match. (input[0].shape[0] = 7919, input[1].shape[0] = 10)
``````

It seems like the switch statement only allows you to switch between one-dimensional random variables, how do I work around this?

### [SOLVED] How do I list all files of a directory?

• 2010-07-08 19:31:22
• duhhunjonn
• 2565849 View
• 2922 Score
• Tags:   python directory

### [SOLVED] How do I check whether a file exists?

• 2008-09-17 12:55:00
• spence91
• 3028199 View
• 4470 Score
• Tags:   python file

### [SOLVED] How do I check if a list is empty?

• 2008-09-10 06:20:11
• Ray Vega
• 1811427 View
• 2809 Score
• Tags:   python list is-empty