コード例 #1
0
    def compute(cls, observation, prediction):
        """
        Computes a Freeman-Tukey score from an observation and a prediction.
        """

        obs_values = observation[~np.isnan(observation)]
        pred_values = prediction[~np.isnan(prediction)]

        assert(all(x<=1.00 for x in obs_values) and all(x<=1.00 for x in pred_values)), \
            "Probabiltity values should not be larger than 1.0"
        obs_values *= 100
        pred_values *= 100

        dof = len(obs_values
                  ) - 1  # degrees of freedom for the Chi-squared distribution
        stat = 4 * sum((np.sqrt(obs_values) - np.sqrt(pred_values))**2)
        pval = scipy.stats.distributions.chi2.sf(stat, dof)

        stat = utils.assert_dimensionless(stat)
        pval = utils.assert_dimensionless(pval)

        # Obtaining a score value normalized respect to the mean and std of the Chi-squared distribution
        chisq_mean = dof
        chisq_std = np.sqrt(2 * dof)
        stat_n = abs(stat - chisq_mean) / chisq_std
        FreemanTukey_Result = FreemanTukeyResult(stat_n, pval)

        return FreemanTukey1Score(FreemanTukey_Result)
コード例 #2
0
    def compute(cls, observation, prediction, distances):
        """Computes average of z-scores from observation and prediction for back-propagating AP amplitudes"""
        errors = {'active_Na':{}, 'blocked_Na':{}}
        
        for i in range (0, len(distances)):
            
            p_value_active = prediction['active_Na']['model_AP1_amp_dendpersoma_at_'+str(distances[i])+'um']['mean']
            p_value_blocked = prediction['blocked_Na']['model_AP1_amp_dendpersoma_at_'+str(distances[i])+'um']['mean']
            o_mean_active = observation['active_Na']['mean_AP1_amp_dendpersoma_at_'+str(distances[i])+'um']
            o_mean_blocked = observation['blocked_Na']['mean_AP1_amp_dendpersoma_at_'+str(distances[i])+'um']
            o_std_active = observation['active_Na']['std_AP1_amp_dendpersoma_at_'+str(distances[i])+'um']
            o_std_blocked = observation['blocked_Na']['std_AP1_amp_dendpersoma_at_'+str(distances[i])+'um']
            
            try:
                error_active = abs(p_value_active - o_mean_active)/o_std_active
                error_active = assert_dimensionless(error_active)
            except (TypeError,AssertionError) as e:
                error_active = e
            errors['active_Na'] = {'AP1_amp_at_'+str(distances[i]) : error_active} 
            
            try:
                error_blocked = abs(p_value_blocked - o_mean_blocked)/o_std_blocked
                error_blocked = assert_dimensionless(error_blocked)
            except (TypeError,AssertionError) as e:
                error_blocked = e
            errors['blocked_Na'] = {'AP1_amp_at_'+str(distances[i]) : error_blocked}


        score_avg = numpy.nanmean(numpy.array([error_active, error_blocked]))

        return score_avg, errors
コード例 #3
0
    def compute(cls, observation, prediction):
        """
        Computes a Neyman score from an observation and a prediction.
        """

        obs_values = observation[~np.isnan(observation)]
        pred_values = prediction[~np.isnan(prediction)]

        assert(all(x<=1.00 for x in obs_values) and all(x<=1.00 for x in pred_values)), \
            "Probabiltity values should not be larger than 1.0"
        obs_values *= 100
        pred_values *= 100

        if type(obs_values) is pq.quantity.Quantity:
            obs_values = obs_values.magnitude
        if type(pred_values) is pq.quantity.Quantity:
            pred_values = pred_values.magnitude

        Neyman_Result = power_divergence(f_obs=pred_values,
                                         f_exp=obs_values,
                                         lambda_='neyman')

        utils.assert_dimensionless(Neyman_Result.statistic)
        utils.assert_dimensionless(Neyman_Result.pvalue)

        # Obtaining a score value normalized respect to the mean and std of the Chi-squared distribution
        dof = len(obs_values
                  ) - 1  # degrees of freedom for the Chi-squared distribution
        stat = Neyman_Result.statistic
        chisq_mean = dof
        chisq_std = np.sqrt(2 * dof)
        stat_n = abs(stat - chisq_mean) / chisq_std
        Neyman_result = NeymanResult(stat_n, Neyman_Result.pvalue)

        return NeymanScore(Neyman_result)
