Пример #1
0
               headers=['<structmember.h>'])


class CFPRF_DotProduct(CFPRF_Plugin):
    """
    Wrapper written to allow transparent non-optimized fallback; 
    equivalent to CFPRF_Plugin(single_cf_fn=DotProduct()).
    """

    # CB: should probably have single_cf_fn here & readonly
    def __init__(self, **params):
        super(CFPRF_DotProduct, self).__init__(single_cf_fn=DotProduct(),
                                               **params)


provide_unoptimized_equivalent("CFPRF_DotProduct_opt", "CFPRF_DotProduct",
                               locals())

try:
    from optimized_cy import CFPRF_DotProduct_cyopt  # pyflakes:ignore (optimized version)
except:
    pass

provide_unoptimized_equivalent_cy("CFPRF_DotProduct_cyopt", "CFPRF_DotProduct",
                                  locals())


# CEBERRORALERT: ignores the sheet mask!
class CFPRF_EuclideanDistance_opt(CFPResponseFn):
    """
    Euclidean-distance response function.
Пример #2
0
                }
            }
        """%c_decorators
        inline(code, ['mask','X', 'strength', 'icols', 'temp_act','cfs','num_cfs','cf_type'], 
               local_dict=locals(), headers=['<structmember.h>'])

class CFPRF_DotProduct(CFPRF_Plugin):
    """
    Wrapper written to allow transparent non-optimized fallback; 
    equivalent to CFPRF_Plugin(single_cf_fn=DotProduct()).
    """
    # CB: should probably have single_cf_fn here & readonly
    def __init__(self,**params):
        super(CFPRF_DotProduct,self).__init__(single_cf_fn=DotProduct(),**params)

provide_unoptimized_equivalent("CFPRF_DotProduct_opt","CFPRF_DotProduct",locals())


try:
    from optimized_cy import CFPRF_DotProduct_cyopt  # pyflakes:ignore (optimized version)
except:
    pass

provide_unoptimized_equivalent_cy("CFPRF_DotProduct_cyopt","CFPRF_DotProduct",locals())



# CEBERRORALERT: ignores the sheet mask!
class CFPRF_EuclideanDistance_opt(CFPResponseFn):
    """
    Euclidean-distance response function.
                    Py_DECREF(cfs);
                }
            }

        }
    """
    inline(code, [
        'projlist', 'active_units_mask', 'sheet_mask', 'num_cfs', 'length',
        'cf_type'
    ],
           local_dict=locals(),
           headers=['<structmember.h>'])


provide_unoptimized_equivalent("compute_joint_norm_totals_opt",
                               "compute_joint_norm_totals", locals())


# CEBALERT: not tested
class LISSOM_Opt(LISSOM):
    """
    Faster but potentially unsafe optimized version of LISSOM.

    Adds a NeighborhoodMask that skips computation for neurons
    sufficiently distant from all those activated in the first few
    steps of settling.  This is safe only if activity bubbles reliably
    shrink after the first few steps; otherwise the results will
    differ from LISSOM.

    Typically useful only for standard LISSOM simulations with
    localized (e.g. Gaussian) inputs and that shrink the lateral
Пример #4
0
                    LOOKUP_FROM_SLOT_OFFSET(int,_has_norm_total,cf);
                    _has_norm_total[0]=1;
                }
            }
        """%c_decorators

        inline(code, ['input_activity', 'output_activity','sheet_mask','num_cfs',
                      'icols', 'cfs', 'single_connection_learning_rate','cf_type'],
               local_dict=locals(),
               headers=['<structmember.h>'])


class CFPLF_Hebbian(CFPLF_Plugin):
    """Same as CFPLF_Plugin(single_cf_fn=Hebbian()); just for non-optimized fallback."""
    single_cf_fn = param.ClassSelector(LearningFn,default=Hebbian(),readonly=True)
provide_unoptimized_equivalent("CFPLF_Hebbian_opt","CFPLF_Hebbian",locals())


# CBERRORALERT: classes from here on probably ignore the sheet mask

# JABALERT: Is this really a fixed-threshold BCM rule?  If so, is that really useful?
class CFPLF_BCMFixed_opt(CFPLearningFn):
    """
    CF-aware BCM learning rule.

    Implemented in C for speed.  Should be equivalent to
    BCMFixed for CF sheets, except faster.

    As a side effect, sets the norm_total attribute on any cf whose
    weights are updated during learning, to speed up later operations
    that might depend on it.
Пример #5
0
                    LOOKUP_FROM_SLOT_OFFSET(double,_norm_total,cf);
                    _norm_total[0] = nt;
                    LOOKUP_FROM_SLOT_OFFSET(int,_has_norm_total,cf);
                    _has_norm_total[0] = 1;

                    Py_DECREF(cfs);
                }
            }

        }
    """
    inline(code, ['projlist','active_units_mask','sheet_mask','num_cfs','length','cf_type'],
           local_dict=locals(),
           headers=['<structmember.h>'])

provide_unoptimized_equivalent("compute_joint_norm_totals_opt",
                               "compute_joint_norm_totals",locals())

