Пример #1
0
def calc_equilibrium_point(epileptor_model, model_configuration, weights):
    # Update zeq given the specific model, and assuming the model_configuration x1eq for the moment in the context of a 2d model:
    # It is assumed that the model.x0_values has been adjusted already at the phase of model creation
    if epileptor_model._ui_name == "EpileptorDP2D":
        x1eq = model_configuration.x1EQ
        zeq = model_configuration.zEQ
        equilibrium_point = numpy.c_[x1eq, zeq].T
    elif epileptor_model._ui_name == "EpileptorDP":
        #EpileptorDP
        equilibrium_point = calc_eq_6d(epileptor_model.x0, epileptor_model.K, weights,
                                       epileptor_model.yc, epileptor_model.Iext1, epileptor_model.Iext2,
                                       model_configuration.x1EQ, epileptor_model.a, epileptor_model.b,
                                       epileptor_model.d, epileptor_model.s, epileptor_model.gamma,
                                       zmode=epileptor_model.zmode)
    elif epileptor_model._ui_name == "EpileptorDPrealistic":
            equilibrium_point = calc_eq_11d(epileptor_model.x0, epileptor_model.K, weights,
                                            epileptor_model.yc, epileptor_model.Iext1, epileptor_model.Iext2,
                                            epileptor_model.slope, epileptor_model.fun_slope_Iext2,
                                            model_configuration.x1EQ, epileptor_model.a, epileptor_model.b,
                                            epileptor_model.d, epileptor_model.s,
                                            epileptor_model.gamma, zmode=epileptor_model.zmode,
                                            pmode=epileptor_model.pmode)[0]
    else:
        # all 6D models (tvb, java)
        equilibrium_point = calc_eq_6d(epileptor_model.x0, epileptor_model.Ks, weights,
                                       epileptor_model.c, epileptor_model.Iext, epileptor_model.Iext2,
                                       model_configuration.x1EQ, epileptor_model.a, epileptor_model.b,
                                       epileptor_model.d, epileptor_model.aa, gamma=GAMMA_DEF, zmode=numpy.array("lin"))
    if (epileptor_model._ui_name != "JavaEpileptor"):
        assert_equilibrium_point(epileptor_model, weights, equilibrium_point)
    else:
        #TODO: Implement dfun for the Java simulator
        raise_not_implemented_error("The dfun for Java simulator is not implemented yet!")
    return equilibrium_point
 def get_epileptor_parameters(self, model_config):
     self.logger.info("Unpacking epileptor parameters...")
     epileptor_params = {}
     for p in ["a", "b", "d", "yc", "Iext1", "slope"]:
         temp = getattr(model_config, p)
         if isinstance(temp, (np.ndarray, list)):
             if np.all(temp[0], np.array(temp)):
                 temp = temp[0]
             else:
                 raise_not_implemented_error(
                     "Statistical models where not all regions have the same value "
                     + " for parameter " + p + " are not implemented yet!")
         epileptor_params.update({p: temp})
     x0cr, rx0 = calc_x0cr_r(epileptor_params["yc"],
                             epileptor_params["Iext1"],
                             epileptor_params["a"],
                             epileptor_params["b"],
                             epileptor_params["d"],
                             zmode=np.array("lin"),
                             x1_rest=X1_DEF,
                             x1_cr=X1_EQ_CR_DEF,
                             x0def=X0_DEF,
                             x0cr_def=X0_CR_DEF,
                             test=False,
                             shape=None,
                             calc_mode="non_symbol")
     epileptor_params.update({"x0cr": x0cr, "rx0": rx0})
     return epileptor_params
Пример #3
0
 def read_vb_results(self, fit):
     est = {}
     samples = {}
     for ip, p in enumerate(fit['sampler_param_names']):
         p_split = p.split('.')
         p_name = p_split.pop(0)
         if est.get(p_name) is None:
             samples.update({p_name: []})
             est.update({p_name: []})
         if len(p_split) == 0:
             # scalar parameters
             samples[p_name] = fit["sampler_params"][ip]
             est[p_name] = fit["mean_pars"][ip]
         else:
             if len(p_split) == 1:
                 # vector parameters
                 samples[p_name].append(fit["sampler_params"][ip])
                 est[p_name].append(fit["mean_pars"][ip])
             else:
                 ii = int(p_split.pop(0)) - 1
                 if len(p_split) == 0:
                     # 2D matrix parameters
                     if len(est[p_name]) < ii + 1:
                         samples[p_name].append([fit["sampler_params"][ip]])
                         est[p_name].append([fit["mean_pars"][ip]])
                     else:
                         samples[p_name][ii].append(
                             fit["sampler_params"][ip])
                         est[p_name][ii].append(fit["mean_pars"][ip])
                 else:
                     if len(est[p_name]) < ii + 1:
                         samples[p_name].append([])
                         est[p_name].append([])
                     jj = int(p_split.pop(0)) - 1
                     if len(p_split) == 0:
                         # 3D matrix parameters
                         if len(est[p_name][ii]) < jj + 1:
                             samples[p_name][ii].append(
                                 [fit["sampler_params"][ip]])
                             est[p_name][ii].append([fit["mean_pars"][ip]])
                         else:
                             if len(est[p_name][ii]) < jj + 1:
                                 samples[p_name][ii].append([])
                                 est[p_name][ii].append([])
                                 samples[p_name][ii][jj].append(
                                     fit["sampler_params"][ip])
                             est[p_name][ii][jj].append(
                                 fit["mean_pars"][ip])
                     else:
                         raise_not_implemented_error(
                             "Extracting of parameters of more than 3 dimensions is not "
                             + "implemented yet for vb!", self.logger)
     for key in est.keys():
         if isinstance(est[key], list):
             est[key] = np.squeeze(np.array(est[key]))
         if isinstance(samples[key], list):
             samples[key] = np.squeeze(np.array(samples[key]))
     return samples, est