コード例 #4
0
    def compute(cls, observation, prediction):
        """
        Computes a Log-Likelihood Ratio score from an observation and a prediction.
        """

        obs_values = observation[~np.isnan(observation)]
        pred_values = prediction[~np.isnan(prediction)]

        dof = len(obs_values
                  ) - 1  # degrees of freedom for the Chi-squared distribution
        Log_LikelihoodRatio_Result = power_divergence(obs_values,
                                                      pred_values,
                                                      ddof=dof,
                                                      lambda_='log-likelihood')

        utils.assert_dimensionless(Log_LikelihoodRatio_Result.statistic)
        utils.assert_dimensionless(Log_LikelihoodRatio_Result.pvalue)

        # Obtaining a score value normalized respect to the mean and std of the Chi-squared distribution
        stat = Log_LikelihoodRatio_Result.statistic
        chisq_mean = dof
        chisq_std = np.sqrt(2 * dof)
        stat_n = abs(stat - chisq_mean) / chisq_std

        Log_LikelihoodRatio_result = Log_LikelihoodRatioResult(
            stat_n, Log_LikelihoodRatio_Result.pvalue)
        return Log_LikelihoodRatioScore(Log_LikelihoodRatio_result)
コード例 #5
0
ファイル: utils_tests.py プロジェクト: vrhaynes/sciunit
    def test_assert_dimensionless(self):
        import quantities as pq
        from sciunit.utils import assert_dimensionless

        assert_dimensionless(3 * pq.s * pq.Hz)
        try:
            assert_dimensionless(3 * pq.s)
        except TypeError:
            pass
        else:
            raise Exception("Should have produced a type error")
コード例 #6
0
ファイル: utils_tests.py プロジェクト: scidash/sciunit
    def test_assert_dimensionless(self):
        import quantities as pq
        from sciunit.utils import assert_dimensionless

        assert_dimensionless(3*pq.s*pq.Hz)
        try:
            assert_dimensionless(3*pq.s)
        except TypeError:
            pass
        else:
            raise Exception("Should have produced a type error")
コード例 #7
0
    def compute(cls, observation, prediction):
        """Computes a z-scores from an observation and a prediction."""

        p_value_I_maxNumAP = prediction['model_I_maxNumAP']
        p_value_I_below_depol_block = prediction['model_I_below_depol_block']
        o_mean_Ith = observation['mean_Ith']
        o_std_Ith = observation['Ith_std']
        p_value_Veq = prediction['model_Veq']
        o_mean_Veq = observation['mean_Veq']
        o_std_Veq = observation['Veq_std']

        try:
            result_I_maxNumAP = abs(p_value_I_maxNumAP -
                                    o_mean_Ith) / o_std_Ith
            result_I_maxNumAP = assert_dimensionless(result_I_maxNumAP)
            if not math.isnan(p_value_I_below_depol_block):
                result_I_below_depol_block = abs(p_value_I_below_depol_block -
                                                 o_mean_Ith) / o_std_Ith
            else:
                result_I_below_depol_block = float('NaN')
            result_I_below_depol_block = assert_dimensionless(
                result_I_below_depol_block)
            if not math.isnan(p_value_Veq):
                result_Veq = abs(p_value_Veq - o_mean_Veq) / o_std_Veq
            else:
                result_Veq = float('NaN')
            result_Veq = assert_dimensionless(result_Veq)

        except (TypeError, AssertionError) as e:
            result_I_maxNumAP = e
            result_I_below_depol_block = e
            result_Veq = e

        if p_value_I_maxNumAP != p_value_I_below_depol_block and not math.isnan(
                result_I_below_depol_block
        ):  # according to the experiment thesetwo should be equal
            I_diff_penalty = 200.0 * (
                abs(p_value_I_maxNumAP - p_value_I_below_depol_block) /
                (1 * nA))  # divided be (1*nA) to make it dimensionless
            I_diff_penalty = assert_dimensionless(I_diff_penalty)
        else:
            I_diff_penalty = 0

        if math.isnan(result_I_below_depol_block) or math.isnan(result_Veq):
            final_score = 100.0
        else:
            final_score = numpy.nanmean([
                result_I_maxNumAP, result_I_below_depol_block, result_Veq
            ]) + I_diff_penalty

        return final_score, result_I_maxNumAP, result_I_below_depol_block, result_Veq, I_diff_penalty
