예제 #1
0
'''Author: 		mlwave.com'''
'''Description:	Python benchmark code for Pearson Correlation with Descretization, in use for Kaggle Connectomics Contest'''
import brainparse as bp
import scipy.stats as stats
import numpy as np
from datetime import datetime
start = datetime.now()
last = datetime.now()

neuron_activities = bp.parse_time_series("d:\\brain\\fluorescence_valid.txt")
neuron_activities = bp.discretize_time_series(neuron_activities, threshold=0.12)
neuron_positions = bp.parse_neuron_positions("d:\\brain\\networkPositions_valid.txt")
predictions_loc = "d:\\brain\\kaggle_preds.csv"

def create_predictions(predictions_loc,neuron_activities,neuron_positions,start=datetime.now(),last=datetime.now()):
	print "\nWriting:", predictions_loc
	cache = {}
	with open(predictions_loc, "wb") as outfile:
		outfile.write( "NET_neuronI_neuronJ,Strength\n" )
		for e, neuron_i_id in enumerate( xrange(len(neuron_positions)) ):
			for neuron_j_id, neuron_position in neuron_positions.items():
				if (neuron_i_id, neuron_j_id) in cache:
					outfile.write( "valid_"+str(neuron_i_id+1)+"_"+str(neuron_j_id+1)+","+cache[(neuron_i_id, neuron_j_id)] + "\n" )
				elif neuron_i_id == neuron_j_id:
					outfile.write( "valid_"+str(neuron_i_id+1)+"_"+str(neuron_j_id+1)+",0\n" )
				else:
					corr = str(stats.pearsonr(neuron_activities[neuron_i_id], neuron_activities[neuron_j_id])[0])
					cache[(neuron_j_id, neuron_i_id)] = corr
					outfile.write( "valid_"+str(neuron_i_id+1)+"_"+str(neuron_j_id+1)+","+corr + "\n" )
			print e+1,"/",len(neuron_positions),"\t",datetime.now()-start,"\t",datetime.now()-last
			last = datetime.now()
예제 #2
0
import brainparse
import pygame
import sys

#parse all data
neuron_activities = brainparse.parse_time_series(
    "d:\\brain\\fluorescence_iNet1_Size100_CC02inh.txt")
neuron_positions = brainparse.parse_neuron_positions(
    "d:\\brain\\networkPositions_iNet1_Size100_CC02inh.txt")
neuron_connections, blocked = brainparse.parse_neuron_connections(
    "d:\\brain\\network_iNet1_Size100_CC02inh.txt")

white = (255, 255, 255)
grey = (190, 190, 190)
lightgrey = (0, 128, 255)

#initialize pygame
pygame.init()
screen = pygame.display.set_mode((500, 500))
screen.fill(white)

#draw our network connections between the neurons
for neuron_connection, connection_type in neuron_connections.items():
    if connection_type == -1:
        pygame.draw.lines(screen, lightgrey, False, [
            neuron_positions[neuron_connection[0]],
            neuron_positions[neuron_connection[1]]
        ], 1)
    else:
        pygame.draw.lines(screen, grey, False, [
            neuron_positions[neuron_connection[0]],
예제 #3
0
CALC_SCORE = len(sys.argv[1:]) > 2
JUST_SCORE = False

predictions_loc = "kaggle_preds.csv"
if CALC_SCORE:
  flurofn, posfn, networkfn = sys.argv[1:]
else:
  flurofn, posfn = sys.argv[1:]

if not JUST_SCORE:
  neuron_activities = bp.parse_time_series(flurofn)
  neuron_activities = bp.discretize_time_series(neuron_activities, threshold=0.12)
  #neuron_activities = bp.blur_time_series(neuron_activities)
  #neuron_activities = bp.normalize_time_series(neuron_activities)
  #neuron_activities = bp.discretize_time_series(neuron_activities, threshold=np.max(neuron_activities[0]) * 0.12)
  neuron_positions = bp.parse_neuron_positions(posfn)
  avg_spikes = []
  for k, v in neuron_activities.items():
    avg_spikes.append(np.sum(v))
  avg_spikes = np.mean(avg_spikes)
  print 'Average spikes:', avg_spikes


def compare_neuron_activities(X, Y):
  return stats.pearsonr(X, Y)[0]
  #return stats.spearmanr(X, Y)[0]
  #from statsmodels.tsa.stattools import grangercausalitytests
  #return 1 - grangercausalitytests(np.array([X[:1000], Y[:1000]]).T, 1, verbose=False)[1][0]['params_ftest'][0]


def create_predictions(predictions_loc, neuron_activities, neuron_positions, start=datetime.now(), last=datetime.now()):
예제 #4
0
import brainparse
import pygame
import sys

# parse all data
neuron_activities = brainparse.parse_time_series("d:\\brain\\fluorescence_iNet1_Size100_CC02inh.txt")
neuron_positions = brainparse.parse_neuron_positions("d:\\brain\\networkPositions_iNet1_Size100_CC02inh.txt")
neuron_connections, blocked = brainparse.parse_neuron_connections("d:\\brain\\network_iNet1_Size100_CC02inh.txt")

white = (255, 255, 255)
grey = (190, 190, 190)
lightgrey = (0, 128, 255)

# initialize pygame
pygame.init()
screen = pygame.display.set_mode((500, 500))
screen.fill(white)

# draw our network connections between the neurons
for neuron_connection, connection_type in neuron_connections.items():
    if connection_type == -1:
        pygame.draw.lines(
            screen,
            lightgrey,
            False,
            [neuron_positions[neuron_connection[0]], neuron_positions[neuron_connection[1]]],
            1,
        )
    else:
        pygame.draw.lines(
            screen, grey, False, [neuron_positions[neuron_connection[0]], neuron_positions[neuron_connection[1]]], 1