<jupyter_start><jupyter_text>Figure curve fitting analysis population model<jupyter_code>%%javascript
Jupyter.notebook.session.restart({kernel_name: 'python2'})<jupyter_output><empty_output><jupyter_text>After running the cell above you can go ahead and run the ones below, even if the cell above appears 'busy'<jupyter_code>%matplotlib inline
import warnings
warnings.filterwarnings("ignore")
from brian2 import *
import os<jupyter_output><empty_output><jupyter_text>Creating random target data and computing the corresponding max error<jupyter_code>def max_error_random(filename,carrier,ind,cdt='random'):
    path='./fig_param_space_pop/param_space_pop_data_files/'
    phase=load(path+filename)
    res_rand=np.zeros(5)
    if cdt=='mono':
        for i in range(5):
            res_rand[i]=np.random.uniform(0,180,1)
        res_rand_sort=np.sort(res_rand)
        res_rand=res_rand_sort
    else:
        for i in range(5):
            res_rand[i]=np.random.uniform(0,360,1)
            
    print res_rand
    nbr_param_sets=int(1.*phase.size/phase.shape[0])
    max_error_flat=np.zeros(nbr_param_sets)
    phase_flat=phase.reshape((5,nbr_param_sets))
    for i in xrange(nbr_param_sets):
        if sum(isnan(phase_flat[:,i]))!=0:
            max_error_flat[i]=nan
        else:
            max_error_flat[i]=amax(abs(phase_flat[:,i]-res_rand))
    
    max_error=max_error_flat.reshape((1,phase.shape[1],phase.shape[2],phase.shape[3],phase.shape[4],phase.shape[5]))
    save(path+'max_error_random_'+str(ind)+'.npy',max_error)
    
    return max_error.shape
def random_test(num_rep,cdt):
    seed(34032483)
    path='./fig_param_space_pop/param_space_pop_data_files/'
    cp=0
    b_err=np.zeros(num_rep)
    for i in range(num_rep): 
        max_error_random('phase_500.npy',500,i,cdt)    
        b_err[i]=nanmin(load(path+'max_error_random_'+str(i)+'.npy'))
        os.remove(path+'max_error_random_'+str(i)+'.npy')
        cp+=1
        print 100.0*cp/num_rep
        print b_err[i]
    save(path+'rand_err_1000_'+cdt+'.npy',b_err)
## Cell below can take a fairly long time, few hours. 
#The precomputed data can be found in the files 'rand_err_1000_random.npy' and 'rand_err_1000_mono.npy'

random_test(1000,'random')
random_test(1000,'mono')<jupyter_output><empty_output><jupyter_text>The two cell belows can be run without running the cells above, it will use already computed data to plot the curve fitting analysis figure<jupyter_code>path='./fig_param_space_pop/param_space_pop_data_files/'
res_err=load(path+'rand_err_1000_random.npy')
print('Percentage of fully random data leading to errors below 5 degrees: '+str(len(res_err[res_err<=5.0])) + '%')
res_mono=load(path+'rand_err_1000_mono.npy')
print('Percentage of random monotonic data (below 180 degrees) leading to errors below 5 degrees: ' + str(len(res_mono[res_mono<=5.0])*100.0/1000) +'%')
figure(figsize=(4, 3), dpi=85)
hist(res_mono, linspace(0, 180, 181), cumulative=True,weights=ones(len(res_mono))*100./len(res_mono),label='Random increasing IPD (<180)',lw=0)
hist(res_err, linspace(0, 180, 181), cumulative=True,weights=ones(len(res_err))*100./len(res_err),label='Random IPD',lw=0)
axvline(5, c='r', lw=2, label='Minimum error (target=data)')
#ylim(0, 100)
xlim(0, 180)
xticks([0,15,30,45,90,135,180])
legend(loc='upper right')
xlabel('Minimum error (deg)')
ylabel('% dist below min error')
tight_layout()
savefig('fig_pop_model_curve_fitting_analysis.pdf')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.140224589691909, 'fraction_numerical': 0.041462712352433054, 'mean_word_length': 5.493457943925233, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '471877', 'license': 'MIT', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1293, 'n_words': 219, 'path': 'population_model/fig_curve_fitting_analysis_pop.ipynb', 'repo_name': 'neural-reckoning/simple_ambb_modelling', 'size': '3473'}