Пример #1
0
 def generate_ballpark_prediction(self, x, y, sigma, sigma_ratio, volume_ratio):
     
     # extract the center response
     rf_center = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x0, self.stimulus.deg_y0)
     
     # extract surround response
     rf_surround = generate_og_receptive_field(x, y, sigma*sigma_ratio, 
                                               self.stimulus.deg_x0, self.stimulus.deg_x0) * 1/sigma_ratio**2
     
     # difference
     rf = ne.evaluate('rf_center - sqrt(volume_ratio)*rf_surround')
     
     # extract the response
     mask = self.distance_mask(x, y, sigma*sigma_ratio)
     response = generate_rf_timeseries(self.stimulus.stim_arr0, rf, mask)
     
     # generate the hrf
     hrf = self.hrf_model(self.hrf_delay, self.stimulus.tr_length)
     
     # convolve it
     model = fftconvolve(response, hrf)[0:len(response)]
     
     # units
     model = self.normalizer(model)
     
     # regress out mean and linear
     beta, baseline = self.regress(model, self.data)
     
     # offset
     model += baseline
     
     # scale
     model *= beta
     
     return model
Пример #2
0
    def generate_ballpark_prediction(self, x, y, sigma, weight):
        r"""
        Predict signal for the Gaussian Model using the downsampled stimulus.
        The rate of stimulus downsampling is defined in `model.stimulus.scale_factor`.
        
        Parameters
        __________
        x : float
            Horizontal location of the Gaussian RF.
        
        y: float 
            Vertical location of the Gaussian RF.
        
        sigma: float
            Dipsersion of the Gaussian RF.
        
        weight: float
            Mixture of the magnocellar and parvocellular temporal response to
            a flickering visual stimulus. The `weight` ranges between 0 and 1, 
            with 0 being a totally magnocellular response and ` being a totally
            parvocellular response.
        
        """
        # mask for speed
        mask = self.distance_mask_coarse(x, y, sigma)

        # generate the RF
        spatial_rf = generate_og_receptive_field(x, y, sigma,
                                                 self.stimulus.deg_x0,
                                                 self.stimulus.deg_y0)
        spatial_rf /= ((2 * np.pi * sigma**2) * 1 /
                       np.diff(self.stimulus.deg_x0[0, 0:2])**2)

        # spatial_response
        spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr0,
                                            spatial_rf, mask)

        # temporal response
        m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp,
                                            self.stimulus.flicker_vec)

        # mix them
        mp_ts = (1 - weight) * m_ts + weight * p_ts

        # convolve with HRF
        model = fftconvolve(mp_ts, self.hrf())[0:len(mp_ts)]

        # units
        model = self.normalizer(model)

        # regress out mean and linear
        p = linregress(model, self.data)

        # scale
        model *= p[0]

        # offset
        model += p[1]

        return model
Пример #3
0
 def generate_ballpark_prediction(self, x, y, sigma, hrf_delay):
     
     # mask for speed
     mask = self.distance_mask_coarse(x, y, sigma)
     
     # generate the RF
     rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x0, self.stimulus.deg_y0)
     rf /= (2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x0[0,0:2])**2
             
     # extract the stimulus time-series
     response = generate_rf_timeseries(self.stimulus.stim_arr0, rf, mask)
     
     # convolve it with the stimulus
     hrf = self.hrf_model(hrf_delay, self.stimulus.tr_length)
     model = fftconvolve(response, hrf)[0:len(response)]
     
     # units
     model = (model-np.mean(model)) / np.mean(model)
     
     # regress out mean and linear
     p = linregress(model, self.data)
     
     # offset
     model += p[1]
     
     # scale
     model *= np.abs(p[0])
     
     return model
Пример #4
0
 def generate_ballpark_prediction(self, x, y, sigma, weight):
     
     # mask for speed
     mask = self.distance_mask_coarse(x, y, sigma)
     
     # generate the RF
     spatial_rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x0, self.stimulus.deg_y0)
     spatial_rf /= ((2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x0[0,0:2])**2)
     
     # spatial_response
     spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr0, spatial_rf, mask)
     
     # temporal response
     m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp, self.stimulus.flicker_vec)
     
     # mix them
     mp_ts = (1-weight) * m_ts + weight * p_ts
     
     # convolve with HRF
     model = fftconvolve(mp_ts, self.hrf())[0:len(mp_ts)]
     
     # units
     model = (model - np.mean(model)) / np.mean(model)
     
     # regress out mean and linear
     p = linregress(model, self.data)
     
     # offset
     model += p[1]
     
     # scale
     model *= np.abs(p[0])
     
     return model