コード例 #8
0
 def compute(cls, observation, prediction):
     """Compute a z-score from an observation and a prediction."""
     assert isinstance(observation, dict),\
         "Observation must be a dict when using ZScore, not type %s" \
         % type(observation)
     try:
         p_value = prediction['mean']  # Use the prediction's mean.
     except (TypeError, KeyError, IndexError):  # If there isn't one...
         try:
             p_value = prediction['value']  # Use the prediction's value.
         except (TypeError, IndexError):  # If there isn't one...
             p_value = prediction  # Use the prediction (assume numeric).
     try:
         o_mean = observation['mean']
         o_std = observation['std']
     except KeyError:
         error = ("Observation must have keys 'mean' and 'std' "
                  "when using ZScore")
         return InsufficientDataScore(error)
     if not o_std > 0:
         error = 'Observation standard deviation must be > 0'
         return InsufficientDataScore(error)
     value = (p_value - o_mean) / o_std
     value = utils.assert_dimensionless(value)
     if np.isnan(value):
         error = 'One of the input values was NaN'
         return InsufficientDataScore(error)
     score = ZScore(value)
     return score
コード例 #9
0
    def compute(cls, observation, prediction):
        """Computes average of z-scores from observation and prediction for somatic spiking features"""

        feature_errors = numpy.array([])
        features_names = (list(observation.keys()))
        feature_results_dict = {}
        bad_features = []

        for i in range(0, len(features_names)):
            p_value = prediction[features_names[i]]['feature mean']
            o_mean = float(observation[features_names[i]]['Mean'])
            o_std = float(observation[features_names[i]]['Std'])

            p_std = prediction[features_names[i]]['feature sd']

            try:
                feature_error = abs(p_value - o_mean) / o_std
                feature_error = assert_dimensionless(feature_error)
            except ZeroDivisionError:
                feature_error = float("inf")
                feature_error = float("inf")
            except (TypeError, AssertionError) as e:
                feature_error = e
            #feature_errors=numpy.append(feature_errors,feature_error)
            feature_result = {features_names[i]: feature_error}

            feature_results_dict.update(feature_result)

            if numpy.isnan(feature_error) or numpy.isinf(feature_error):
                bad_features.append(features_names[i])
            else:
                feature_errors = numpy.append(feature_errors, feature_error)
        score_avg = numpy.nanmean(feature_errors)

        return score_avg, feature_results_dict, features_names, bad_features
コード例 #10
0
ファイル: scores.py プロジェクト: mwatts15/sciunit
    def compute(cls, observation, prediction, key=None):
        """
        Computes a ratio from an observation and a prediction.
        """
        assert type(observation) is dict
        assert type(prediction) is dict

        def extract_mean_or_value(observation, prediction):
            values = {}
            for name, data in [('observation', observation),
                               ('prediction', prediction)]:
                if key is not None:
                    values[name] = data[key]
                else:
                    try:
                        values[name] = data['mean']  # Use the mean.
                    except KeyError:  # If there isn't a mean...
                        try:
                            values[name] = data['value']  # Use the value.
                        except KeyError:
                            raise KeyError(
                                ("%s has neither a mean nor a single "
                                 "value" % name))
            return values['observation'], values['prediction']

        pred, obs = extract_mean_or_value(observation, prediction)
        value = pred / obs
        value = utils.assert_dimensionless(value)
        return RatioScore(value)
