Beispiel #1
0
def scm_analysis(netw, terminate_times, delay=0.1, flag=False):
    """
    Anaylsis of the scm and compare to normal PyNAM (first spikes after input spike)
    :param netw: Should be of NetworkAnalysis type
    :param flag: Simple model flag
    :return: Information in the SCM, output-matrix and an errors object
    """

    # Calculate the SCM  information
    mat_out_res = calc_scm_output_matrix(netw, terminate_times, delay, max)
    N, n = mat_out_res.shape
    errs = entropy.calculate_errs(mat_out_res, netw["mat_out"])
    I = entropy.entropy_hetero(errs, n, netw["data_params"]["n_ones_out"])

    # Get the spike times of the source population
    tem, _, _ = pynam.network.NetworkInstance.flatten(netw["input_times"],
                                                      netw["input_indices"])
    start_times = np.unique(tem)
    for i in xrange(len(start_times)):
        start_times = start_times + 0.98 + delay * 2.5
    # calc_scm_output_matrix needs such an array
    start_times_ar = np.zeros((2, len(start_times)))
    start_times_ar[0] = start_times

    # Finally calculate the BiNAM information from the start
    mat_out_first = calc_scm_output_matrix(netw, start_times_ar, delay)
    errs_start = entropy.calculate_errs(mat_out_first, netw["mat_out"])
    I_start = entropy.entropy_hetero(errs_start, n,
                                     netw["data_params"]["n_ones_out"])

    # Calculate non-spiking information for Reference
    I_ref, mat_ref, errs_ref = netw.calculate_max_storage_capacity()
    # Noramlized information values
    I_norm = 0.0 if I_ref == 0.0 else I / float(I_ref)
    I_norm_start = 0.0 if I_ref == 0.0 else I_start / float(I_ref)

    # The number of False Positives and Negatives for both SCM and BiNAM
    fp = sum(map(lambda x: x["fp"], errs))
    fn = sum(map(lambda x: x["fn"], errs))
    fp_start = sum(map(lambda x: x["fp"], errs_start))
    fn_start = sum(map(lambda x: x["fn"], errs_start))

    if (flag):
        print "\t\t\t\tBiNAM \t\tSimple_Net"
    else:
        print "\t\t\t\tBiNAM \t\tSCM"
    print "Information:\t\t\t", format(I_start, '.2f'), "\t", format(I, '.2f')
    print "Normalized information:\t\t", format(I_norm_start,
                                                '.2f'), "\t\t", format(
                                                    I_norm, '.2f')
    print "False positives:\t\t", format(fp_start,
                                         '.0f'), "\t\t", format(fp, '.0f')
    print "False negatives:\t\t", format(fn_start,
                                         '.0f'), "\t\t", format(fn, '.0f')
    return I, I_norm, fp, fn, I_start, I_norm_start, fp_start, fn_start
Beispiel #2
0
def scm_analysis(netw, terminate_times, delay=0.1, flag=False):
    """
    Anaylsis of the scm and compare to normal PyNAM (first spikes after input spike)
    :param netw: Should be of NetworkAnalysis type
    :param flag: Simple model flag
    :return: Information in the SCM, output-matrix and an errors object
    """

    # Calculate the SCM  information
    mat_out_res = calc_scm_output_matrix(netw, terminate_times, delay, max)
    N, n = mat_out_res.shape
    errs = entropy.calculate_errs(mat_out_res, netw["mat_out"])
    I = entropy.entropy_hetero(errs, n, netw["data_params"]["n_ones_out"])

    # Get the spike times of the source population
    tem, _, _ = pynam.network.NetworkInstance.flatten(netw["input_times"],
                                                      netw["input_indices"])
    start_times = np.unique(tem)
    for i in xrange(len(start_times)):
        start_times = start_times + 0.98 + delay * 2.5
    # calc_scm_output_matrix needs such an array
    start_times_ar = np.zeros((2, len(start_times)))
    start_times_ar[0] = start_times

    # Finally calculate the BiNAM information from the start
    mat_out_first = calc_scm_output_matrix(netw, start_times_ar, delay)
    errs_start = entropy.calculate_errs(mat_out_first, netw["mat_out"])
    I_start = entropy.entropy_hetero(errs_start, n,
                                     netw["data_params"]["n_ones_out"])

    # Calculate non-spiking information for Reference
    I_ref, mat_ref, errs_ref = netw.calculate_max_storage_capacity()
    # Noramlized information values
    I_norm = 0.0 if I_ref == 0.0 else I / float(I_ref)
    I_norm_start = 0.0 if I_ref == 0.0 else I_start / float(I_ref)

    # The number of False Positives and Negatives for both SCM and BiNAM
    fp = sum(map(lambda x: x["fp"], errs))
    fn = sum(map(lambda x: x["fn"], errs))
    fp_start = sum(map(lambda x: x["fp"], errs_start))
    fn_start = sum(map(lambda x: x["fn"], errs_start))

    if (flag):
        print "\t\t\t\tBiNAM \t\tSimple_Net"
    else:
        print "\t\t\t\tBiNAM \t\tSCM"
    print "Information:\t\t\t", format(I_start, '.2f'), "\t", format(I, '.2f')
    print "Normalized information:\t\t", format(I_norm_start,
                                                '.2f'), "\t\t", format(I_norm,
                                                                       '.2f')
    print "False positives:\t\t", format(fp_start, '.0f'), "\t\t", format(fp,
                                                                          '.0f')
    print "False negatives:\t\t", format(fn_start, '.0f'), "\t\t", format(fn,
                                                                          '.0f')
    return I, I_norm, fp, fn, I_start, I_norm_start, fp_start, fn_start
Beispiel #3
0
 def test_calculate_errs(self):
     mat_out_expected = np.array([
         [1, 0, 1, 0],
         [1, 0, 0, 1],
         [0, 1, 0, 1],
     ])
     mat_out = np.array([
         [1, 0.25, 0.2, 0],
         [1.5, 1.2, 0.25, 1],
         [0.1, 1, 0, 1],
     ])
     errs = calculate_errs(mat_out, mat_out_expected)
     self.assertAlmostEqual([{'fp': 0.25, 'fn': 0.8},
             {'fp': 1.25, 'fn': 0}, {'fp': 0.1, 'fn': 0}], errs)
Beispiel #4
0
 def test_calculate_errs(self):
     mat_out_expected = np.array([[1, 0, 1, 0], [1, 0, 0, 1], [0, 1, 0, 1]])
     mat_out = np.array([[1, 0.25, 0.2, 0], [1.5, 1.2, 0.25, 1], [0.1, 1, 0, 1]])
     errs = calculate_errs(mat_out, mat_out_expected)
     self.assertAlmostEqual([{"fp": 0.25, "fn": 0.8}, {"fp": 1.25, "fn": 0}, {"fp": 0.1, "fn": 0}], errs)