Esempio n. 1
0
 def __init__(self, score, related_data={}):
     if not isinstance(score, Exception) and not isinstance(score, float):
         raise sciunit.InvalidScoreError("Score must be a float.")
     elif score < 0.0 or score > 100.0:
         raise sciunit.InvalidScoreError(("Score of %f must be in "
                                          "range 0.0-100.0" % score))
     else:
         super(PercentScore, self).__init__(score,
                                            related_data=related_data)
Esempio n. 2
0
 def __init__(self, score, related_data={}):
     if not isinstance(score, Exception) and \
        not isinstance(score, float) and \
        not (isinstance(score, pq.Quantity) and score.size==1):
         raise sciunit.InvalidScoreError("Score must be a float.")
     else:
         super(FloatScore, self).__init__(score, related_data=related_data)
Esempio n. 3
0
    def compute_score(self, observation, prediction, verbose=False):
        """Implementation of sciunit.Test.score_prediction."""
        try:
            assert len(observation) == len(prediction)
        except Exception:
            # or return InsufficientDataScore ??
            raise sciunit.InvalidScoreError(
                ("Difference in # of layers."
                 " Cannot continue test for layer heights."))

        zscores = {}
        for key0 in observation.keys():
            zscores[key0] = sciunit.scores.ZScore.compute(
                observation[key0]["height"], prediction[key0]["height"]).score
        self.score = morphounit.scores.CombineZScores.compute(zscores.values())
        self.score_dict = zscores
        self.score.description = "Mean of absolute Z-scores"

        # create output directory
        self.path_test_output = self.directory_output + 'layer_height/' + self.model_name + '/'
        if not os.path.exists(self.path_test_output):
            os.makedirs(self.path_test_output)

        self.observation = observation
        self.prediction = prediction
        # create relevant output files
        # 1. Error Plot
        err_plot = plots.ErrorPlot(self)
        err_plot.xlabels = OrderedDict(
            sorted(self.observation.items(), key=lambda t: t[0]))
        err_plot.ylabel = "Layer Height (um)"
        file1 = err_plot.create()
        self.figures.append(file1)
        # 2. Text Table
        txt_table = plots.TxtTable(self)
        file2 = txt_table.create(mid_keys=["height"])
        self.figures.append(file2)
        """
        # save document with Z-score data
        filename = path_test_output + 'score_summary' + '.txt'
        dataFile = open(filename, 'w')
        dataFile.write("==============================================================================\n")
        dataFile.write("Test Name: %s\n" % self.name)
        dataFile.write("Model Name: %s\n" % self.model_name)
        dataFile.write("------------------------------------------------------------------------------\n")
        dataFile.write("Layer #\tExpt. mean\tExpt. std\tModel value\tZ-score\n")
        dataFile.write("..............................................................................\n")
        for key0 in zscores.keys():
            o_mean = observation[key0]["height"]["mean"]
            o_std = observation[key0]["height"]["std"]
            p_value = prediction[key0]["height"]["value"]
            dataFile.write("%s\t%s\t%s\t%s\t%s\n" % (key0, o_mean, o_std, p_value, zscores[key0]))
        dataFile.write("------------------------------------------------------------------------------\n")
        dataFile.write("Combined Score: %s\n" % score)
        dataFile.write("==============================================================================\n")
        dataFile.close()
        self.figures.append(filename)
        """

        return self.score
    def compute_score(self, observation, prediction, verbose=True):
        """Implementation of sciunit.Test.score_prediction"""

        assert len(observation) == len(prediction), \
            sciunit.InvalidScoreError(("Difference in # of m-type cells. Cannot continue test"
                                        "for laminar distribution of synapses across CA1 layers"))

        # print "observation = ", observation, "\n"
        # print "prediction = ", prediction, "\n"

        # Computing the score
        scores_cell = dict.fromkeys(observation.keys(),[])
        for key0 in scores_cell.keys():  # m-type cell (AA, BP, BS, CCKBC, Ivy, OLM, PC, PPA, SCA, Tri)
            scores_cell[key0] = getattr(hpn_scores, score_str).compute(observation[key0], prediction[key0])

        # create output directory
        path_test_output = self.directory_output + self.model_name + '/'
        if not os.path.exists(path_test_output):
            os.makedirs(path_test_output)

        # save figure with score data
        scores_cell_floats = dict.fromkeys(observation.keys(), [])
        for key0, score_cell in scores_cell.items():
            scores_cell_floats[key0] = [score_cell.score.statistic_n, score_cell.score.pvalue]

        score_label = score_str[:-5] + '-score'
        scores_cell_df = pd.DataFrame(scores_cell_floats, index=[score_label, 'p-value'])
        scores_cell_df = scores_cell_df.transpose()
        print scores_cell_df, '\n'

        # pal = sns.cubehelix_palette(len(observation))
        pal = sns.color_palette('Reds', len(observation))
        rank = [int(value)-1 for value in scores_cell_df[score_label].rank()]
        axis_obj = sns.barplot(x=scores_cell_df[score_label], y=scores_cell_df.index, palette=np.array(pal)[rank])
        axis_obj.set(xlabel=score_label, ylabel='Cell')
        sns.despine()

        for i, p in enumerate(axis_obj.patches):
                axis_obj.annotate("p = %.2f" % scores_cell_df['p-value'].values[i],
                xy=(p.get_x() + p.get_width(), p.get_y() + 0.5),
                xytext=(3, 0), textcoords='offset points')

        filename = path_test_output + score_str + '_plot' + '.png'
        plt.savefig(filename, dpi=600,)
        self.figures.append(filename)

        # self.score = morphounit.scores.CombineZScores.compute(zscores.values())
        self.score = scores_cell_floats["PC"][0]

        return hpn_scores.FreemanTukey2Score(self.score)
    def compute_score(self, observation, prediction, verbose=True):
        """Implementation of sciunit.Test.score_prediction"""

        assert len(observation) == len(prediction), \
            sciunit.InvalidScoreError(("Difference in # of m-type cells. Cannot continue test"
                                        "for laminar distribution of synapses across CA1 layers"))

        # print "observation = ", observation, "\n"
        # print "prediction = ", prediction, "\n"

        # Computing the score
        scores_cell = dict.fromkeys(observation.keys(),[])
        for key0 in scores_cell.keys():  # m-type cell (AA, BP, BS, CCKBC, Ivy, OLM, PC, PPA, SCA, Tri)
            scores_cell[key0] = getattr(hpn_scores, score_str).compute(observation[key0], prediction[key0])

        # create output directory
        path_test_output = self.directory_output + self.model_name + '/'
        if not os.path.exists(path_test_output):
            os.makedirs(path_test_output)

        # save figure with score data
        scores_cell_floats = dict.fromkeys(observation.keys(), [])
        for key0, score_cell in scores_cell.items():
            scores_cell_floats[key0] = [score_cell.score]

        score_label = score_str[:-5] + '-score'
        scores_cell_df = pd.DataFrame(scores_cell_floats, index=[score_label])
        scores_cell_df = scores_cell_df.transpose()
        print scores_cell_df, '\n'

        # pal = sns.cubehelix_palette(len(observation))
        pal = sns.color_palette('Reds', len(observation))
        rank = [int(value)-1 for value in scores_cell_df[score_label].rank()]
        axis_obj = sns.barplot(x=scores_cell_df[score_label], y=scores_cell_df.index, palette=np.array(pal)[rank])
        axis_obj.set(xlabel=score_label, ylabel='Cell')
        sns.despine()

        filename = path_test_output + score_str + '_plot' + '.pdf'
        plt.savefig(filename, dpi=600,)
        self.figures.append(filename)

        scores_array = scores_cell_df[score_label].array
        self.score = sum(map(abs,scores_array)) / len(scores_array)

        return hpn_scores.KLdivScore(self.score)
Esempio n. 6
0
 def __init__(self, score, related_data={}):
     if not isinstance(score, Exception) and not isinstance(score, float):
         raise sciunit.InvalidScoreError("Score must be a float.")
     else:
         super(ZScore, self).__init__(score, related_data=related_data)
Esempio n. 7
0
 def __init__(self, score, related_data={}):
     if isinstance(score, Exception) or score in [True, False]:
         super(BooleanScore, self).__init__(score,
                                            related_data=related_data)
     else:
         raise sciunit.InvalidScoreError("Score must be True or False.")