CP_01: transformation of the real-number-CP-decompositions to Binary

Description Usage Arguments Value Author(s) See Also Examples

View source: R/CP_01.R

Description

transforms CP tensor decomposition generated by real-number methods (like nmu) to Binary by trying different threshold values.

Usage

1
2
CP_01(X, P, pthr = c(0.001, 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8),
          testAll = FALSE)

Arguments

X

the original tensor as sptensor list(subs,vals,size,nnz)

P

a LIST containing the CP transformation

pthr

list of threshold values to be tried

testAll

a flag to try all threshold values or stop after having a zero in fp or tp

Value

If it is a LIST, use

Res

the tp, fn, fp result of each threshold value.

bestSol

best solution in terms of minimum error (fn+fp)

Author(s)

Abdelmoneim Amer Desouki

See Also

cp_apr serial_parCube rescal rescal_01 cp_nmu

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
trp=rbind(
    cbind('Alex',  'loves', 'Don'),
    cbind('Alex',  'loves', 'Elly'),
    cbind('Alex',  'hates', 'Bob'),
    cbind('Don',   'loves', 'Alex'),
    cbind('Don',   'hates', 'Chris'),
    cbind('Chris', 'hates', 'Bob'),
    cbind('Bob',   'hates', 'Chris'),
    cbind('Elly',  'hates', 'Chris'),
    cbind('Elly',  'hates', 'Bob'),
    cbind('Elly',  'loves', 'Alex')
    )
######
# form tensor as a set of frontal slices (Predicate mode)
    tnsr=getTensor(trp)
    subs=getTnsrijk(tnsr$X)
    X=list(subs=subs,vals=rep(1,nrow(subs)),size=c(5,2,5))
    normX=sqrt(sum(X$vals))
    set.seed(123)
    # NMU decomposition with rank 2
    P1=cp_nmu(X,2)
    res=CP_01(X,P1[[1]])
    Fac=res$sol$u # The factorization
    # TP,FP,FN
    print(sprintf("TP=%d, FP=%d, FN=%d, Threshold=%f",res$sol$TP,res$sol$FP,res$sol$FN,res$sol$thr))

RDFTensor documentation built on Jan. 16, 2021, 5:19 p.m.