Exemplo n.º 1
0
def _samples_generator(
        sample_iterator: JavaObject, vertices_unwrapped: JavaList,
        live_plot: bool, refresh_every: int, ax: Any, all_scalar: bool,
        id_to_label: Dict[Tuple[int, ...], str]) -> sample_generator_types:
    traces = []
    x0 = 0
    while (True):
        network_sample = sample_iterator.next()

        if all_scalar:
            sample: sample_generator_dict_type = {
                id_to_label[Vertex._get_python_id(vertex_unwrapped)]:
                Tensor._to_ndarray(
                    network_sample.get(vertex_unwrapped)).item()
                for vertex_unwrapped in vertices_unwrapped
            }
        else:
            sample = __create_multi_indexed_samples_generated(
                vertices_unwrapped, network_sample, id_to_label)

        if live_plot:
            traces.append(sample)
            if len(traces) % refresh_every == 0:
                joined_trace: sample_types = {
                    k: [t[k] for t in traces]
                    for k in sample.keys()
                }
                if ax is None:
                    ax = traceplot(joined_trace, x0=x0)
                else:
                    traceplot(joined_trace, ax=ax, x0=x0)
                x0 += refresh_every
                traces = []

        yield sample
Exemplo n.º 2
0
def _samples_generator(sample_iterator: JavaObject,
                       vertices_unwrapped: JavaList, live_plot: bool,
                       refresh_every: int, ax: Any) -> sample_generator_types:
    traces = []
    x0 = 0
    while (True):
        network_sample = sample_iterator.next()
        sample = {
            Vertex._get_python_label(vertex_unwrapped):
            Tensor._to_ndarray(network_sample.get(vertex_unwrapped))
            for vertex_unwrapped in vertices_unwrapped
        }

        if live_plot:
            traces.append(sample)
            if len(traces) % refresh_every == 0:
                joined_trace = {
                    k: [t[k] for t in traces]
                    for k in sample.keys()
                }
                if ax is None:
                    ax = traceplot(joined_trace, x0=x0)
                else:
                    traceplot(joined_trace, ax=ax, x0=x0)
                x0 += refresh_every
                traces = []

        yield sample
Exemplo n.º 3
0
def _samples_generator(sample_iterator: JavaObject,
                       vertices_unwrapped: JavaList) -> sample_generator_types:
    while (True):
        network_sample = sample_iterator.next()
        sample = {
            Vertex._get_python_id(vertex_unwrapped):
            Tensor._to_ndarray(network_sample.get(vertex_unwrapped))
            for vertex_unwrapped in vertices_unwrapped
        }
        yield sample