コード例 #11
0
    def compute(cls, observation, prediction, key=None):
        """
        Computes a ratio from an observation and a prediction.
        """
        assert type(observation) is dict
        assert type(prediction) is dict

        def extract_mean_or_value(observation, prediction):
            values = {}
            for name,data in [('observation',observation),
                              ('prediction',prediction)]:
                if key is not None:
                    values[name] = data[key]
                else:
                    try:
                        values[name] = data['mean'] # Use the mean.  
                    except KeyError: # If there isn't a mean...
                        try:
                            values[name] = data['value'] # Use the value.  
                        except KeyError:
                            raise KeyError(("%s has neither a mean nor a single "
                                            "value" % name))
            return values['observation'], values['prediction']

        pred, obs = extract_mean_or_value(observation, prediction)
        value = pred / obs
        value = utils.assert_dimensionless(value)
        return RatioScore(value)
コード例 #12
0
    def compute(cls, observation, prediction, distances):
        """Computes average of z-scores from observation and prediction for PSP attenuation values"""

        errors = collections.OrderedDict()

        for i in range (0, len(distances)):
            p_value = prediction['mean_attenuation_soma/dend_'+str(distances[i])+'_um']['mean']
            o_mean = observation['mean_attenuation_soma/dend_'+str(distances[i])+'_um']
            o_std = observation['std_attenuation_soma/dend_'+str(distances[i])+'_um']

            try:
                error = abs(p_value - o_mean)/o_std
                error = assert_dimensionless(error)
            except (TypeError,AssertionError) as e:
                error = e

            errors['error_attenuation_soma/dend_'+str(distances[i])+'_um'] = error

        error_list = []
        for key, value in errors.items():
            error_list.append(value)

        score_avg = numpy.nanmean(error_list)

        return score_avg, errors
コード例 #13
0
ファイル: complete.py プロジェクト: AditiRM/sciunit
    def compute(
        cls,
        observation: Union[dict, float, int, pq.Quantity],
        prediction: Union[dict, float, int, pq.Quantity],
        key=None,
        scale: Union[float, int, pq.Quantity, None] = None,
    ) -> "RelativeDifferenceScore":
        """Compute the relative difference between the observation and a prediction.

        Returns:
            RelativeDifferenceScore: A relative difference between an observation and a prediction.
        """
        assert isinstance(observation, (dict, float, int, pq.Quantity))
        assert isinstance(prediction, (dict, float, int, pq.Quantity))

        obs, pred = cls.extract_means_or_values(observation, prediction, key=key)

        scale = scale or cls.scale or (obs / float(obs))
        assert type(obs) is type(scale)
        assert type(obs) is type(pred)
        if isinstance(obs, pq.Quantity):
            assert (
                obs.units == pred.units
            ), "Prediction must have the same units as the observation"
            assert (
                obs.units == scale.units
            ), "RelativeDifferenceScore.Scale must have the same units as the observation"
        assert scale > 0, (
            "RelativeDifferenceScore.scale must be positive (not %g)" % scale
        )
        value = np.abs(pred - obs) / scale
        value = utils.assert_dimensionless(value)
        return RelativeDifferenceScore(value)
コード例 #14
0
    def compute(cls, observation: dict, prediction: dict) -> "ZScore":
        """Compute a z-score from an observation and a prediction.

        Returns:
            ZScore: The computed Z-Score.
        """
        assert isinstance(
            observation, dict
        ), "Observation must be a dict when using ZScore, not type %s" % type(
            observation)
        try:
            p_value = prediction["mean"]  # Use the prediction's mean.
        except (TypeError, KeyError, IndexError):  # If there isn't one...
            try:
                p_value = prediction["value"]  # Use the prediction's value.
            except (TypeError, IndexError):  # If there isn't one...
                p_value = prediction  # Use the prediction (assume numeric).
        try:
            o_mean = observation["mean"]
            o_std = observation["std"]
        except KeyError:
            error = "Observation must have keys 'mean' and 'std' " "when using ZScore"
            return InsufficientDataScore(error)
        if o_std <= 0:
            error = "Observation standard deviation must be > 0"
            return InsufficientDataScore(error)
        value = (p_value - o_mean) / o_std
        value = utils.assert_dimensionless(value)
        if np.isnan(value):
            error = "One of the input values was NaN"
            return InsufficientDataScore(error)
        score = ZScore(value)
        return score
