Beispiel #1
0
    refex_features = np.loadtxt(node_feature, delimiter=',')
    np.savetxt(out_dir + '/out-' + out_prefix + '-ids.txt',
               X=refex_features[:, 0])
    actual_fx_matrix = refex_features[:, 1:]

    n, f = actual_fx_matrix.shape
    print 'Number of Features: ', f
    print 'Number of Nodes: ', n

    number_bins = int(np.log2(n))
    max_roles = min([n, f])
    best_G = None
    best_F = None

    mdlo = mdl.MDL(number_bins)
    minimum_description_length = 1e20
    min_des_not_changed_counter = 0
    sparsity_threshold = 1.0
    for rank in xrange(1, max_roles + 1):
        snmf = nimfa.Snmf(actual_fx_matrix,
                          seed="random_vcol",
                          version='r',
                          rank=rank,
                          beta=2.0)
        snmf_fit = snmf()
        G = np.asarray(snmf_fit.basis())
        F = np.asarray(snmf_fit.coef())

        code_length_G = mdlo.get_huffman_code_length(G)
        code_length_F = mdlo.get_huffman_code_length(F)
Beispiel #2
0
    def generateTestMDL():
        test = mdl.MDL()
        test.skinWidth = 8
        test.skinHeight = 8

        # add some texture/skin data
        pixels = bytes([
            208,
            208,
            208,
            208,
            208,
            208,
            208,
            208,
            208,
            250,
            250,
            250,
            250,
            250,
            250,
            208,
            208,
            250,
            250,
            250,
            250,
            250,
            144,
            208,
            208,
            250,
            250,
            250,
            144,
            144,
            144,
            208,
            208,
            250,
            250,
            144,
            144,
            144,
            144,
            208,
            208,
            250,
            144,
            144,
            144,
            144,
            144,
            208,
            208,
            250,
            144,
            144,
            144,
            144,
            144,
            208,
            208,
            208,
            208,
            208,
            208,
            208,
            208,
            208,
        ])
        t = mdl.MDL.Texture(pixels)
        s = mdl.MDL.Skin([t], [1.0])

        #add texture coordinates
        test.texCoords.append(mdl.MDL.TextureCoords(False, 0, 0))
        test.texCoords.append(mdl.MDL.TextureCoords(False, 1, 0))
        test.texCoords.append(mdl.MDL.TextureCoords(False, 0, 1))
        test.texCoords.append(mdl.MDL.TextureCoords(False, 0, 0))
        test.texCoords.append(mdl.MDL.TextureCoords(False, 1, 0))
        test.texCoords.append(mdl.MDL.TextureCoords(False, 0, 1))
        test.texCoords.append(mdl.MDL.TextureCoords(False, 0, 0))
        test.texCoords.append(mdl.MDL.TextureCoords(False, 1, 0))

        # foo
        f = mdl.MDL.SimpleFrame()
        f.box_min = mdl.MDL.Vertex(0, 0, 0, 0)
        f.box_max = mdl.MDL.Vertex(1, 1, 1, 0)
        f.name = "test cube"
        f.vertices.append(mdl.MDL.Vertex(0, 0, 0, 0))
        f.vertices.append(mdl.MDL.Vertex(1, 0, 0, 0))
        f.vertices.append(mdl.MDL.Vertex(1, 1, 0, 0))
        f.vertices.append(mdl.MDL.Vertex(0, 1, 0, 0))
        f.vertices.append(mdl.MDL.Vertex(0, 1, 1, 0))
        f.vertices.append(mdl.MDL.Vertex(0, 0, 1, 0))
        f.vertices.append(mdl.MDL.Vertex(1, 0, 1, 0))
        f.vertices.append(mdl.MDL.Vertex(1, 1, 1, 0))

        return test
Beispiel #3
0
    bins = int(args.bins)
    out_prefix = args.output_prefix

    fx = features.Features()

    full_fx_matrix = fx.prune_matrix(fx.only_riders(graph_file=graph_file,
                                                    rider_dir=rider_dir,
                                                    bins=bins,
                                                    bin_features=False),
                                     max_diff=0.0)
    number_nodes = fx.graph.number_of_nodes()
    number_bins = int(np.log2(number_nodes))

    n, f = full_fx_matrix.shape

    mdlo = mdl.MDL(number_bins)
    code_length = mdlo.get_huffman_code_length(full_fx_matrix)
    model_cost = code_length * (n + f)

    print '*' * 50
    print 'Base Model Cost: ', model_cost
    print '*' * 50
    print 'Num Nodes: ', n
    print 'Num FX: ', f

    primary_ari = []
    primary_ari_uniform = []
    secondary_ari = []
    secondary_ari_uniform = []
    model_costs = []
    model_costs_uniform = []
Beispiel #4
0
                                 help='output dir',
                                 required=True)

    args = argument_parser.parse_args()

    curr_graph = args.graph
    base_fx_dir = args.base_rider_dir
    rf_matrix = args.role_feature
    rider_dir = args.rider_dir
    out_dir = args.output_dir
    H = load_role_fx_matrix(rf_matrix)

    losses = []
    original = []

    mdlo = mdl.MDL(15)

    for i in xrange(2, 13):
        fx = features.Features()
        actual_matrix = fx.dyn_rider(curr_graph,
                                     151,
                                     base_fx_dir,
                                     rider_dir + '/' + str(i) + '/',
                                     bins=15)
        # W = estimate_W(actual_matrix, H)
        # losses.append(mdlo.get_reconstruction_error(actual_matrix, W.dot(H)))
        out_prefix = out_dir + '/' + str(i)

        fctr = nimfa.mf(actual_matrix, rank=8, method="lsnmf", max_iter=100)
        fctr_res = nimfa.mf_run(fctr)
        Wa = np.asarray(fctr_res.basis())