Пример #5
0
 def generate_prediction(self, x, y, sigma, mbeta, pbeta):
     
     # mask for speed
     mask = self.distance_mask(x, y, sigma)
     
     # generate the RF
     spatial_rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
     spatial_rf /= ((2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x[0,0:2])**2)
     
     # spatial response
     spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr, spatial_rf, mask)
     
     # temporal response
     m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp, self.stimulus.flicker_vec)
     
     # convolve with HRF
     hrf = self.hrf_model(self.hrf_delay, self.stimulus.tr_length)
     
     # M
     m_model = fftconvolve(m_ts, hrf)[0:len(m_ts)]
     
     # P
     p_model = fftconvolve(p_ts, hrf)[0:len(p_ts)]
     
     # convert units
     m_model = (m_model - np.mean(m_model))/np.mean(m_model)
     p_model = (p_model - np.mean(p_model))/np.mean(p_model)
     
     # mix
     model = m_model * mbeta + p_model * pbeta
     
     return model
Пример #6
0
 def generate_prediction(self, x, y, sigma, hrf_delay, beta, baseline):
     
     # mask for speed
     mask = self.distance_mask(x, y, sigma)
     
     # generate the RF
     rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
     rf /= (2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x[0,0:2])**2
     
     # extract the stimulus time-series
     response = generate_rf_timeseries(self.stimulus.stim_arr, rf, mask)
     
     # convolve it with the stimulus
     hrf = self.hrf_model(hrf_delay, self.stimulus.tr_length)
     model = fftconvolve(response, hrf)[0:len(response)]
     
     # units
     model = (model-np.mean(model)) / np.mean(model)
     
     # offset
     model += baseline
     
     # scale it by beta
     model *= beta
     
     return model
Пример #7
0
 def generate_prediction(self, x, y, sigma, theta, phi, cpd):
     
     # make sure theta and phi are 0-2*pi
     theta = np.mod(theta, 2*np.pi)
     phi = np.mod(theta, 2*np.pi)
     
     # create mask for speed
     distance = (self.stimulus.deg_x - x)**2 + (self.stimulus.deg_y - y)**2
     mask = np.zeros_like(distance, dtype='uint8')
     mask[distance < (5*sigma)**2] = 1
     
     # generate the RF
     rf = generate_gabor_receptive_field(x, y, sigma, theta, phi, cpd,
                                         self.stimulus.deg_x, self.stimulus.deg_y)
     
     # extract the stimulus time-series
     response = generate_rf_timeseries(self.stimulus.stim_arr, rf, mask)
     
     # convolve with the HRF
     hrf = self.hrf_model(0, self.stimulus.tr_length)
     
     # convolve it with the stimulus
     model = fftconvolve(response, hrf, 'same')
     
     return model
Пример #8
0
    def generate_prediction(self, x, y, sigma, weight, beta, hrf_delay):

        # mask for speed
        mask = self.distance_mask(x, y, sigma)

        # generate the RF
        spatial_rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
        spatial_rf /= (2 * np.pi * sigma ** 2) * 1 / np.diff(self.stimulus.deg_x[0, 0:2]) ** 2

        # spatial response
        spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr, spatial_rf, mask)

        # temporal response
        m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp, self.stimulus.flicker_vec)

        # mix them
        mp_ts = (1 - weight) * m_ts + weight * p_ts

        # convolve with HRF
        model = fftconvolve(mp_ts, self.hrf_model(hrf_delay, self.stimulus.tr_length))[0 : len(mp_ts)]

        # convert units
        model = (model - np.mean(model)) / np.mean(model)

        # scale
        model *= beta

        return model
Пример #9
0
 def generate_prediction(self, x, y, sigma, n, weight, beta, baseline):
     
     # mask for speed
     mask = self.distance_mask(x, y, sigma)
     
     # generate the RF
     spatial_rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
     spatial_rf /= ((2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x[0,0:2])**2)
     
     # spatial response
     spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr, spatial_rf, mask)
     
     # compression
     spatial_ts **= n
     
     # temporal response
     m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp, self.stimulus.flicker_vec)
     
     # mix them
     mp_ts = (1-weight) * m_ts + weight * p_ts
     
     # convolve with HRF
     model = fftconvolve(mp_ts, self.hrf())[0:len(mp_ts)]
     
     # convert units
     model = (model - np.mean(model)) / np.mean(model)
     
     # scale
     model *= beta
     
     # offset
     model += baseline
     
     return model