コード例 #15
0
    def compute(cls, observation, prediction):
        """Computes average of z-scores from observation and prediction for features of dendritic integration in oblique dendrites"""
        #print observation
        #print prediction

        errors_dict = collections.OrderedDict()
        errors = []

        for feat_name, value in observation.items():
            if 'mean' in feat_name:
                p_mean = prediction['model_' + feat_name]
                o_mean = observation[feat_name]
                o_std = observation[feat_name[5:] + '_std']

                try:
                    feature_error = abs(p_mean - o_mean) / o_std
                    feature_error = assert_dimensionless(feature_error)

                except (TypeError, AssertionError) as e:
                    feature_error = e
                errors.append(feature_error)
                errors_dict[feat_name[5:] + '_error'] = feature_error

        #print errors_dict

        score_avg = numpy.nanmean(errors)

        return score_avg, errors_dict
コード例 #16
0
    def compute(cls, observation, prediction):
        """Computes average of z-scores from observation and prediction for Pathway Interaction features"""

        errors_dict = collections.OrderedDict()
        errors = []

        for pathway, value in prediction.items():
            if pathway not in list(errors_dict.keys()):
                errors_dict[pathway] = {}
            for feat_name, feat_value in prediction[pathway].items():
                p_mean = prediction[pathway][feat_name]['mean']
                o_mean = observation[pathway][feat_name]['mean']
                o_std = observation[pathway][feat_name]['std']

                try:
                    feature_error = abs(p_mean - o_mean) / o_std
                    feature_error = assert_dimensionless(feature_error)

                except (TypeError, AssertionError) as e:
                    feature_error = e
                errors.append(feature_error)
                errors_dict[pathway].update({feat_name: feature_error})

        penalty_PP_depol = 0
        penalty_SC_PP = 0
        if numpy.isnan(errors_dict['PP+depol']['plateau duration']):
            penalty_PP_depol += 100
        if numpy.isnan(errors_dict['SC+PP']['plateau duration']):
            penalty_SC_PP += 100

        score_avg = numpy.nanmean(errors) + penalty_PP_depol + penalty_SC_PP

        return score_avg, errors_dict, penalty_PP_depol, penalty_SC_PP
コード例 #17
0
ファイル: complete.py プロジェクト: scidash/sciunit
    def compute(cls, observation, prediction, key=None):
        """Compute a ratio from an observation and a prediction."""
        assert isinstance(observation, (dict, float, int, pq.Quantity))
        assert isinstance(prediction, (dict, float, int, pq.Quantity))

        obs, pred = cls.extract_means_or_values(observation, prediction,
                                                key=key)
        value = pred / obs
        value = utils.assert_dimensionless(value)
        return RatioScore(value)
コード例 #18
0
ファイル: complete.py プロジェクト: vrhaynes/sciunit
    def compute(cls, observation, prediction, key=None):
        """Compute a ratio from an observation and a prediction."""
        assert isinstance(observation, (dict, float, int, pq.Quantity))
        assert isinstance(prediction, (dict, float, int, pq.Quantity))

        obs, pred = cls.extract_means_or_values(observation,
                                                prediction,
                                                key=key)
        value = pred / obs
        value = utils.assert_dimensionless(value)
        return RatioScore(value)
コード例 #19
0
    def compute(cls, observation, prediction):
        """
        Computes a KLdiv-score from an observation and a prediction.
        """

        obs_values = observation[~np.isnan(observation)]
        pred_values = prediction[~np.isnan(prediction)]

        value = entropy(obs_values, pred_values)
        value = utils.assert_dimensionless(value)
        return KLdivScore(value)
コード例 #20
0
    def compute(cls, observation, prediction):
        """
        Computes a Pearson's chi-squared score from an observation and a prediction.
        """

        obs_values = observation[~np.isnan(observation)]
        pred_values = prediction[~np.isnan(prediction)]

        dof = len(obs_values)-1  # degrees of freedom for the Chi-squared distribution
        Pearson_Result = power_divergence(obs_values, pred_values, ddof=dof, lambda_='pearson')

        utils.assert_dimensionless(Pearson_Result.statistic)
        utils.assert_dimensionless(Pearson_Result.pvalue)

        # Obtaining a score value normalized respect to the mean and std of the Chi-squared distribution
	stat = Pearson_Result.statistic
        chisq_mean = dof
        chisq_std = np.sqrt(2*dof)
        stat_n = abs(stat-chisq_mean)/chisq_std

	Pearson_result = PearsonResult(stat_n, Pearson_Result.pvalue)
        return PearsonChiSquaredScore(Pearson_result)
