Example #1
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
Example #2
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
Example #3
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
Example #4
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
Example #5
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
Example #6
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
Example #7
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
Example #8
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
Example #9
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
Example #10
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
Example #11
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
Example #12
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
Example #13
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