Пример #10
0
 def generate_prediction(self, x, y, sigma, weight, beta, baseline):
     
     r"""
     Predict signal for the Gaussian Model using the full resolution stimulus.
     
     Parameters
     __________
     x : float
         Horizontal location of the Gaussian RF.
     
     y: float 
         Vertical location of the Gaussian RF.
     
     sigma: float
         Dipsersion of the Gaussian RF.
     
     weight: float
         Mixture of the magnocellar and parvocellular temporal response to
         a flickering visual stimulus. The `weight` ranges between 0 and 1, 
         with 0 being a totally magnocellular response and ` being a totally
         parvocellular response.
         
     beta : float
         Amplitude scaling factor to account for units.
         
     baseline: float
         Amplitude intercept to account for baseline.
     
     """
     
     # mask for speed
     mask = self.distance_mask(x, y, sigma)
     
     # generate the RF
     spatial_rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
     spatial_rf /= ((2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x[0,0:2])**2)
     
     # spatial response
     spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr, spatial_rf, mask)
     
     # temporal response
     m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp, self.stimulus.flicker_vec)
     
     # mix them
     mp_ts = (1-weight) * m_ts + weight * p_ts 
     
     # convolve with HRF
     model = fftconvolve(mp_ts, self.hrf())[0:len(mp_ts)]
     
     # units
     model = (model - np.mean(model)) / np.mean(model)
     
     # offset
     model += baseline
     
     # scale it by beta
     model *= beta
     
     return model
Пример #11
0
 def generate_ballpark_prediction(self, x, y, sigma, weight):
     
     r"""
     Predict signal for the Gaussian Model using the downsampled stimulus.
     The rate of stimulus downsampling is defined in `model.stimulus.scale_factor`.
     
     Parameters
     __________
     x : float
         Horizontal location of the 2D Cosine RF.
     
     y: float 
         Vertical location of the 2D Cosine RF.
     
     sigma: float
         Dipsersion of the 2D Cosine RF.
     
     weight: float
         Mixture of the magnocellar and parvocellular temporal response to
         a flickering visual stimulus. The `weight` ranges between 0 and 1, 
         with 0 being a totally magnocellular response and ` being a totally
         parvocellular response.
     
     """
     # generate the RF
     spatial_rf = generate_2dcos_receptive_field(x, y, sigma, self.power, self.stimulus.deg_x0, self.stimulus.deg_y0)
     
     # normalize by volume
     spatial_rf /= (trapz(trapz(spatial_rf)) * 1/np.diff(self.stimulus.deg_x0[0,0:2])**2)
     
     # make mask
     mask = np.uint8(spatial_rf>0)
     
     # spatial_response
     spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr0, spatial_rf, mask)
     
     # temporal response
     m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp, self.stimulus.flicker_vec)
     
     # mix them
     mp_ts = (1-weight) * m_ts + weight * p_ts
     
     # convolve with HRF
     model = fftconvolve(mp_ts, self.hrf())[0:len(mp_ts)]
     
     # units
     model = (model - np.mean(model)) / np.mean(model)
     
     # regress out mean and linear
     p = linregress(model, self.data)
     
     # offset
     model += p[1]
     
     # scale
     model *= p[0]
     
     return model
Пример #12
0
 def generate_prediction(self, x, y, sigma, hrf_delay, beta, baseline, unscaled=False):
     
     r"""
     Predict signal for the Gaussian Model.
     
     Parameters
     __________
     x : float
         Horizontal location of the Gaussian RF.
     
     y: float 
         Vertical location of the Gaussian RF.
     
     sigma: float
         Dipsersion of the Gaussian RF.
     
     hrf_delay: float
         The delay of the hemodynamic response function (HRF). We assume the 
         cannonical HRF delay is 5 s, and that this parameter is a deviation
         +/- that 5 s.
     
     beta : float
         Amplitude scaling factor to account for units.
     
     baseline: float
         Amplitude intercept to account for baseline.
     
     """
     
     
     # mask for speed
     mask = self.distance_mask(x, y, sigma)
     
     # generate the RF
     rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
     rf /= (2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x[0,0:2])**2
     
     # extract the stimulus time-series
     response = generate_rf_timeseries(self.stimulus.stim_arr, rf, mask)
     
     # convolve it with the stimulus
     hrf = self.hrf_model(hrf_delay, self.stimulus.tr_length)
     model = fftconvolve(response, hrf)[0:len(response)]
     
     # units
     model = self.normalizer(model)
     
     if unscaled:
         return model
     else:
         # offset
         model += baseline
 
         # scale it by beta
         model *= beta
 
         return model
