コード例 #1
0
 def build_model_config_from_tvb(self):
     model = self.model
     del model["model_name"]
     model_config = ModelConfiguration(self.model_name, self.connectivity, self.coupling,
                                       self.monitor, self.initial_conditions, self.noise,
                                       self.x0_values, self.e_values, x1eq=None, zeq=None, Ceq=None, **model)
     if model_config.initial_conditions is None:
         model_config.initial_conditions = compute_initial_conditions_from_eq_point(model_config)
     return model_config
コード例 #2
0
 def _configure_model_from_equilibrium(self, x1eq, zeq, model_connectivity):
     # x1eq, zeq = self._ensure_equilibrum(x1eq, zeq) # We don't this by default anymore
     x0, Ceq, x0_values, e_values = self._compute_params_after_equilibration(x1eq, zeq, model_connectivity)
     self.x0 = x0
     model = self.model
     del model["model_name"]
     model_config = ModelConfiguration(self.model_name, model_connectivity, self.coupling,
                                       self.monitor, self.initial_conditions, self.noise,
                                       x0_values, e_values, x1eq, zeq, Ceq, **model)
     if model_config.initial_conditions is None:
         model_config.initial_conditions = compute_initial_conditions_from_eq_point(model_config)
     return model_config
コード例 #3
0
 def build_model_config_from_model_config(self, model_config):
     if not isinstance(model_config, dict):
         model_config_dict = model_config.__dict__
     else:
         model_config_dict = model_config
     model_configuration = ModelConfiguration()
     for attr, value in model_configuration.__dict__.items():
         value = model_config_dict.get(attr, None)
         if value is None:
             warning(attr + " not found in the input model configuration dictionary!" +
                     "\nLeaving default " + attr + ": " + str(getattr(model_configuration, attr)))
         if value is not None:
             setattr(model_configuration, attr, value)
     return model_configuration
コード例 #4
0
 def __init__(self, model_config=ModelConfiguration(), name='vep', target_data_type=Target_Data_Type.EMPIRICAL.value,
              priors_mode=PriorsModes.NONINFORMATIVE.value, normal_flag=1,
              linear_flag=0, x1eq_cr=X1EQ_CR, x1eq_def=X1EQ_DEF,
              parameters={}, ground_truth={}, xmode=XModes.X0MODE.value,
              K=K_DEF, sigma_x=SIGMA_X0_DEF):  #, MC_direction_split=0.5
     super(EpiProbabilisticModel, self).__init__(model_config, name, target_data_type, priors_mode, normal_flag,
                                                 parameters, ground_truth)
     self.xmode = xmode
     self.linear_flag = linear_flag
     self.x1eq_cr = x1eq_cr
     self.x1eq_def = x1eq_def
     self.sigma_x = sigma_x
     self.model_config = model_config
     self.K = K
コード例 #5
0
    def test_write_model_configuration(self):
        test_file = os.path.join(self.config.out.FOLDER_TEMP,
                                 "TestModelConfiguration.h5")
        dummy_mc = ModelConfiguration(
            x1eq=numpy.array([2.0, 3.0, 1.0]),
            zmode=None,
            zeq=numpy.array([3.0, 2.0, 1.0]),
            Ceq=numpy.array([1.0, 2.0, 3.0]),
            connectivity=self.dummy_connectivity.normalized_weights)

        assert not os.path.exists(test_file)

        self.writer.write_model_configuration(dummy_mc, test_file)

        assert os.path.exists(test_file)
コード例 #6
0
    def test_read_model_configuration(self):
        test_file = os.path.join(self.config.out.FOLDER_TEMP,
                                 "TestModelConfiguration.h5")
        dummy_mc = ModelConfiguration(x1eq=numpy.array([2.0, 3.0, 1.0]),
                                      zmode=None,
                                      zeq=numpy.array([3.0, 2.0, 1.0]),
                                      connectivity=numpy.array(
                                          [[1.0, 2.0, 3.0], [1.0, 2.0, 3.0],
                                           [2.0, 2.0, 2.0]]),
                                      Ceq=numpy.array([1.0, 2.0, 3.0]))
        self.writer.write_model_configuration(dummy_mc, test_file)
        mc = self.reader.read_model_configuration(test_file)

        assert numpy.array_equal(dummy_mc.x1eq, mc.x1eq)
        assert numpy.array_equal(dummy_mc.zeq, mc.zeq)
        assert numpy.array_equal(dummy_mc.Ceq, mc.Ceq)
        assert numpy.array_equal(dummy_mc.connectivity, mc.connectivity)
