Пример #1
0
    def add_new_designs(self, weights=None, R=None):
        '''
        This function generates the population.

        :param experiment: The experimental setup of the fMRI experiment.
        :type experiment: experiment
        :param weights: weights for efficiency calculation.
        :type weights: list of floats, summing to 1
        :param seed: The seed for ramdom processes.
        :type seed: integer or None
        '''
        # weights
        if weights == None:
            weights = self.weights

        if not R:
            R = np.round(np.array(self.R) * self.G).tolist()
        print(R)

        if self.exp.n_stimuli in [6, 10] and R[2] > 0:
            print(
                "warning: for this number of conditions/stimuli, there are no msequences possible.  Replaced by random designs."
            )
            R[1] = R[1] + R[2]
            R[2] = 0

        NDes = 0
        self.change_seed()

        k = 0
        while NDes < np.sum(R):
            k = k + 1
            print(k)
            self.change_seed()
            ind = np.sum(NDes >= np.cumsum(R))
            ordertype = ['blocked', 'random', 'msequence'][ind]
            order = generate.order(self.exp.n_stimuli,
                                   self.exp.n_trials,
                                   self.exp.P,
                                   ordertype=ordertype,
                                   seed=self.seed)
            ITI, ITIlam = generate.iti(ntrials=self.exp.n_trials,
                                       model=self.exp.ITImodel,
                                       min=self.exp.ITImin,
                                       max=self.exp.ITImax,
                                       mean=self.exp.ITImean,
                                       lam=self.exp.ITIlam,
                                       seed=self.seed)
            if ITIlam:
                self.exp.ITIlam = ITIlam
            des = design(order=order, ITI=ITI, experiment=self.exp)

            fulldes = self.check_develop(des, weights)
            if fulldes == False:
                continue
            else:
                self.designs.append(fulldes)
                NDes = NDes + 1

        return self
Пример #2
0
    ef = Enforce(TNTpseudM)
    ef.add_constraint(MaxRep,cols=[TNTpseudM.T_ID],maxrep=3)
    ef.add_constraint(MaxRep,cols=[TNTpseudM.NT_ID],maxrep=3)
    ef.add_constraint(MaxRep,cols=[TNTpseudM.neu_ID],maxrep=3)
    ef.add_constraint(MaxRep,cols=[TNTpseudM.neg_ID],maxrep=3)
    ef.add_constraint(MinDist,cols=[TNTpseudM.null_ID],mindist=2)

    # Enforce the constraints
    TNTpseudM = ef.enforce()

    # convert new datamatrix to a list as input for DES1
    TNTorder = list(TNTpseudM.order)

    TNTdES = neurodesign.classes.design(
        order = TNTorder,
        ITI = generate.iti(ntrials=124, model="exponential", min=1.4, mean=2, max=2.6,
                           resolution=0.1, seed=1234)[0],
        onsets = [], experiment = TNTfMRI)

    TNTdES.designmatrix()
    TNTdES.FeCalc();TNTdES.FdCalc();TNTdES.FfCalc();TNTdES.FcCalc()
    TNTdES.FCalc(weights=[0.25, 0.25, 0.25, 0.25])

    print("estimation efficiency = ", TNTdES.Fe, "\tdetection power = ", TNTdES.Fd, "\tstimulus frequency = ", TNTdES.Ff, "\tdesign predictability = ", TNTdES.Fc)

    if TNTdES.Fe > Fe_threshold and TNTdES.Fd > Fd_threshold and TNTdES.Ff > Ff_threshold and TNTdES.Fc > Fc_threshold or time.time() > timeout:

        break

print("FINAL: estimation efficiency = ", TNTdES.Fe, "\tdetection power = ", TNTdES.Fd, "\tstimulus frequency = ", TNTdES.Ff, "\tdesign predictability = ", TNTdES.Fc)

#print('TNT Run-1 Order Matrix:')
Пример #3
0
    experiment=EXP)

# expand to design matrix

DES.designmatrix()
DES.FCalc(weights=[0, 0.5, 0.25, 0.25])
DES.FdCalc()
DES.FcCalc()
DES.FfCalc()
DES.FeCalc()

# define second design

DES2 = neurodesign.design(
    order=[0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 1],
    ITI=generate.iti(20, "exponential", min=1, mean=2, max=4, seed=1234)[0],
    experiment=EXP)

DES2.designmatrix()
DES2.FeCalc()
DES2.FdCalc()
DES2.FcCalc()
DES2.FfCalc()

# crossover to obtain design 3 and 4

DES3, DES4 = DES.crossover(DES2, seed=2000)
DES3.order
DES4.order
DES3.designmatrix()
DES3.FeCalc()