Пример #13
0
 def generate_prediction(self, x, y, sigma, hrf_delay, beta, baseline):
     
     r"""
     Predict signal for the Gaussian Model.
     
     Parameters
     __________
     x : float
         Horizontal location of the Gaussian RF.
     
     y: float 
         Vertical location of the Gaussian RF.
     
     sigma: float
         Dipsersion of the Gaussian RF.
     
     hrf_delay: float
         The delay of the hemodynamic response function (HRF). We assume the 
         cannonical HRF delay is 5 s, and that this parameter is a deviation
         +/- that 5 s.
     
     beta : float
         Amplitude scaling factor to account for units.
     
     baseline: float
         Amplitude intercept to account for baseline.
     
     """
     
     
     # mask for speed
     mask = self.distance_mask(x, y, sigma)
     
     # generate the RF
     rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
     rf /= (2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x[0,0:2])**2
     
     # extract the stimulus time-series
     response = generate_rf_timeseries(self.stimulus.stim_arr, rf, mask)
     
     # convolve it with the stimulus
     hrf = self.hrf_model(hrf_delay, self.stimulus.tr_length)
     model = fftconvolve(response, hrf)[0:len(response)]
     
     # units
     model = (model-np.mean(model)) / np.mean(model)
     
     # offset
     model += baseline
     
     # scale it by beta
     model *= beta
     
     return model
Пример #14
0
    def generate_ballpark_prediction(self, x, y, sigma, hrf_delay):
        r"""
        Predict signal for the Gaussian Model using the downsampled stimulus.
        The rate of stimulus downsampling is defined in `model.stimulus.scale_factor`.
        
        Parameters
        __________
        x : float
            Horizontal location of the Gaussian RF.
        
        y: float 
            Vertical location of the Gaussian RF.
        
        sigma: float
            Dipsersion of the Gaussian RF.
        
        hrf_delay: float
            The delay of the hemodynamic response function (HRF). We assume the 
            cannonical HRF delay is 5 s, and that this parameter is a deviation
            +/- that 5 s.
        
        """

        # mask for speed
        mask = self.distance_mask_coarse(x, y, sigma)

        # generate the RF
        rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x0,
                                         self.stimulus.deg_y0)
        rf /= (2 * np.pi * sigma**2) * 1 / np.diff(
            self.stimulus.deg_x0[0, 0:2])**2

        # extract the stimulus time-series
        response = generate_rf_timeseries(self.stimulus.stim_arr0, rf, mask)

        # convolve it with the stimulus
        hrf = self.hrf_model(hrf_delay, self.stimulus.tr_length)
        model = fftconvolve(response, hrf)[0:len(response)]

        # units
        model = self.normalizer(model)

        # regress out mean and linear
        p = linregress(model, self.data)

        # scale
        model *= p[0]

        # offset
        model += p[1]

        return model
Пример #15
0
    def generate_prediction(self, x, y, sigma, beta, baseline, unscaled=False):
        r"""
        Predict signal for the Gaussian Model.
        
        Parameters
        __________
        x : float
            Horizontal location of the Gaussian RF.
        
        y: float 
            Vertical location of the Gaussian RF.
        
        sigma: float
            Dipsersion of the Gaussian RF.
        
        beta : float
            Amplitude scaling factor to account for units.
        
        baseline: float
            Amplitude intercept to account for baseline.
        
        """

        # mask for speed
        mask = self.distance_mask(x, y, sigma)

        # generate the RF
        rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x,
                                         self.stimulus.deg_y)
        rf /= (2 * np.pi * sigma**2) * 1 / np.diff(self.stimulus.deg_x[0,
                                                                       0:2])**2

        # extract the stimulus time-series
        response = generate_rf_timeseries(self.stimulus.stim_arr, rf, mask)

        # convolve it with the stimulus
        model = fftconvolve(response, self.hrf())[0:len(response)]

        # units
        model = self.normalizer(model)

        if unscaled:
            return model
        else:

            # scale it by beta
            model *= beta

            # offset
            model += baseline

            return model