# CEBALERT: not tested
class SettlingCFSheet_Opt(SettlingCFSheet):
    """
    Faster but potentially unsafe optimized version of SettlingCFSheet.

    Adds a NeighborhoodMask that skips computation for neurons
    sufficiently distant from all those activated in the first few
    steps of settling.  This is safe only if activity bubbles reliably
    shrink after the first few steps; otherwise the results will
    differ from SettlingCFSheet.

    Typically useful only for standard SettlingCFSheet simulations with
    localized (e.g. Gaussian) inputs and that shrink the lateral
    excitatory radius, which results in small patches of activity in
Пример #6
0
                    LOOKUP_FROM_SLOT_OFFSET(double,_norm_total,cf);
                    _norm_total[0] = nt;
                    LOOKUP_FROM_SLOT_OFFSET(int,_has_norm_total,cf);
                    _has_norm_total[0] = 1;

                    Py_DECREF(cfs);
                }
            }

        }
    """
    inline(code, ['projlist','active_units_mask','sheet_mask','num_cfs','length','cf_type'],
           local_dict=locals(),
           headers=['<structmember.h>'])

provide_unoptimized_equivalent("compute_joint_norm_totals_opt",
                               "compute_joint_norm_totals",locals())

# CEBALERT: not tested
class LISSOM_Opt(LISSOM):
    """
    Faster but potentially unsafe optimized version of LISSOM.

    Adds a NeighborhoodMask that skips computation for neurons
    sufficiently distant from all those activated in the first few
    steps of settling.  This is safe only if activity bubbles reliably
    shrink after the first few steps; otherwise the results will
    differ from LISSOM.

    Typically useful only for standard LISSOM simulations with
    localized (e.g. Gaussian) inputs and that shrink the lateral
    excitatory radius, which results in small patches of activity in
Пример #7
0
    single_cf_fn = param.ClassSelector(
        TransferFn,default=DivisiveNormalizeL1(norm_value=1.0),constant=True)

    def __call__(self, iterator, **params):
        """
        Uses the cf.norm_total attribute to allow optimization
        by computing the sum separately, and to allow joint
        normalization.  After use, cf.norm_total is deleted because
        the value it would have has been changed.
        """
        # CEBALERT: fix this here and elsewhere
        if type(self.single_cf_fn) is not IdentityTF:
            norm_value = self.single_cf_fn.norm_value                
            for cf,i in iterator():
                current_sum=cf.norm_total
		if current_sum > 0.0000000000001:
                    factor = norm_value/current_sum
                    cf.weights *= factor
                del cf.norm_total


provide_unoptimized_equivalent("CFPOF_DivisiveNormalizeL1_opt","CFPOF_DivisiveNormalizeL1",locals())


__all__ = list(set([k for k,v in locals().items() if isinstance(v,type) and
                    (issubclass(v,TransferFn) or issubclass(v,CFPOutputFn))]))
__all__.remove("CFPOutputFn")
__all__.remove("TransferFn")
__all__.remove("IdentityTF")
__all__.remove("DivisiveNormalizeL1")
Пример #8
0
            if(HUE2(i,j)<0)
                HUE2(i,j)+=1;
            //else if(HUE2(i,j)>1)
            //    HUE2(i,j)-=1;

        }

    }
}

"""
    inline(code, ['red','grn','blu','hue','sat','val'], local_dict=locals())
    return numpy.dstack((hue,sat,val))


provide_unoptimized_equivalent("_rgb_to_hsv_array_opt","_rgb_to_hsv_array",locals())




def _hsv_to_rgb_array_opt(HSV):
    """Equivalent to hsv_to_rgb_array()."""
    hue = HSV[:,:,0]
    sat = HSV[:,:,1]
    val = HSV[:,:,2]

    shape = hue.shape
    dtype = hue.dtype
    
    red = numpy.zeros(shape,dtype=dtype)
    grn = numpy.zeros(shape,dtype=dtype)
Пример #9
0
        inline(code, [
            'input_activity', 'output_activity', 'sheet_mask', 'num_cfs',
            'icols', 'cfs', 'single_connection_learning_rate', 'cf_type'
        ],
               local_dict=locals(),
               headers=['<structmember.h>'])


class CFPLF_Hebbian(CFPLF_Plugin):
    """Same as CFPLF_Plugin(single_cf_fn=Hebbian()); just for non-optimized fallback."""
    single_cf_fn = param.ClassSelector(LearningFn,
                                       default=Hebbian(),
                                       readonly=True)


provide_unoptimized_equivalent("CFPLF_Hebbian_opt", "CFPLF_Hebbian", locals())

# CBERRORALERT: classes from here on probably ignore the sheet mask


# JABALERT: Is this really a fixed-threshold BCM rule?  If so, is that really useful?
class CFPLF_BCMFixed_opt(CFPLearningFn):
    """
    CF-aware BCM learning rule.

    Implemented in C for speed.  Should be equivalent to
    BCMFixed for CF sheets, except faster.

    As a side effect, sets the norm_total attribute on any cf whose
    weights are updated during learning, to speed up later operations
    that might depend on it.