By Chaow Wu


2018-06-13 14:40:35 8 Comments

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?

0 comments

Related Questions

Sponsored Content

33 Answered Questions

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

  • 2008-09-10 06:20:11
  • Ray Vega
  • 1910689 View
  • 2917 Score
  • 33 Answer
  • Tags:   python list

35 Answered Questions

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

  • 2010-07-08 19:31:22
  • duhhunjonn
  • 2720855 View
  • 3052 Score
  • 35 Answer
  • Tags:   python directory

25 Answered Questions

[SOLVED] How can I safely create a nested directory in Python?

16 Answered Questions

[SOLVED] How to make a chain of function decorators?

49 Answered Questions

[SOLVED] How to merge two dictionaries in a single expression?

40 Answered Questions

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

16 Answered Questions

[SOLVED] Are static class variables possible?

41 Answered Questions

[SOLVED] How do I sort a dictionary by value?

18 Answered Questions

[SOLVED] Using global variables in a function

23 Answered Questions

[SOLVED] How do I pass a variable by reference?

Sponsored Content