Пример #16
0
 def generate_ballpark_prediction(self, x, y, sigma, hrf_delay):
     
     r"""
     Predict signal for the Gaussian Model using the downsampled stimulus.
     The rate of stimulus downsampling is defined in `model.stimulus.scale_factor`.
     
     Parameters
     __________
     x : float
         Horizontal location of the Gaussian RF.
     
     y: float 
         Vertical location of the Gaussian RF.
     
     sigma: float
         Dipsersion of the Gaussian RF.
     
     hrf_delay: float
         The delay of the hemodynamic response function (HRF). We assume the 
         cannonical HRF delay is 5 s, and that this parameter is a deviation
         +/- that 5 s.
     
     """
     
     # mask for speed
     mask = self.distance_mask_coarse(x, y, sigma)
     
     # generate the RF
     rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x0, self.stimulus.deg_y0)
     rf /= (2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x0[0,0:2])**2
             
     # extract the stimulus time-series
     response = generate_rf_timeseries(self.stimulus.stim_arr0, rf, mask)
     
     # convolve it with the stimulus
     hrf = self.hrf_model(hrf_delay, self.stimulus.tr_length)
     model = fftconvolve(response, hrf)[0:len(response)]
     
     # units
     model = self.normalizer(model)
     
     # regress out mean and linear
     p = linregress(model, self.data)
     
     # offset
     model += p[1]
     
     # scale
     model *= p[0]
     
     return model
Пример #17
0
    def generate_ballpark_prediction(self, x, y, sigma):
        r"""
        Predict signal for the Gaussian Model using the downsampled stimulus.
        The rate of stimulus downsampling is defined in `model.stimulus.scale_factor`.
        
        Parameters
        __________
        x : float
            Horizontal location of the Gaussian RF.
        
        y: float 
            Vertical location of the Gaussian RF.
        
        sigma: float
            Dipsersion of the Gaussian RF.
        
        """

        # mask for speed
        mask = self.distance_mask_coarse(x, y, sigma)

        # generate the RF
        rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x0,
                                         self.stimulus.deg_y0)
        rf /= (2 * np.pi * sigma**2) * 1 / np.diff(
            self.stimulus.deg_x0[0, 0:2])**2

        # extract the stimulus time-series
        response = generate_rf_timeseries(self.stimulus.stim_arr0, rf, mask)

        # convolve it with the stimulus
        model = fftconvolve(response, self.hrf())[0:len(response)]

        # units
        model = self.normalizer(model)

        # regress out mean and amplitude
        beta, baseline = self.regress(model, self.data)

        # scale
        model *= beta

        # offset
        model += baseline

        return model
Пример #18
0
 def generate_ballpark_prediction(self, x, y, sigma):
     
     r"""
     Predict signal for the Gaussian Model using the downsampled stimulus.
     The rate of stimulus downsampling is defined in `model.stimulus.scale_factor`.
     
     Parameters
     __________
     x : float
         Horizontal location of the Gaussian RF.
     
     y: float 
         Vertical location of the Gaussian RF.
     
     sigma: float
         Dipsersion of the Gaussian RF.
     
     """
     
     # mask for speed
     mask = self.distance_mask_coarse(x, y, sigma)
     
     # generate the RF
     rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x0, self.stimulus.deg_y0)
     rf /= (2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x0[0,0:2])**2
             
     # extract the stimulus time-series
     response = generate_rf_timeseries(self.stimulus.stim_arr0, rf, mask)
     
     # convolve it with the stimulus
     model = fftconvolve(response, self.hrf())[0:len(response)]
     
     # units
     model = self.normalizer(model)
     
     # regress out mean and amplitude
     beta, baseline = self.regress(model, self.data)
     
     # offset
     model += baseline
     
     # scale
     model *= beta
     
     return model
Пример #19
0
    def generate_prediction(self, x, y, sigma, beta, baseline, hrf_delay):
        r"""
        Predict signal for the Gaussian Model using the downsampled stimulus.
        The rate of stimulus downsampling is defined in `model.stimulus.scale_factor`.
        
        Parameters
        __________
        x : float
            Horizontal location of the Gaussian RF.
        
        y: float 
            Vertical location of the Gaussian RF.
        
        sigma: float
            Dipsersion of the Gaussian RF.
        
        """

        # mask for speed
        mask = self.distance_mask(x, y, sigma)

        # generate the RF
        rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x,
                                         self.stimulus.deg_y)
        rf /= (2 * np.pi * sigma**2) * 1 / np.diff(self.stimulus.deg_x[0,
                                                                       0:2])**2

        # extract the stimulus time-series
        response = generate_rf_timeseries(self.stimulus.stim_arr, rf, mask)

        # convolve it with the stimulus
        model = fftconvolve(response, self.hrf_delay())[0:len(response)]

        # units
        model = (model - np.mean(model)) / np.mean(model)

        # offset
        model += baseline

        # scale it by beta
        model *= beta

        return model