コード例 #7
0
 def __init__(self, model_config=ModelConfiguration(), name='vep_ode',
              target_data_type=Target_Data_Type.EMPIRICAL.value, priors_mode=PriorsModes.NONINFORMATIVE.value,
              normal_flag=1, linear_flag=0, x1eq_cr=X1EQ_CR, x1eq_def=X1EQ_DEF, x1_prior_weight=0.0,
              parameters={}, ground_truth={}, xmode=XModes.X0MODE.value,
              observation_model=OBSERVATION_MODELS.SEEG_LOGPOWER.value, K=K_DEF,
              sigma_x=SIGMA_X0_DEF, sigma_init=SIGMA_INIT_DEF,
              sigma=SIGMA_DEF, tau1=TAU1_DEF, tau0=TAU0_DEF, epsilon=EPSILON_DEF,
              scale=1.0, offset=0.0, x1_scale=1.0, x1_offset=0.0,
              number_of_target_data=0, time_length=0, dt=DT_DEF, upsample=UPSAMPLE, active_regions=np.array([]),
              gain_matrix=None, number_of_seizures=1, sde_mode=SDE_MODES.NONCENTERED.value):
     super(SDEEpiProbabilisticModel, self).__init__(model_config, name, target_data_type, priors_mode, normal_flag,
                                                    linear_flag, x1eq_cr, x1eq_def, x1_prior_weight,
                                                    parameters, ground_truth,
                                                    xmode, observation_model, K,
                                                    sigma_x, sigma_init, tau1, tau0,
                                                    epsilon, scale, offset, x1_scale, x1_offset,
                                                    number_of_target_data, time_length, dt, upsample,
                                                    active_regions, gain_matrix, number_of_seizures)
     self.sigma = sigma
     self.sde_mode = sde_mode
コード例 #8
0
    def __init__(self, model_config=ModelConfiguration(), name='vep_ode',
                 target_data_type=Target_Data_Type.EMPIRICAL.value, priors_mode=PriorsModes.NONINFORMATIVE.value,
                 normal_flag=1, linear_flag=0, x1eq_cr=X1EQ_CR, x1eq_def=X1EQ_DEF, x1_prior_weight=0.0,
                 parameters={}, ground_truth={}, xmode=XModes.X0MODE.value,
                 observation_model=OBSERVATION_MODELS.SEEG_LOGPOWER.value,
                 K=K_DEF, sigma_x=SIGMA_X0_DEF, sigma_init=SIGMA_INIT_DEF,
                 tau1=TAU1_DEF, tau0=TAU0_DEF, epsilon=EPSILON_DEF, scale=1.0, offset=0.0, x1_scale=1.0, x1_offset=0.0,
                 number_of_target_data=0, time_length=0, dt=DT_DEF, upsample=UPSAMPLE,
                 active_regions=np.array([]), gain_matrix=None, number_of_seizures=1):
        super(ODEEpiProbabilisticModel, self).__init__(model_config, name,  target_data_type, priors_mode, normal_flag,
                                                       linear_flag, x1eq_cr, x1eq_def, parameters, ground_truth,
                                                       xmode, K, sigma_x)
        if np.all(np.in1d(active_regions, range(self.number_of_regions))):
            self.active_regions = np.unique(active_regions)
        else:
            raise_value_error("Active regions indices:\n" + str(active_regions) +
                              "\nbeyond number of regions (" + str(self.number_of_regions) + ")!")

        if observation_model in [_.value for _ in OBSERVATION_MODELS]:
            self.observation_model = observation_model
        else:
            raise_value_error("Statistical model's observation model " + str(observation_model) +
                              " is not one of the valid ones: " + str([_.value for _ in OBSERVATION_MODELS]) + "!")
        self.x1_prior_weight = x1_prior_weight
        self.sigma_init = sigma_init
        self.tau1 = tau1
        self.tau0 = tau0
        self.scale = scale
        self.offset = offset
        self.epsilon = epsilon
        self.x1_scale = x1_scale
        self.x1_offset = x1_offset
        self.number_of_target_data = number_of_target_data
        self.time_length = time_length
        self.dt = dt
        self.upsample = upsample
        self.gain_matrix = gain_matrix
        if self.gain_matrix is None:
            self.gain_matrix = np.eye(self.number_of_active_regions)
        self.number_of_seizures =number_of_seizures
コード例 #9
0
class EpiProbabilisticModel(ProbabilisticModelBase):

    name = "vep"
    model_config = ModelConfiguration()
    linear_flag = 0
    normal_flag = 1
    xmode = XModes.X0MODE.value
    x1eq_cr = X1EQ_CR
    x1eq_def = X1EQ_DEF
    sigma_x = SIGMA_X0_DEF
    K = K_DEF
    # MC_direction_split = 0.5

    def __init__(self, model_config=ModelConfiguration(), name='vep', target_data_type=Target_Data_Type.EMPIRICAL.value,
                 priors_mode=PriorsModes.NONINFORMATIVE.value, normal_flag=1,
                 linear_flag=0, x1eq_cr=X1EQ_CR, x1eq_def=X1EQ_DEF,
                 parameters={}, ground_truth={}, xmode=XModes.X0MODE.value,
                 K=K_DEF, sigma_x=SIGMA_X0_DEF):  #, MC_direction_split=0.5
        super(EpiProbabilisticModel, self).__init__(model_config, name, target_data_type, priors_mode, normal_flag,
                                                    parameters, ground_truth)
        self.xmode = xmode
        self.linear_flag = linear_flag
        self.x1eq_cr = x1eq_cr
        self.x1eq_def = x1eq_def
        self.sigma_x = sigma_x
        self.model_config = model_config
        self.K = K
        # self.MC_direction_split = MC_direction_split

    def get_truth(self, parameter_name):
        truth = super(EpiProbabilisticModel, self).get_truth(parameter_name)
        if parameter_name in ["K", "tau1", "tau0"]:
            truth = np.mean(truth)
        return truth

    def get_prior(self, parameter_name):
        pmean, parameter = super(EpiProbabilisticModel, self).get_prior(parameter_name)
        if parameter_name in ["K", "tau1", "tau0"]:
            pmean = np.mean(pmean)
        return pmean, parameter