コード例 #21
0
    def compute(cls, observation, prediction):
        """
        Computes a Freeman-Tukey score from an observation and a prediction.
        """

        obs_values = observation[~np.isnan(observation)]
        pred_values = prediction[~np.isnan(prediction)]

        dof = len(obs_values
                  ) - 1  # degrees of freedom for the Chi-squared distribution
        stat = sum((np.sqrt(pred_values) + np.sqrt(pred_values + 1) -
                    np.sqrt(4 * obs_values + 1))**2)
        pval = scipy.stats.distributions.chi2.sf(stat, dof)

        stat = utils.assert_dimensionless(stat)
        pval = utils.assert_dimensionless(pval)

        # Obtaining a score value normalized respect to the mean and std of the Chi-squared distribution
        chisq_mean = dof
        chisq_std = np.sqrt(2 * dof)
        stat_n = abs(stat - chisq_mean) / chisq_std
        FreemanTukey_Result = FreemanTukeyResult(stat_n, pval)

        return FreemanTukey2Score(FreemanTukey_Result)
コード例 #22
0
ファイル: complete.py プロジェクト: scidash/sciunit
 def compute(cls, observation, prediction):
     """Compute a Cohen's D from an observation and a prediction."""
     assert isinstance(observation, dict)
     assert isinstance(prediction, dict)
     p_mean = prediction['mean']  # Use the prediction's mean.
     p_std = prediction['std']
     o_mean = observation['mean']
     o_std = observation['std']
     try:  # Try to pool taking samples sizes into account.
         p_n = prediction['n']
         o_n = observation['n']
         s = (((p_n-1)*(p_std**2) + (o_n-1)*(o_std**2))/(p_n+o_n-2))**0.5
     except KeyError:  # If sample sizes are not available.
         s = (p_std**2 + o_std**2)**0.5
     value = (p_mean - o_mean)/s
     value = utils.assert_dimensionless(value)
     return CohenDScore(value)
コード例 #23
0
ファイル: complete.py プロジェクト: vrhaynes/sciunit
 def compute(cls, observation, prediction):
     """Compute a Cohen's D from an observation and a prediction."""
     assert isinstance(observation, dict)
     assert isinstance(prediction, dict)
     p_mean = prediction['mean']  # Use the prediction's mean.
     p_std = prediction['std']
     o_mean = observation['mean']
     o_std = observation['std']
     try:  # Try to pool taking samples sizes into account.
         p_n = prediction['n']
         o_n = observation['n']
         s = (((p_n - 1) * (p_std**2) + (o_n - 1) * (o_std**2)) /
              (p_n + o_n - 2))**0.5
     except KeyError:  # If sample sizes are not available.
         s = (p_std**2 + o_std**2)**0.5
     value = (p_mean - o_mean) / s
     value = utils.assert_dimensionless(value)
     return CohenDScore(value)
コード例 #24
0
 def compute(cls, observation, prediction):
     """
     Computes a z-score from an observation and a prediction.
     """
     assert type(observation) is dict
     assert type(prediction) is dict
     try:
         p_value = prediction['mean'] # Use the prediction's mean.  
     except (TypeError,KeyError): # If there isn't one...
         try:
             p_value = prediction['value'] # Use the prediction's value.  
         except TypeError: # If there isn't one...
             p_value = prediction # Use the prediction (assume it is numeric).
     o_mean = observation['mean']
     o_std = observation['std']
     value = (p_value - o_mean)/o_std
     value = utils.assert_dimensionless(value)
     return ZScore(value)