Пример #20
0
    def generate_ballpark_prediction(self, x, y, sigma, n, weight):

        # mask for speed
        mask = self.distance_mask_coarse(x, y, sigma)

        # generate the RF
        spatial_rf = generate_og_receptive_field(x, y, sigma,
                                                 self.stimulus.deg_x0,
                                                 self.stimulus.deg_y0)
        spatial_rf /= ((2 * np.pi * sigma**2) * 1 /
                       np.diff(self.stimulus.deg_x0[0, 0:2])**2)

        # spatial_response
        spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr0,
                                            spatial_rf, mask)

        # compression
        spatial_ts **= n

        # temporal response
        m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp,
                                            self.stimulus.flicker_vec)

        # mix them
        mp_ts = (1 - weight) * m_ts + weight * p_ts

        # convolve with HRF
        model = fftconvolve(mp_ts, self.hrf())[0:len(mp_ts)]

        # units
        # model = (model - np.mean(model)) / np.mean(model)
        model = self.normalizer(model)

        # regress out mean and linear
        p = linregress(model, self.data)

        # scale
        model *= p[0]

        # offset
        model += p[1]

        return model
Пример #21
0
 def generate_prediction(self, x, y, sigma, beta, baseline, hrf_delay):
     
     r"""
     Predict signal for the Gaussian Model using the downsampled stimulus.
     The rate of stimulus downsampling is defined in `model.stimulus.scale_factor`.
     
     Parameters
     __________
     x : float
         Horizontal location of the Gaussian RF.
     
     y: float 
         Vertical location of the Gaussian RF.
     
     sigma: float
         Dipsersion of the Gaussian RF.
     
     """
     
     # mask for speed
     mask = self.distance_mask(x, y, sigma)
     
     # generate the RF
     rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
     rf /= (2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x[0,0:2])**2
     
     # extract the stimulus time-series
     response = generate_rf_timeseries(self.stimulus.stim_arr, rf, mask)
     
     # convolve it with the stimulus
     model = fftconvolve(response, self.hrf_delay())[0:len(response)]
     
     # units
     model = (model-np.mean(model)) / np.mean(model)
     
     # offset
     model += baseline
     
     # scale it by beta
     model *= beta
     
     return model
Пример #22
0
 def estimate_scaling(self, x, y, sigma):
     
     # mask for speed
     mask = self.distance_mask_coarse(x, y, sigma)
     
     # generate the RF
     rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x0, self.stimulus.deg_y0)
     rf /= (2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x0[0,0:2])**2
     
     # extract the stimulus time-series
     response = generate_rf_timeseries(self.stimulus.stim_arr0, rf, mask)
     
     # convolve it with the stimulus
     model = fftconvolve(response, self.hrf())[0:len(response)]
     
     # units
     model = (model-np.mean(model)) / np.mean(model)
     
     # regress out mean and linear
     p = linregress(model, self.data)
     
     return p
Пример #23
0
 def generate_prediction(self, x, y, sigma, n, weight, beta, baseline, unscaled=False):
     
     # mask for speed
     mask = self.distance_mask(x, y, sigma)
     
     # generate the RF
     spatial_rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
     spatial_rf /= ((2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x[0,0:2])**2)
     
     # spatial response
     spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr, spatial_rf, mask)
     
     # compression
     spatial_ts **= n
     
     # temporal response
     m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp, self.stimulus.flicker_vec)
     
     # mix them
     mp_ts = (1-weight) * m_ts + weight * p_ts
     
     # convolve with HRF
     model = fftconvolve(mp_ts, self.hrf())[0:len(mp_ts)]
     
     # convert units
     model = self.normalizer(model)
     
     if unscaled:
         return model
     else:
         # scale
         model *= beta
         
         # offset
         model += baseline
         
         return model