Пример #4
0
 def jacobian(self,
              state_variables,
              coupling,
              local_coupling=0.0,
              array=numpy.array,
              where=numpy.where,
              concat=numpy.concatenate):
     raise_not_implemented_error("Jacobian calculation of model " +
                                 self._ui_name + " is not implemented yet!")
Пример #5
0
 def scipy_method(self, method, *args, **kwargs):
     if method in [
             "rvs", "ppf", "isf", "stats", "moment", "median", "mean",
             "interval"
     ]:
         return self._scipy_method(method, self.loc, self.scale, *args,
                                   **kwargs)
     elif method in ["pdf", "logpdf", "cdf", "logcdf", "sf", "logsf"]:
         x, args, kwargs = get_x_arg_for_param_distrib(
             self, *args, **kwargs)
         return x, self._scipy_method(method, self.loc, self.scale, *args,
                                      **kwargs)
     else:
         raise_not_implemented_error("Scipy method " + method +
                                     " is not implemented for parameter " +
                                     self.name + "!")
Пример #6
0
 def scipy_method(self, method, *args, **kwargs):
     if method in [
             "rvs", "ppf", "isf", "stats", "moment", "median", "mean",
             "interval"
     ]:
         return self.max - self.star.scipy_method(method, *args, **kwargs)
     elif method in ["pdf", "logpdf", "cdf", "logcdf", "sf", "logsf"]:
         x, args, kwargs = get_x_arg_for_param_distrib(
             self, *args, **kwargs)
         args[0] = self.max - x
         pdf = self.star.scipy_method(method, *args, **kwargs)[1]
         return x, pdf
     else:
         raise_not_implemented_error(
             "Scipy method " + method +
             " is not implemented for transformed parameter " + self.name +
             "!")
Пример #7
0
 def sample(self, parameter=(), loc=0.0, scale=1.0, **kwargs):
     if isinstance(parameter, Parameter):
         parameter_shape = parameter.p_shape
         low = parameter.low
         high = parameter.high
         loc = getattr(parameter, "loc", loc)
         scale = getattr(parameter, "scale", scale)
     else:
         low = np.array(kwargs.pop("low", -CalculusConfig.MAX_SINGLE_VALUE))
         high = np.array(kwargs.pop("high",
                                    CalculusConfig.MAX_SINGLE_VALUE))
         parameter_shape = kwargs.pop("shape", (1, ))
     scale = (high - low) * scale
     low = low + loc
     high = low + scale
     low, high = self.check_for_infinite_bounds(low.tolist(), high.tolist())
     low, high, n_outputs, parameter_shape = self.check_size(
         low, high, parameter_shape)
     bounds = [list(b) for b in zip(low.tolist(), high.tolist())]
     self.adjust_shape(parameter_shape)
     self.sampler = importlib.import_module("SALib.sample." +
                                            self.sampler).sample
     size = self.n_samples
     problem = {'num_vars': n_outputs, 'bounds': bounds}
     if self.sampler is ff.sample:
         samples = (self.sampler(problem)).T
     else:
         other_params = {}
         if self.sampler is saltelli.sample:
             size = int(np.round(1.0 * size / (2 * n_outputs + 2)))
         elif self.sampler is fast_sampler.sample:
             other_params = {"M": kwargs.get("M", 4)}
         elif self.sampler is morris.sample:
             # I don't understand this method and its inputs. I don't think we will ever use it.
             raise_not_implemented_error()
         samples = self.sampler(problem, size, **other_params)
     # Adjust samples number:
     self.n_samples = samples.shape[0]
     self.shape = list(self.shape)
     self.shape[-1] = self.n_samples
     self.shape = tuple(self.shape)
     transpose_shape = tuple([self.n_samples] + list(self.shape)[0:-1])
     return np.reshape(samples.T, transpose_shape).T
Пример #8
0
 def load_model_data_from_file(self, reset_path=False, **kwargs):
     model_data_path = kwargs.get("model_data_path", self.model_data_path)
     if reset_path:
         self.model_data_path = model_data_path
     extension = model_data_path.split(".", -1)[-1]
     if isequal_string(extension, "R"):
         model_data = rload(model_data_path)
     elif isequal_string(extension, "npy"):
         model_data = np.load(model_data_path).item()
     elif isequal_string(extension, "mat"):
         model_data = loadmat(model_data_path)
     elif isequal_string(extension, "pkl"):
         with open(model_data_path, 'wb') as f:
             model_data = pickle.load(f)
     elif isequal_string(extension, "h5"):
         model_data = H5Reader().read_dictionary(model_data_path)
     else:
         raise_not_implemented_error("model_data file (" + model_data_path +
                                     ") that are not one of (.R, .npy, .mat, .pkl) cannot be read!")
     for key in model_data.keys():
         if key[:3] == "EPI":
             del model_data[key]
     return model_data
Пример #9
0
 def run_pse_parallel(self):
     raise_not_implemented_error("PSE parallel not implemented!", self.logger)
Пример #10
0
 def _numpy(self, loc=0.0, scale=1.0, size=(1, )):
     raise_not_implemented_error(
         "No implementation of bernoulli distribution in numpy.random module!"
     )