コード例 #25
0
ファイル: scores.py プロジェクト: mwatts15/sciunit
 def compute(cls, observation, prediction):
     """
     Computes a z-score from an observation and a prediction.
     """
     assert type(observation) is dict
     assert type(prediction) is dict
     try:
         p_value = prediction['mean']  # Use the prediction's mean.
     except (TypeError, KeyError):  # If there isn't one...
         try:
             p_value = prediction['value']  # Use the prediction's value.
         except TypeError:  # If there isn't one...
             p_value = prediction  # Use the prediction (assume it is numeric).
     o_mean = observation['mean']
     o_std = observation['std']
     value = (p_value - o_mean) / o_std
     value = utils.assert_dimensionless(value)
     return ZScore(value)
コード例 #26
0
ファイル: complete.py プロジェクト: vrhaynes/sciunit
 def compute(cls, observation, prediction):
     """Compute a z-score from an observation and a prediction."""
     assert isinstance(observation, dict)
     try:
         p_value = prediction['mean']  # Use the prediction's mean.
     except (TypeError, KeyError, IndexError):  # If there isn't one...
         try:
             p_value = prediction['value']  # Use the prediction's value.
         except (TypeError, IndexError):  # If there isn't one...
             p_value = prediction  # Use the prediction (assume numeric).
     o_mean = observation['mean']
     o_std = observation['std']
     value = (p_value - o_mean) / o_std
     value = utils.assert_dimensionless(value)
     if np.isnan(value):
         score = InsufficientDataScore('One of the input values was NaN')
     else:
         score = ZScore(value)
     return score
コード例 #27
0
ファイル: complete.py プロジェクト: scidash/sciunit
 def compute(cls, observation, prediction):
     """Compute a z-score from an observation and a prediction."""
     assert isinstance(observation, dict)
     try:
         p_value = prediction['mean']  # Use the prediction's mean.
     except (TypeError, KeyError, IndexError):  # If there isn't one...
         try:
             p_value = prediction['value']  # Use the prediction's value.
         except (TypeError, IndexError):  # If there isn't one...
             p_value = prediction  # Use the prediction (assume numeric).
     o_mean = observation['mean']
     o_std = observation['std']
     value = (p_value - o_mean)/o_std
     value = utils.assert_dimensionless(value)
     if np.isnan(value):
         score = InsufficientDataScore('One of the input values was NaN')
     else:
         score = ZScore(value)
     return score
コード例 #28
0
    def ttest_calc(cls, observation, prediction):

        exp_means=[observation['mean_threshold'], observation['mean_prox_threshold'], observation['mean_dist_threshold'], observation['mean_peak_deriv'], observation['mean_nonlin_at_th'], observation['mean_nonlin_suprath'],  observation['mean_amp_at_th'], observation['mean_time_to_peak'], observation['mean_async_nonlin']]
        exp_SDs=[observation['threshold_std'], observation['prox_threshold_std'], observation['dist_threshold_std'], observation['peak_deriv_std'], observation['nonlin_at_th_std'], observation['nonlin_suprath_std'],  observation['amp_at_th_std'], observation['time_to_peak_std'], observation['async_nonlin_std']]
        exp_Ns=[observation['exp_n'], observation['prox_n'], observation['dist_n'], observation['exp_n'], observation['exp_n'], observation['exp_n'], observation['exp_n'], observation['exp_n'], observation['async_n']]

        model_means = [prediction['model_mean_threshold'], prediction['model_mean_prox_threshold'], prediction['model_mean_dist_threshold'], prediction['model_mean_peak_deriv'], prediction['model_mean_nonlin_at_th'], prediction['model_mean_nonlin_suprath'],  prediction['model_mean_amp_at_th'], prediction['model_mean_time_to_peak'], prediction['model_mean_async_nonlin']]
        model_SDs = [prediction['model_threshold_std'], prediction['model_prox_threshold_std'], prediction['model_dist_threshold_std'], prediction['model_peak_deriv_std'], prediction['model_nonlin_at_th_std'], prediction['model_nonlin_suprath_std'], prediction['model_amp_at_th_std'], prediction['model_time_to_peak_std'], prediction['model_async_nonlin_std']]
        model_N= [prediction['model_n'], prediction['model_prox_n'], prediction['model_dist_n'], prediction['model_n'], prediction['model_n'], prediction['model_n'], prediction['model_n'], prediction['model_n'], prediction['model_n']]

        p_values=[]

        for i in range (0, len(exp_means)):

            try:
                ttest_result = cls.ttest(exp_means[i], model_means[i], exp_SDs[i], model_SDs[i], exp_Ns[i], model_N[i])
                ttest_result = assert_dimensionless(ttest_result)
                p_values.append(ttest_result)

            except (TypeError,AssertionError) as e:
                ttest_result = e

        return p_values