Пример #24
0
 def generate_prediction(self, x, y, sigma, sigma_ratio, volume_ratio, beta, baseline, unscaled=False):
     
     # extract the center response
     rf_center = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
     
     # extract surround response
     rf_surround = generate_og_receptive_field(x, y, sigma*sigma_ratio, 
                                               self.stimulus.deg_x, self.stimulus.deg_y) * 1/sigma_ratio**2
     
     # difference
     rf = ne.evaluate('rf_center - sqrt(volume_ratio)*rf_surround')
     
     # extract the response
     mask = self.distance_mask(x, y, sigma*sigma_ratio)
     response = generate_rf_timeseries(self.stimulus.stim_arr, rf, mask)
     
     # generate the hrf
     hrf = self.hrf_model(self.hrf_delay, self.stimulus.tr_length)
     
     # convolve it
     model = fftconvolve(response, hrf)[0:len(response)]
     
     # units
     model = self.normalizer(model)
     
     if unscaled:
         return model
     else:
         
         # offset
         model += baseline
         
         # scale it by beta
         model *= beta
         
         return model
Пример #25
0
 def generate_prediction(self, x, y, sigma, weight, beta, baseline,  unscaled=False):
     
     r"""
     Predict signal for the Gaussian Model using the full resolution stimulus.
     
     Parameters
     __________
     x : float
         Horizontal location of the 2D Cosine RF.
     
     y: float 
         Vertical location of the 2D Cosine RF.
     
     sigma: float
         Dipsersion of the 2D Cosine RF.
     
     weight: float
         Mixture of the magnocellar and parvocellular temporal response to
         a flickering visual stimulus. The `weight` ranges between 0 and 1, 
         with 0 being a totally magnocellular response and ` being a totally
         parvocellular response.
         
     beta : float
         Amplitude scaling factor to account for units.
         
     baseline: float
         Amplitude intercept to account for baseline.
     
     """
     
     # generate the RF
     spatial_rf = generate_2dcos_receptive_field(x, y, sigma, self.power, self.stimulus.deg_x, self.stimulus.deg_y)
     
     # normalize by volume
     spatial_rf /= (trapz(trapz(spatial_rf)) * 1/np.diff(self.stimulus.deg_x[0,0:2])**2)
     
     # make mask
     mask = np.uint8(spatial_rf>0)
     
     # spatial response
     spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr, spatial_rf, mask)
     
     # temporal response
     m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp, self.stimulus.flicker_vec)
     
     # mix them
     mp_ts = (1-weight) * m_ts + weight * p_ts 
     
     # convolve with HRF
     model = fftconvolve(mp_ts, self.hrf())[0:len(mp_ts)]
     
     # units
     model = (model - np.mean(model)) / np.mean(model)
     
     if unscaled:
         return model
     else:
         
         # offset
         model += baseline
         
         # scale it by beta
         model *= beta
         
         return model
Пример #26
0
 def generate_ballpark_prediction(self, x, y, sigma, weight, hrf_delay):
     
     r"""
     Predict signal for the Gaussian Model using the downsampled stimulus.
     The rate of stimulus downsampling is defined in `model.stimulus.scale_factor`.
     
     Parameters
     __________
     x : float
         Horizontal location of the Gaussian RF.
     
     y: float 
         Vertical location of the Gaussian RF.
     
     sigma: float
         Dipsersion of the Gaussian RF.
     
     weight: float
         Mixture of the magnocellar and parvocellular temporal response to
         a flickering visual stimulus. The `weight` ranges between 0 and 1, 
         with 0 being a totally magnocellular response and ` being a totally
         parvocellular response.
     
     hrf_delay : float
         The delay of the peak and undershoot of the hemodynamic response
         function in seconds. This is a number varying about 0 which will
         be added to the 5 and 15, representing the constant delay of the
         peak and undershoot.
     
     """
     # mask for speed
     mask = self.distance_mask_coarse(x, y, sigma)
     
     # generate the RF
     spatial_rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x0, self.stimulus.deg_y0)
     spatial_rf /= ((2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x0[0,0:2])**2)
     
     # spatial_response
     spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr0, spatial_rf, mask)
     
     # temporal response
     m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp, self.stimulus.flicker_vec)
     
     # mix them
     mp_ts = (1-weight) * m_ts + weight * p_ts
     
     # convolve with HRF
     model = fftconvolve(mp_ts, self.hrf_model(hrf_delay, self.stimulus.tr_length))[0:len(mp_ts)]
     
     # units
     model = self.normalizer(model)
     
     # regress out mean and linear
     p = linregress(model, self.data)
     
     # offset
     model += p[1]
     
     # scale
     model *= p[0]
     
     return model
