コード例 #1
0
def run(args):
    params = helper.parseArguments(args)

    # default values
    size = 40
    probabilityOfInfection = 0.02
    probabilityOfDeath = 0
    infectionLength = [6, 9]

    # check size for user input
    if '-N' in params:
        val = int(params['-N'])
        if val < 1:
            raise ValueError("Size of the simulation has to be positive.")
        size = val

    # check probability of infection for user input
    if '-S' in params:
        val = float(params['-S'])
        if val < 0 or val > 1:
            raise ValueError("Probabilities have to be within [0,1].")
        probabilityOfInfection = val

    # check probability of death for user input
    if '-L' in params:
        val = float(params['-L'])
        if val < 0 or val > 1:
            raise ValueError("Probabilities have to be within [0,1].")
        probabilityOfDeath = val

    # check length of infection for user input
    if '-minDays' in params and '-maxDays' in params:
        min = int(params['-minDays'])
        max = int(params['-maxDays'])
        if min < 0 or min > max:
            raise ValueError("Infection interval has to be positive and min > max.")
        infectionLength = [min, max]

    # init simulation
    simulation = Simulation(size, probabilityOfInfection, probabilityOfDeath, infectionLength)

    #  contaminate chosen individuals
    if '-x' in params and len(params['-x']) > 0:
        for i in range(0, len(params['-x'])):
            point = params['-x'][i].split(",")
            x = int(point[0])
            y = int(point[1])

            if x < 0 or x > size or y < 0 or y > size:
                raise ValueError("One of your individuals was out of bounds.")

            simulation.contaminate(x, y)
    else:
        # contaminate one cell
        simulation.contaminate(0,0)

    if '--frames' in params and params['--frames']:
        simulation.writeFrames = True

    if '-seed' in params:
        simulation.setSeed(int(params['-seed']))

    # run simulation
    iteration, avgInfectedPerDay, avgDeathsPerDay, avgRecoveredPerDay, avgIllPerDay, sumInfectedPerDay, sumDeathsPerDay = simulation.run()

    # print output
    if '--iterations' in params or '--print' in params:
        print("Simulation took {0} iterations.".format(iteration))
    
    if '--avgInfected' in params or '--print' in params:
        print("Average infected per iteration: {0}".format(avgInfectedPerDay))
    
    if '--avgDead' in params or '--print' in params:
        print("Average deaths per iteration: {0}".format(avgDeathsPerDay))

    if '--avgRecovered' in params or '--print' in params:
        print("Average recovered per iteration: {0}".format(avgRecoveredPerDay))
    
    if '--avgIll' in params or '--print' in params:
        print("Average ill per iteration: {0}".format(avgIllPerDay))

    if '--sumInfected' in params or '--print' in params:
        print("Sum of infected: {0}".format(sumInfectedPerDay))

    if '--sumDeaths' in params or '--print' in params:
        print("Sum of deaths: {0}".format(sumDeathsPerDay))

    return sumInfectedPerDay
コード例 #2
0
    # print(images)
    with tf.Session() as sess:
        # get image embeddings
        features = get_image_list_embeddings(images, sess, jpeg_data_tensor,
                                             bottleneck_tensor)

        saver = tf.train.Saver([features])

        sess.run(features.initializer)
        saver.save(sess, os.path.join(FLAGS.summaries_dir, 'embeddings.ckpt'))

        config = projector.ProjectorConfig()
        # One can add multiple embeddings.
        embedding = config.embeddings.add()
        embedding.tensor_name = features.name
        embedding.metadata_path = os.path.join(FLAGS.summaries_dir,
                                               'metadata.tsv')
        embedding.sprite.image_path = os.path.join(FLAGS.summaries_dir,
                                                   'images_sprite.png')
        embedding.sprite.single_image_dim.extend(
            [image_data.shape[1], image_data.shape[1]])
        # Saves a config file that TensorBoard will read during startup.
        projector.visualize_embeddings(
            tf.summary.FileWriter(FLAGS.summaries_dir), config)


if __name__ == '__main__':
    FLAGS, unparsed = parseArguments()

    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
コード例 #3
0
import run, helper, sys, pylab, math

# pares input parameters for potential custom ranges
params = helper.parseArguments(sys.argv)