コード例 #29
0
    def compute(cls, observation, prediction, distances):
        """Computes average of z-scores from observation and prediction for back-propagating AP amplitudes"""

        errors = collections.OrderedDict()

        for i in range(0, len(distances)):
            if 'mean_AP1_amp_strong_propagating_at_' + str(
                    distances[i]) + 'um' in list(observation.keys(
                    )) or 'mean_AP1_amp_weak_propagating_at_' + str(
                        distances[i]) + 'um' in list(observation.keys()):
                p_value = prediction['model_AP1_amp_at_' + str(distances[i]) +
                                     'um']['mean']
                o_mean = observation['mean_AP1_amp_strong_propagating_at_' +
                                     str(distances[i]) + 'um']
                o_std = observation['std_AP1_amp_strong_propagating_at_' +
                                    str(distances[i]) + 'um']

                try:
                    error = abs(p_value - o_mean) / o_std
                    error = assert_dimensionless(error)
                except (TypeError, AssertionError) as e:
                    error = e
                errors['AP1_amp_strong_propagating_at_' +
                       str(distances[i])] = error

                o_mean = observation['mean_AP1_amp_weak_propagating_at_' +
                                     str(distances[i]) + 'um']
                o_std = observation['std_AP1_amp_weak_propagating_at_' +
                                    str(distances[i]) + 'um']

                try:
                    error = abs(p_value - o_mean) / o_std
                    error = assert_dimensionless(error)
                except (TypeError, AssertionError) as e:
                    error = e
                errors['AP1_amp_weak_propagating_at_' +
                       str(distances[i])] = error

            else:
                p_value = prediction['model_AP1_amp_at_' + str(distances[i]) +
                                     'um']['mean']
                o_mean = observation['mean_AP1_amp_at_' + str(distances[i]) +
                                     'um']
                o_std = observation['std_AP1_amp_at_' + str(distances[i]) +
                                    'um']

                try:
                    error = abs(p_value - o_mean) / o_std
                    error = assert_dimensionless(error)
                except (TypeError, AssertionError) as e:
                    error = e
                errors['AP1_amp_at_' + str(distances[i])] = error

        for i in range(
                0, len(distances)
        ):  # to keep better order: first all AP1, then all APlast
            p_value_l = prediction['model_APlast_amp_at_' + str(distances[i]) +
                                   'um']['mean']
            o_mean_l = observation['mean_APlast_amp_at_' + str(distances[i]) +
                                   'um']
            o_std_l = observation['std_APlast_amp_at_' + str(distances[i]) +
                                  'um']

            try:
                error_l = abs(p_value_l - o_mean_l) / o_std_l
                error_l = assert_dimensionless(error_l)
            except (TypeError, AssertionError) as e:
                error_l = e
            errors['APlast_amp_at_' + str(distances[i])] = error_l

        score_strong_propagating = []
        score_weak_propagating = []

        for key, value in errors.items():
            if 'strong' not in key:  # everything except 'strong'
                score_weak_propagating.append(value)
        for key, value in errors.items():
            if 'weak' not in key:
                score_strong_propagating.append(value)

        score_avg_weak_propagating = numpy.nanmean(score_weak_propagating)
        score_avg_strong_propagating = numpy.nanmean(score_strong_propagating)

        if score_avg_weak_propagating < score_avg_strong_propagating:
            cls.strong = False
        elif score_avg_weak_propagating > score_avg_strong_propagating:
            cls.strong = True
        elif score_avg_weak_propagating == score_avg_strong_propagating:
            cls.strong = None

        return [score_avg_strong_propagating,
                score_avg_weak_propagating], errors