예제 #1
0
파일: generatore.py 프로젝트: Carlovan/oii
def run(N, K, S):
    random.seed(S)
    seed(S)
    s = ""
    for i in range(K):
        s += choice("abcdefghijklmnopqrstuvwxyz")
    Q = randint(1, N+1)
    trip = {}
    curr = 1
    for i in s:
        if (curr, i) in trip:
            curr = trip[(curr, i)]
        else:
            dest = randint(1, N+1)
            trip[(curr, i)] = dest
            curr = dest

    M = randint(K, MAXM+1)
    tent = 0
    while tent < 100 and len(trip) != M:
        curr = randint(1, N+1)
        c = choice("abcdefghijklmnopqrstuvwxyz")
        if (curr, c) not in trip:
            dest = randint(1, N+1)
            trip[(curr, c)] = dest
        else:
            tent += 1

    print len(trip), N, K
    for i in s:
        print i,
    print
    for i in trip:
        print i[0], trip[i], i[1]
예제 #2
0
def run(N, K, S):
    random.seed(S)
    seed(S)
    s = ""
    for i in range(K):
        s += choice("abcdefghijklmnopqrstuvwxyz")
    Q = randint(1, N + 1)
    trip = {}
    curr = 1
    for i in s:
        if (curr, i) in trip:
            curr = trip[(curr, i)]
        else:
            dest = randint(1, N + 1)
            trip[(curr, i)] = dest
            curr = dest

    M = randint(K, MAXM + 1)
    tent = 0
    while tent < 100 and len(trip) != M:
        curr = randint(1, N + 1)
        c = choice("abcdefghijklmnopqrstuvwxyz")
        if (curr, c) not in trip:
            dest = randint(1, N + 1)
            trip[(curr, c)] = dest
        else:
            tent += 1

    print len(trip), N, K
    for i in s:
        print i,
    print
    for i in trip:
        print i[0], trip[i], i[1]
예제 #3
0
def semaphore_func(sema, mutex, running):
    sema.acquire()
    mutex.acquire()
    running.value += 1
    print running.value, 'tasks are running'
    mutex.release()
    random.seed()
    time.sleep(random.random()*2)
    mutex.acquire()
    running.value -= 1
    print '%s has finished' % multiprocessing.current_process()
    mutex.release()
    sema.release()
예제 #4
0
def semaphore_func(running):
    #sema.acquire()
    #mutex.acquire()
    running.value += 1
    print running.value, 'tasks are running'
    #mutex.release()
    random.seed()
    time.sleep(random.random()*5)
    #mutex.acquire()
    running.value -= 1
    print '%s has finished' % multiprocessing.current_process().name
    #mutex.release()
    #sema.release()
    return
예제 #5
0
def rand_n(L, config):
    csplit = config.split('_')
    ns = csplit[0]
    nssplit = ns.split('-')
    n = int(nssplit[0])
    if len(nssplit) > 1:
        s = int(nssplit[1]) * L * n
    else:
        s = None
    random.seed(s)
    fock_config = '-'.join([str(i) for i in random.sample(range(L), n)])
    if len(csplit) > 1:
        config = csplit[1:]
        fock_config = ''.join([fock_config, config])
    return fock(L, fock_config)
예제 #6
0
from psychopy import visual, core, data, event, logging, sound, gui
from psychopy.constants import *  # things like STARTED, FINISHED
import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray
from numpy.random import random, randint, normal, shuffle
import os  # handy system and path functions
import random

# Store info about the experiment session
expName = u'sublim2'  # from the Builder filename that created this script
expInfo = {'participant': '', 'session': '001'}
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
if dlg.OK == False: core.quit()  # user pressed cancel
expInfo['date'] = data.getDateStr()  # add a simple timestamp
expInfo['expName'] = expName
random.seed()
bilyvlevo = random.randint(
    0, 1)  #nahodne urcim, jestli bily ctverec bud pro sipku vlevo nebo vpravo
expInfo['bilyvlevo'] = bilyvlevo

# Setup filename for saving
filename = 'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])

# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName,
                                 version='',
                                 extraInfo=expInfo,
                                 runtimeInfo=None,
                                 originPath=None,
                                 savePickle=True,
                                 saveWideText=True,
예제 #7
0
win = visual.Window(size=(800, 600), fullscr=False, screen=0, allowGUI=False, allowStencil=False,
    monitor='Lab', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True,
    )
# store frame rate of monitor if we can measure it successfully
expInfo['frameRate']=win.getActualFrameRate()
if expInfo['frameRate']!=None:
    frameDur = 1.0/round(expInfo['frameRate'])
else:
    frameDur = 1.0/60.0 # couldn't get a reliable measure so guess

# Initialize components for Routine "trial" this component generates 30 trials, each
# consisting of  targets
variables=[]
# generate 30 random orientation gradients to be used as target orientations in the trials.
random.seed(45)
randomori=[random.randint(0,3)*90 for x in range (30)]
# creates the list called variables, a list containing 30 trails each consisting of 300 randomly
# places and oriented c's
for a in range (30):
 random.seed(a)
 # generates random orientations for the stimuli. 
 placeholder= [random.randint(0,3)*90 for x in range (600)]
 # Removes the orientations which equal the target for this trial,
 # since targets will be assigned their orientation separately
 orientationlist= [x for x in placeholder if x != randomori[a] ]
 # generaties random locations for stimuli. This needs to be higher
 # than the actual number of stimuli since many will be removed.
 Q = [random.randint(-60,60)/4 for x in range (1000)]
 R = [random.randint(-46,46)/4 for x in range (1000)]
 x=0
예제 #8
0
def bunda(name):
    print "value: ",name
    random.seed()
    time.sleep(random.random()*5)
    print '%s has finished' % multiprocessing.current_process().name
    return
예제 #9
0
import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray
from numpy.random import random, randint, normal, shuffle
import os  # handy system and path functions


# Python version = 2.7.2
# Platform = Win32
import random
import itertools
from itertools import groupby
import os
import csv

from datetime import datetime
random.seed(datetime.now())

configFile=os.path.abspath( os.path.join(os.path.abspath(__file__), '../..'))
configFile=os.path.join(configFile,'config.csv')
if os.path.exists(configFile):
    with open(configFile, 'rb') as csvfile:
        spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
        for row in spamreader:
            if row[0]=="output":
                output=row[1]
else:
    # CHANGED FOR THIS FILE!!
    #outerpath = '/Users/amennen/Dropbox/rtPennBehavData/facematching/'
    #output=os.path.abspath(os.path.join(outerpath,"tfMRI_output"))
    # changing back to just save data in this directory so the data will be stored on this computer only
    output=os.path.abspath(os.path.join(os.path.dirname( __file__ ), '../..',"tfMRI_output"))