コード例 #1
0
ファイル: test_text.py プロジェクト: SwarajPawar/SPFlow
    def check_obj_and_reconstruction(self, obj):

        str_val = spn_to_str_equation(obj)

        obj_val = str_to_spn(str_val)

        self.assertEqual(str_val, spn_to_str_equation(obj_val))
コード例 #2
0
ファイル: test_text.py プロジェクト: twistedmove/SPN-Spk-Rec
from spn.io.Text import str_to_spn, to_JSON, spn_to_str_equation
from spn.structure.StatisticalTypes import MetaType
from spn.structure.leaves.parametric.Inference import add_parametric_inference_support

from spn.structure.leaves.parametric.Parametric import *
from spn.structure.leaves.parametric.Text import add_parametric_text_support

if __name__ == '__main__':
    add_parametric_text_support()
    add_parametric_inference_support()


    cat = Categorical(p=[0.1, 0.2, 0.7])
    cat.scope.append(0)
    print(spn_to_str_equation(cat))
    catspn = str_to_spn(spn_to_str_equation(cat))
    print(spn_to_str_equation(catspn))

    original = Gaussian(mean=0, stdev=10)
    original.scope.append(0)
    s = spn_to_str_equation(original)
    print(s)
    recovered = str_to_spn(s)

    print(str_to_spn("Gaussian(V0|mean=1;stdev=10)"))

    gamma = Gamma(alpha=1, beta=2)
    gamma.scope.append(0)
    print(spn_to_str_equation(gamma))

    lnorm = LogNormal(mean=1, stdev=2)
コード例 #3
0
            row_set = set.union(*instances_sets)
            assert set(node.row_ids) == row_set
            return row_set

    whole_row_ids = _validate_row_partitioning(node)
    instance_set = set(instance_set)
    assert instance_set == whole_row_ids, ' Expected row ids {}, got {}'.format(
        instance_set, whole_row_ids)


if __name__ == '__main__':
    n = str_to_spn(
        """
            (
            Histogram(W1|[ 0., 1., 2.];[0.3, 0.7])
            *
            Histogram(W2|[ 0., 1., 2.];[0.3, 0.7])
            )    
            """, ["W1", "W2"])

    n = str_to_spn(
        """
            (0.3 * Histogram(W1|[ 0., 1., 2.];[0.2, 0.8])
            +
            0.7 * Histogram(W1|[ 0., 1., 2.];[0.1, 0.9])
            )    
            """, ["W1", "W2"])

    print(to_JSON(n))

    map_id_node = init_spn_sampling(n)
コード例 #4
0
'''
Created on March 29, 2018

@author: Alejandro Molina
'''
from spn.leaves.Histograms import Histogram_str_to_spn

from spn.experiments.FPGA.GenerateSPNs import fpga_count_ops
from spn.io.Graphics import plot_spn
from spn.io.Text import str_to_spn

if __name__ == '__main__':
    with open('../experiments/FPGA/spns/NIPS_30/eqq.txt', 'r') as myfile:
        eq = myfile.read()
    with open('../experiments/FPGA/spns/NIPS_30/all_data.txt', 'r') as myfile:
        words = myfile.readline().strip()
        words = words[2:]
        words = words.split(';')

    print(words)

    spn = str_to_spn(eq, words, Histogram_str_to_spn)

    print(spn)

    print(fpga_count_ops(spn))
    plot_spn(spn)


コード例 #5
0
def load(eq, words):
    return str_to_spn(eq, words)
コード例 #6
0
 def check_obj_and_reconstruction(self, obj):
     self.assertEqual(
         spn_to_str_equation(obj),
         spn_to_str_equation(str_to_spn(spn_to_str_equation(obj))))
コード例 #7
0
ファイル: EvalFPGA.py プロジェクト: twistedmove/SPN-Spk-Rec
from spn.algorithms.Statistics import get_structure_stats
from spn.data.datasets import get_nips_data
from spn.io.Text import str_to_spn

if __name__ == '__main__':
    with open('40_eqq.txt', 'r') as myfile:
        eq = myfile.read()
    with open('40_testdata.txt', 'r') as myfile:
        words = myfile.readline().strip()
        words = words[2:]
        words = words.split(';')

    # print(eq)
    print(words)

    spn = str_to_spn(eq, words)

    print(get_structure_stats(spn))

    # print(Text.toJSON(spn))

    data = np.loadtxt("40_testdata.txt", delimiter=';')

    ll = Inference.likelihood(spn, data)

    print(ll)
    print("average LL", np.mean(ll))

    ds_name, words, data, _, _, _, _ = get_nips_data()

    top_n_features = 40
コード例 #8
0
import tensorflow as tf
from spn.io.Text import spn_to_str_equation, str_to_spn
from spn.gpu.TensorFlow import optimize_tf
import sys
import numpy as np

#Increase recursion limit as otherwise conversion will fail

sys.setrecursionlimit(15000)

#Load string, convert to SPN

with open('./ca.txt', 'r') as myfile:
    data = myfile.read().replace('\n', '')

thespn = str_to_spn(data)

#Load data

testdata = np.load('./test.npy')

testdata += 0.0

print(testdata.dtype)
print(np.amax(testdata))
#testdata = whiten(testdata)
print(np.amax(testdata))

testdata = testdata.astype(np.float32)

print(testdata.dtype)