コード例 #1
0
    def _process_what_to_run_expand(self,
                                    num_random_exp=100,
                                    random_dirs=None):
        """Get tuples of parameters to run TCAV with.

    TCAV builds random concept to conduct statistical significance testing
    againts the concept. To do this, we build many concept vectors, and many
    random vectors. This function prepares runs by expanding parameters.

    Args:
      num_random_exp: number of random experiments to run to compare.
      random_dirs: A list of names of random concepts for the random experiments
                   to draw from. Optional, if not provided, the names will be
                   random500_{i} for i in num_random_exp.
    """

        target_concept_pairs = [(self.target, self.concepts)]

        all_concepts_concepts, pairs_to_run_concepts = utils.process_what_to_run_expand(
            utils.process_what_to_run_concepts(target_concept_pairs),
            self.random_counterpart,
            num_random_exp=num_random_exp,
            random_dirs=random_dirs)
        all_concepts_randoms, pairs_to_run_randoms = utils.process_what_to_run_expand(
            utils.process_what_to_run_randoms(target_concept_pairs,
                                              self.random_counterpart),
            self.random_counterpart,
            num_random_exp=num_random_exp,
            random_dirs=random_dirs)
        self.all_concepts = list(
            set(all_concepts_concepts + all_concepts_randoms))
        self.pairs_to_test = pairs_to_run_concepts + pairs_to_run_randoms
コード例 #2
0
    def _process_what_to_run_expand(self, num_random_exp=100):
        """Get tuples of parameters to run TCAV with.

    TCAV builds random concept to conduct statistical significance testing
    againts the concept. To do this, we build many concept vectors, and many
    random vectors. This function prepares runs by expanding parameters.

    Args:
      num_random_exp: number of random experiments to run to compare.
    """

        target_concept_pairs = [(self.target, self.concepts)]

        all_concepts_concepts, pairs_to_run_concepts = utils.process_what_to_run_expand(
            utils.process_what_to_run_concepts(target_concept_pairs),
            self.random_counterpart,
            num_random_exp=num_random_exp,
        )
        all_concepts_randoms, pairs_to_run_randoms = utils.process_what_to_run_expand(
            utils.process_what_to_run_randoms(target_concept_pairs,
                                              self.random_counterpart),
            self.random_counterpart,
            num_random_exp=num_random_exp,
        )
        self.all_concepts = list(
            set(all_concepts_concepts + all_concepts_randoms))
        self.pairs_to_test = pairs_to_run_concepts + pairs_to_run_randoms
コード例 #3
0
    def _process_what_to_run_expand(self, num_random_exp=100):
        """
		Get tuples of parameters to run TCAV with.

		:param num_random_exp: number of random experiments to run to compare.
		"""
        target_concept_pairs = [(self.target, self.concepts)]
        all_concepts_concepts, pairs_to_run_concepts = utils.process_what_to_run_expand(
            utils.process_what_to_run_concepts(target_concept_pairs),
            self.random_counterpart,
            num_random_exp=num_random_exp)
        all_concepts_randoms, pairs_to_run_randoms = utils.process_what_to_run_expand(
            utils.process_what_to_run_randoms(target_concept_pairs,
                                              self.random_counterpart),
            self.random_counterpart,
            num_random_exp=num_random_exp)
        self.all_concepts = list(
            set(all_concepts_concepts + all_concepts_randoms))
        self.pairs_to_test = pairs_to_run_concepts + pairs_to_run_randoms
コード例 #4
0
    def _process_what_to_run_expand(self,
                                    num_random_exp=100,
                                    random_concepts=None):
        """Get tuples of parameters to run TCAV with.

        TCAV builds random concept to conduct statistical significance testing
        againts the concept. To do this, we build many concept vectors, and many
        random vectors. This function prepares runs by expanding parameters.

        Args:
          num_random_exp: number of random experiments to run to compare.
          random_concepts: A list of names of random concepts for the random experiments
                       to draw from. Optional, if not provided, the names will be
                       random500_{i} for i in num_random_exp.
        """

        target_concept_pairs = [(self.target, self.concepts)]

        # take away 1 random experiment if the random counterpart already in random concepts
        all_concepts_concepts, pairs_to_run_concepts = (
            utils.process_what_to_run_expand(
                utils.process_what_to_run_concepts(target_concept_pairs),
                self.random_counterpart,
                num_random_exp=num_random_exp -
                (1 if random_concepts
                 and self.random_counterpart in random_concepts else 0),
                random_concepts=random_concepts))

        pairs_to_run_randoms = []
        all_concepts_randoms = []

        # ith random concept
        def get_random_concept(i):
            return (random_concepts[i]
                    if random_concepts else 'random500_{}'.format(i))

        if self.random_counterpart is None:
            # TODO random500_1 vs random500_0 is the same as 1 - (random500_0 vs random500_1)
            for i in xrange(num_random_exp):
                all_concepts_randoms_tmp, pairs_to_run_randoms_tmp = (
                    utils.process_what_to_run_expand(
                        utils.process_what_to_run_randoms(
                            target_concept_pairs, get_random_concept(i)),
                        num_random_exp=num_random_exp - 1,
                        random_concepts=random_concepts))

                pairs_to_run_randoms.extend(pairs_to_run_randoms_tmp)
                all_concepts_randoms.extend(all_concepts_randoms_tmp)

        else:
            # run only random_counterpart as the positve set for random experiments
            all_concepts_randoms_tmp, pairs_to_run_randoms_tmp = (
                utils.process_what_to_run_expand(
                    utils.process_what_to_run_randoms(target_concept_pairs,
                                                      self.random_counterpart),
                    self.random_counterpart,
                    num_random_exp=num_random_exp -
                    (1 if random_concepts
                     and self.random_counterpart in random_concepts else 0),
                    random_concepts=random_concepts))

            pairs_to_run_randoms.extend(pairs_to_run_randoms_tmp)
            all_concepts_randoms.extend(all_concepts_randoms_tmp)

        self.all_concepts = list(
            set(all_concepts_concepts + all_concepts_randoms))
        self.pairs_to_test = pairs_to_run_concepts + pairs_to_run_randoms
        print('<<<<<<<< Pairs to test: ', self.pairs_to_test, '\n')
コード例 #5
0
 def test_process_what_to_run_randoms(self):
     self.assertEqual(
         sorted(
             process_what_to_run_randoms(self.pairs_to_test,
                                         'random500_1')),
         sorted([['t1', ['random500_1']], ['t2', ['random500_1']]]))