Esempio n. 1
0
        y = np.random.uniform(size=(batch_size, )).astype(np.float32)
        return x, y

    def __len__(self):
        return 256


net_input = keras.layers.Input(shape=input_shape, dtype=np.float32)
net = keras.layers.Flatten()(net_input)
net = keras.layers.Dense(32, activation='relu')(net)
net = keras.layers.Dense(1, activation='sigmoid')(net)
model = keras.Model(net_input, net)
model.compile(optimizer='rmsprop', loss='mse')
generator = MyGenerator()

graph1 = hg.Graph(name="keras_exec_opt")
with graph1.as_default():
    time_history = TimeHistory()
    set_batch_size = hg.call(generator.set_batch_size) << [
        hg.tweak(hg.QUniform(low=2, high=64), name='batch_size')
    ]
    fit = hg.call(model.fit_generator) << {
        'generator':
        generator,
        'epochs':
        1,
        'max_queue_size':
        hg.tweak(hg.QUniform(low=2, high=64), name='max_queue_size'),
        'workers':
        hg.tweak(hg.QLogUniform(low=1, high=16), name='workers'),
        'callbacks': [time_history],
Esempio n. 2
0
import hypergraph as hg


def test1(x, y):
    return x + y


graph1 = hg.Graph(name='g1')
with graph1.as_default():
    hg.mark("x_value") << 5
    hg.output() << (
        hg.invoke() << [test1, {
            'x': hg.node_ref("x_value"),
            'y': 3
        }])
    # Note, in a more realistic scenario, the first param of the invoke, that is the function to be invoked,
    # may be the result of another computation or tweak

print(hg.run(graph1))
Esempio n. 3
0
import hypergraph as hg
import numpy as np

graph1 = hg.Graph()
with graph1.as_default():
    hg.mark("abc1") << (hg.dump() << "** abc1 **")
    n = hg.mark("abc2") << (hg.dump() << "** abc2 **")

    idx = hg.node(lambda _: np.random.randint(0, 2))
    hg.output() << (hg.select(idx) << ["abc1", "abc2"])

for _ in range(3):
    ctx = hg.ExecutionContext()
    with ctx.as_default():
        print(graph1())
    print("*** end of execution ***")
Esempio n. 4
0
import hypergraph as hg
from hypergraph.genetic import GeneticOperators

graph1 = hg.Graph(name="g1")
with graph1.as_default():
    hg.output() << (hg.permutation(size=3) << list('abcdef'))

# create a population from graph's phenotype
genetic = GeneticOperators(graph1)
print(genetic.phenotype)

population = genetic.create_population(3)
print(population[:2])
# crossover two parent to get a new individual
child = genetic.crossover_uniform_multi_parents(population[:2])
print(child)
genetic.mutations(child, prob=0.5)
# apply mutations to an individual
print(child)

# use an individual as graph's tweaks
print(hg.run(graph1, tweaks=child))