# chosen prime numbers as base seeds
selectedRandomPrimes = [
    982434227, 982390301, 982449889, 982406627, 982406809, 982400521,
    982412141, 982394291, 982430263, 982447637, 982396931, 982430819,
    982399151, 982419479, 982412329, 982426883, 982427539, 982401317,
    982399799, 982445341, 982425713, 982401757, 982398419, 982443211,
    982388467, 982402781, 982388947, 982403369, 982415297, 982450039,
    982405103, 982432883, 982426309, 982447021, 982443331, 982412933,
    982389403, 982402697, 982391741, 982441259, 982439413, 982427443,
    982405069, 982390567, 982439891, 982426201, 982399441, 982440299,
    982419433, 982445587, 982418221, 982449239, 982443589, 982402921,
    982420609, 982435007, 982410097, 982394293, 982413319, 982391273,
    982431823, 982427987, 982450943, 982440587, 982418243, 982415857,
    982413983, 982418873, 982415429, 982399813, 982394737, 982398799,
    982400183, 982418209, 982409521, 982417697, 982441637, 982415381,
    982396637, 982444417, 982436311, 982413227, 982429909, 982421203,
    982427273, 982396003, 982431493, 982391737, 982423543, 982389073,
    982402823, 982414061, 982429229, 982415689, 982389613, 982407707,
    982440941, 982443733, 982409873, 982403033
]

# simulation parameters
size = 40
probabilityOfDeath = 0
infectionLengthFrom = 6
infectionLengthTo = 9
コード例 #4
0
def run(args):
    params = helper.parseArguments(args)

    # Generate base data
    classA, classB = datagen.generateRandomData(100)
    data = classA + classB
    random.shuffle(data)
    n = len(data)

    p = 3
    if '-p' in params:
        p = int(params['-p'])

    sigma = 2
    if '-sigma' in params:
        sigma = float(params['-sigma'])

    k = 0.05
    if '-k' in params:
        k = float(params['-k'])

    delta = 0
    if '-delta' in params:
        delta = int(params['-delta'])

    C = 0
    if '-C' in params:
        C = float(params['-C'])

    # Choose kernel
    if '--polynomial' in params:
        kernel = kernels.polynomialClosure(p)
    elif '--radial' in params:
        kernel = kernels.radialBasisClosure(sigma)
    elif '--sigmoid' in params:
        kernel = kernels.sigmoidClosure(k, delta)
    else:
        kernel = kernels.linear

    # Create dual formulation terms
    # P_i,j = t_i * t_j * K(\vec{x_i}, \vec{x_j})
    P = []
    for i in range(n):
        P.append([])

    for i in range(n):
        for j in range(n):
            P[i].append(
                data[i][2] * data[j][2] *
                kernel([data[i][0], data[i][1]], [data[j][0], data[j][1]]))

    q = -1 * numpy.ones((n, 1))
    h = numpy.zeros_like(q)
    G = -1 * numpy.eye(n)

    # Slack variables
    if C != 0:
        G = numpy.concatenate((numpy.eye(n), G))
        h = numpy.concatenate((C * numpy.ones((n, 1)), h))

    # Find \vec{a} which minimizes dual formulation
    r = qp(matrix(P), matrix(q), matrix(G), matrix(h))
    alpha = list(r['x'])

    # Set up indicator closure
    indicator = generateIndiciator(data, alpha, kernel)

    # Find decision boundary
    xrange = numpy.arange(-4, 4, 0.05)
    yrange = numpy.arange(-4, 4, 0.05)
    grid = matrix([[indicator(x, y) for y in yrange] for x in xrange])

    #  plot all the things
    # pylab.hold(True)
    pylab.clf()
    pylab.plot([p[0] for p in classA], [p[1] for p in classA], 'bo')
    pylab.plot([p[0] for p in classB], [p[1] for p in classB], 'ro')
    pylab.contour(xrange,
                  yrange,
                  grid, (-1.0, 0.0, 1.0),
                  colors=('red', 'black', 'blue'),
                  linewidths=(1, 3, 1))

    if '--save' in params:
        filename = 'foo.png'
        if '-o' in params:
            filename = params['-o']
        # pylab.savefig("out/{0}".format(filename), bbox_inches='tight')
        pylab.savefig("out/{0}".format(filename))
    else:
        pylab.show()