Пример #27
0
 def generate_prediction(self, x, y, sigma, weight, hrf_delay, beta, baseline, unscaled=False):
     
     r"""
     Predict signal for the Gaussian Model using the full resolution stimulus.
     
     Parameters
     __________
     x : float
         Horizontal location of the Gaussian RF.
     
     y: float 
         Vertical location of the Gaussian RF.
     
     sigma: float
         Dipsersion of the Gaussian RF.
     
     weight: float
         Mixture of the magnocellar and parvocellular temporal response to
         a flickering visual stimulus. The `weight` ranges between 0 and 1, 
         with 0 being a totally magnocellular response and ` being a totally
         parvocellular response.
     
     hrf_delay : float
         The delay of the peak and undershoot of the hemodynamic response
         function in seconds. This is a number varying about 0 which will
         be added to the 5 and 15, representing the constant delay of the
         peak and undershoot.
     
     beta : float
         Amplitude scaling factor to account for units.
         
     baseline: float
         Amplitude intercept to account for baseline.
     
     """
     
     # mask for speed
     mask = self.distance_mask(x, y, sigma)
     
     # generate the RF
     spatial_rf = generate_og_receptive_field(x, y, sigma, self.stimulus.deg_x, self.stimulus.deg_y)
     spatial_rf /= ((2 * np.pi * sigma**2) * 1/np.diff(self.stimulus.deg_x[0,0:2])**2)
     
     # spatial response
     spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr, spatial_rf, mask)
     
     # temporal response
     m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp, self.stimulus.flicker_vec)
     
     # mix them
     mp_ts = (1-weight) * m_ts + weight * p_ts 
     
     # convolve with HRF
     model = fftconvolve(mp_ts, self.hrf_model(hrf_delay, self.stimulus.tr_length))[0:len(mp_ts)]
     
     # convert units
     model = self.normalizer(model)
     
     if unscaled:
         return model
     else:
         
         # scale
         model *= beta
         
         # offset
         model += baseline
         
         return model
Пример #28
0
    def generate_prediction(self,
                            x,
                            y,
                            sigma,
                            weight,
                            hrf_delay,
                            beta,
                            baseline,
                            unscaled=False):
        r"""
        Predict signal for the Gaussian Model using the full resolution stimulus.
        
        Parameters
        __________
        x : float
            Horizontal location of the Gaussian RF.
        
        y: float 
            Vertical location of the Gaussian RF.
        
        sigma: float
            Dipsersion of the Gaussian RF.
        
        weight: float
            Mixture of the magnocellar and parvocellular temporal response to
            a flickering visual stimulus. The `weight` ranges between 0 and 1, 
            with 0 being a totally magnocellular response and ` being a totally
            parvocellular response.
        
        hrf_delay : float
            The delay of the peak and undershoot of the hemodynamic response
            function in seconds. This is a number varying about 0 which will
            be added to the 5 and 15, representing the constant delay of the
            peak and undershoot.
        
        beta : float
            Amplitude scaling factor to account for units.
            
        baseline: float
            Amplitude intercept to account for baseline.
        
        """

        # mask for speed
        mask = self.distance_mask(x, y, sigma)

        # generate the RF
        spatial_rf = generate_og_receptive_field(x, y, sigma,
                                                 self.stimulus.deg_x,
                                                 self.stimulus.deg_y)
        spatial_rf /= ((2 * np.pi * sigma**2) * 1 /
                       np.diff(self.stimulus.deg_x[0, 0:2])**2)

        # spatial response
        spatial_ts = generate_rf_timeseries(self.stimulus.stim_arr, spatial_rf,
                                            mask)

        # temporal response
        m_ts, p_ts = generate_mp_timeseries(spatial_ts, self.m_amp, self.p_amp,
                                            self.stimulus.flicker_vec)

        # mix them
        mp_ts = (1 - weight) * m_ts + weight * p_ts

        # convolve with HRF
        model = fftconvolve(
            mp_ts, self.hrf_model(hrf_delay,
                                  self.stimulus.tr_length))[0:len(mp_ts)]

        # convert units
        model = self.normalizer(model)

        if unscaled:
            return model
        else:

            # scale
            model *= beta

            # offset
            model += baseline

            return model